Skip to content

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

Add reset prompts button in ai prompts sections (#2367)

Stanimir22d082f8a437
diff --git a/package.json b/package.json
index f8a90e784..b1f599c73 100644
--- a/package.json
+++ b/package.json
@@ -246,7 +246,7 @@
"zod-to-json-schema": "^3.24.1"
},
"optionalDependencies": {
- "@tagspacespro/tagspacespro": "5.0.180"
+ "@tagspacespro/tagspacespro": "5.0.181-alpha.0"
},
"devDependencies": {
"@electron/notarize": "^2.5.0",
diff --git a/src/renderer/components/dialogs/components/SettingsAI.tsx b/src/renderer/components/dialogs/components/SettingsAI.tsx
index b3b54f412..af1687270 100644
--- a/src/renderer/components/dialogs/components/SettingsAI.tsx
+++ b/src/renderer/components/dialogs/components/SettingsAI.tsx
@@ -172,6 +172,14 @@ function SettingsAI(props: Props) {
}
}
+ function resetTemplate(key: string) {
+ const template = aiTemplatesContext.getDefaultTemplate(key);
+ if (template) {
+ aiTemplatesContext.setTemplate(key, template);
+ aiTemplates.current[key] = undefined;
+ }
+ }
+
function cancelSavingTemplate(key: string) {
aiTemplates.current[key] = undefined;
forceUpdate();
@@ -179,6 +187,44 @@ function SettingsAI(props: Props) {
const externalConfig = typeof window.ExtAI !== 'undefined';
+ const actionButtons = (key) => (
+ <InputAdornment position="end">
+ <TsButton
+ variant="contained"
+ data-tid={'save' + key + 'TID'}
+ onClick={() => saveTemplate(key)}
+ style={{
+ // @ts-ignore
+ WebkitAppRegion: 'no-drag',
+ }}
+ >
+ {t('core:save')}
+ </TsButton>
+ <TsButton
+ variant="contained"
+ data-tid={'reset' + key + 'TID'}
+ onClick={() => resetTemplate(key)}
+ style={{
+ // @ts-ignore
+ WebkitAppRegion: 'no-drag',
+ }}
+ >
+ {t('core:resetBtn')}
+ </TsButton>
+ <TsButton
+ variant="contained"
+ data-tid={'cancel' + key + 'TID'}
+ onClick={() => cancelSavingTemplate(key)}
+ style={{
+ // @ts-ignore
+ WebkitAppRegion: 'no-drag',
+ }}
+ >
+ {t('core:cancel')}
+ </TsButton>
+ </InputAdornment>
+ );
+
return (
<div
style={{
@@ -519,36 +565,9 @@ function SettingsAI(props: Props) {
}}
slotProps={{
input: {
- endAdornment: aiTemplates.current[
- 'DEFAULT_QUESTION_PROMPT'
- ] && (
- <InputAdornment position="end">
- <TsButton
- variant="contained"
- data-tid={'saveDefaultQuestionPromptTID'}
- onClick={() => saveTemplate('DEFAULT_QUESTION_PROMPT')}
- style={{
- // @ts-ignore
- WebkitAppRegion: 'no-drag',
- }}
- >
- {t('core:save')}
- </TsButton>
- <TsButton
- variant="contained"
- data-tid={'saveDefaultQuestionPromptTID'}
- onClick={() =>
- cancelSavingTemplate('DEFAULT_QUESTION_PROMPT')
- }
- style={{
- // @ts-ignore
- WebkitAppRegion: 'no-drag',
- }}
- >
- {t('core:cancel')}
- </TsButton>
- </InputAdornment>
- ),
+ endAdornment:
+ aiTemplates.current['DEFAULT_QUESTION_PROMPT'] &&
+ actionButtons('DEFAULT_QUESTION_PROMPT'),
},
}}
/>
@@ -568,34 +587,9 @@ function SettingsAI(props: Props) {
}}
slotProps={{
input: {
- endAdornment: aiTemplates.current[
- 'DEFAULT_SYSTEM_PROMPT'
- ] && (
- <InputAdornment position="end">
- <TsButton
- variant="contained"
- onClick={() => saveTemplate('DEFAULT_SYSTEM_PROMPT')}
- style={{
- // @ts-ignore
- WebkitAppRegion: 'no-drag',
- }}
- >
- {t('core:save')}
- </TsButton>
- <TsButton
- variant="contained"
- onClick={() =>
- cancelSavingTemplate('DEFAULT_SYSTEM_PROMPT')
- }
- style={{
- // @ts-ignore
- WebkitAppRegion: 'no-drag',
- }}
- >
- {t('core:cancel')}
- </TsButton>
- </InputAdornment>
- ),
+ endAdornment:
+ aiTemplates.current['DEFAULT_SYSTEM_PROMPT'] &&
+ actionButtons('DEFAULT_SYSTEM_PROMPT'),
},
}}
/>
@@ -615,30 +609,9 @@ function SettingsAI(props: Props) {
}}
slotProps={{
input: {
- endAdornment: aiTemplates.current['SUMMARIZE_PROMPT'] && (
- <InputAdornment position="end">
- <TsButton
- variant="contained"
- onClick={() => saveTemplate('SUMMARIZE_PROMPT')}
- style={{
- // @ts-ignore
- WebkitAppRegion: 'no-drag',
- }}
- >
- {t('core:save')}
- </TsButton>
- <TsButton
- variant="contained"
- onClick={() => cancelSavingTemplate('SUMMARIZE_PROMPT')}
- style={{
- // @ts-ignore
- WebkitAppRegion: 'no-drag',
- }}
- >
- {t('core:cancel')}
- </TsButton>
- </InputAdornment>
- ),
+ endAdornment:
+ aiTemplates.current['SUMMARIZE_PROMPT'] &&
+ actionButtons('SUMMARIZE_PROMPT'),
},
}}
/>
@@ -659,34 +632,9 @@ function SettingsAI(props: Props) {
}}
slotProps={{
input: {
- endAdornment: aiTemplates.current[
- 'IMAGE_DESCRIPTION_PROMPT'
- ] && (
- <InputAdornment position="end">
- <TsButton
- variant="contained"
- onClick={() => saveTemplate('IMAGE_DESCRIPTION_PROMPT')}
- style={{
- // @ts-ignore
- WebkitAppRegion: 'no-drag',
- }}
- >
- {t('core:save')}
- </TsButton>
- <TsButton
- variant="contained"
- onClick={() =>
- cancelSavingTemplate('IMAGE_DESCRIPTION_PROMPT')
- }
- style={{
- // @ts-ignore
- WebkitAppRegion: 'no-drag',
- }}
- >
- {t('core:cancel')}
- </TsButton>
- </InputAdornment>
- ),
+ endAdornment:
+ aiTemplates.current['IMAGE_DESCRIPTION_PROMPT'] &&
+ actionButtons('IMAGE_DESCRIPTION_PROMPT'),
},
}}
/>
@@ -709,38 +657,10 @@ function SettingsAI(props: Props) {
}}
slotProps={{
input: {
- endAdornment: aiTemplates.current[
- 'IMAGE_DESCRIPTION_STRUCTURED_PROMPT'
- ] && (
- <InputAdornment position="end">
- <TsButton
- variant="contained"
- onClick={() =>
- saveTemplate('IMAGE_DESCRIPTION_STRUCTURED_PROMPT')
- }
- style={{
- // @ts-ignore
- WebkitAppRegion: 'no-drag',
- }}
- >
- {t('core:save')}
- </TsButton>
- <TsButton
- variant="contained"
- onClick={() =>
- cancelSavingTemplate(
- 'IMAGE_DESCRIPTION_STRUCTURED_PROMPT',
- )
- }
- style={{
- // @ts-ignore
- WebkitAppRegion: 'no-drag',
- }}
- >
- {t('core:cancel')}
- </TsButton>
- </InputAdornment>
- ),
+ endAdornment:
+ aiTemplates.current[
+ 'IMAGE_DESCRIPTION_STRUCTURED_PROMPT'
+ ] && actionButtons('IMAGE_DESCRIPTION_STRUCTURED_PROMPT'),
},
}}
/>
@@ -760,34 +680,9 @@ function SettingsAI(props: Props) {
}}
slotProps={{
input: {
- endAdornment: aiTemplates.current[
- 'TEXT_DESCRIPTION_PROMPT'
- ] && (
- <InputAdornment position="end">
- <TsButton
- variant="contained"
- onClick={() => saveTemplate('TEXT_DESCRIPTION_PROMPT')}
- style={{
- // @ts-ignore
- WebkitAppRegion: 'no-drag',
- }}
- >
- {t('core:save')}
- </TsButton>
- <TsButton
- variant="contained"
- onClick={() =>
- cancelSavingTemplate('TEXT_DESCRIPTION_PROMPT')
- }
- style={{
- // @ts-ignore
- WebkitAppRegion: 'no-drag',
- }}
- >
- {t('core:cancel')}
- </TsButton>
- </InputAdornment>
- ),
+ endAdornment:
+ aiTemplates.current['TEXT_DESCRIPTION_PROMPT'] &&
+ actionButtons('TEXT_DESCRIPTION_PROMPT'),
},
}}
/>
@@ -807,32 +702,9 @@ function SettingsAI(props: Props) {
}}
slotProps={{
input: {
- endAdornment: aiTemplates.current['IMAGE_TAGS_PROMPT'] && (
- <InputAdornment position="end">
- <TsButton
- variant="contained"
- onClick={() => saveTemplate('IMAGE_TAGS_PROMPT')}
- style={{
- // @ts-ignore
- WebkitAppRegion: 'no-drag',
- }}
- >
- {t('core:save')}
- </TsButton>
- <TsButton
- variant="contained"
- onClick={() =>
- cancelSavingTemplate('IMAGE_TAGS_PROMPT')
- }
- style={{
- // @ts-ignore
- WebkitAppRegion: 'no-drag',
- }}
- >
- {t('core:cancel')}
- </TsButton>
- </InputAdornment>
- ),
+ endAdornment:
+ aiTemplates.current['IMAGE_TAGS_PROMPT'] &&
+ actionButtons('IMAGE_TAGS_PROMPT'),
},
}}
/>
@@ -852,30 +724,9 @@ function SettingsAI(props: Props) {
}}
slotProps={{
input: {
- endAdornment: aiTemplates.current['TEXT_TAGS_PROMPT'] && (
- <InputAdornment position="end">
- <TsButton
- variant="contained"
- onClick={() => saveTemplate('TEXT_TAGS_PROMPT')}
- style={{
- // @ts-ignore
- WebkitAppRegion: 'no-drag',
- }}
- >
- {t('core:save')}
- </TsButton>
- <TsButton
- variant="contained"
- onClick={() => cancelSavingTemplate('TEXT_TAGS_PROMPT')}
- style={{
- // @ts-ignore
- WebkitAppRegion: 'no-drag',
- }}
- >
- {t('core:cancel')}
- </TsButton>
- </InputAdornment>
- ),
+ endAdornment:
+ aiTemplates.current['TEXT_TAGS_PROMPT'] &&
+ actionButtons('TEXT_TAGS_PROMPT'),
},
}}
/>
diff --git a/src/renderer/tagspaces.namespace.d.ts b/src/renderer/tagspaces.namespace.d.ts
index 4e54487ac..43e33f8a2 100644
--- a/src/renderer/tagspaces.namespace.d.ts
+++ b/src/renderer/tagspaces.namespace.d.ts
@@ -321,6 +321,7 @@ export namespace TS {
type AiTemplatesContextData = {
getTemplate: (key: string) => string;
+ getDefaultTemplate: (key: string) => string;
setTemplate: (key: string, value: string) => void;
};