mirror of
https://github.com/langgenius/dify.git
synced 2026-07-29 08:19:34 +08:00
Co-authored-by: yunlu.wen <yunlu.wen@dify.ai> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Yunlu Wen <wylswz@163.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: Yanli 盐粒 <yanli@dify.ai> Co-authored-by: 盐粒 Yanli <beautyyuyanli@gmail.com> Co-authored-by: zyssyz123 <916125788@qq.com> Co-authored-by: 盐粒 Yanli <mail@yanli.one>
38 lines
1.5 KiB
TypeScript
38 lines
1.5 KiB
TypeScript
import type { AgentSoulConfig } from '@dify/contracts/api/console/agent/types.gen'
|
|
import type { AgentSoulConfigFormState } from './form-state'
|
|
import isEqual from 'fast-deep-equal'
|
|
import { atom } from 'jotai'
|
|
import { defaultAgentSoulConfigFormState } from './form-state'
|
|
|
|
export const agentComposerOriginalConfigAtom = atom<AgentSoulConfig | undefined>(undefined)
|
|
export const agentComposerOriginalDraftAtom = atom<AgentSoulConfigFormState | undefined>(defaultAgentSoulConfigFormState)
|
|
export const agentComposerPublishedDraftAtom = atom<AgentSoulConfigFormState | undefined>(defaultAgentSoulConfigFormState)
|
|
export const agentComposerDraftAtom = atom<AgentSoulConfigFormState>(defaultAgentSoulConfigFormState)
|
|
|
|
export const rebaseAgentComposerDraftAtom = atom(null, (_get, set, {
|
|
draft,
|
|
originalConfig,
|
|
}: {
|
|
draft: AgentSoulConfigFormState
|
|
originalConfig?: AgentSoulConfig
|
|
}) => {
|
|
set(agentComposerOriginalConfigAtom, originalConfig)
|
|
set(agentComposerDraftAtom, draft)
|
|
set(agentComposerOriginalDraftAtom, draft)
|
|
set(agentComposerPublishedDraftAtom, draft)
|
|
})
|
|
|
|
export const isAgentComposerDirtyAtom = atom((get) => {
|
|
const originalDraft = get(agentComposerOriginalDraftAtom)
|
|
const draft = get(agentComposerDraftAtom)
|
|
|
|
return !isEqual(draft, originalDraft ?? defaultAgentSoulConfigFormState)
|
|
})
|
|
|
|
export const hasAgentComposerUnpublishedChangesAtom = atom((get) => {
|
|
const publishedDraft = get(agentComposerPublishedDraftAtom)
|
|
const draft = get(agentComposerDraftAtom)
|
|
|
|
return !isEqual(draft, publishedDraft ?? defaultAgentSoulConfigFormState)
|
|
})
|