handlers
Mutation Response Builder
Assembles the full OOB response for handlers that mutate segment data. Includes decomposition-specific elements (stats, toolbar) in addition to card stack elements.
build_mutation_response
def build_mutation_response(
segment_dicts:List, # Serialized segments
focused_index:int, # Currently focused segment index
visible_count:int, # Number of visible cards
history_depth:int, # Current undo history depth
urls:SegmentationUrls, # URL bundle
is_split_mode:bool=False, # Whether split mode is active
extra_actions:tuple=(), # Additional toolbar elements (e.g., FA controls, sync toggle)
nltk_split_disabled:bool=False, # Whether NLTK Split button is disabled
)->Tuple: # OOB elements (slots + progress + focus + stats + toolbar + source position)
Build the standard OOB response for mutation handlers.
Returns domain-specific OOB elements. The combined layer wrapper adds cross-domain elements (mini-stats badge, alignment status).
Initialize Handler
SegMutationResult
def SegMutationResult(
args:VAR_POSITIONAL, kwargs:VAR_KEYWORD
):
Result from a segmentation mutation handler (split, merge, undo, reset, NLTK split).
Contains data for the caller to build targeted OOB responses via build_mutation_response(). The caller controls toolbar extra_actions and any cross-domain OOB elements (alignment status, mini-stats).
SegInitResult
def SegInitResult(
args:VAR_POSITIONAL, kwargs:VAR_KEYWORD
):
Result from pure segmentation init handler.
Contains domain-specific data for the combined layer wrapper to use when building cross-domain OOB elements (KB system, shared chrome).
Split Handler
Merge Handler
Undo Handler
Reset Handler
NLTK Split Handler
Router Initialization
Creates the workflow router with init, split, merge, undo, reset, and AI split routes.
init_workflow_router
def init_workflow_router(
state_store:SQLiteWorkflowStateStore, # The workflow state store
workflow_id:str, # The workflow identifier
source_service:SourceService, # Service for fetching source blocks
segmentation_service:SegmentationService, # Service for NLTK sentence splitting
prefix:str, # Route prefix (e.g., "/workflow/seg/workflow")
urls:SegmentationUrls, # URL bundle (populated after routes defined)
max_history_depth:int=50, # Maximum history stack depth
handler_init:Callable=None, # Optional wrapped init handler
handler_split:Callable=None, # Optional wrapped split handler
handler_merge:Callable=None, # Optional wrapped merge handler
handler_undo:Callable=None, # Optional wrapped undo handler
handler_reset:Callable=None, # Optional wrapped reset handler
handler_ai_split:Callable=None, # Optional wrapped ai_split handler
)->Tuple: # (router, route_dict)
Initialize workflow routes for segmentation.
Accepts optional handler overrides for wrapping with cross-domain coordination (e.g., KB system, shared chrome, alignment status).