feat: save ai summary as description, close #3478
This commit is contained in:
parent
54e1be0096
commit
b472db3b8e
|
|
@ -178,6 +178,13 @@ export function useActionLanguage() {
|
|||
) as SupportedLanguages
|
||||
}
|
||||
|
||||
export function getActionLanguage() {
|
||||
const { actionLanguage, language } = getGeneralSettingsInternal()
|
||||
return (
|
||||
actionLanguage === DEFAULT_ACTION_LANGUAGE ? language : actionLanguage
|
||||
) as SupportedLanguages
|
||||
}
|
||||
|
||||
export const subscribeShouldUseIndexedDB = (callback: (value: boolean) => void) =>
|
||||
jotaiStore.sub(__generalSettingAtom, () => callback(getGeneralSettingsInternal().dataPersist))
|
||||
|
||||
|
|
|
|||
|
|
@ -16,10 +16,13 @@ import { useTranslation } from "react-i18next"
|
|||
import { toast } from "sonner"
|
||||
|
||||
import { getReadabilityContent, getReadabilityStatus, ReadabilityStatus } from "~/atoms/readability"
|
||||
import { useIntegrationSettingKey } from "~/atoms/settings/integration"
|
||||
import { getActionLanguage } from "~/atoms/settings/general"
|
||||
import { getIntegrationSettings, useIntegrationSettingKey } from "~/atoms/settings/integration"
|
||||
import { useRouteParams } from "~/hooks/biz/useRouteParams"
|
||||
import { tipcClient } from "~/lib/client"
|
||||
import { parseHtml } from "~/lib/parse-html"
|
||||
import { queryClient } from "~/lib/query-client"
|
||||
import { Queries } from "~/queries"
|
||||
import type { FlatEntryModel } from "~/store/entry"
|
||||
import { useEntryStore } from "~/store/entry"
|
||||
|
||||
|
|
@ -464,29 +467,6 @@ const useRegisterCuboxCommands = () => {
|
|||
const enableCuboxAutoMemo = useIntegrationSettingKey("enableCuboxAutoMemo")
|
||||
const cuboxAvailable = enableCubox && !!cuboxToken
|
||||
|
||||
const buildUrlRequestBody = (entry: FlatEntryModel) => {
|
||||
return {
|
||||
type: "url",
|
||||
content: entry.entries.url || "",
|
||||
title: entry.entries.title || "",
|
||||
description: entry.entries.description || "",
|
||||
tags: [],
|
||||
folder: "",
|
||||
}
|
||||
}
|
||||
|
||||
const buildMemoRequestBody = (entry: FlatEntryModel, selectedText: string) => {
|
||||
return {
|
||||
type: "memo",
|
||||
content: selectedText,
|
||||
title: entry.entries.title || "",
|
||||
description: entry.entries.description || "",
|
||||
tags: [],
|
||||
folder: "",
|
||||
source_url: entry.entries.url,
|
||||
}
|
||||
}
|
||||
|
||||
useRegisterCommandEffect(
|
||||
!cuboxAvailable
|
||||
? []
|
||||
|
|
@ -539,3 +519,42 @@ const useRegisterCuboxCommands = () => {
|
|||
},
|
||||
)
|
||||
}
|
||||
|
||||
const getDescription = (entry: FlatEntryModel) => {
|
||||
const actionLanguage = getActionLanguage()
|
||||
const { saveSummaryAsDescription } = getIntegrationSettings()
|
||||
|
||||
if (!saveSummaryAsDescription) {
|
||||
return entry.entries.description || ""
|
||||
}
|
||||
const summary = queryClient
|
||||
.getQueriesData({
|
||||
queryKey: Queries.ai.summary({ entryId: entry.entries.id, language: actionLanguage }).key,
|
||||
})
|
||||
.at(0)
|
||||
?.at(1) as string | undefined
|
||||
return summary || entry.entries.description || ""
|
||||
}
|
||||
|
||||
const buildUrlRequestBody = (entry: FlatEntryModel) => {
|
||||
return {
|
||||
type: "url",
|
||||
content: entry.entries.url || "",
|
||||
title: entry.entries.title || "",
|
||||
description: getDescription(entry),
|
||||
tags: [],
|
||||
folder: "",
|
||||
}
|
||||
}
|
||||
|
||||
const buildMemoRequestBody = (entry: FlatEntryModel, selectedText: string) => {
|
||||
return {
|
||||
type: "memo",
|
||||
content: selectedText,
|
||||
title: entry.entries.title || "",
|
||||
description: getDescription(entry),
|
||||
tags: [],
|
||||
folder: "",
|
||||
source_url: entry.entries.url,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@ export const useRegisterCommandEffect = (
|
|||
const { t } = useTranslation()
|
||||
useEffect(() => {
|
||||
if (!Array.isArray(options)) {
|
||||
return registerCommand(options)
|
||||
const unsubscribe = registerCommand(options)
|
||||
return () => unsubscribe()
|
||||
}
|
||||
|
||||
const unsubscribes = options.map((option) => registerCommand(option))
|
||||
|
|
|
|||
|
|
@ -210,6 +210,9 @@ export const SettingIntegration = () => {
|
|||
label: t("integration.cubox.autoMemo.label"),
|
||||
description: t("integration.cubox.autoMemo.description"),
|
||||
}),
|
||||
defineSettingItem("saveSummaryAsDescription", {
|
||||
label: t("integration.save_ai_summary_as_description.label"),
|
||||
}),
|
||||
BottomTip,
|
||||
]}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -259,6 +259,7 @@
|
|||
"integration.readwise.title": "Readwise",
|
||||
"integration.readwise.token.description": "You can get it here: ",
|
||||
"integration.readwise.token.label": "Readwise Access Token",
|
||||
"integration.save_ai_summary_as_description.label": "Save AI Summary as description",
|
||||
"integration.sidebar_title": "Integration",
|
||||
"integration.tip": "Tip: Your sensitive data is stored locally and is not uploaded to the server.",
|
||||
"integration.title": "Integration",
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ export const defaultUISettings: UISettings = {
|
|||
|
||||
export const defaultIntegrationSettings: IntegrationSettings = {
|
||||
// eagle
|
||||
enableEagle: true,
|
||||
enableEagle: false,
|
||||
|
||||
// readwise
|
||||
enableReadwise: false,
|
||||
|
|
@ -120,6 +120,8 @@ export const defaultIntegrationSettings: IntegrationSettings = {
|
|||
enableCubox: false,
|
||||
cuboxToken: "",
|
||||
enableCuboxAutoMemo: false,
|
||||
|
||||
saveSummaryAsDescription: false,
|
||||
}
|
||||
|
||||
export const defaultSettings = {
|
||||
|
|
|
|||
|
|
@ -106,4 +106,6 @@ export interface IntegrationSettings {
|
|||
enableCubox: boolean
|
||||
cuboxToken: string
|
||||
enableCuboxAutoMemo: boolean
|
||||
|
||||
saveSummaryAsDescription: boolean
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue