vibe.assistant.services.draft_manager

DraftManager - manages draft block storage and rendering.

Responsibilities: - Block ID generation - Block storage and retrieval - Draft content rendering with semantic IDs - In-memory block accumulation during streaming - Content splitting into blocks

DraftManager

Manages draft blocks for the assistant.

This class consolidates: - _get_next_block_id_direct - _add_block_to_state_direct - _finalize_block_content_direct - get_current_draft - _split_content_into_blocks - _find_block_uuid_by_semantic_id - _add_or_update_block

__init__

__init__(assistant_name: str, state_getter: Callable[[], dict[str, Any]], state_updater: Callable[[dict[str, Any]], None]) -> None

Initialize the draft manager.

Parameters:
  • assistant_name (str) –

    Name of the assistant

  • state_getter (Callable[[], dict[str, Any]]) –

    Callable that returns current state dict

  • state_updater (Callable[[dict[str, Any]], None]) –

    Callable that updates state dict

get_current_draft

get_current_draft() -> str

Get the current draft content from blocks.

Returns:
  • str

    Draft content as string with semantic block IDs for the model

get_next_block_id

get_next_block_id() -> str

Get next block ID and increment counter.

Returns:
  • str

    Block ID string like "b1", "b2", etc.

find_block_uuid_by_semantic_id

find_block_uuid_by_semantic_id(semantic_id: str) -> str | None

Find block UUID by semantic ID (llm_id).

Parameters:
  • semantic_id (str) –

    The llm_id to search for

Returns:
  • str | None

    Block UUID if found, None otherwise

add_block

add_block(semantic_id: str, content: str = '') -> str

Add a new block with the given semantic ID.

Parameters:
  • semantic_id (str) –

    The llm_id for this block

  • content (str, default: '' ) –

    Initial content

Returns:
  • str

    Generated UUID for the new block

add_or_update_block

add_or_update_block(semantic_id: str, content: str = '') -> str

Add or update a block with the given semantic ID.

Parameters:
  • semantic_id (str) –

    The llm_id for this block

  • content (str, default: '' ) –

    Content to set

Returns:
  • str

    UUID of the block (existing or new)

finalize_block_content

finalize_block_content(block_id: str, content: str) -> None

Finalize a block by replacing its entire content.

Parameters:
  • block_id (str) –

    ID of the block to update

  • content (str) –

    Complete content to set

add_block_to_state

add_block_to_state(block_id: str, target: str) -> None

Add a new block to the draft state.

Parameters:
  • block_id (str) –

    ID for the new block

  • target (str) –

    Target location - "new_block" to append, "insert_after_X" to insert

split_content_into_blocks

split_content_into_blocks(content: str) -> list[str]

Split content into logical blocks based on markdown structure.

Parameters:
  • content (str) –

    Markdown content to split

Returns:
  • list[str]

    List of block content strings

start_in_memory_block

start_in_memory_block(block_id: str) -> None

Start accumulating content for an in-memory block.

Parameters:
  • block_id (str) –

    Semantic ID for the block

append_to_in_memory_block

append_to_in_memory_block(block_id: str, content: str) -> None

Append content to an in-memory block.

Parameters:
  • block_id (str) –

    Semantic ID for the block

  • content (str) –

    Content to append

flush_in_memory_blocks

flush_in_memory_blocks() -> None

Flush all in-memory blocks to persistent state.

Updates existing blocks or creates new ones as needed.