mirror of
https://github.com/enricoros/big-AGI.git
synced 2026-05-10 21:50:14 -07:00
MP: improve Ego-Fragments
This commit is contained in:
@@ -157,7 +157,7 @@ export function Composer(props: {
|
||||
// attachments-overlay: comes from the attachments slice of the conversation overlay
|
||||
const {
|
||||
/* items */ attachmentDrafts,
|
||||
/* append */ attachAppendClipboardItems, attachAppendDataTransfer, attachAppendEgoContent, attachAppendFile,
|
||||
/* append */ attachAppendClipboardItems, attachAppendDataTransfer, attachAppendEgoFragments, attachAppendFile,
|
||||
/* take */ attachmentsRemoveAll, attachmentsTakeAllFragments, attachmentsTakeTextFragments,
|
||||
} = useAttachmentDrafts(conversationOverlayStore, enableLoadURLsInComposer);
|
||||
|
||||
@@ -315,22 +315,21 @@ export function Composer(props: {
|
||||
}
|
||||
}, [composerTextAreaRef, setComposeText]);
|
||||
|
||||
const onActileEmbedMessage = React.useCallback(async (starredItem: StarredMessageItem) => {
|
||||
const onActileEmbedMessage = React.useCallback(async ({ conversationId, messageId }: StarredMessageItem) => {
|
||||
// get the message
|
||||
const conversation = getConversation(starredItem.conversationId);
|
||||
const messageToEmbed = conversation?.messages.find(m => m.id === starredItem.messageId);
|
||||
const conversation = getConversation(conversationId);
|
||||
const messageToEmbed = conversation?.messages.find(m => m.id === messageId);
|
||||
if (conversation && messageToEmbed) {
|
||||
const contentToEmbed = duplicateDMessageFragments(messageToEmbed.fragments)
|
||||
const fragmentsCopy = duplicateDMessageFragments(messageToEmbed.fragments)
|
||||
.filter(isContentFragment);
|
||||
if (contentToEmbed.length) {
|
||||
if (fragmentsCopy.length) {
|
||||
const chatTitle = conversationTitle(conversation);
|
||||
const messageText = messageFragmentsReduceText(contentToEmbed);
|
||||
const refLabel = `${chatTitle} > ${messageText.slice(0, 10)}...`;
|
||||
const refId = `${starredItem.messageId} - ${chatTitle}`;
|
||||
await attachAppendEgoContent(refLabel, refId, contentToEmbed);
|
||||
const messageText = messageFragmentsReduceText(fragmentsCopy);
|
||||
const label = `${chatTitle} > ${messageText.slice(0, 10)}...`;
|
||||
await attachAppendEgoFragments(fragmentsCopy, label, chatTitle, conversationId, messageId);
|
||||
}
|
||||
}
|
||||
}, [attachAppendEgoContent]);
|
||||
}, [attachAppendEgoFragments]);
|
||||
|
||||
const actileProviders = React.useMemo(() => {
|
||||
return [providerCommands(onActileCommandPaste), providerStarredMessage(onActileEmbedMessage)];
|
||||
|
||||
@@ -80,7 +80,7 @@ const converterTypeToIconMap: { [key in AttachmentDraftConverterType]: React.Com
|
||||
'image-resized-low': PhotoSizeSelectSmallOutlinedIcon,
|
||||
'image-to-default': ImageOutlinedIcon,
|
||||
'image-ocr': AbcIcon,
|
||||
'ego-contents-inlined': TelegramIcon,
|
||||
'ego-fragments-inlined': TelegramIcon,
|
||||
'unhandled': TextureIcon,
|
||||
};
|
||||
|
||||
|
||||
@@ -198,11 +198,11 @@ export async function attachmentLoadInputAsync(source: Readonly<AttachmentDraftS
|
||||
case 'ego':
|
||||
edit({
|
||||
label: source.label,
|
||||
ref: source.refId,
|
||||
ref: `${source.refMessageId} - ${source.refConversationTitle}`,
|
||||
input: {
|
||||
mimeType: 'ego/contents',
|
||||
data: source.contents,
|
||||
dataSize: source.contents.length,
|
||||
mimeType: 'application/vnd.agi.ego.fragments',
|
||||
data: source.fragments,
|
||||
dataSize: source.fragments.length,
|
||||
},
|
||||
});
|
||||
break;
|
||||
@@ -262,8 +262,8 @@ export function attachmentDefineConverters(sourceType: AttachmentDraftSource['me
|
||||
break;
|
||||
|
||||
// EGO
|
||||
case input.mimeType === 'ego/contents':
|
||||
converters.push({ id: 'ego-contents-inlined', name: 'Message' });
|
||||
case input.mimeType === 'application/vnd.agi.ego.fragments':
|
||||
converters.push({ id: 'ego-fragments-inlined', name: 'Message' });
|
||||
break;
|
||||
|
||||
// catch-all
|
||||
@@ -438,16 +438,16 @@ export async function attachmentPerformConversion(
|
||||
|
||||
|
||||
// self: message
|
||||
case 'ego-contents-inlined':
|
||||
case 'ego-fragments-inlined':
|
||||
if (!Array.isArray(input.data)) {
|
||||
console.log('Expected DMessageContentFragment[] for ego-contents-inlined, got:', typeof input.data);
|
||||
console.log('Expected DMessageContentFragment[] for ego-fragments-inlined, got:', typeof input.data);
|
||||
break;
|
||||
}
|
||||
for (const contentFragment of input.data) {
|
||||
if (contentFragment.part.pt === 'text' || isImageRefPart(contentFragment.part))
|
||||
newFragments.push(createContentPartAttachmentFragment(source.media === 'ego' ? source.refId : 'Message', contentFragment.part));
|
||||
else
|
||||
console.log('Unhandled ego-contents-inlined part:', contentFragment.part.pt);
|
||||
console.log('Unhandled ego-fragments-inlined part:', contentFragment.part.pt);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { FileWithHandle } from 'browser-fs-access';
|
||||
|
||||
import type { DConversationId } from '~/common/stores/chat/chat.conversation';
|
||||
import type { DMessageAttachmentFragment, DMessageContentFragment } from '~/common/stores/chat/chat.fragments';
|
||||
import type { DMessageId } from '~/common/stores/chat/chat.message';
|
||||
|
||||
|
||||
// Attachment Draft
|
||||
@@ -51,10 +53,13 @@ export type AttachmentDraftSource = {
|
||||
} | {
|
||||
// special type for attachments thar are references to self (ego, application) objects
|
||||
media: 'ego';
|
||||
method: 'ego-contents';
|
||||
contents: DMessageContentFragment[];
|
||||
method: 'ego-fragments';
|
||||
label: string;
|
||||
refId: string; // message ID where the context came from (unused..)
|
||||
// this is overfit to fragments for now
|
||||
fragments: DMessageContentFragment[];
|
||||
refConversationTitle: string;
|
||||
refConversationId: DConversationId;
|
||||
refMessageId: DMessageId;
|
||||
};
|
||||
|
||||
export type AttachmentDraftSourceOriginFile = 'camera' | 'screencapture' | 'file-open' | 'clipboard-read' | AttachmentDraftSourceOriginDTO;
|
||||
@@ -92,7 +97,7 @@ export type AttachmentDraftConverterType =
|
||||
| 'text' | 'rich-text' | 'rich-text-table'
|
||||
| 'pdf-text' | 'pdf-images'
|
||||
| 'image-original' | 'image-resized-high' | 'image-resized-low' | 'image-ocr' | 'image-to-default'
|
||||
| 'ego-contents-inlined'
|
||||
| 'ego-fragments-inlined'
|
||||
| 'unhandled';
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,9 @@ import { asValidURL } from '~/common/util/urlUtils';
|
||||
import { extractFilePathsWithCommonRadix } from '~/common/util/dropTextUtils';
|
||||
import { getClipboardItems } from '~/common/util/clipboardUtils';
|
||||
|
||||
import type { DConversationId } from '~/common/stores/chat/chat.conversation';
|
||||
import type { DMessageContentFragment } from '~/common/stores/chat/chat.fragments';
|
||||
import type { DMessageId } from '~/common/stores/chat/chat.message';
|
||||
import { useChatAttachmentsStore } from '~/common/chats/store-chat-overlay';
|
||||
|
||||
import type { AttachmentDraftSourceOriginDTO, AttachmentDraftSourceOriginFile } from './attachment.types';
|
||||
@@ -184,12 +186,12 @@ export const useAttachmentDrafts = (attachmentsStoreApi: AttachmentDraftsStoreAp
|
||||
/**
|
||||
* Append ego content to the attachments.
|
||||
*/
|
||||
const attachAppendEgoContent = React.useCallback((label: string, refId: string, contents: DMessageContentFragment[]) => {
|
||||
const attachAppendEgoFragments = React.useCallback((fragments: DMessageContentFragment[], label: string, conversationTitle: string, conversationId: DConversationId, messageId: DMessageId) => {
|
||||
if (ATTACHMENTS_DEBUG_INTAKE)
|
||||
console.log('attachAppendEgoContent', label, refId, contents);
|
||||
console.log('attachAppendEgoContent', fragments, label, conversationId, messageId);
|
||||
|
||||
return _createAttachmentDraft({
|
||||
media: 'ego', method: 'ego-contents', label, refId, contents,
|
||||
media: 'ego', method: 'ego-fragments', label, fragments, refConversationTitle: conversationTitle, refConversationId: conversationId, refMessageId: messageId,
|
||||
});
|
||||
}, [_createAttachmentDraft]);
|
||||
|
||||
@@ -201,7 +203,7 @@ export const useAttachmentDrafts = (attachmentsStoreApi: AttachmentDraftsStoreAp
|
||||
// create drafts
|
||||
attachAppendClipboardItems,
|
||||
attachAppendDataTransfer,
|
||||
attachAppendEgoContent,
|
||||
attachAppendEgoFragments,
|
||||
attachAppendFile,
|
||||
|
||||
// manage attachments
|
||||
|
||||
Reference in New Issue
Block a user