feat(agent-office): AI 토큰 사용량 뱃지 표시
- api.js: getAgentTokenUsage 헬퍼 추가 - AgentColumn: 헤더에 오늘 토큰 사용량 뱃지 (🧮 N,NNN) - 30초 폴링 + state 변경 시 즉시 갱신 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { getAgentTasks } from '../../../api';
|
||||
import { getAgentTasks, getAgentTokenUsage } from '../../../api';
|
||||
|
||||
const STATUS_BADGE = {
|
||||
pending: { label: '대기', bg: '#92400e' },
|
||||
@@ -26,6 +26,7 @@ const AgentColumn = ({ agentId, meta, agentState, notification, onCommand, onApp
|
||||
const [tasks, setTasks] = useState([]);
|
||||
const [input, setInput] = useState('');
|
||||
const [activeCommand, setActiveCommand] = useState(null);
|
||||
const [tokenUsage, setTokenUsage] = useState(null);
|
||||
|
||||
const state = agentState || { state: 'offline' };
|
||||
const commands = AGENT_COMMANDS[agentId] || [];
|
||||
@@ -45,6 +46,22 @@ const AgentColumn = ({ agentId, meta, agentState, notification, onCommand, onApp
|
||||
}
|
||||
}, [agentId, state.state, state.detail]);
|
||||
|
||||
// 오늘자 AI 토큰 사용량 폴링 (30초 간격 + 작업 완료 시 즉시 갱신)
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
const fetchUsage = () => {
|
||||
getAgentTokenUsage(agentId, 1)
|
||||
.then(d => { if (!cancelled) setTokenUsage(d); })
|
||||
.catch(() => {});
|
||||
};
|
||||
fetchUsage();
|
||||
const interval = setInterval(fetchUsage, 30000);
|
||||
return () => {
|
||||
cancelled = true;
|
||||
clearInterval(interval);
|
||||
};
|
||||
}, [agentId, state.state, state.detail]);
|
||||
|
||||
const handleQuickAction = (cmd) => {
|
||||
if (cmd.needsInput) {
|
||||
setActiveCommand(cmd.action);
|
||||
@@ -67,6 +84,14 @@ const AgentColumn = ({ agentId, meta, agentState, notification, onCommand, onApp
|
||||
<div className="ao-col" onClick={onClearNotification}>
|
||||
<div className="ao-col-header" style={{ borderColor: meta.color }}>
|
||||
<span className="ao-col-name" style={{ color: meta.color }}>{meta.name}</span>
|
||||
{tokenUsage && tokenUsage.total_tokens > 0 && (
|
||||
<span
|
||||
className="ao-col-tokens"
|
||||
title={`오늘 ${tokenUsage.task_count}건 작업 · ${tokenUsage.total_tokens.toLocaleString()} 토큰`}
|
||||
>
|
||||
🧮 {tokenUsage.total_tokens.toLocaleString()}
|
||||
</span>
|
||||
)}
|
||||
<span className={`ao-col-state ao-col-state--${state.state}`}>{state.state}</span>
|
||||
{notification > 0 && <span className="ao-col-badge">{notification}</span>}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user