mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
import type { ReactNode } from 'react'
|
|
import { createContext, useContext } from 'react'
|
|
import type { ApiClient } from '@/api/client'
|
|
import type { TerminalToolDisplayMode } from '@/hooks/useTerminalToolDisplayMode'
|
|
import type { SessionMetadataSummary } from '@/types/api'
|
|
|
|
export type HappyChatContextValue = {
|
|
api: ApiClient
|
|
sessionId: string
|
|
metadata: SessionMetadataSummary | null
|
|
terminalToolDisplayMode: TerminalToolDisplayMode
|
|
disabled: boolean
|
|
onRefresh: () => void
|
|
onRetryMessage?: (localId: string) => void
|
|
}
|
|
|
|
const HappyChatContext = createContext<HappyChatContextValue | null>(null)
|
|
|
|
export function HappyChatProvider(props: { value: HappyChatContextValue; children: ReactNode }) {
|
|
return (
|
|
<HappyChatContext.Provider value={props.value}>
|
|
{props.children}
|
|
</HappyChatContext.Provider>
|
|
)
|
|
}
|
|
|
|
export function useHappyChatContext(): HappyChatContextValue {
|
|
const ctx = useContext(HappyChatContext)
|
|
if (!ctx) {
|
|
throw new Error('HappyChatContext is missing')
|
|
}
|
|
return ctx
|
|
}
|