@elizaos/plugin-bootstrap 1.0.0-beta.74 → 1.0.0-beta.76

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.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Action, Evaluator, Provider, Plugin, Media } from '@elizaos/core';
1
+ import { Action, Evaluator, Provider, Plugin, Media, IAgentRuntime } from '@elizaos/core';
2
2
 
3
3
  /**
4
4
  * Represents an action that allows selecting an option for a pending task that has multiple options.
@@ -425,6 +425,15 @@ type MediaData = {
425
425
  * @returns {Promise<MediaData[]>} - A Promise that resolves with an array of MediaData objects.
426
426
  */
427
427
  declare function fetchMediaData(attachments: Media[]): Promise<MediaData[]>;
428
+ /**
429
+ * Processes attachments by generating descriptions for supported media types.
430
+ * Currently supports image description generation.
431
+ *
432
+ * @param {Media[]} attachments - Array of attachments to process
433
+ * @param {IAgentRuntime} runtime - The agent runtime for accessing AI models
434
+ * @returns {Promise<Media[]>} - Returns a new array of processed attachments with added description, title, and text properties
435
+ */
436
+ declare function processAttachments(attachments: Media[], runtime: IAgentRuntime): Promise<Media[]>;
428
437
  declare const bootstrapPlugin: Plugin;
429
438
 
430
- export { actionsProvider, anxietyProvider, attachmentsProvider, bootstrapPlugin, capabilitiesProvider, characterProvider, choiceAction, choiceProvider, bootstrapPlugin as default, entitiesProvider, evaluatorsProvider, factsProvider, fetchMediaData, followRoomAction, ignoreAction, muteRoomAction, noneAction, providersProvider, recentMessagesProvider, reflectionEvaluator, relationshipsProvider, replyAction, roleProvider, sendMessageAction, settingsProvider, timeProvider, unfollowRoomAction, unmuteRoomAction, updateEntityAction, updateRoleAction, updateSettingsAction, worldProvider };
439
+ export { actionsProvider, anxietyProvider, attachmentsProvider, bootstrapPlugin, capabilitiesProvider, characterProvider, choiceAction, choiceProvider, bootstrapPlugin as default, entitiesProvider, evaluatorsProvider, factsProvider, fetchMediaData, followRoomAction, ignoreAction, muteRoomAction, noneAction, processAttachments, providersProvider, recentMessagesProvider, reflectionEvaluator, relationshipsProvider, replyAction, roleProvider, sendMessageAction, settingsProvider, timeProvider, unfollowRoomAction, unmuteRoomAction, updateEntityAction, updateRoleAction, updateSettingsAction, worldProvider };
package/dist/index.js CHANGED
@@ -82,7 +82,9 @@ import {
82
82
  postCreationTemplate,
83
83
  shouldRespondTemplate,
84
84
  truncateToCompleteSentence,
85
- parseKeyValueXml
85
+ parseKeyValueXml,
86
+ imageDescriptionTemplate,
87
+ ContentType
86
88
  } from "@elizaos/core";
87
89
 
88
90
  // ../../node_modules/uuid/dist/esm/stringify.js
@@ -3820,7 +3822,8 @@ var attachmentsProvider = {
3820
3822
  description: "List of attachments sent during the current conversation, including names, descriptions, and summaries",
3821
3823
  dynamic: true,
3822
3824
  get: async (runtime, message) => {
3823
- let allAttachments = message.content.attachments || [];
3825
+ const currentMessageAttachments = message.content.attachments || [];
3826
+ let allAttachments = [...currentMessageAttachments];
3824
3827
  const { roomId } = message;
3825
3828
  const conversationLength = runtime.getConversationLength();
3826
3829
  const recentMessagesData = await runtime.getMemories({
@@ -3836,17 +3839,24 @@ var attachmentsProvider = {
3836
3839
  if (lastMessageWithAttachment) {
3837
3840
  const lastMessageTime = lastMessageWithAttachment?.createdAt ?? Date.now();
3838
3841
  const oneHourBeforeLastMessage = lastMessageTime - 60 * 60 * 1e3;
3839
- allAttachments = recentMessagesData.reverse().flatMap((msg) => {
3842
+ const currentAttachmentsMap = new Map(
3843
+ currentMessageAttachments.map((att) => [att.id, att])
3844
+ );
3845
+ const recentAttachments = recentMessagesData.reverse().flatMap((msg) => {
3840
3846
  const msgTime = msg.createdAt ?? Date.now();
3841
3847
  const isWithinTime = msgTime >= oneHourBeforeLastMessage;
3842
3848
  const attachments = msg.content.attachments || [];
3843
- if (!isWithinTime) {
3844
- for (const attachment of attachments) {
3845
- attachment.text = "[Hidden]";
3849
+ return attachments.map((attachment) => {
3850
+ if (currentAttachmentsMap.has(attachment.id)) {
3851
+ return null;
3846
3852
  }
3847
- }
3848
- return attachments;
3853
+ if (!isWithinTime) {
3854
+ return { ...attachment, text: "[Hidden]" };
3855
+ }
3856
+ return attachment;
3857
+ }).filter((att) => att !== null);
3849
3858
  });
3859
+ allAttachments = [...currentMessageAttachments, ...recentAttachments];
3850
3860
  }
3851
3861
  }
3852
3862
  const formattedAttachments = allAttachments.map(
@@ -5641,6 +5651,56 @@ async function fetchMediaData(attachments) {
5641
5651
  })
5642
5652
  );
5643
5653
  }
5654
+ async function processAttachments(attachments, runtime) {
5655
+ if (!attachments || attachments.length === 0) {
5656
+ return [];
5657
+ }
5658
+ logger19.debug(`[Bootstrap] Processing ${attachments.length} attachment(s)`);
5659
+ const processedAttachments = [];
5660
+ for (const attachment of attachments) {
5661
+ try {
5662
+ const processedAttachment = { ...attachment };
5663
+ if (attachment.contentType === ContentType.IMAGE && !attachment.description) {
5664
+ logger19.debug(`[Bootstrap] Generating description for image: ${attachment.url}`);
5665
+ try {
5666
+ const response = await runtime.useModel(ModelType13.IMAGE_DESCRIPTION, {
5667
+ prompt: imageDescriptionTemplate,
5668
+ imageUrl: attachment.url
5669
+ });
5670
+ if (typeof response === "string") {
5671
+ const parsedXml = parseKeyValueXml(response);
5672
+ if (parsedXml?.description && parsedXml?.text) {
5673
+ processedAttachment.description = parsedXml.description;
5674
+ processedAttachment.title = parsedXml.title || "Image";
5675
+ processedAttachment.text = parsedXml.text;
5676
+ logger19.debug(
5677
+ `[Bootstrap] Generated description: ${processedAttachment.description?.substring(0, 100)}...`
5678
+ );
5679
+ } else {
5680
+ logger19.warn(`[Bootstrap] Failed to parse XML response for image description`);
5681
+ }
5682
+ } else if (response && typeof response === "object" && "description" in response) {
5683
+ processedAttachment.description = response.description;
5684
+ processedAttachment.title = response.title || "Image";
5685
+ processedAttachment.text = response.description;
5686
+ logger19.debug(
5687
+ `[Bootstrap] Generated description: ${processedAttachment.description?.substring(0, 100)}...`
5688
+ );
5689
+ } else {
5690
+ logger19.warn(`[Bootstrap] Unexpected response format for image description`);
5691
+ }
5692
+ } catch (error) {
5693
+ logger19.error(`[Bootstrap] Error generating image description:`, error);
5694
+ }
5695
+ }
5696
+ processedAttachments.push(processedAttachment);
5697
+ } catch (error) {
5698
+ logger19.error(`[Bootstrap] Failed to process attachment ${attachment.url}:`, error);
5699
+ processedAttachments.push(attachment);
5700
+ }
5701
+ }
5702
+ return processedAttachments;
5703
+ }
5644
5704
  var messageReceivedHandler = async ({
5645
5705
  runtime,
5646
5706
  message,
@@ -5728,6 +5788,12 @@ var messageReceivedHandler = async ({
5728
5788
  logger19.debug(
5729
5789
  `[Bootstrap] Skipping shouldRespond check for ${runtime.character.name} because ${room?.type} ${room?.source}`
5730
5790
  );
5791
+ if (message.content.attachments && message.content.attachments.length > 0) {
5792
+ message.content.attachments = await processAttachments(
5793
+ message.content.attachments,
5794
+ runtime
5795
+ );
5796
+ }
5731
5797
  let shouldRespond = true;
5732
5798
  if (!shouldSkipShouldRespond) {
5733
5799
  const shouldRespondPrompt = composePromptFromState9({
@@ -6404,6 +6470,7 @@ export {
6404
6470
  ignoreAction,
6405
6471
  muteRoomAction,
6406
6472
  noneAction,
6473
+ processAttachments,
6407
6474
  providersProvider,
6408
6475
  recentMessagesProvider,
6409
6476
  reflectionEvaluator,