|
89 | 89 | } from '@deta/services/constants' |
90 | 90 | import type { MentionAction } from '@deta/editor/src/lib/extensions/Mention' |
91 | 91 | import { type AITool, ModelTiers, Provider } from '@deta/types/src/ai.types' |
92 | | - import { Toast, useToasts } from '@deta/ui' |
93 | 92 | import { useConfig } from '@deta/services' |
94 | 93 | import { createWikipediaAPI, WebParser } from '@deta/web-parser' |
95 | 94 | import EmbeddedResource from './EmbeddedResource.svelte' |
|
137 | 136 | const log = useLogScope('TextCard') |
138 | 137 | const resourceManager = useResourceManager() |
139 | 138 | const ai = useAI() |
140 | | - const toasts = useToasts() |
141 | 139 | const config = useConfig() |
142 | 140 | const wikipediaAPI = createWikipediaAPI() |
143 | 141 |
|
|
717 | 715 | } |
718 | 716 |
|
719 | 717 | const handleEditorFilePaste = async (e: CustomEvent<{ files: File[]; htmlData?: string }>) => { |
720 | | - let toast: Toast | null = null |
721 | 718 | try { |
722 | 719 | const { files, htmlData } = e.detail |
723 | 720 |
|
724 | | - if (toasts) { |
725 | | - toast = toasts.loading('Importing pasted items…') |
726 | | - } |
727 | | -
|
728 | 721 | let parsed: any[] = [] |
729 | 722 |
|
730 | 723 | // If we have direct files, use them |
|
831 | 824 | } |
832 | 825 | } |
833 | 826 |
|
834 | | - if (toast) { |
835 | | - toast.success('Items imported!') |
836 | | - } |
837 | 827 | return |
838 | 828 | } |
839 | 829 | } |
|
873 | 863 |
|
874 | 864 | await processDropResource(position, resource, true, { x: 0, y: 0 }) |
875 | 865 | } |
876 | | -
|
877 | | - if (toast) { |
878 | | - toast.success('Items imported!') |
879 | | - } |
880 | 866 | } catch (err) { |
881 | | - if (toast) { |
882 | | - toast.error('Failed to import pasted items!') |
883 | | - } |
884 | 867 | log.error(err) |
885 | 868 | } |
886 | 869 | } |
887 | 870 |
|
888 | 871 | const handlePaste = async (e: ClipboardEvent) => { |
889 | | - let toast: Toast | null = null |
890 | 872 | e.preventDefault() |
891 | 873 | try { |
892 | 874 | var parsed = await processPaste(e) |
|
895 | 877 | parsed = parsed.filter((e) => e.type === 'file') |
896 | 878 | if (parsed.length <= 0) return |
897 | 879 |
|
898 | | - toast = toasts.loading('Importing pasted items…') |
899 | | -
|
900 | 880 | const newResources = await createResourcesFromMediaItems(resourceManager, parsed, '', [ |
901 | 881 | ResourceTag.paste(), |
902 | 882 | ResourceTag.silent() |
|
911 | 891 |
|
912 | 892 | await processDropResource(position, resource, true, { x: 0, y: 0 }) |
913 | 893 | } |
914 | | -
|
915 | | - toast.success('Items imported!') |
916 | 894 | } catch (e) { |
917 | | - toast?.error('Failed to import pasted items!') |
918 | | -
|
919 | 895 | log.error(e) |
920 | 896 | } |
921 | 897 | } |
922 | 898 |
|
923 | 899 | const handleDrop = async (drag) => { |
924 | | - let toast: Toast | null = null |
925 | 900 | try { |
926 | 901 | const editor = editorElem.getEditor() |
927 | 902 | const position = dragPosition ?? editor.view.state.selection.from |
|
932 | 907 |
|
933 | 908 | if (drag.isNative) { |
934 | 909 | if (drag.dataTransfer?.getData('text/html')?.includes('<img ')) { |
935 | | - toast = toasts.loading('Embedding image…') |
936 | | -
|
937 | 910 | try { |
938 | 911 | let srcUrl = drag.dataTransfer?.getData('text/html').split('<img ')[1].split('src="')[1] |
939 | 912 | srcUrl = srcUrl.slice(0, srcUrl.indexOf('"')) |
|
965 | 938 | await processDropResource(position, resource, isBlock) |
966 | 939 | } catch (error) { |
967 | 940 | log.error('Failed to embedd image: ', error) |
968 | | - toast.error('Failed to embedd image!') |
969 | 941 | drag.abort() |
970 | 942 | return |
971 | 943 | } |
972 | 944 |
|
973 | | - toast.success('Image embedded!') |
974 | 945 | drag.continue() |
975 | 946 | return |
976 | 947 | } |
|
1004 | 975 | // } |
1005 | 976 | // } else { |
1006 | 977 | // log.debug('Creating resource from tab', tab) |
1007 | | - // toast = toasts.loading('Processing Tab…') |
1008 | 978 | // const { resource } = await tabsManager.createResourceFromTab(tab, { silent: true }) |
1009 | 979 | // if (resource) { |
1010 | 980 | // log.debug('Created resource from tab', resource) |
|
1017 | 987 | // y: drag.event.clientY |
1018 | 988 | // } |
1019 | 989 | // ) |
1020 | | - // toast.success(isBlock ? 'Tab Embedded!' : 'Tab Linked!') |
1021 | 990 | // drag.continue() |
1022 | 991 | // return |
1023 | 992 | // } |
|
1071 | 1040 | } |
1072 | 1041 | } catch (e) { |
1073 | 1042 | log.error('Error handling drop', e) |
1074 | | - if (toast) { |
1075 | | - toast.error('Failed to handle drop') |
1076 | | - } else { |
1077 | | - toasts.error('Failed to handle drop') |
1078 | | - } |
1079 | 1043 | drag.abort() |
1080 | 1044 | } |
1081 | 1045 | } |
|
1147 | 1111 | true |
1148 | 1112 | ) |
1149 | 1113 | // await tabsManager.openResourceAsTab(resource, { active: true }) |
1150 | | - toasts.success('Note created!') |
1151 | 1114 | } |
1152 | 1115 |
|
1153 | 1116 | const getLastNode = (type: string) => { |
|
1375 | 1338 | log.debug('autocomplete response', response) |
1376 | 1339 | if (response.error) { |
1377 | 1340 | log.error('Error generating AI output', response.error) |
1378 | | - let errorMsg = response.error.message |
1379 | | - if (response.error.type === PageChatMessageSentEventError.TooManyRequests) { |
1380 | | - errorMsg = 'Too many requests, please try again later' |
1381 | | - } else if (response.error.type === PageChatMessageSentEventError.BadRequest) { |
1382 | | - errorMsg = |
1383 | | - 'Sorry your query did not pass our content policy, please try again with a different query.' |
1384 | | - } else if (response.error.type === PageChatMessageSentEventError.RAGEmptyContext) { |
1385 | | - errorMsg = |
1386 | | - 'No relevant context found. Please add more resources or try a different query.' |
1387 | | - } |
| 1341 | + let errorMsg = response.error.message || 'An unknown error occurred' |
1388 | 1342 | aiGeneration.updateStatus('failed') |
1389 | 1343 | chatInputComp?.showStatus({ |
1390 | 1344 | type: 'error', |
|
1472 | 1426 |
|
1473 | 1427 | if (type === MentionItemType.BUILT_IN || type === MentionItemType.MODEL) { |
1474 | 1428 | log.debug('Built-in or model mention clicked, cannot be opened') |
1475 | | - toasts.info('This is a built-in mention and cannot be opened') |
1476 | 1429 | return |
1477 | 1430 | } |
1478 | 1431 |
|
|
1501 | 1454 | log.debug('Cannot open mention', item, action) |
1502 | 1455 | return |
1503 | 1456 | } |
1504 | | -
|
1505 | | - if (action === 'overlay') { |
1506 | | - if (id === INBOX_MENTION.id) { |
1507 | | - openSpaceInStuff('inbox') |
1508 | | - } else if (id === EVERYTHING_MENTION.id) { |
1509 | | - openSpaceInStuff('all') |
1510 | | - } else if (type === MentionItemType.RESOURCE) { |
1511 | | - // oasis.openResourceDetailsSidebar(id, { select: true, selectedSpace: 'auto' }) |
1512 | | - } else if (type === MentionItemType.CONTEXT) { |
1513 | | - openSpaceInStuff(id) |
1514 | | - } else { |
1515 | | - toasts.info('This is a built-in mention and cannot be opened') |
1516 | | - } |
1517 | | - } else { |
1518 | | - if (type === MentionItemType.BUILT_IN || type === MentionItemType.MODEL) { |
1519 | | - toasts.info('This is a built-in mention and cannot be opened') |
1520 | | - return |
1521 | | - } |
1522 | | -
|
1523 | | - // if (type === MentionItemType.RESOURCE) { |
1524 | | - // tabsManager.openResourcFromContextAsPageTab(id, { |
1525 | | - // active: action !== 'new-background-tab' |
1526 | | - // }) |
1527 | | - // return |
1528 | | - // } |
1529 | | -
|
1530 | | - // if (action === 'open') { |
1531 | | - // tabsManager.changeScope( |
1532 | | - // id === INBOX_MENTION.id || id === EVERYTHING_MENTION.id ? null : id, |
1533 | | - // ChangeContextEventTrigger.Note |
1534 | | - // ) |
1535 | | -
|
1536 | | - // return |
1537 | | - // } |
1538 | | -
|
1539 | | - // const space = await oasis.getSpace(id) |
1540 | | - // if (!space) { |
1541 | | - // log.error('Space not found', id) |
1542 | | - // return |
1543 | | - // } |
1544 | | -
|
1545 | | - // tabsManager.addSpaceTab(space, { |
1546 | | - // active: action === 'new-tab' |
1547 | | - // }) |
1548 | | - } |
1549 | 1457 | } catch (e) { |
1550 | 1458 | log.error('Error handling mention click', e) |
1551 | | - toasts.error('Failed to handle mention click') |
1552 | 1459 | } |
1553 | 1460 | } |
1554 | 1461 |
|
|
1594 | 1501 | if (response.error) { |
1595 | 1502 | log.error('Error generating AI output', response.error) |
1596 | 1503 |
|
1597 | | - if (response.error.type === PageChatMessageSentEventError.TooManyRequests) { |
1598 | | - toasts.error('Too many requests, please try again later') |
1599 | | - } else if (response.error.type === PageChatMessageSentEventError.RAGEmptyContext) { |
1600 | | - toasts.error( |
1601 | | - 'No relevant context found. Please add more resources or try a different query.' |
1602 | | - ) |
1603 | | - } else if (response.error.type === PageChatMessageSentEventError.BadRequest) { |
1604 | | - toasts.error( |
1605 | | - 'Sorry your query did not pass our content policy, please try again with a different query.' |
1606 | | - ) |
1607 | | - } else { |
1608 | | - toasts.error('Something went wrong generating the AI output. Please try again.') |
1609 | | - } |
1610 | | -
|
1611 | 1504 | return |
1612 | 1505 | } |
1613 | 1506 |
|
|
1636 | 1529 | showBubbleMenu.set(true) |
1637 | 1530 | } catch (e) { |
1638 | 1531 | log.error('Error rewriting', e) |
1639 | | - toasts.error('Failed to rewrite') |
1640 | 1532 | showBubbleMenu.set(false) |
1641 | 1533 | } |
1642 | 1534 | } |
|
1715 | 1607 | const checkIfAlreadyRunning = (kind: string = 'ai generation') => { |
1716 | 1608 | if ($isGeneratingAI) { |
1717 | 1609 | log.debug(`Ignoring ${kind} request - AI generation already in progress`) |
1718 | | - toasts.info('AI generation already running, please wait') |
1719 | 1610 | return true |
1720 | 1611 | } |
1721 | 1612 |
|
|
1755 | 1646 | selectedContext.set(e.detail) |
1756 | 1647 | } catch (e) { |
1757 | 1648 | log.error('Error selecting context', e) |
1758 | | - toasts.error('Failed to select context') |
1759 | 1649 | } |
1760 | 1650 | } |
1761 | 1651 |
|
|
1841 | 1731 | } |
1842 | 1732 | } catch (e) { |
1843 | 1733 | log.error('Error handling note button click', e) |
1844 | | - toasts.error('Failed to handle note button click') |
1845 | 1734 | } |
1846 | 1735 | } |
1847 | 1736 |
|
|
2021 | 1910 | ) |
2022 | 1911 | } catch (e) { |
2023 | 1912 | log.error('Error doing magic', e) |
2024 | | - toasts.error('Failed to autocomplete') |
2025 | 1913 | } |
2026 | 1914 | } |
2027 | 1915 |
|
|
2058 | 1946 |
|
2059 | 1947 | if (!generatedPrompts) { |
2060 | 1948 | log.error('Failed to generate prompts') |
2061 | | - toasts.error('Failed to generate suggestions') |
2062 | 1949 | generatingPrompts.set(false) |
2063 | 1950 | return |
2064 | 1951 | } |
|
2067 | 1954 | prompts.set(generatedPrompts) |
2068 | 1955 | } catch (e) { |
2069 | 1956 | log.error('Error generating prompts', e) |
2070 | | - toasts.error('Failed to generate suggestions') |
2071 | 1957 | } finally { |
2072 | 1958 | generatingPrompts.set(false) |
2073 | 1959 | } |
|
2100 | 1986 | ) |
2101 | 1987 | } catch (e) { |
2102 | 1988 | log.error('Error doing magic', e) |
2103 | | - toasts.error('Failed to generate suggestion') |
2104 | 1989 | } |
2105 | 1990 | } |
2106 | 1991 |
|
|
2391 | 2276 | log.debug('Inserted onboarding mention into editor', mentionItem) |
2392 | 2277 | } catch (error) { |
2393 | 2278 | log.error('Error inserting onboarding mention', error) |
2394 | | - toasts.error('Failed to insert mention') |
2395 | 2279 | } |
2396 | 2280 | } |
2397 | 2281 |
|
|
2425 | 2309 | log.debug('UseAsDefaultBrowser extension inserted successfully at the end of the document') |
2426 | 2310 | } catch (err) { |
2427 | 2311 | log.error('Error inserting UseAsDefaultBrowser extension', err) |
2428 | | - toasts.error('Failed to insert default browser prompt') |
2429 | 2312 | } |
2430 | 2313 | } |
2431 | 2314 |
|
|
2475 | 2358 | // editor.commands.focus() |
2476 | 2359 | } catch (err) { |
2477 | 2360 | log.error('Error inserting extension', err) |
2478 | | - toasts.error('Failed to insert content') |
2479 | 2361 | } |
2480 | 2362 | } |
2481 | 2363 |
|
|
2539 | 2421 | log.debug('Onboarding footer with links inserted successfully') |
2540 | 2422 | } catch (err) { |
2541 | 2423 | log.error('Error inserting onboarding footer', err) |
2542 | | - toasts.error('Failed to insert resource links') |
2543 | 2424 | } |
2544 | 2425 | } |
2545 | 2426 |
|
|
0 commit comments