@elizaos/plugin-bootstrap 1.6.2-alpha.24 → 1.6.2-alpha.25

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 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
- shouldRespondTemplate,
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(/^\[|\]$/g, "");
7273
+ const cleaned = value.trim().replace(/^[\[]|[\]]$/g, "");
7257
7274
  return cleaned.split(",").map((v) => v.trim()).filter(Boolean);
7258
7275
  }
7259
7276
  const alwaysRespondChannels = [
@@ -7286,567 +7303,6 @@ function shouldRespond(runtime, message, room, mentionContext) {
7286
7303
  }
7287
7304
  return { shouldRespond: false, skipEvaluation: false, reason: "needs LLM evaluation" };
7288
7305
  }
7289
- var messageReceivedHandler = async ({
7290
- runtime,
7291
- message,
7292
- callback,
7293
- onComplete
7294
- }) => {
7295
- const useMultiStep = runtime.getSetting("USE_MULTI_STEP");
7296
- const timeoutDuration = 60 * 60 * 1000;
7297
- let timeoutId = undefined;
7298
- try {
7299
- runtime.logger.info(`[Bootstrap] Message received from ${message.entityId} in room ${message.roomId}`);
7300
- const responseId = v4_default();
7301
- if (!latestResponseIds.has(runtime.agentId)) {
7302
- latestResponseIds.set(runtime.agentId, new Map);
7303
- }
7304
- const agentResponses = latestResponseIds.get(runtime.agentId);
7305
- if (!agentResponses)
7306
- throw new Error("Agent responses map not found");
7307
- const previousResponseId = agentResponses.get(message.roomId);
7308
- if (previousResponseId) {
7309
- logger22.warn(`[Bootstrap] Updating response ID for room ${message.roomId} from ${previousResponseId} to ${responseId} - this may discard in-progress responses`);
7310
- }
7311
- agentResponses.set(message.roomId, responseId);
7312
- const runId = runtime.startRun();
7313
- const startTime = Date.now();
7314
- await runtime.emitEvent(EventType2.RUN_STARTED, {
7315
- runtime,
7316
- runId,
7317
- messageId: message.id,
7318
- roomId: message.roomId,
7319
- entityId: message.entityId,
7320
- startTime,
7321
- status: "started",
7322
- source: "messageHandler",
7323
- metadata: message.content
7324
- });
7325
- const timeoutPromise = new Promise((_, reject) => {
7326
- timeoutId = setTimeout(async () => {
7327
- await runtime.emitEvent(EventType2.RUN_TIMEOUT, {
7328
- runtime,
7329
- runId,
7330
- messageId: message.id,
7331
- roomId: message.roomId,
7332
- entityId: message.entityId,
7333
- startTime,
7334
- status: "timeout",
7335
- endTime: Date.now(),
7336
- duration: Date.now() - startTime,
7337
- error: "Run exceeded 60 minute timeout",
7338
- source: "messageHandler"
7339
- });
7340
- reject(new Error("Run exceeded 60 minute timeout"));
7341
- }, timeoutDuration);
7342
- });
7343
- const processingPromise = (async () => {
7344
- try {
7345
- if (message.entityId === runtime.agentId) {
7346
- runtime.logger.debug(`[Bootstrap] Skipping message from self (${runtime.agentId})`);
7347
- throw new Error("Message is from the agent itself");
7348
- }
7349
- runtime.logger.debug(`[Bootstrap] Processing message: ${truncateToCompleteSentence(message.content.text || "", 50)}...`);
7350
- runtime.logger.debug("[Bootstrap] Saving message to memory and queueing embeddings");
7351
- let memoryToQueue;
7352
- if (message.id) {
7353
- const existingMemory = await runtime.getMemoryById(message.id);
7354
- if (existingMemory) {
7355
- runtime.logger.debug("[Bootstrap] Memory already exists, skipping creation");
7356
- memoryToQueue = existingMemory;
7357
- } else {
7358
- const createdMemoryId = await runtime.createMemory(message, "messages");
7359
- memoryToQueue = { ...message, id: createdMemoryId };
7360
- }
7361
- await runtime.queueEmbeddingGeneration(memoryToQueue, "high");
7362
- } else {
7363
- const memoryId = await runtime.createMemory(message, "messages");
7364
- message.id = memoryId;
7365
- memoryToQueue = { ...message, id: memoryId };
7366
- await runtime.queueEmbeddingGeneration(memoryToQueue, "normal");
7367
- }
7368
- const agentUserState = await runtime.getParticipantUserState(message.roomId, runtime.agentId);
7369
- const defLllmOff = parseBooleanFromText2(runtime.getSetting("BOOTSTRAP_DEFLLMOFF"));
7370
- if (defLllmOff && agentUserState === null) {
7371
- runtime.logger.debug("bootstrap - LLM is off by default");
7372
- await runtime.emitEvent(EventType2.RUN_ENDED, {
7373
- runtime,
7374
- runId,
7375
- messageId: message.id,
7376
- roomId: message.roomId,
7377
- entityId: message.entityId,
7378
- startTime,
7379
- status: "off",
7380
- endTime: Date.now(),
7381
- duration: Date.now() - startTime,
7382
- source: "messageHandler"
7383
- });
7384
- return;
7385
- }
7386
- if (agentUserState === "MUTED" && !message.content.text?.toLowerCase().includes(runtime.character.name.toLowerCase())) {
7387
- runtime.logger.debug(`[Bootstrap] Ignoring muted room ${message.roomId}`);
7388
- await runtime.emitEvent(EventType2.RUN_ENDED, {
7389
- runtime,
7390
- runId,
7391
- messageId: message.id,
7392
- roomId: message.roomId,
7393
- entityId: message.entityId,
7394
- startTime,
7395
- status: "muted",
7396
- endTime: Date.now(),
7397
- duration: Date.now() - startTime,
7398
- source: "messageHandler"
7399
- });
7400
- return;
7401
- }
7402
- let state = await runtime.composeState(message, ["ANXIETY", "ENTITIES", "CHARACTER", "RECENT_MESSAGES", "ACTIONS"], true);
7403
- const mentionContext = message.content.mentionContext;
7404
- const room = await runtime.getRoom(message.roomId);
7405
- if (message.content.attachments && message.content.attachments.length > 0) {
7406
- message.content.attachments = await processAttachments(message.content.attachments, runtime);
7407
- if (message.id) {
7408
- await runtime.updateMemory({ id: message.id, content: message.content });
7409
- }
7410
- }
7411
- const responseDecision = shouldRespond(runtime, message, room ?? undefined, mentionContext);
7412
- runtime.logger.debug(`[Bootstrap] Response decision: ${JSON.stringify(responseDecision)}`);
7413
- let shouldRespondToMessage = true;
7414
- if (responseDecision.skipEvaluation) {
7415
- runtime.logger.debug(`[Bootstrap] Skipping evaluation for ${runtime.character.name} (${responseDecision.reason})`);
7416
- shouldRespondToMessage = responseDecision.shouldRespond;
7417
- } else {
7418
- const shouldRespondPrompt = composePromptFromState10({
7419
- state,
7420
- template: runtime.character.templates?.shouldRespondTemplate || shouldRespondTemplate
7421
- });
7422
- runtime.logger.debug(`[Bootstrap] Using LLM evaluation for ${runtime.character.name} (${responseDecision.reason})`);
7423
- const response = await runtime.useModel(ModelType15.TEXT_SMALL, {
7424
- prompt: shouldRespondPrompt
7425
- });
7426
- runtime.logger.debug(`[Bootstrap] LLM evaluation result:
7427
- ${response}`);
7428
- const responseObject = parseKeyValueXml9(response);
7429
- runtime.logger.debug({ responseObject }, "[Bootstrap] Parsed evaluation result:");
7430
- const nonResponseActions = ["IGNORE", "NONE"];
7431
- shouldRespondToMessage = responseObject?.action && !nonResponseActions.includes(responseObject.action.toUpperCase());
7432
- }
7433
- let responseContent = null;
7434
- let responseMessages = [];
7435
- const keepResp = parseBooleanFromText2(runtime.getSetting("BOOTSTRAP_KEEP_RESP"));
7436
- if (shouldRespondToMessage) {
7437
- const result = useMultiStep ? await runMultiStepCore({ runtime, message, state, callback }) : await runSingleShotCore({ runtime, message, state });
7438
- responseContent = result.responseContent;
7439
- responseMessages = result.responseMessages;
7440
- state = result.state;
7441
- const currentResponseId = agentResponses.get(message.roomId);
7442
- if (currentResponseId !== responseId && !keepResp) {
7443
- runtime.logger.info(`Response discarded - newer message being processed for agent: ${runtime.agentId}, room: ${message.roomId}`);
7444
- return;
7445
- }
7446
- if (responseContent && message.id) {
7447
- responseContent.inReplyTo = createUniqueUuid3(runtime, message.id);
7448
- }
7449
- if (responseContent?.providers?.length && responseContent.providers.length > 0) {
7450
- state = await runtime.composeState(message, responseContent.providers || []);
7451
- }
7452
- if (responseContent) {
7453
- const mode = result.mode ?? "actions";
7454
- if (mode === "simple") {
7455
- if (responseContent.providers && responseContent.providers.length > 0) {
7456
- runtime.logger.debug({ providers: responseContent.providers }, "[Bootstrap] Simple response used providers");
7457
- }
7458
- if (callback) {
7459
- await callback(responseContent);
7460
- }
7461
- } else if (mode === "actions") {
7462
- await runtime.processActions(message, responseMessages, state, async (content) => {
7463
- runtime.logger.debug({ content }, "action callback");
7464
- responseContent.actionCallbacks = content;
7465
- if (callback) {
7466
- return callback(content);
7467
- }
7468
- return [];
7469
- });
7470
- }
7471
- }
7472
- } else {
7473
- runtime.logger.debug("[Bootstrap] Agent decided not to respond (shouldRespond is false).");
7474
- const currentResponseId = agentResponses.get(message.roomId);
7475
- if (currentResponseId !== responseId && !keepResp) {
7476
- runtime.logger.info(`Ignore response discarded - newer message being processed for agent: ${runtime.agentId}, room: ${message.roomId}`);
7477
- await runtime.emitEvent(EventType2.RUN_ENDED, {
7478
- runtime,
7479
- runId,
7480
- messageId: message.id,
7481
- roomId: message.roomId,
7482
- entityId: message.entityId,
7483
- startTime,
7484
- status: "replaced",
7485
- endTime: Date.now(),
7486
- duration: Date.now() - startTime,
7487
- source: "messageHandler"
7488
- });
7489
- return;
7490
- }
7491
- if (!message.id) {
7492
- runtime.logger.error("[Bootstrap] Message ID is missing, cannot create ignore response.");
7493
- await runtime.emitEvent(EventType2.RUN_ENDED, {
7494
- runtime,
7495
- runId,
7496
- messageId: message.id,
7497
- roomId: message.roomId,
7498
- entityId: message.entityId,
7499
- startTime,
7500
- status: "noMessageId",
7501
- endTime: Date.now(),
7502
- duration: Date.now() - startTime,
7503
- source: "messageHandler"
7504
- });
7505
- return;
7506
- }
7507
- const ignoreContent = {
7508
- thought: "Agent decided not to respond to this message.",
7509
- actions: ["IGNORE"],
7510
- simple: true,
7511
- inReplyTo: createUniqueUuid3(runtime, message.id)
7512
- };
7513
- if (callback) {
7514
- await callback(ignoreContent);
7515
- }
7516
- const ignoreMemory = {
7517
- id: asUUID2(v4_default()),
7518
- entityId: runtime.agentId,
7519
- agentId: runtime.agentId,
7520
- content: ignoreContent,
7521
- roomId: message.roomId,
7522
- createdAt: Date.now()
7523
- };
7524
- await runtime.createMemory(ignoreMemory, "messages");
7525
- runtime.logger.debug("[Bootstrap] Saved ignore response to memory", `memoryId: ${ignoreMemory.id}`);
7526
- }
7527
- agentResponses.delete(message.roomId);
7528
- if (agentResponses.size === 0) {
7529
- latestResponseIds.delete(runtime.agentId);
7530
- }
7531
- runtime.evaluate(message, state, shouldRespondToMessage, async (content) => {
7532
- runtime.logger.debug({ content }, "evaluate callback");
7533
- if (responseContent) {
7534
- responseContent.evalCallbacks = content;
7535
- }
7536
- if (callback) {
7537
- return callback(content);
7538
- }
7539
- return [];
7540
- }, responseMessages).catch((error) => {
7541
- runtime.logger.error({ error, messageId: message.id, roomId: message.roomId }, "[Bootstrap] Error in background evaluator execution");
7542
- });
7543
- let entityName = "noname";
7544
- if (message.metadata && "entityName" in message.metadata) {
7545
- entityName = message.metadata.entityName;
7546
- }
7547
- const isDM = message.content?.channelType === ChannelType9.DM;
7548
- let roomName = entityName;
7549
- if (!isDM) {
7550
- const roomDatas = await runtime.getRoomsByIds([message.roomId]);
7551
- if (roomDatas?.length) {
7552
- const roomData = roomDatas[0];
7553
- if (roomData.name) {
7554
- roomName = roomData.name;
7555
- }
7556
- if (roomData.worldId) {
7557
- const worldData = await runtime.getWorld(roomData.worldId);
7558
- if (worldData) {
7559
- roomName = worldData.name + "-" + roomName;
7560
- }
7561
- }
7562
- }
7563
- }
7564
- const date = new Date;
7565
- const availableActions = state.data?.providers?.ACTIONS?.data?.actionsData?.map((a) => a.name) || [-1];
7566
- const logData = {
7567
- at: date.toString(),
7568
- timestamp: parseInt("" + date.getTime() / 1000),
7569
- messageId: message.id,
7570
- userEntityId: message.entityId,
7571
- input: message.content.text,
7572
- thought: responseContent?.thought,
7573
- simple: responseContent?.simple,
7574
- availableActions,
7575
- actions: responseContent?.actions,
7576
- providers: responseContent?.providers,
7577
- irt: responseContent?.inReplyTo,
7578
- output: responseContent?.text,
7579
- entityName,
7580
- source: message.content.source,
7581
- channelType: message.content.channelType,
7582
- roomName
7583
- };
7584
- await runtime.emitEvent(EventType2.RUN_ENDED, {
7585
- runtime,
7586
- runId,
7587
- messageId: message.id,
7588
- roomId: message.roomId,
7589
- entityId: message.entityId,
7590
- startTime,
7591
- status: "completed",
7592
- endTime: Date.now(),
7593
- duration: Date.now() - startTime,
7594
- source: "messageHandler",
7595
- entityName,
7596
- responseContent,
7597
- metadata: logData
7598
- });
7599
- } catch (error) {
7600
- console.error("error is", error);
7601
- await runtime.emitEvent(EventType2.RUN_ENDED, {
7602
- runtime,
7603
- runId,
7604
- messageId: message.id,
7605
- roomId: message.roomId,
7606
- entityId: message.entityId,
7607
- startTime,
7608
- status: "error",
7609
- endTime: Date.now(),
7610
- duration: Date.now() - startTime,
7611
- error: error.message,
7612
- source: "messageHandler"
7613
- });
7614
- }
7615
- })();
7616
- await Promise.race([processingPromise, timeoutPromise]);
7617
- } finally {
7618
- clearTimeout(timeoutId);
7619
- onComplete?.();
7620
- }
7621
- };
7622
- async function runSingleShotCore({
7623
- runtime,
7624
- message,
7625
- state
7626
- }) {
7627
- state = await runtime.composeState(message, ["ACTIONS"]);
7628
- if (!state.values?.actionNames) {
7629
- runtime.logger.warn("actionNames data missing from state, even though it was requested");
7630
- }
7631
- const prompt = composePromptFromState10({
7632
- state,
7633
- template: runtime.character.templates?.messageHandlerTemplate || messageHandlerTemplate
7634
- });
7635
- let responseContent = null;
7636
- let retries = 0;
7637
- const maxRetries = 3;
7638
- while (retries < maxRetries && (!responseContent?.thought || !responseContent?.actions)) {
7639
- const response = await runtime.useModel(ModelType15.TEXT_LARGE, { prompt });
7640
- runtime.logger.debug({ response }, "[Bootstrap] *** Raw LLM Response ***");
7641
- const parsedXml = parseKeyValueXml9(response);
7642
- runtime.logger.debug({ parsedXml }, "[Bootstrap] *** Parsed XML Content ***");
7643
- if (parsedXml) {
7644
- responseContent = {
7645
- ...parsedXml,
7646
- thought: parsedXml.thought || "",
7647
- actions: parsedXml.actions || ["IGNORE"],
7648
- providers: parsedXml.providers || [],
7649
- text: parsedXml.text || "",
7650
- simple: parsedXml.simple || false
7651
- };
7652
- } else {
7653
- responseContent = null;
7654
- }
7655
- retries++;
7656
- if (!responseContent?.thought || !responseContent?.actions) {
7657
- runtime.logger.warn({ response, parsedXml, responseContent }, "[Bootstrap] *** Missing required fields (thought or actions), retrying... ***");
7658
- }
7659
- }
7660
- if (!responseContent) {
7661
- return { responseContent: null, responseMessages: [], state, mode: "none" };
7662
- }
7663
- if (responseContent.actions && responseContent.actions.length > 1) {
7664
- const isIgnore = (a) => typeof a === "string" && a.toUpperCase() === "IGNORE";
7665
- const hasIgnore = responseContent.actions.some(isIgnore);
7666
- if (hasIgnore) {
7667
- if (!responseContent.text || responseContent.text.trim() === "") {
7668
- responseContent.actions = ["IGNORE"];
7669
- } else {
7670
- const filtered = responseContent.actions.filter((a) => !isIgnore(a));
7671
- responseContent.actions = filtered.length ? filtered : ["REPLY"];
7672
- }
7673
- }
7674
- }
7675
- const isSimple = responseContent.actions?.length === 1 && typeof responseContent.actions[0] === "string" && responseContent.actions[0].toUpperCase() === "REPLY" && (!responseContent.providers || responseContent.providers.length === 0);
7676
- responseContent.simple = isSimple;
7677
- const responseMessages = [
7678
- {
7679
- id: asUUID2(v4_default()),
7680
- entityId: runtime.agentId,
7681
- agentId: runtime.agentId,
7682
- content: responseContent,
7683
- roomId: message.roomId,
7684
- createdAt: Date.now()
7685
- }
7686
- ];
7687
- return {
7688
- responseContent,
7689
- responseMessages,
7690
- state,
7691
- mode: isSimple && responseContent.text ? "simple" : "actions"
7692
- };
7693
- }
7694
- async function runMultiStepCore({
7695
- runtime,
7696
- message,
7697
- state,
7698
- callback
7699
- }) {
7700
- const traceActionResult = [];
7701
- let accumulatedState = state;
7702
- const maxIterations = parseInt(runtime.getSetting("MAX_MULTISTEP_ITERATIONS") || "6");
7703
- let iterationCount = 0;
7704
- while (iterationCount < maxIterations) {
7705
- iterationCount++;
7706
- runtime.logger.debug(`[MultiStep] Starting iteration ${iterationCount}/${maxIterations}`);
7707
- accumulatedState = await runtime.composeState(message, ["RECENT_MESSAGES", "ACTION_STATE"]);
7708
- accumulatedState.data.actionResults = traceActionResult;
7709
- const prompt = composePromptFromState10({
7710
- state: accumulatedState,
7711
- template: runtime.character.templates?.multiStepDecisionTemplate || multiStepDecisionTemplate
7712
- });
7713
- const stepResultRaw = await runtime.useModel(ModelType15.TEXT_LARGE, { prompt });
7714
- const parsedStep = parseKeyValueXml9(stepResultRaw);
7715
- if (!parsedStep) {
7716
- runtime.logger.warn(`[MultiStep] Failed to parse step result at iteration ${iterationCount}`);
7717
- traceActionResult.push({
7718
- data: { actionName: "parse_error" },
7719
- success: false,
7720
- error: "Failed to parse step result"
7721
- });
7722
- break;
7723
- }
7724
- const { thought, providers: providers2 = [], action, isFinish } = parsedStep;
7725
- if (isFinish === "true" || isFinish === true) {
7726
- runtime.logger.info(`[MultiStep] Task marked as complete at iteration ${iterationCount}`);
7727
- if (callback) {
7728
- await callback({
7729
- text: "",
7730
- thought: thought ?? ""
7731
- });
7732
- }
7733
- break;
7734
- }
7735
- if ((!providers2 || providers2.length === 0) && !action) {
7736
- runtime.logger.warn(`[MultiStep] No providers or action specified at iteration ${iterationCount}, forcing completion`);
7737
- break;
7738
- }
7739
- try {
7740
- for (const providerName of providers2) {
7741
- const provider = runtime.providers.find((p) => p.name === providerName);
7742
- if (!provider) {
7743
- runtime.logger.warn(`[MultiStep] Provider not found: ${providerName}`);
7744
- traceActionResult.push({
7745
- data: { actionName: providerName },
7746
- success: false,
7747
- error: `Provider not found: ${providerName}`
7748
- });
7749
- continue;
7750
- }
7751
- const providerResult = await provider.get(runtime, message, state);
7752
- if (!providerResult) {
7753
- runtime.logger.warn(`[MultiStep] Provider returned no result: ${providerName}`);
7754
- traceActionResult.push({
7755
- data: { actionName: providerName },
7756
- success: false,
7757
- error: `Provider returned no result`
7758
- });
7759
- continue;
7760
- }
7761
- const success = !!providerResult.text;
7762
- traceActionResult.push({
7763
- data: { actionName: providerName },
7764
- success,
7765
- text: success ? providerResult.text : undefined,
7766
- error: success ? undefined : providerResult?.text
7767
- });
7768
- if (callback) {
7769
- await callback({
7770
- text: `\uD83D\uDD0E Provider executed: ${providerName}`,
7771
- actions: [providerName],
7772
- thought: thought ?? ""
7773
- });
7774
- }
7775
- }
7776
- if (action) {
7777
- const actionContent = {
7778
- text: `\uD83D\uDD0E Executing action: ${action}`,
7779
- actions: [action],
7780
- thought: thought ?? ""
7781
- };
7782
- await runtime.processActions(message, [
7783
- {
7784
- id: v4_default(),
7785
- entityId: runtime.agentId,
7786
- roomId: message.roomId,
7787
- createdAt: Date.now(),
7788
- content: actionContent
7789
- }
7790
- ], state, async () => {
7791
- return [];
7792
- });
7793
- const cachedState = runtime.stateCache.get(`${message.id}_action_results`);
7794
- const actionResults = cachedState?.values?.actionResults || [];
7795
- const result = actionResults.length > 0 ? actionResults[0] : null;
7796
- const success = result?.success ?? false;
7797
- traceActionResult.push({
7798
- data: { actionName: action },
7799
- success,
7800
- text: result?.text,
7801
- values: result?.values,
7802
- error: success ? undefined : result?.text
7803
- });
7804
- }
7805
- } catch (err) {
7806
- runtime.logger.error({ err }, "[MultiStep] Error executing step");
7807
- traceActionResult.push({
7808
- data: { actionName: action || "unknown" },
7809
- success: false,
7810
- error: err instanceof Error ? err.message : String(err)
7811
- });
7812
- }
7813
- }
7814
- if (iterationCount >= maxIterations) {
7815
- runtime.logger.warn(`[MultiStep] Reached maximum iterations (${maxIterations}), forcing completion`);
7816
- }
7817
- accumulatedState = await runtime.composeState(message, ["RECENT_MESSAGES", "ACTION_STATE"]);
7818
- const summaryPrompt = composePromptFromState10({
7819
- state: accumulatedState,
7820
- template: runtime.character.templates?.multiStepSummaryTemplate || multiStepSummaryTemplate
7821
- });
7822
- const finalOutput = await runtime.useModel(ModelType15.TEXT_LARGE, { prompt: summaryPrompt });
7823
- const summary = parseKeyValueXml9(finalOutput);
7824
- let responseContent = null;
7825
- if (summary?.text) {
7826
- responseContent = {
7827
- actions: ["MULTI_STEP_SUMMARY"],
7828
- text: summary.text,
7829
- thought: summary.thought || "Final user-facing message after task completion.",
7830
- simple: true
7831
- };
7832
- }
7833
- const responseMessages = responseContent ? [
7834
- {
7835
- id: asUUID2(v4_default()),
7836
- entityId: runtime.agentId,
7837
- agentId: runtime.agentId,
7838
- content: responseContent,
7839
- roomId: message.roomId,
7840
- createdAt: Date.now()
7841
- }
7842
- ] : [];
7843
- return {
7844
- responseContent,
7845
- responseMessages,
7846
- state: accumulatedState,
7847
- mode: responseContent ? "simple" : "none"
7848
- };
7849
- }
7850
7306
  var reactionReceivedHandler = async ({
7851
7307
  runtime,
7852
7308
  message
@@ -7861,50 +7317,6 @@ var reactionReceivedHandler = async ({
7861
7317
  runtime.logger.error({ error }, "[Bootstrap] Error in reaction handler:");
7862
7318
  }
7863
7319
  };
7864
- var messageDeletedHandler = async ({
7865
- runtime,
7866
- message
7867
- }) => {
7868
- try {
7869
- if (!message.id) {
7870
- runtime.logger.error("[Bootstrap] Cannot delete memory: message ID is missing");
7871
- return;
7872
- }
7873
- runtime.logger.info("[Bootstrap] Deleting memory for message", message.id, "from room", message.roomId);
7874
- await runtime.deleteMemory(message.id);
7875
- runtime.logger.debug({ messageId: message.id }, "[Bootstrap] Successfully deleted memory for message");
7876
- } catch (error) {
7877
- runtime.logger.error({ error }, "[Bootstrap] Error in message deleted handler:");
7878
- }
7879
- };
7880
- var channelClearedHandler = async ({
7881
- runtime,
7882
- roomId,
7883
- channelId,
7884
- memoryCount
7885
- }) => {
7886
- try {
7887
- runtime.logger.info(`[Bootstrap] Clearing ${memoryCount} message memories from channel ${channelId} -> room ${roomId}`);
7888
- const memories = await runtime.getMemoriesByRoomIds({
7889
- tableName: "messages",
7890
- roomIds: [roomId]
7891
- });
7892
- let deletedCount = 0;
7893
- for (const memory of memories) {
7894
- if (memory.id) {
7895
- try {
7896
- await runtime.deleteMemory(memory.id);
7897
- deletedCount++;
7898
- } catch (error) {
7899
- runtime.logger.warn({ error, memoryId: memory.id }, `[Bootstrap] Failed to delete message memory ${memory.id}:`);
7900
- }
7901
- }
7902
- }
7903
- runtime.logger.info(`[Bootstrap] Successfully cleared ${deletedCount}/${memories.length} message memories from channel ${channelId}`);
7904
- } catch (error) {
7905
- runtime.logger.error({ error }, "[Bootstrap] Error in channel cleared handler:");
7906
- }
7907
- };
7908
7320
  var postGeneratedHandler = async ({
7909
7321
  runtime,
7910
7322
  callback,
@@ -8146,24 +7558,6 @@ var controlMessageHandler = async ({
8146
7558
  }
8147
7559
  };
8148
7560
  var events = {
8149
- [EventType2.MESSAGE_RECEIVED]: [
8150
- async (payload) => {
8151
- if (!payload.callback) {
8152
- payload.runtime.logger.error("No callback provided for message");
8153
- return;
8154
- }
8155
- await messageReceivedHandler(payload);
8156
- }
8157
- ],
8158
- [EventType2.VOICE_MESSAGE_RECEIVED]: [
8159
- async (payload) => {
8160
- if (!payload.callback) {
8161
- payload.runtime.logger.error("No callback provided for voice message");
8162
- return;
8163
- }
8164
- await messageReceivedHandler(payload);
8165
- }
8166
- ],
8167
7561
  [EventType2.REACTION_RECEIVED]: [
8168
7562
  async (payload) => {
8169
7563
  await reactionReceivedHandler(payload);
@@ -8179,21 +7573,6 @@ var events = {
8179
7573
  payload.runtime.logger.debug(`[Bootstrap] Message sent: ${payload.message.content.text}`);
8180
7574
  }
8181
7575
  ],
8182
- [EventType2.MESSAGE_DELETED]: [
8183
- async (payload) => {
8184
- await messageDeletedHandler(payload);
8185
- }
8186
- ],
8187
- [EventType2.CHANNEL_CLEARED]: [
8188
- async (payload) => {
8189
- await channelClearedHandler({
8190
- runtime: payload.runtime,
8191
- roomId: payload.roomId,
8192
- channelId: payload.channelId,
8193
- memoryCount: payload.memoryCount
8194
- });
8195
- }
8196
- ],
8197
7576
  [EventType2.WORLD_JOINED]: [
8198
7577
  async (payload) => {
8199
7578
  await handleServerSync(payload);
@@ -8458,5 +7837,5 @@ export {
8458
7837
  actionStateProvider
8459
7838
  };
8460
7839
 
8461
- //# debugId=0D5C974CD619FF2264756E2164756E21
7840
+ //# debugId=AFB990BB999AB3A964756E2164756E21
8462
7841
  //# sourceMappingURL=index.js.map