Co-authored-by: Jingyi-Dify <[email protected]> Co-authored-by: yyh <[email protected]> Co-authored-by: Joel <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: hjlarry <[email protected]> Co-authored-by: Bond Zhu <[email protected]> Co-authored-by: Yansong Zhang <[email protected]> Co-authored-by: yyh <[email protected]>
25 lines
952 B
TypeScript
25 lines
952 B
TypeScript
import type { AgentKnowledgeRetrievalItem } from '../form-state'
|
|
import type { DraftFieldUpdate } from './utils'
|
|
import { atom } from 'jotai'
|
|
import { syncKnowledgeReferenceLabels } from '../reference-labels'
|
|
import { agentComposerDraftAtom } from '../store'
|
|
import { resolveDraftFieldUpdate } from './utils'
|
|
|
|
export const agentComposerKnowledgeRetrievalsAtom = atom(
|
|
get => get(agentComposerDraftAtom).knowledgeRetrievals,
|
|
(get, set, knowledgeRetrievalsUpdate: DraftFieldUpdate<AgentKnowledgeRetrievalItem[]>) => {
|
|
const draft = get(agentComposerDraftAtom)
|
|
const knowledgeRetrievals = resolveDraftFieldUpdate(draft.knowledgeRetrievals, knowledgeRetrievalsUpdate)
|
|
|
|
set(agentComposerDraftAtom, {
|
|
...draft,
|
|
prompt: syncKnowledgeReferenceLabels({
|
|
prompt: draft.prompt,
|
|
currentRetrievals: draft.knowledgeRetrievals,
|
|
nextRetrievals: knowledgeRetrievals,
|
|
}),
|
|
knowledgeRetrievals,
|
|
})
|
|
},
|
|
)
|