Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

939 B
Raw Blame
"use client";

import { useCallback, useState } from "react";
import { addUsage, type ProviderUsage } from "./turn-usage";

// Per-turn and per-thread token accounting for the Alfa chat. Extracted from
// ChatPanel (which was tripping max-lines) so the panel stays about the run loop
// and this state has one home: `record` folds each turn's usage into the thread
// total, `reset` clears both when the conversation switches.
export function useTurnUsage() {
  const [turnUsage, setTurnUsage] = useState<ProviderUsage | null>(null);
  const [threadUsage, setThreadUsage] = useState<ProviderUsage | null>(null);
  const record = useCallback((usage?: ProviderUsage | null) => {
    if (!usage) return;
    setTurnUsage(usage);
    setThreadUsage((prev) => addUsage(prev, usage));
  }, []);
  const reset = useCallback(() => {
    setTurnUsage(null);
    setThreadUsage(null);
  }, []);
  return { turnUsage, threadUsage, record, reset };
}