mirror of
https://github.com/hanzoai/commerce.git
synced 2026-10-30 15:08:42 +00:00
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans, usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0. Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
"use client"
|
|
|
|
import { createContext, useContext, useRef, useState, type ReactNode } from "react"
|
|
|
|
type AiAssistantContextType = {
|
|
chatOpened: boolean
|
|
setChatOpened: (v: boolean) => void
|
|
inputRef: React.RefObject<HTMLTextAreaElement | null>
|
|
contentRef: React.RefObject<HTMLDivElement | null>
|
|
loading: boolean
|
|
isCaptchaLoaded: boolean
|
|
submitQuery: (q: string) => void
|
|
deepThinkingEnabled: boolean
|
|
toggleDeepThinking: () => void
|
|
suggestions: string[]
|
|
hideAiToolsMessage: boolean
|
|
}
|
|
|
|
const AiAssistantContext = createContext<AiAssistantContextType>({
|
|
chatOpened: false,
|
|
setChatOpened: () => {},
|
|
inputRef: { current: null },
|
|
contentRef: { current: null },
|
|
loading: false,
|
|
isCaptchaLoaded: false,
|
|
submitQuery: () => {},
|
|
deepThinkingEnabled: false,
|
|
toggleDeepThinking: () => {},
|
|
suggestions: [],
|
|
hideAiToolsMessage: true,
|
|
})
|
|
|
|
export function useAiAssistant() {
|
|
return useContext(AiAssistantContext)
|
|
}
|
|
|
|
export function AiAssistantProvider({ children }: { children: ReactNode }) {
|
|
const [chatOpened, setChatOpened] = useState(false)
|
|
const inputRef = useRef<HTMLTextAreaElement>(null)
|
|
const contentRef = useRef<HTMLDivElement>(null)
|
|
|
|
return (
|
|
<AiAssistantContext.Provider
|
|
value={{
|
|
chatOpened,
|
|
setChatOpened,
|
|
inputRef,
|
|
contentRef,
|
|
loading: false,
|
|
isCaptchaLoaded: false,
|
|
submitQuery: () => {},
|
|
deepThinkingEnabled: false,
|
|
toggleDeepThinking: () => {},
|
|
suggestions: [],
|
|
hideAiToolsMessage: true,
|
|
}}
|
|
>
|
|
{children}
|
|
</AiAssistantContext.Provider>
|
|
)
|
|
}
|
|
|
|
export type AiAssistantThreadItem = {
|
|
type: "question" | "answer"
|
|
content: string
|
|
}
|