feat: emit log entries from chat streaming and model operations

This commit is contained in:
Jon Saad-Falcon
2026-03-14 12:54:59 -07:00
parent df91835165
commit dc54555158
2 changed files with 34 additions and 0 deletions
@@ -137,6 +137,12 @@ export function InputArea() {
activeToolCalls: [],
content: '',
});
useAppStore.getState().addLogEntry({
timestamp: Date.now(),
level: 'info',
category: 'chat',
message: `Request: "${content.slice(0, 80)}${content.length > 80 ? '...' : ''}" → ${selectedModel}`,
});
try {
for await (const sseEvent of streamChat(
@@ -149,6 +155,10 @@ export function InputArea() {
setStreamState({ phase: 'Agent thinking...' });
} else if (eventName === 'inference_start') {
setStreamState({ phase: 'Generating...' });
useAppStore.getState().addLogEntry({
timestamp: Date.now(), level: 'info', category: 'chat',
message: `Generating with ${selectedModel}...`,
});
} else if (eventName === 'tool_call_start') {
try {
const data = JSON.parse(sseEvent.data);
@@ -164,6 +174,10 @@ export function InputArea() {
activeToolCalls: [...toolCalls],
});
updateLastAssistant(convId, accumulatedContent, [...toolCalls]);
useAppStore.getState().addLogEntry({
timestamp: Date.now(), level: 'info', category: 'tool',
message: `Calling ${data.tool}(${data.arguments || ''})`,
});
} catch {}
} else if (eventName === 'tool_call_end') {
try {
@@ -213,6 +227,10 @@ export function InputArea() {
const errMsg = err?.message || String(err);
accumulatedContent =
accumulatedContent || `Error: ${errMsg}`;
useAppStore.getState().addLogEntry({
timestamp: Date.now(), level: 'error', category: 'chat',
message: `Stream error: ${errMsg}`,
});
}
} finally {
if (!accumulatedContent) {
@@ -229,6 +247,10 @@ export function InputArea() {
timerRef.current = null;
}
resetStream();
useAppStore.getState().addLogEntry({
timestamp: Date.now(), level: 'info', category: 'chat',
message: `Response: ${accumulatedContent.length} chars`,
});
abortRef.current = null;
fetchSavings()
@@ -99,11 +99,19 @@ export function CommandPalette() {
try {
await pullModel(modelId);
setPullSuccess(modelId);
useAppStore.getState().addLogEntry({
timestamp: Date.now(), level: 'info', category: 'model',
message: `Downloaded ${modelId}`,
});
await refreshModels();
// Auto-select the newly pulled model
setSelectedModel(modelId);
} catch (e: any) {
setPullError(e.message || 'Download failed');
useAppStore.getState().addLogEntry({
timestamp: Date.now(), level: 'error', category: 'model',
message: `Download failed for ${modelId}: ${e.message}`,
});
} finally {
setPulling(null);
}
@@ -114,6 +122,10 @@ export function CommandPalette() {
setDeleting(modelId);
try {
await deleteModel(modelId);
useAppStore.getState().addLogEntry({
timestamp: Date.now(), level: 'info', category: 'model',
message: `Deleted ${modelId}`,
});
await refreshModels();
if (selectedModel === modelId) {
const remaining = models.filter((m) => m.id !== modelId);