Files
ss-tools/frontend/src/lib/stores/datasetReviewSession.js
busya a3c7c402b7 fix(llm): add fetch-models endpoint, fix SQL Lab INSERT (client_id truncation, sync mode, target_column, timestamp normalization)
- Add POST /api/llm/providers/fetch-models route with LLMClient.fetch_models()
- Add target_column to TranslationJob model/schema/service/orchestrator
- Fix SQL Lab execute: truncate client_id to 11 chars (varchar(11))
- Switch SQL Lab to sync mode (runAsync: false) — no Celery workers
- Fix polling: unwrap nested result from Superset query API
- Fix ClickHouse timestamp: normalize float timestamps to YYYY-MM-DD
2026-05-13 20:06:15 +03:00

126 lines
4.5 KiB
JavaScript

// #region DatasetReviewSessionStore [C:4] [TYPE Store] [SEMANTICS dataset, review, session, store, state]
// @BRIEF Manage active dataset review session state including loading, local edits, error capture, and reset semantics.
// @RELATION DEPENDS_ON -> [ApiModule]
// @PRE Consumers provide session-shaped payloads and initialize the store before reading derived session fields.
// @POST Store transitions keep session, loading, error, and dirty flags internally consistent after each helper call.
// @SIDE_EFFECT Mutates the writable dataset review session store in frontend memory.
// @UX_STATE Loading -> Session detail is being fetched
// @UX_STATE Ready -> Session detail available for UI binding
// @UX_STATE Saving -> Updates are being persisted
// @UX_STATE Error -> Failed to load or update session
// #region datasetReviewSession:Store [TYPE Function]
// @PURPOSE: Manage active dataset review session state, including loading, local edits, error capture, and reset semantics for the active review workspace.
// @LAYER: UI
// @RELATION: DEPENDS_ON -> [api_module]
// @PRE: Consumers provide session-shaped payloads when setting or patching state and initialize the store before reading derived session fields.
// @POST: Store transitions keep session, loading, error, and dirty flags internally consistent after each helper call.
// @SIDE_EFFECT: Mutates the writable dataset review session store in frontend memory.
// @DATA_CONTRACT: Input[SessionDetail | Partial<SessionDetail> | boolean | string | null] -> Output[DatasetReviewSessionStoreState]
//
// @UX_STATE: Loading -> Session detail is being fetched.
// @UX_STATE: Ready -> Session detail is available for UI binding.
// @UX_STATE: Saving -> Updates are being persisted.
// @UX_STATE: Error -> Failed to load or update session.
// @UX_STATE: PartialPreview -> Session has preview data but launch gates are not yet satisfied.
// @UX_STATE: LaunchBlocked -> Session remains reviewable while explicit launch blockers are unresolved.
// @UX_REACTIVITY: Uses Svelte writable store for session aggregate.
import { writable } from 'svelte/store';
// [SECTION: INITIAL STATE]
const initialState = {
session: null,
isLoading: false,
isSaving: false,
error: null,
lastUpdated: null,
isDirty: false
};
// [/SECTION]
export const datasetReviewSessionStore = writable(initialState);
/**
* Set active session data
* @param {Object} session - Full SessionDetail aggregate
*/
export function setSession(session) {
datasetReviewSessionStore.update(state => ({
...state,
session,
isLoading: false,
error: null,
lastUpdated: new Date(),
isDirty: false
}));
}
/**
* Update session loading state
* @param {boolean} isLoading
*/
export function setLoading(isLoading) {
datasetReviewSessionStore.update(state => ({ ...state, isLoading }));
}
/**
* Set session error state
* @param {string|null} error
*/
export function setError(error) {
datasetReviewSessionStore.update(state => ({ ...state, error, isLoading: false, isSaving: false }));
}
/**
* Mark session as dirty (unsaved changes)
* @param {boolean} isDirty
*/
export function setDirty(isDirty) {
datasetReviewSessionStore.update(state => ({ ...state, isDirty }));
}
/**
* Reset store to initial state
*/
export function resetSession() {
datasetReviewSessionStore.set(initialState);
}
/**
* Patch session data locally
* @param {Object} patch - Partial session data
*/
export function patchSession(patch) {
datasetReviewSessionStore.update(state => {
if (!state.session) return state;
return {
...state,
session: { ...state.session, ...patch },
isDirty: true
};
});
}
/**
* Derive a conservative UI phase label from persisted session state.
* This helper is additive and does not alter orchestration behavior.
*
* @param {Object|null} session
* @returns {"empty"|"importing"|"review"|"partial_preview"|"launch_blocked"|"run_ready"|"run_in_progress"}
*/
export function getSessionUiPhase(session) {
if (!session) return "empty";
const readiness = String(session.readiness_state || "");
if (readiness === "importing") return "importing";
if (readiness === "partially_ready" || readiness === "compiled_preview_ready") return "partial_preview";
if (readiness === "recovery_required") return "launch_blocked";
if (readiness === "run_ready") return "run_ready";
if (readiness === "run_in_progress") return "run_in_progress";
return "review";
}
// #endregion datasetReviewSession:Store
// #endregion DatasetReviewSessionStore