server-flow.md 4.3 KB

sequenceDiagram
    participant UI as ๐Ÿงฉ +layout.svelte
    participant serverStore as ๐Ÿ—„๏ธ serverStore
    participant PropsSvc as โš™๏ธ PropsService
    participant API as ๐ŸŒ llama-server

    Note over serverStore: State:<br/>props: ApiLlamaCppServerProps | null<br/>loading, error<br/>role: ServerRole | null (MODEL | ROUTER)<br/>fetchPromise (deduplication)

    %% โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
    Note over UI,API: ๐Ÿš€ INITIALIZATION
    %% โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

    UI->>serverStore: fetch()
    activate serverStore

    alt fetchPromise exists (already fetching)
        serverStore-->>UI: return fetchPromise
        Note right of serverStore: Deduplicate concurrent calls
    end

    serverStore->>serverStore: loading = true
    serverStore->>serverStore: fetchPromise = new Promise()

    serverStore->>PropsSvc: fetch()
    PropsSvc->>API: GET /props
    API-->>PropsSvc: ApiLlamaCppServerProps
    Note right of API: {role, model_path, model_alias,<br/>modalities, default_generation_settings, ...}

    PropsSvc-->>serverStore: props
    serverStore->>serverStore: props = $state(data)

    serverStore->>serverStore: detectRole(props)
    Note right of serverStore: role = props.role === "router"<br/>  ? ServerRole.ROUTER<br/>  : ServerRole.MODEL

    serverStore->>serverStore: loading = false
    serverStore->>serverStore: fetchPromise = null
    deactivate serverStore

    %% โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
    Note over UI,API: ๐Ÿ“Š COMPUTED GETTERS
    %% โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

    Note over serverStore: Getters from props:

    rect rgb(240, 255, 240)
        Note over serverStore: defaultParams<br/>โ†’ props.default_generation_settings.params<br/>(temperature, top_p, top_k, etc.)
    end

    rect rgb(240, 255, 240)
        Note over serverStore: contextSize<br/>โ†’ props.default_generation_settings.n_ctx
    end

    rect rgb(255, 240, 240)
        Note over serverStore: isRouterMode<br/>โ†’ role === ServerRole.ROUTER
    end

    rect rgb(255, 240, 240)
        Note over serverStore: isModelMode<br/>โ†’ role === ServerRole.MODEL
    end

    %% โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
    Note over UI,API: ๐Ÿ”— RELATIONSHIPS
    %% โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

    Note over serverStore: Used by:
    Note right of serverStore: - modelsStore: role detection, MODEL mode modalities<br/>- settingsStore: syncWithServerDefaults (defaultParams)<br/>- chatStore: contextSize for processing state<br/>- UI components: isRouterMode for conditional rendering

    %% โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
    Note over UI,API: โŒ ERROR HANDLING
    %% โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

    Note over serverStore: getErrorMessage(): string | null<br/>Returns formatted error for UI display

    Note over serverStore: clear(): void<br/>Resets all state (props, error, loading, role)