Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

2.9 KB
Raw Blame
'use client'

import type { RefObject } from 'react'
import type { ChatConfig, ChatItem, OnFeedback } from '../types'
import type { Theme } from './theme/theme'
import type { AppConversationData, AppData, AppMeta, ConversationItem } from '@/models/share'
import { noop } from 'es-toolkit/function'
import { createContext, useContext } from 'use-context-selector'
import { AppSourceType } from '@/service/share'

export type EmbeddedChatbotContextValue = {
  appMeta: AppMeta | null
  appData: AppData | null
  appParams: ChatConfig | null
  appChatListDataLoading?: boolean
  currentConversationId: string
  currentConversationItem?: ConversationItem
  appPrevChatList: ChatItem[]
  pinnedConversationList: AppConversationData['data']
  conversationList: AppConversationData['data']
  newConversationInputs: Record<string, any>
  newConversationInputsRef: RefObject<Record<string, any>>
  handleNewConversationInputsChange: (v: Record<string, any>) => void
  inputsForms: any[]
  handleNewConversation: () => void
  handleStartChat: (callback?: () => void) => void
  handleChangeConversation: (conversationId: string) => void
  handleNewConversationCompleted: (newConversationId: string) => void
  chatShouldReloadKey: string
  isBelowSm: boolean
  isInstalledApp: boolean
  appSourceType: AppSourceType
  allowResetChat: boolean
  appId?: string
  disableFeedback?: boolean
  handleFeedback: OnFeedback
  currentChatInstanceRef: RefObject<{ handleStop: () => void }>
  theme?: Theme
  clearChatList?: boolean
  setClearChatList: (state: boolean) => void
  isResponding?: boolean
  setIsResponding: (state: boolean) => void
  currentConversationInputs: Record<string, any> | null
  setCurrentConversationInputs: (v: Record<string, any>) => void
  allInputsHidden: boolean
  initUserVariables?: {
    name?: string
    avatar_url?: string
  }
}

export const EmbeddedChatbotContext = createContext<EmbeddedChatbotContextValue>({
  appData: null,
  appMeta: null,
  appParams: null,
  appChatListDataLoading: false,
  currentConversationId: '',
  appPrevChatList: [],
  pinnedConversationList: [],
  conversationList: [],
  newConversationInputs: {},
  newConversationInputsRef: { current: {} },
  handleNewConversationInputsChange: noop,
  inputsForms: [],
  handleNewConversation: noop,
  handleStartChat: noop,
  handleChangeConversation: noop,
  handleNewConversationCompleted: noop,
  chatShouldReloadKey: '',
  isBelowSm: false,
  appSourceType: AppSourceType.webApp,
  isInstalledApp: false,
  allowResetChat: true,
  handleFeedback: () => Promise.resolve(),
  currentChatInstanceRef: { current: { handleStop: noop } },
  clearChatList: false,
  setClearChatList: noop,
  isResponding: false,
  setIsResponding: noop,
  currentConversationInputs: {},
  setCurrentConversationInputs: noop,
  allInputsHidden: false,
  initUserVariables: {},
})
export const useEmbeddedChatbotContext = () => useContext(EmbeddedChatbotContext)