refac
This commit is contained in:
1 parent
e389874fe2
commit
f7716fcbaf
2 files changed
+30
-45
No files matched your search
@@ -123,7 +123,7 @@
|
|||||||
export let embeddedTitle = '';
|
export let embeddedTitle = '';
|
||||||
export let embeddedChats = [];
|
export let embeddedChats = [];
|
||||||
export let embeddedDraftKey = '';
|
export let embeddedDraftKey = '';
|
||||||
export let initialFiles = [];
|
export let suggestedPrompts = [];
|
||||||
export let selectedText = '';
|
export let selectedText = '';
|
||||||
export let onInsertToNote: ((content: string) => void) | null = null;
|
export let onInsertToNote: ((content: string) => void) | null = null;
|
||||||
export let onCloseEmbedded: (() => void) | null = null;
|
export let onCloseEmbedded: (() => void) | null = null;
|
||||||
@@ -137,12 +137,6 @@
|
|||||||
let loading = true;
|
let loading = true;
|
||||||
$: chatContainerId = embedded ? 'note-chat-container' : 'chat-container';
|
$: chatContainerId = embedded ? 'note-chat-container' : 'chat-container';
|
||||||
$: messageInputDropzoneId = embedded ? 'note-chat-input-dropzone' : 'chat-pane';
|
$: messageInputDropzoneId = embedded ? 'note-chat-input-dropzone' : 'chat-pane';
|
||||||
const embeddedSuggestedPrompts = [
|
|
||||||
'Enhance this note and update it.',
|
|
||||||
'Summarize this note.',
|
|
||||||
'Extract action items from this note.',
|
|
||||||
'Rewrite the selected text.'
|
|
||||||
];
|
|
||||||
|
|
||||||
const eventTarget = new EventTarget();
|
const eventTarget = new EventTarget();
|
||||||
let controlPane: Pane | undefined;
|
let controlPane: Pane | undefined;
|
||||||
@@ -369,7 +363,6 @@
|
|||||||
let chatFiles = [];
|
let chatFiles = [];
|
||||||
let files = [];
|
let files = [];
|
||||||
let params = {};
|
let params = {};
|
||||||
let attachedFilesKey = '';
|
|
||||||
let loadedChatIdProp = '';
|
let loadedChatIdProp = '';
|
||||||
let currentDraftKey = '';
|
let currentDraftKey = '';
|
||||||
|
|
||||||
@@ -382,18 +375,6 @@
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const applyInitialFiles = () => {
|
|
||||||
if (!embedded || !initialFiles?.length) return;
|
|
||||||
|
|
||||||
const key = JSON.stringify(
|
|
||||||
initialFiles.map((file) => `${file?.type ?? ''}:${file?.id ?? file?.url ?? file?.name ?? ''}`)
|
|
||||||
);
|
|
||||||
if (key === attachedFilesKey) return;
|
|
||||||
|
|
||||||
files = mergeFiles(files, initialFiles);
|
|
||||||
chatFiles = mergeFiles(chatFiles, initialFiles);
|
|
||||||
attachedFilesKey = key;
|
|
||||||
};
|
|
||||||
const withSelectedText = (text: string) =>
|
const withSelectedText = (text: string) =>
|
||||||
embedded && selectedText?.trim()
|
embedded && selectedText?.trim()
|
||||||
? `${text}\n\nSelected note text for replace_note_content operations:\n${selectedText.trim()}`
|
? `${text}\n\nSelected note text for replace_note_content operations:\n${selectedText.trim()}`
|
||||||
@@ -408,10 +389,6 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$: if (embedded && !loading) {
|
|
||||||
applyInitialFiles();
|
|
||||||
}
|
|
||||||
|
|
||||||
$: if (chatIdProp && chatIdProp !== loadedChatIdProp) {
|
$: if (chatIdProp && chatIdProp !== loadedChatIdProp) {
|
||||||
noteChatDebug('chatIdProp changed; loading linked chat', {
|
noteChatDebug('chatIdProp changed; loading linked chat', {
|
||||||
previousChatIdProp: loadedChatIdProp
|
previousChatIdProp: loadedChatIdProp
|
||||||
@@ -549,7 +526,6 @@
|
|||||||
await setDefaults();
|
await setDefaults();
|
||||||
loading = false;
|
loading = false;
|
||||||
await tick();
|
await tick();
|
||||||
applyInitialFiles();
|
|
||||||
document.getElementById('chat-input')?.focus();
|
document.getElementById('chat-input')?.focus();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -2727,7 +2703,6 @@
|
|||||||
params = structuredClone(createdChat?.chat?.params ?? {});
|
params = structuredClone(createdChat?.chat?.params ?? {});
|
||||||
delete params.note_id;
|
delete params.note_id;
|
||||||
chatFiles = mergeFiles(chatFiles, createdChat?.chat?.files ?? []);
|
chatFiles = mergeFiles(chatFiles, createdChat?.chat?.files ?? []);
|
||||||
applyInitialFiles();
|
|
||||||
await onSelectEmbeddedChat?.(_chatId);
|
await onSelectEmbeddedChat?.(_chatId);
|
||||||
} else if ($temporaryChatEnabled) {
|
} else if ($temporaryChatEnabled) {
|
||||||
_chatId = `local:${$socket?.id}`;
|
_chatId = `local:${$socket?.id}`;
|
||||||
@@ -3846,27 +3821,29 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{:else if embedded}
|
{:else if embedded}
|
||||||
<div class="flex h-full min-h-0 flex-col justify-end">
|
<div class="flex h-full min-h-0 flex-col justify-end">
|
||||||
<div class="flex flex-1 items-end px-5 pb-8">
|
{#if suggestedPrompts.length > 0}
|
||||||
<div class="w-full">
|
<div class="flex flex-1 items-end px-5 pb-8">
|
||||||
<div class="mb-2 text-[12px] text-gray-300 dark:text-gray-700">
|
<div class="w-full">
|
||||||
{$i18n.t('Suggested prompts')}
|
<div class="mb-2 text-[12px] text-gray-300 dark:text-gray-700">
|
||||||
</div>
|
{$i18n.t('Suggested prompts')}
|
||||||
<div class="flex flex-col">
|
</div>
|
||||||
{#each embeddedSuggestedPrompts as suggestion}
|
<div class="flex flex-col">
|
||||||
<button
|
{#each suggestedPrompts as suggestion}
|
||||||
type="button"
|
<button
|
||||||
class="flex min-h-8 w-full items-center justify-between py-1 text-left text-[13px] leading-5 text-gray-500 transition hover:text-gray-700 dark:text-gray-500 dark:hover:text-gray-300"
|
type="button"
|
||||||
on:click={async () => {
|
class="flex min-h-8 w-full items-center justify-between py-1 text-left text-[13px] leading-5 text-gray-500 transition hover:text-gray-700 dark:text-gray-500 dark:hover:text-gray-300"
|
||||||
await tick();
|
on:click={async () => {
|
||||||
await submitHandler(withSelectedText(suggestion));
|
await tick();
|
||||||
}}
|
await submitHandler(withSelectedText(suggestion));
|
||||||
>
|
}}
|
||||||
<span class="min-w-0 truncate">{$i18n.t(suggestion)}</span>
|
>
|
||||||
</button>
|
<span class="min-w-0 truncate">{suggestion}</span>
|
||||||
{/each}
|
</button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{/if}
|
||||||
<div id={embedded ? messageInputDropzoneId : undefined} class="pb-2 z-10">
|
<div id={embedded ? messageInputDropzoneId : undefined} class="pb-2 z-10">
|
||||||
<MessageInput
|
<MessageInput
|
||||||
bind:this={messageInput}
|
bind:this={messageInput}
|
||||||
|
|||||||
@@ -144,12 +144,19 @@
|
|||||||
|
|
||||||
let selectedContent = null;
|
let selectedContent = null;
|
||||||
let noteAttachmentFiles = [];
|
let noteAttachmentFiles = [];
|
||||||
|
let noteChatSuggestedPrompts = [];
|
||||||
let pendingNoteEvent = null;
|
let pendingNoteEvent = null;
|
||||||
let pendingNoteEventTimer = null;
|
let pendingNoteEventTimer = null;
|
||||||
let lastLocalContentChangeAt = 0;
|
let lastLocalContentChangeAt = 0;
|
||||||
$: noteAttachmentFiles = (files ?? []).filter(
|
$: noteAttachmentFiles = (files ?? []).filter(
|
||||||
(file) => file?.type !== 'image' && !(file?.content_type ?? '').startsWith('image/')
|
(file) => file?.type !== 'image' && !(file?.content_type ?? '').startsWith('image/')
|
||||||
);
|
);
|
||||||
|
$: noteChatSuggestedPrompts = [
|
||||||
|
$i18n.t('Enhance this note and update it.'),
|
||||||
|
$i18n.t('Summarize this note.'),
|
||||||
|
$i18n.t('Extract action items from this note.'),
|
||||||
|
$i18n.t('Rewrite the selected text.')
|
||||||
|
];
|
||||||
|
|
||||||
let showDeleteConfirm = false;
|
let showDeleteConfirm = false;
|
||||||
let showAccessControlModal = false;
|
let showAccessControlModal = false;
|
||||||
@@ -1470,6 +1477,7 @@ ${content}
|
|||||||
chatIdProp={noteChatId ?? ''}
|
chatIdProp={noteChatId ?? ''}
|
||||||
embeddedChats={noteChats}
|
embeddedChats={noteChats}
|
||||||
embeddedDraftKey={noteChatDraftKey}
|
embeddedDraftKey={noteChatDraftKey}
|
||||||
|
suggestedPrompts={noteChatSuggestedPrompts}
|
||||||
selectedText={selectedContent?.text ?? ''}
|
selectedText={selectedContent?.text ?? ''}
|
||||||
onInsertToNote={insertHandler}
|
onInsertToNote={insertHandler}
|
||||||
onNewEmbeddedChat={createNoteChat}
|
onNewEmbeddedChat={createNoteChat}
|
||||||
|
|||||||
Reference in new issue
Block a user