mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-10-12 20:49:53 +08:00
- stores/versions-store.ts, hooks/use-session-manager.ts, lib/session-storage.ts: remove the diagramHistory conversion layer, the localStorage chat migration and the empty templates store - stores/canvas-store.ts, lib/drawio/editor-bridge.ts: remove the pages list nothing read - components/chat/chat-engine.tsx: use the context's chartXMLRef and latestSvgRef instead of local copies, subscribe to one settings field, stop prefetching quota limits (lib/use-quota-manager.tsx takes the values from the 429 body), readDiagramFile delegates to the MCP loader (which now strips XML prologs and accepts <svg:svg>) - contexts/diagram-context.tsx: one requestTaggedExport path for thumbnails, validation, fetch and save; fetchDiagramXml replaces handleExport plus the exported resolver map - hooks/use-validate-diagram.ts and app/api/validate-diagram: plain fetch returning JSON instead of a streamed object nobody consumed - hooks/use-diagram-tool-handlers.ts: drop the DEBUG blocks; canvas vars inheritance lives in placeOnPage (lib/diagram-pages.ts) - lobby-hero, icon-button, drawio-frame: remove unreachable branches and unused props
83 lines
2.4 KiB
TypeScript
83 lines
2.4 KiB
TypeScript
"use client"
|
|
|
|
import { useCallback } from "react"
|
|
import { toast } from "sonner"
|
|
import { QuotaLimitToast } from "@/components/quota-limit-toast"
|
|
import { useDictionary } from "@/hooks/use-dictionary"
|
|
import { formatMessage } from "@/lib/i18n/utils"
|
|
|
|
export interface QuotaConfig {
|
|
onConfigModel?: () => void
|
|
}
|
|
|
|
/**
|
|
* Hook for displaying quota limit toasts.
|
|
* Server-side handles actual quota enforcement via DynamoDB, and its 429
|
|
* responses carry the used and limit values shown here.
|
|
*/
|
|
export function useQuotaManager(config: QuotaConfig): {
|
|
showQuotaLimitToast: (used: number, limit: number) => void
|
|
showTokenLimitToast: (used: number, limit: number) => void
|
|
showTPMLimitToast: (limit: number) => void
|
|
} {
|
|
const { onConfigModel } = config
|
|
const dict = useDictionary()
|
|
|
|
// Show quota limit toast (request-based)
|
|
const showQuotaLimitToast = useCallback(
|
|
(used: number, limit: number) => {
|
|
toast.custom(
|
|
(t) => (
|
|
<QuotaLimitToast
|
|
used={used}
|
|
limit={limit}
|
|
onDismiss={() => toast.dismiss(t)}
|
|
onConfigModel={onConfigModel}
|
|
/>
|
|
),
|
|
{ duration: 15000 },
|
|
)
|
|
},
|
|
[onConfigModel],
|
|
)
|
|
|
|
// Show token limit toast
|
|
const showTokenLimitToast = useCallback(
|
|
(used: number, limit: number) => {
|
|
toast.custom(
|
|
(t) => (
|
|
<QuotaLimitToast
|
|
type="token"
|
|
used={used}
|
|
limit={limit}
|
|
onDismiss={() => toast.dismiss(t)}
|
|
onConfigModel={onConfigModel}
|
|
/>
|
|
),
|
|
{ duration: 15000 },
|
|
)
|
|
},
|
|
[onConfigModel],
|
|
)
|
|
|
|
// Show TPM limit toast
|
|
const showTPMLimitToast = useCallback(
|
|
(limit: number) => {
|
|
const limitDisplay =
|
|
limit >= 1000 ? `${limit / 1000}k` : String(limit)
|
|
const message = formatMessage(dict.quota.tpmMessageDetailed, {
|
|
limit: limitDisplay,
|
|
seconds: 60,
|
|
})
|
|
toast.error(message, { duration: 8000 })
|
|
},
|
|
[dict],
|
|
)
|
|
|
|
return {
|
|
showQuotaLimitToast,
|
|
showTokenLimitToast,
|
|
showTPMLimitToast,
|
|
}
|
|
}
|