Skip to content

TagSpaces is an offline, open source, document manager with tagging support

fix: issues with AI generation content

Ilian Sapundshiev349b4e47c2ae
diff --git a/src/renderer/components/chat/AiGenTagsButton.tsx b/src/renderer/components/chat/AiGenTagsButton.tsx
index 6c6941e6f..74445785c 100644
--- a/src/renderer/components/chat/AiGenTagsButton.tsx
+++ b/src/renderer/components/chat/AiGenTagsButton.tsx
@@ -87,17 +87,22 @@ function AiGenTagsButton(props: Props) {
setIsLoading(true);
checkOllamaModels().then((success) => {
if (success) {
- const promises = generateEntries.map((entry) => {
- tagsGenerate(entry, fromDescription).then(() => {
+ const promises = generateEntries.map((entry) =>
+ tagsGenerate(entry, fromDescription).then((tagsSuccess) => {
if (generationCompleted) {
generationCompleted();
}
- });
- });
+ return tagsSuccess;
+ }),
+ );
Promise.all(promises)
.then((results) => {
setIsLoading(false);
- if (results && results.every((result) => result)) {
+ if (
+ results &&
+ results.length > 0 &&
+ results.every((result) => result)
+ ) {
showNotification(t('core:tagsGeneratedByAI'));
}
})
diff --git a/src/renderer/components/dialogs/components/SelectedItemsSummary.tsx b/src/renderer/components/dialogs/components/SelectedItemsSummary.tsx
index 20404072f..662f64803 100644
--- a/src/renderer/components/dialogs/components/SelectedItemsSummary.tsx
+++ b/src/renderer/components/dialogs/components/SelectedItemsSummary.tsx
@@ -38,7 +38,7 @@ import Paper from '@mui/material/Paper';
import Stack from '@mui/material/Stack';
import Typography from '@mui/material/Typography';
import { formatBytes } from '@tagspaces/tagspaces-common/misc';
-import { useState } from 'react';
+import { ReactNode, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';
@@ -50,6 +50,16 @@ interface Props {
dirProp?: Record<string, DirSize>;
/** When true (e.g. on <md or large selections), the pill starts collapsed. */
defaultCollapsed?: boolean;
+ /**
+ * Controlled expanded state. When provided, the component stops keeping its
+ * own open/closed state and the parent drives it via onExpandedChange.
+ */
+ expanded?: boolean;
+ onExpandedChange?: (expanded: boolean) => void;
+ /** Optional: render an entry dimmed (e.g. unsupported for the operation). */
+ isDimmed?: (entry: TS.FileSystemEntry) => boolean;
+ /** Optional: trailing per-entry status adornment (e.g. a processed mark). */
+ getItemAdornment?: (entry: TS.FileSystemEntry) => ReactNode;
}
function getTotalSize(
@@ -122,12 +132,29 @@ function ExtensionTile({
);
}
-function SelectedItemsSummary({ entries, dirProp, defaultCollapsed }: Props) {
+function SelectedItemsSummary({
+ entries,
+ dirProp,
+ defaultCollapsed,
+ expanded,
+ onExpandedChange,
+ isDimmed,
+ getItemAdornment,
+}: Props) {
const { t } = useTranslation();
const supportedFileTypes = useSelector(getSupportedFileTypes);
const defaultFolderColor = useSelector(getDefaultFolderColor);
const itemCount = entries.length;
- const [expanded, setExpanded] = useState(!defaultCollapsed);
+ const [internalExpanded, setInternalExpanded] = useState(!defaultCollapsed);
+ const isExpandedControlled = expanded !== undefined;
+ const isExpanded = isExpandedControlled ? expanded : internalExpanded;
+ const toggleExpanded = () => {
+ const next = !isExpanded;
+ if (!isExpandedControlled) {
+ setInternalExpanded(next);
+ }
+ onExpandedChange?.(next);
+ };
if (itemCount === 0) {
return null;
@@ -142,6 +169,7 @@ function SelectedItemsSummary({ entries, dirProp, defaultCollapsed }: Props) {
const itemSize = entry.isFile
? entry.size
: dirProp?.[entry.path]?.totalSize;
+ const adornment = getItemAdornment?.(entry);
return (
<Paper
variant="outlined"
@@ -161,7 +189,12 @@ function SelectedItemsSummary({ entries, dirProp, defaultCollapsed }: Props) {
defaultFolderColor={defaultFolderColor}
/>
<Box sx={{ flex: 1, minWidth: 0 }}>
- <Typography variant="body2" noWrap title={entry.path}>
+ <Typography
+ variant="body2"
+ noWrap
+ title={entry.path}
+ sx={{ ...(isDimmed?.(entry) && { color: 'text.disabled' }) }}
+ >
{entry.name}
</Typography>
</Box>
@@ -174,6 +207,13 @@ function SelectedItemsSummary({ entries, dirProp, defaultCollapsed }: Props) {
{formatBytes(itemSize)}
</Typography>
)}
+ {adornment && (
+ <Box
+ sx={{ flexShrink: 0, display: 'inline-flex', alignItems: 'center' }}
+ >
+ {adornment}
+ </Box>
+ )}
</Paper>
);
}
@@ -193,7 +233,7 @@ function SelectedItemsSummary({ entries, dirProp, defaultCollapsed }: Props) {
}}
>
<ButtonBase
- onClick={() => setExpanded((v) => !v)}
+ onClick={toggleExpanded}
sx={{
display: 'flex',
alignItems: 'center',
@@ -203,7 +243,7 @@ function SelectedItemsSummary({ entries, dirProp, defaultCollapsed }: Props) {
justifyContent: 'flex-start',
textAlign: 'left',
}}
- aria-expanded={expanded}
+ aria-expanded={isExpanded}
aria-label={t('core:selectedFilesAndFolders')}
>
<Stack
@@ -257,13 +297,13 @@ function SelectedItemsSummary({ entries, dirProp, defaultCollapsed }: Props) {
)}
</Typography>
</Box>
- {expanded ? (
+ {isExpanded ? (
<ExpandLess fontSize="small" />
) : (
<ExpandMore fontSize="small" />
)}
</ButtonBase>
- <Collapse in={expanded} unmountOnExit>
+ <Collapse in={isExpanded} unmountOnExit>
<Box sx={{ borderTop: '1px solid', borderColor: 'divider' }}>
<List
dense
@@ -281,6 +321,7 @@ function SelectedItemsSummary({ entries, dirProp, defaultCollapsed }: Props) {
typeof itemSize === 'number' && itemSize > 0
? formatBytes(itemSize)
: null;
+ const adornment = getItemAdornment?.(entry);
return (
<ListItem title={entry.path} key={entry.path} sx={{ gap: 1 }}>
<ListItemIcon sx={{ minWidth: 44 }}>
@@ -291,7 +332,13 @@ function SelectedItemsSummary({ entries, dirProp, defaultCollapsed }: Props) {
/>
</ListItemIcon>
<Box sx={{ flex: 1, minWidth: 0 }}>
- <Typography variant="body2" noWrap>
+ <Typography
+ variant="body2"
+ noWrap
+ sx={{
+ ...(isDimmed?.(entry) && { color: 'text.disabled' }),
+ }}
+ >
{entry.name}
</Typography>
</Box>
@@ -304,6 +351,17 @@ function SelectedItemsSummary({ entries, dirProp, defaultCollapsed }: Props) {
{sizeText}
</Typography>
)}
+ {adornment && (
+ <Box
+ sx={{
+ flexShrink: 0,
+ display: 'inline-flex',
+ alignItems: 'center',
+ }}
+ >
+ {adornment}
+ </Box>
+ )}
</ListItem>
);
})}
diff --git a/src/renderer/components/dialogs/components/SettingsGeneral.tsx b/src/renderer/components/dialogs/components/SettingsGeneral.tsx
index 46a6a9ce2..7a235c22f 100644
--- a/src/renderer/components/dialogs/components/SettingsGeneral.tsx
+++ b/src/renderer/components/dialogs/components/SettingsGeneral.tsx
@@ -466,12 +466,32 @@ function SettingsGeneral() {
!persistTagsInSidecarFile && {
label: t('core:fileNameTagSetting'),
jsx: (
- <ListItem>
- <ListItemText primary={t('core:fileNameTagSetting')} />
+ <ListItem
+ title={
+ AppConfig.ExtFilenameTagPlacedAtEnd !== undefined
+ ? t('core:settingExternallyConfigured')
+ : ''
+ }
+ >
+ <ListItemText
+ primary={
+ AppConfig.ExtFilenameTagPlacedAtEnd !== undefined ? (
+ <>
+ {t('core:fileNameTagSetting')}
+ <InfoIcon
+ tooltip={t('core:settingExternallyConfigured')}
+ />
+ </>
+ ) : (
+ t('core:fileNameTagSetting')
+ )
+ }
+ />
<ToggleButtonGroup
value={filenameTagPlacedAtEnd}
size="small"
exclusive
+ disabled={AppConfig.ExtFilenameTagPlacedAtEnd !== undefined}
>
<TsToggleButton
value={false}
diff --git a/src/renderer/hooks/ChatProvider.tsx b/src/renderer/hooks/ChatProvider.tsx
index 6e93e27ca..2fb9ac7d3 100644
--- a/src/renderer/hooks/ChatProvider.tsx
+++ b/src/renderer/hooks/ChatProvider.tsx
@@ -368,13 +368,15 @@ export const ChatContextProvider = ({ children }: ChatContextProviderProps) => {
* return true if model is loaded successful false otherwise
*/
function checkOllamaModels(): Promise<boolean> {
+ if (!defaultAiProvider) {
+ // No AI provider configured/enabled — generation cannot start.
+ return Promise.resolve(false);
+ }
if (!models.current || models.current.length === 0) {
- if (defaultAiProvider) {
- return getOllamaClient(defaultAiProvider.url).then((client) => {
- ollamaClient.current = client;
- return refreshOllamaModels();
- });
- }
+ return getOllamaClient(defaultAiProvider.url).then((client) => {
+ ollamaClient.current = client;
+ return refreshOllamaModels();
+ });
}
return Promise.resolve(true);
}
@@ -1163,7 +1165,13 @@ export const ChatContextProvider = ({ children }: ChatContextProviderProps) => {
showNotification(t('core:ollamaConnectionError'));
return Promise.resolve(undefined);
}
- return Promise.resolve(entry);
+ // Extension is neither image, text/pdf nor a folder — skip it instead
+ // of resolving the unchanged entry (which would mark it processed and
+ // could overwrite an existing description with undefined).
+ showNotification(
+ t('core:generationNotSupportedFor', { name: entry.name }),
+ );
+ return Promise.resolve(undefined);
} else {
showNotification(t('core:noModelsLoaded'));
return Promise.resolve(undefined);
diff --git a/src/renderer/locales/en/core.json b/src/renderer/locales/en/core.json
index bec87e16c..c450048d0 100644
--- a/src/renderer/locales/en/core.json
+++ b/src/renderer/locales/en/core.json
@@ -1050,6 +1050,9 @@
"modelNotFoundTryPull": "Model not found, try pulling it first",
"ollamaConnectionError": "There is a problem with the Ollama service connection",
"tagsGenerationNotSupportedFor": "Tags generation not supported for: {{name}}",
+ "generationNotSupportedFor": "AI generation not supported for: {{name}}",
+ "aiNoProviderConfigured": "No AI provider is configured. Open the AI settings to add one.",
+ "aiNoSupportedFiles": "None of the selected items can be processed by the AI.",
"fileCreated": "File '{{name}}' created.",
"errorCreatingNamedFile": "Error creating file '{{name}}'",
"errorCreatingFileInDir": "Error creating file in '{{dir}}'",