mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-10-11 20:19:51 +08:00
fix: what the batch C review found
- A redirect followed for a custom base URL (quota on) no longer carries
the user's key or cookies to another origin, as fetch itself does, and
a private address may redirect to another private one (already counted).
- The admin Test of an Ollama or Vertex AI entry without a URL goes where
chat sends that entry's key: the environment's own URL variable, for
Ollama else the local default. The Test of an Ollama Cloud key without
a URL went to the cloud while chat went to local Ollama.
- Chat saves: each save notes the chat on screen and the order of the
reads before reading its data. A save read before switching chats no
longer writes into the chat switched to, and a copy that waited for its
thumbnail no longer replaces a newer one.
- "Continue without saving" keeps its button when a later auto-save fails,
and goes away when a new message is sent.
- A screenshot check that was waiting for its image when the user pressed
Stop stays skipped after the next message.
- MCP History: draw.io's own copy of a diagram (after get_diagram) no
longer adds an entry without a picture; a change of background is still
its own version. The tab ignores an edit's answer that arrives after a
newer AI write loaded.
- Desktop: a deleted preset is not brought back by a failed switch, and a
request naming no preset does not stop a rollback. An origin keeping
an access code counts as having settings.
- .env: a quoted value ending in a backslash ("C:\dir\") is read as dotenv
reads it.
- The tool card no longer crashes on an id that does not turn into text;
an older Test's success timer no longer ends a newer Test's spinner.
- Tests that passed without their fix now check it.
This commit is contained in:
@@ -64,9 +64,11 @@ interface UseDiagramToolHandlersParams {
|
||||
validateDiagram?: ValidateDiagramFn
|
||||
enableVlmValidation?: boolean
|
||||
sessionId?: string
|
||||
// The user pressed Stop: a screenshot check that has not started is
|
||||
// skipped (one already running is cancelled by the caller)
|
||||
isStopped?: () => boolean
|
||||
// Called when a screenshot check begins; the function it returns
|
||||
// tells whether the user pressed Stop in this turn, also after the next
|
||||
// message was sent. A check that has not started then is skipped (one
|
||||
// already running is cancelled by the caller).
|
||||
watchStop?: () => () => boolean
|
||||
onValidationStateChange?: (
|
||||
toolCallId: string,
|
||||
state: ValidationState,
|
||||
@@ -93,7 +95,7 @@ export function useDiagramToolHandlers({
|
||||
validateDiagram,
|
||||
enableVlmValidation = true,
|
||||
sessionId,
|
||||
isStopped,
|
||||
watchStop,
|
||||
onValidationStateChange,
|
||||
}: UseDiagramToolHandlersParams) {
|
||||
// Helper to update validation state
|
||||
@@ -252,6 +254,7 @@ ${finalXml}
|
||||
validateDiagram
|
||||
) {
|
||||
let capturedPngData: string | null = null
|
||||
const stopped = watchStop?.()
|
||||
try {
|
||||
// Notify UI that we're starting capture
|
||||
updateValidationState(toolCall.toolCallId, "capturing")
|
||||
@@ -263,7 +266,7 @@ ${finalXml}
|
||||
capturedPngData = await captureValidationPng()
|
||||
// Stopped while the screenshot was taken: no check. The
|
||||
// chat waits for this handler, so it must end now.
|
||||
if (isStopped?.()) {
|
||||
if (stopped?.()) {
|
||||
updateValidationState(toolCall.toolCallId, "skipped")
|
||||
} else if (capturedPngData) {
|
||||
if (DEBUG) {
|
||||
|
||||
@@ -28,6 +28,13 @@ export interface SessionData {
|
||||
diagramHistory?: { svg: string; xml: string }[]
|
||||
}
|
||||
|
||||
// Taken right before a save's data is read: the chat on screen then, and
|
||||
// the order of the reads
|
||||
export interface SaveTicket {
|
||||
generation: number
|
||||
seq: number
|
||||
}
|
||||
|
||||
export interface UseSessionManagerReturn {
|
||||
// State
|
||||
sessions: SessionMetadata[]
|
||||
@@ -39,17 +46,18 @@ export interface UseSessionManagerReturn {
|
||||
// Actions
|
||||
switchSession: (id: string) => Promise<SessionData | null>
|
||||
deleteSession: (id: string) => Promise<{ wasCurrentSession: boolean }>
|
||||
// chatGeneration: getChatGeneration() when the save was scheduled (by
|
||||
// default, now); the save is dropped if another chat is on screen when
|
||||
// its turn comes
|
||||
// ticket: getSaveTicket() before the data was read (by default, now).
|
||||
// The save is dropped if another chat is on screen when its turn comes,
|
||||
// or if a copy of this chat read later was saved already.
|
||||
// Resolves to false when the save failed (the user was told)
|
||||
saveCurrentSession: (
|
||||
data: SessionData,
|
||||
chatGeneration?: number,
|
||||
ticket?: SaveTicket,
|
||||
) => Promise<boolean>
|
||||
refreshSessions: () => Promise<void>
|
||||
clearCurrentSession: () => void
|
||||
getChatGeneration: () => number
|
||||
getSaveTicket: () => SaveTicket
|
||||
}
|
||||
|
||||
// Reading the session list loads every stored session in full, and window
|
||||
@@ -91,6 +99,9 @@ export function useSessionManager(
|
||||
const chatGenerationRef = useRef(0)
|
||||
// Saves run one at a time, so two saves of a new chat create it once
|
||||
const saveQueueRef = useRef<Promise<unknown>>(Promise.resolve())
|
||||
// The last ticket number, and that of the newest data saved
|
||||
const saveSeqRef = useRef(0)
|
||||
const savedSeqRef = useRef(0)
|
||||
|
||||
const changeChat = useCallback((session: ChatSession | null) => {
|
||||
chatGenerationRef.current++
|
||||
@@ -140,14 +151,17 @@ export function useSessionManager(
|
||||
if (window.electronAPI?.chatsLoaded) {
|
||||
const count = await readSessionCount()
|
||||
// The app saves an empty config on its first load; the
|
||||
// providers are what holds the keys
|
||||
// providers are what holds the keys, besides an access
|
||||
// code
|
||||
let hasSettings = true
|
||||
try {
|
||||
const config = JSON.parse(
|
||||
localStorage.getItem(STORAGE_KEYS.modelConfigs) ??
|
||||
"{}",
|
||||
)
|
||||
hasSettings = (config.providers?.length ?? 0) > 0
|
||||
hasSettings =
|
||||
(config.providers?.length ?? 0) > 0 ||
|
||||
!!localStorage.getItem(STORAGE_KEYS.accessCode)
|
||||
} catch {
|
||||
// Unreadable: treat as settings, and stay
|
||||
}
|
||||
@@ -277,12 +291,18 @@ export function useSessionManager(
|
||||
|
||||
// Save current session data (debounced externally by caller)
|
||||
const saveCurrentSession = useCallback(
|
||||
(data: SessionData, chatGeneration?: number): Promise<boolean> => {
|
||||
// The data is of the chat on screen when the save was asked for
|
||||
const generation = chatGeneration ?? chatGenerationRef.current
|
||||
(data: SessionData, ticket?: SaveTicket): Promise<boolean> => {
|
||||
// The data is of the chat on screen when it was read
|
||||
const { generation, seq } = ticket ?? {
|
||||
generation: chatGenerationRef.current,
|
||||
seq: ++saveSeqRef.current,
|
||||
}
|
||||
const run = async (): Promise<boolean> => {
|
||||
// That chat is no longer on screen (leaving it saved it)
|
||||
if (generation !== chatGenerationRef.current) return true
|
||||
// A copy read later was saved already (one that waited for
|
||||
// its thumbnail must not undo it)
|
||||
if (seq < savedSeqRef.current) return true
|
||||
// Nothing can be stored without IndexedDB
|
||||
if (!isIndexedDBAvailable()) return true
|
||||
// The user may put another chat on screen while this one is
|
||||
@@ -308,6 +328,7 @@ export function useSessionManager(
|
||||
notifySaveFailed(dict.errors.sessionSaveFailed)
|
||||
return false
|
||||
}
|
||||
savedSeqRef.current = seq
|
||||
await enforceSessionLimit()
|
||||
if (stillOnScreen()) {
|
||||
currentSessionRef.current = newSession
|
||||
@@ -342,6 +363,7 @@ export function useSessionManager(
|
||||
notifySaveFailed(dict.errors.sessionSaveFailed)
|
||||
return false
|
||||
}
|
||||
savedSeqRef.current = seq
|
||||
if (stillOnScreen()) {
|
||||
currentSessionRef.current = updatedSession
|
||||
setCurrentSession(updatedSession)
|
||||
@@ -382,6 +404,14 @@ export function useSessionManager(
|
||||
|
||||
const getChatGeneration = useCallback(() => chatGenerationRef.current, [])
|
||||
|
||||
const getSaveTicket = useCallback(
|
||||
(): SaveTicket => ({
|
||||
generation: chatGenerationRef.current,
|
||||
seq: ++saveSeqRef.current,
|
||||
}),
|
||||
[],
|
||||
)
|
||||
|
||||
return {
|
||||
sessions,
|
||||
currentSessionId,
|
||||
@@ -394,5 +424,6 @@ export function useSessionManager(
|
||||
refreshSessions,
|
||||
clearCurrentSession,
|
||||
getChatGeneration,
|
||||
getSaveTicket,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user