@elizaos/plugin-bootstrap 1.0.0-beta.37 → 1.0.0-beta.38

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
@@ -3842,7 +3842,7 @@ var characterProvider = {
3842
3842
  const bio = addHeader4(`# About ${character.name}`, bioText);
3843
3843
  const system = character.system ?? "";
3844
3844
  const topicString = character.topics && character.topics.length > 0 ? character.topics[Math.floor(Math.random() * character.topics.length)] : null;
3845
- const topic = topicString ? `${character.name} is currently interested in ${topicString}` : "";
3845
+ const topic = topicString || "";
3846
3846
  const topics = character.topics && character.topics.length > 0 ? `${character.name} is also interested in ${character.topics.filter((topic2) => topic2 !== topicString).sort(() => 0.5 - Math.random()).slice(0, 5).map((topic2, index, array) => {
3847
3847
  if (index === array.length - 2) {
3848
3848
  return `${topic2} and `;
@@ -3853,7 +3853,7 @@ var characterProvider = {
3853
3853
  return `${topic2}, `;
3854
3854
  }).join("")}` : "";
3855
3855
  const adjectiveString = character.adjectives && character.adjectives.length > 0 ? character.adjectives[Math.floor(Math.random() * character.adjectives.length)] : "";
3856
- const adjective = adjectiveString ? `${character.name} is ${adjectiveString}` : "";
3856
+ const adjective = adjectiveString || "";
3857
3857
  const formattedCharacterPostExamples = !character.postExamples ? "" : character.postExamples.sort(() => 0.5 - Math.random()).map((post) => {
3858
3858
  const messageString = `${post}`;
3859
3859
  return messageString;
@@ -3921,7 +3921,9 @@ var characterProvider = {
3921
3921
  examples,
3922
3922
  system
3923
3923
  };
3924
- const text = [bio, adjective, topic, topics, adjective, directions, examples, system].filter(Boolean).join("\n\n");
3924
+ const topicSentence = topicString ? `${character.name} is currently interested in ${topicString}` : "";
3925
+ const adjectiveSentence = adjectiveString ? `${character.name} is ${adjectiveString}` : "";
3926
+ const text = [bio, adjectiveSentence, topicSentence, topics, directions, examples, system].filter(Boolean).join("\n\n");
3925
3927
  return {
3926
3928
  values,
3927
3929
  data,
@@ -5387,6 +5389,10 @@ var TaskService = class _TaskService extends Service2 {
5387
5389
  const now = Date.now();
5388
5390
  for (const task of tasks) {
5389
5391
  let taskStartTime;
5392
+ if (!task.tags?.includes("repeat")) {
5393
+ await this.executeTask(task);
5394
+ continue;
5395
+ }
5390
5396
  if (typeof task.updatedAt === "number") {
5391
5397
  taskStartTime = task.updatedAt;
5392
5398
  } else if (task.metadata?.updatedAt && typeof task.metadata.updatedAt === "number") {
@@ -5401,6 +5407,13 @@ var TaskService = class _TaskService extends Service2 {
5401
5407
  await this.executeTask(task);
5402
5408
  continue;
5403
5409
  }
5410
+ if (task.metadata.updatedAt === task.metadata.createdAt) {
5411
+ if (task.tags?.includes("immediate")) {
5412
+ logger16.debug("immediately running task", task.name);
5413
+ await this.executeTask(task);
5414
+ continue;
5415
+ }
5416
+ }
5404
5417
  if (now - taskStartTime >= updateIntervalMs) {
5405
5418
  logger16.debug(
5406
5419
  `Executing task ${task.name} - interval of ${updateIntervalMs}ms has elapsed`
@@ -5428,9 +5441,6 @@ var TaskService = class _TaskService extends Service2 {
5428
5441
  logger16.debug(`No worker found for task type: ${task.name}`);
5429
5442
  return;
5430
5443
  }
5431
- logger16.debug(`Executing task ${task.name} (${task.id})`);
5432
- await worker.execute(this.runtime, task.metadata || {}, task);
5433
- logger16.debug("task.tags are", task.tags);
5434
5444
  if (task.tags?.includes("repeat")) {
5435
5445
  await this.runtime.updateTask(task.id, {
5436
5446
  metadata: {
@@ -5439,7 +5449,10 @@ var TaskService = class _TaskService extends Service2 {
5439
5449
  }
5440
5450
  });
5441
5451
  logger16.debug(`Updated repeating task ${task.name} (${task.id}) with new timestamp`);
5442
- } else {
5452
+ }
5453
+ logger16.debug(`Executing task ${task.name} (${task.id})`);
5454
+ await worker.execute(this.runtime, task.metadata || {}, task);
5455
+ if (!task.tags?.includes("repeat")) {
5443
5456
  await this.runtime.deleteTask(task.id);
5444
5457
  logger16.debug(`Deleted non-repeating task ${task.name} (${task.id}) after execution`);
5445
5458
  }
@@ -5727,13 +5740,39 @@ var postGeneratedHandler = async ({
5727
5740
  entityId: runtime.agentId,
5728
5741
  agentId: runtime.agentId,
5729
5742
  roomId,
5730
- content: {}
5743
+ content: {},
5744
+ metadata: {
5745
+ entityName: runtime.character.name
5746
+ }
5731
5747
  };
5732
- const state = await runtime.composeState(message, null, [
5748
+ let state = await runtime.composeState(message, null, [
5749
+ "PROVIDERS",
5733
5750
  "CHARACTER",
5734
- "RECENT_MESSAGES",
5751
+ //'RECENT_MESSAGES',
5735
5752
  "ENTITIES"
5736
5753
  ]);
5754
+ const entity = await runtime.getEntityById(runtime.agentId);
5755
+ if (entity?.metadata?.twitter?.userName) {
5756
+ state.values.twitterUserName = entity?.metadata?.twitter?.userName;
5757
+ }
5758
+ const prompt = composePromptFromState9({
5759
+ state,
5760
+ template: runtime.character.templates?.messageHandlerTemplate || messageHandlerTemplate
5761
+ });
5762
+ let responseContent = null;
5763
+ let retries = 0;
5764
+ const maxRetries = 3;
5765
+ while (retries < maxRetries && (!responseContent?.thought || !responseContent?.actions)) {
5766
+ const response = await runtime.useModel(ModelType13.TEXT_SMALL, {
5767
+ prompt
5768
+ });
5769
+ responseContent = parseJSONObjectFromText4(response);
5770
+ retries++;
5771
+ if (!responseContent?.thought && !responseContent?.actions) {
5772
+ logger17.warn("*** Missing required fields, retrying... ***");
5773
+ }
5774
+ }
5775
+ state = await runtime.composeState(message, responseContent.providers);
5737
5776
  const postPrompt = composePromptFromState9({
5738
5777
  state,
5739
5778
  template: runtime.character.templates?.postCreationTemplate || postCreationTemplate
@@ -5751,6 +5790,39 @@ var postGeneratedHandler = async ({
5751
5790
  return cleanedText2;
5752
5791
  }
5753
5792
  const cleanedText = cleanupPostText(jsonResponse.post);
5793
+ const RM = state.providerData?.find((pd) => pd.providerName === "RECENT_MESSAGES");
5794
+ if (RM) {
5795
+ for (const m of RM.data.recentMessages) {
5796
+ if (cleanedText === m.content.text) {
5797
+ logger17.log("we've already recently posted that, retrying", cleanedText);
5798
+ postGeneratedHandler({
5799
+ runtime,
5800
+ callback,
5801
+ worldId,
5802
+ userId,
5803
+ roomId,
5804
+ source
5805
+ });
5806
+ return;
5807
+ }
5808
+ }
5809
+ }
5810
+ const oaiRefusalRegex = /((i\s+do\s+not|i'm\s+not)\s+(feel\s+)?comfortable\s+generating\s+that\s+type\s+of\s+content)|(inappropriate|explicit|respectful|offensive|guidelines|aim\s+to\s+(be\s+)?helpful|communicate\s+respectfully)/i;
5811
+ const anthropicRefusalRegex = /(i'?m\s+unable\s+to\s+help\s+with\s+that\s+request|due\s+to\s+safety\s+concerns|that\s+may\s+violate\s+(our\s+)?guidelines|provide\s+helpful\s+and\s+safe\s+responses|let'?s\s+try\s+a\s+different\s+direction|goes\s+against\s+(our\s+)?use\s+case\s+policies|ensure\s+safe\s+and\s+responsible\s+use)/i;
5812
+ const googleRefusalRegex = /(i\s+can'?t\s+help\s+with\s+that|that\s+goes\s+against\s+(our\s+)?(policy|policies)|i'?m\s+still\s+learning|response\s+must\s+follow\s+(usage|safety)\s+policies|i'?ve\s+been\s+designed\s+to\s+avoid\s+that)/i;
5813
+ const generalRefusalRegex = /(response\s+was\s+withheld|content\s+was\s+filtered|this\s+request\s+cannot\s+be\s+completed|violates\s+our\s+safety\s+policy|content\s+is\s+not\s+available)/i;
5814
+ if (oaiRefusalRegex.test(cleanedText) || anthropicRefusalRegex.test(cleanedText) || googleRefusalRegex.test(cleanedText) || generalRefusalRegex.test(cleanedText)) {
5815
+ logger17.log("got prompt moderation refusal, retrying", cleanedText);
5816
+ postGeneratedHandler({
5817
+ runtime,
5818
+ callback,
5819
+ worldId,
5820
+ userId,
5821
+ roomId,
5822
+ source
5823
+ });
5824
+ return;
5825
+ }
5754
5826
  const responseMessages = [
5755
5827
  {
5756
5828
  id: v4_default(),
@@ -5772,11 +5844,11 @@ var postGeneratedHandler = async ({
5772
5844
  }
5773
5845
  };
5774
5846
  var syncSingleUser = async (entityId, runtime, serverId, channelId, type, source) => {
5775
- const entity = await runtime.getEntityById(entityId);
5776
- logger17.info(`Syncing user: ${entity.metadata[source].username || entity.id}`);
5777
5847
  try {
5848
+ const entity = await runtime.getEntityById(entityId);
5849
+ logger17.info(`Syncing user: ${entity?.metadata[source]?.username || entityId}`);
5778
5850
  if (!channelId) {
5779
- logger17.warn(`Cannot sync user ${entity.id} without a valid channelId`);
5851
+ logger17.warn(`Cannot sync user ${entity?.id} without a valid channelId`);
5780
5852
  return;
5781
5853
  }
5782
5854
  const roomId = createUniqueUuid4(runtime, channelId);
@@ -5784,15 +5856,15 @@ var syncSingleUser = async (entityId, runtime, serverId, channelId, type, source
5784
5856
  await runtime.ensureConnection({
5785
5857
  entityId,
5786
5858
  roomId,
5787
- userName: entity.metadata[source].username || entity.id,
5788
- name: entity.metadata[source].name || entity.metadata[source].username || `User${entity.id}`,
5859
+ userName: entity?.metadata[source].username || entityId,
5860
+ name: entity?.metadata[source].name || entity?.metadata[source].username || `User${entityId}`,
5789
5861
  source,
5790
5862
  channelId,
5791
5863
  serverId,
5792
5864
  type,
5793
5865
  worldId
5794
5866
  });
5795
- logger17.success(`Successfully synced user: ${entity.id}`);
5867
+ logger17.success(`Successfully synced user: ${entity?.id}`);
5796
5868
  } catch (error) {
5797
5869
  logger17.error(`Error syncing user: ${error instanceof Error ? error.message : String(error)}`);
5798
5870
  }