mirror of
https://github.com/langgenius/dify.git
synced 2026-08-03 03:26:35 +08:00
Co-authored-by: Jingyi-Dify <jingyi.qi@dify.ai> Co-authored-by: yyh <yuanyouhuilyz@gmail.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: hjlarry <hjlarry@163.com> Co-authored-by: Bond Zhu <783504079@qq.com> Co-authored-by: Yansong Zhang <916125788@qq.com> Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com>
38 lines
1005 B
TypeScript
38 lines
1005 B
TypeScript
'use client'
|
|
|
|
import type { ReactNode } from 'react'
|
|
import type { AgentSoulConfigFormState } from './form-state'
|
|
import { createStore, Provider as JotaiProvider } from 'jotai'
|
|
import { useRef } from 'react'
|
|
import { agentComposerDraftAtom, agentComposerOriginalDraftAtom } from './store'
|
|
|
|
function createAgentComposerStore(initialDraft?: AgentSoulConfigFormState) {
|
|
const store = createStore()
|
|
|
|
if (initialDraft)
|
|
store.set(agentComposerDraftAtom, initialDraft)
|
|
if (initialDraft)
|
|
store.set(agentComposerOriginalDraftAtom, initialDraft)
|
|
|
|
return store
|
|
}
|
|
|
|
export function AgentComposerProvider({
|
|
children,
|
|
initialDraft,
|
|
}: {
|
|
children: ReactNode
|
|
initialDraft?: AgentSoulConfigFormState
|
|
}) {
|
|
const storeRef = useRef<ReturnType<typeof createAgentComposerStore> | null>(null)
|
|
if (!storeRef.current)
|
|
storeRef.current = createAgentComposerStore(initialDraft)
|
|
const store = storeRef.current
|
|
|
|
return (
|
|
<JotaiProvider store={store}>
|
|
{children}
|
|
</JotaiProvider>
|
|
)
|
|
}
|