create branch dev and commit code

This commit is contained in:
thanawat saiyota 2026-06-09 10:50:59 +07:00
parent 3b70cc9fe8
commit ea68fa5cc4
44 changed files with 12421 additions and 214 deletions

View file

@ -12,6 +12,24 @@ import {
toppingGroupFromServerQuery,
toppingListFromServerQuery
} from '../stores/recipeStore';
import {
handleSheetStreamStart,
handleSheetStreamChunk,
handleSheetStreamEnd,
handleSheetStreamError,
handleCatalogsResponse,
handleListMenuResponse,
sheetCatalogsLoading,
handleRawStreamHeader,
handleRawStreamChunk,
handleRawStreamEnd
} from '../stores/sheetStore';
import {
handleGenLayoutBatchStart,
handleGenLayoutFile,
handleGenLayoutBatchEnd,
handleGenLayoutError
} from '../stores/genLayoutStore';
import { buildOverviewFromServer } from '$lib/data/recipeService';
import { auth } from '../client/firebase';
import { type RecipeVersion } from '$lib/models/recipe_version.model';
@ -202,19 +220,105 @@ const handlers: Record<string, (payload: any) => void> = {
},
stream_patch_update: (p) => {},
notify: (p) => {
let noti_level = p.level ?? 'INFO';
let msg = p.msg ?? `Notify from ${p.from}`;
let target = p.to;
const from = p.from;
const level = p.level ?? 'INFO';
const msg = p.msg;
const target = p.to;
// Handle list-menu response
if (from === 'list-menu') {
const currentUid = auth.currentUser?.uid;
if (target && currentUid && target === currentUid && p.value) {
handleListMenuResponse({ codes: p.value });
}
return;
}
// Handle gen-service responses
if (from === 'gen-service') {
switch (level) {
case 'batch_start':
handleGenLayoutBatchStart({
batch_id: p.batch_id,
total_files: p.total_files,
total_size_bytes: p.total_size_bytes
});
addNotification(`INFO:Gen Layout started (${p.total_files} files)`);
break;
case 'file':
handleGenLayoutFile({
batch_id: p.batch_id,
file_index: p.file_index,
total_files: p.total_files,
file: p.file,
content: p.content,
is_chunked: p.is_chunked,
part_index: p.part_index,
total_parts: p.total_parts,
is_last_part: p.is_last_part
});
break;
case 'batch_end':
handleGenLayoutBatchEnd({
batch_id: p.batch_id,
total_files: p.total_files
});
addNotification('INFO:Gen Layout complete');
break;
case 'ERROR':
handleGenLayoutError(msg);
addNotification(`ERR:Gen Layout error: ${msg}`);
break;
default:
console.log('[GenService] Received:', level, msg);
}
return;
}
if (from === 'sheet-service' && level === 'content') {
const currentUid = auth.currentUser?.uid;
if (target && currentUid && target === currentUid) {
if (!msg && p.content?.catalogs) {
handleCatalogsResponse(p.content);
addNotification(`INFO:Loaded ${p.content.catalogs?.length || 0} catalogs`);
return;
}
// Handle streaming messages (with msg field)
switch (msg) {
case 'start':
handleSheetStreamStart(p);
addNotification('INFO:Sheet data streaming started');
break;
case 'chunk':
handleSheetStreamChunk(p);
break;
case 'end':
handleSheetStreamEnd(p);
addNotification('INFO:Sheet data streaming complete');
break;
case 'error':
handleSheetStreamError(p);
addNotification(`ERR:Sheet streaming error: ${p.content?.error_detail}`);
break;
default:
// Handle other content notifications from sheet-service
console.log('[Sheet] Received content:', p.content);
}
}
return;
}
// Default notification handling
if (target) {
//
let currentUsername = auth.currentUser?.displayName;
if (currentUsername && currentUsername === target) {
addNotification(`${noti_level}:${msg}`);
addNotification(`${level}:${msg}`);
}
} else {
// broadcast to all
addNotification(`${noti_level}:${msg}`);
addNotification(`${level}:${msg}`);
}
},
ui_action: (p) => {
@ -259,12 +363,33 @@ const handlers: Record<string, (payload: any) => void> = {
socketConnectionOfflineCount.set(0);
socketAlreadySendHeartbeat.set(0);
console.log('heartbeat reset offline count');
},
// Raw stream handlers for sheet data (e.g., price)
raw_stream: (p) => {
// Format: raw_stream with subtype in payload
// Header: { subtype: 'price', request_id, header?, country? }
const subtype = p.subtype;
if (subtype) {
handleRawStreamHeader(subtype, p);
}
},
raw_stream_price: (p) => {
// Header for price stream
handleRawStreamHeader('price', p);
},
raw_stream_chunk_price: (p) => {
// Chunk for price stream
handleRawStreamChunk('price', p);
},
raw_stream_end_price: (p) => {
// End for price stream
handleRawStreamEnd('price', p);
}
};
export function handleIncomingMessages(raw: string) {
const msg: WSMessage = JSON.parse(raw);
// console.log(`${new Date().toLocaleTimeString()}:ws msg`, msg);
// console.log(`[WS MSG] type=${msg.type}`, msg.payload);
if (msg == null) {
// error response
addNotification('ERR:No response from server');