Initial import

This commit is contained in:
how2ice
2026-04-21 03:33:23 +09:00
commit 9e4b70f1f1
495 changed files with 94680 additions and 0 deletions

View File

@@ -0,0 +1,94 @@
import { useEffect, useState } from 'react';
import { chatConnectionGateway } from '../data/chatConnectionGateway';
import { chatGateway } from '../data/chatGateway';
import type { ChatRuntimeJobDetail, ChatRuntimeSnapshot } from '../../mainChatPanel/types';
type UseRuntimeDataOptions = {
activeSessionId: string;
isDeferringAuxiliaryChatRequests: boolean;
};
export function useRuntimeData({
activeSessionId,
isDeferringAuxiliaryChatRequests,
}: UseRuntimeDataOptions) {
const [runtimeSnapshot, setRuntimeSnapshot] = useState<ChatRuntimeSnapshot | null>(null);
const [runtimeJobDetail, setRuntimeJobDetail] = useState<ChatRuntimeJobDetail | null>(null);
useEffect(() => {
let isCancelled = false;
const loadRuntimeSnapshot = async () => {
try {
const snapshot = await chatGateway.fetchRuntimeSnapshot();
if (!isCancelled) {
setRuntimeSnapshot(snapshot);
chatConnectionGateway.setSharedRuntimeSnapshot(snapshot);
}
} catch {
if (!isCancelled) {
setRuntimeSnapshot(null);
chatConnectionGateway.setSharedRuntimeSnapshot(null);
}
}
};
void loadRuntimeSnapshot();
return () => {
isCancelled = true;
};
}, []);
useEffect(() => {
if (!activeSessionId.trim()) {
return;
}
if (isDeferringAuxiliaryChatRequests) {
return;
}
let isCancelled = false;
const syncRuntimeSnapshotForActiveSession = async () => {
try {
const snapshot = await chatGateway.fetchRuntimeSnapshot();
if (!isCancelled) {
setRuntimeSnapshot(snapshot);
chatConnectionGateway.setSharedRuntimeSnapshot(snapshot);
}
} catch {
if (!isCancelled) {
setRuntimeSnapshot(null);
chatConnectionGateway.setSharedRuntimeSnapshot(null);
}
}
};
void syncRuntimeSnapshotForActiveSession();
return () => {
isCancelled = true;
};
}, [activeSessionId, isDeferringAuxiliaryChatRequests]);
const handleRuntimeEvent = (snapshot: ChatRuntimeSnapshot) => {
setRuntimeSnapshot(snapshot);
chatConnectionGateway.setSharedRuntimeSnapshot(snapshot);
};
const handleRuntimeDetailEvent = (detail: ChatRuntimeJobDetail) => {
setRuntimeJobDetail(detail);
};
return {
runtimeSnapshot,
runtimeJobDetail,
setRuntimeSnapshot,
handleRuntimeEvent,
handleRuntimeDetailEvent,
};
}