agenthub/frontend/lib/types.ts

320 lines
7.0 KiB
TypeScript

// Shapes returned by the hub console API (see backend/agenthub/api/serializers.py).
export type AgentStatus = "online" | "offline" | "degraded" | "unknown";
export type TaskStatus = "queued" | "running" | "completed" | "failed" | "cancelled";
// Which product an agent is (backend/agenthub/db/models.py: AGENT_TYPES).
// "custom" is what anything outside the four named products resolves to.
export type AgentType = "nanobot" | "deepseek_harness" | "openclaw" | "hermes" | "custom";
export interface ConnectorInfo {
connected: boolean;
token_preview: string;
version: string;
protocol_version: number;
connected_at: string | null;
remote: string;
pending_requests: number;
}
export interface Agent {
id: string;
name: string;
display_name: string;
description: string;
emoji: string;
agent_type: AgentType;
driver: string;
connection_mode: "direct" | "connector" | "embedded";
deployment_kind: "local" | "docker" | "cloud";
deployment_ref: string;
base_url: string;
model: string;
role: string;
labels: Record<string, string>;
capabilities: Record<string, unknown>;
status: AgentStatus;
live: boolean;
reachable: boolean;
source: string;
max_concurrency: number;
active_tasks: number;
last_error: string;
last_heartbeat_at: string | null;
heartbeat_age_s: number | null;
last_probe_at: string | null;
last_task_at: string | null;
created_at: string;
teams: string[];
auth: Record<string, unknown>;
config: Record<string, unknown>;
health: Record<string, unknown>;
connector: ConnectorInfo;
//: Which credential is installed — the plaintext comes from GET /agents/{ref}/credentials.
credential?: { installed: boolean; preview: string; viewable: boolean };
}
export interface Task {
id: string;
title: string;
prompt: string;
context: Record<string, unknown>;
agent_id: string;
agent_name: string;
team_id: string;
run_id: string;
step_id: string;
session_key: string;
status: TaskStatus;
source: string;
result: string;
error: string;
usage: Record<string, unknown>;
created_at: string;
started_at: string | null;
finished_at: string | null;
duration_s: number | null;
}
export interface TaskEvent {
id?: string;
task_id?: string;
seq: number;
kind: string;
payload: Record<string, unknown>;
created_at?: string;
}
export interface TeamMember {
id: string;
agent_id: string;
agent_name: string;
emoji: string;
driver: string;
role: string;
instructions: string;
position: number;
}
export interface Team {
id: string;
name: string;
description: string;
playbook: string;
spec: Record<string, unknown>;
members: TeamMember[];
member_count: number;
created_at: string;
updated_at: string;
}
export interface RunStep {
id: string;
run_id: string;
agent_id: string;
agent_name: string;
role: string;
position: number;
round: number;
title: string;
input: string;
output: string;
status: string;
error: string;
task_id: string;
started_at: string | null;
finished_at: string | null;
}
export interface BlackboardEntry {
id: string;
team_id: string;
run_id: string;
agent_id: string;
key: string;
value: Record<string, unknown>;
created_at: string;
updated_at: string;
}
export interface TeamMessage {
id: string;
team_id: string;
run_id: string;
from_agent_id: string;
to_agent_id: string;
kind: string;
body: string;
payload: Record<string, unknown>;
created_at: string;
}
export interface Run {
id: string;
team_id: string;
objective: string;
playbook: string;
spec: Record<string, unknown>;
status: string;
output: string;
error: string;
grant_preview: string;
created_at: string;
started_at: string | null;
finished_at: string | null;
duration_s: number | null;
steps?: RunStep[];
messages?: TeamMessage[];
blackboard?: BlackboardEntry[];
}
export interface PresenceEntry {
id: string;
name: string;
status: string;
live: boolean;
heartbeat_age_s: number | null;
origin: string;
error: string;
}
export interface AgentPresence {
agent_id: string;
status: string;
live: boolean;
origin: string;
remote: string;
pending_requests: number;
inflight_tasks: string[];
heartbeat_age_s: number | null;
health: Record<string, unknown>;
error: string;
}
export interface Frame {
v: number;
id: string;
ts: number;
type: string;
kind: string;
topic?: string;
actor?: string;
agent_id?: string;
task_id?: string;
run_id?: string;
seq?: number;
payload: Record<string, unknown>;
}
export interface Stats {
hub: {
uptime_s: number;
connector_connections: number;
connected_agents: string[];
bus: Record<string, unknown>;
};
agents: {
total: number;
by_status: Record<string, number>;
by_driver: Record<string, number>;
by_deployment: Record<string, number>;
online_live: number;
connected_agent_ids: string[];
};
tasks: { by_status: Record<string, number>; inflight: number };
teams: number;
recent_runs: { id: string; team_id: string; status: string; objective: string; created_at: string }[];
uptime_note: string;
}
export interface NamedInfo {
name: string;
description: string;
}
export interface DriverInfo extends NamedInfo {
title: string;
connection_modes: string[];
config_schema: Record<string, string>;
experimental: boolean;
}
export interface Meta {
app: string;
version: string;
url: string;
ws_url: string;
auth_required: boolean;
/** 驱动能力清单(含第三方 entry-point 注册进来的)。 */
drivers: DriverInfo[];
playbooks: NamedInfo[];
/** 下面四个枚举都由 /meta 下发:控制台不另存硬编码副本,避免和 hub 漂移。 */
agent_types: string[];
connection_modes: string[];
deployment_kinds: string[];
}
export interface ApiKey {
id: string;
name: string;
scope: string;
key_preview: string;
created_at: string;
last_used_at: string | null;
revoked: boolean;
token?: string;
}
export interface AuditEntry {
id: number;
ts: number;
actor: string;
action: string;
target_type: string;
target_id: string;
detail: Record<string, unknown>;
}
export interface DeployFile {
kind: string;
filename: string;
content: string;
}
export interface DeployPlan {
agent: Record<string, unknown>;
hub_url: string;
files: DeployFile[];
next_steps: string[];
note: string;
}
/** 一次签发的存档:当时那段配置连 token 一起留着,所以回看就是原样。 */
export interface Issuance {
id: string;
agent_id: string;
agent_name: string;
kind: string;
hub_url: string;
agent_token: string;
files: DeployFile[];
active: boolean;
created_at: string;
}
export interface GatewayStatus {
uptime_s: number;
connector_connections: number;
connected_agents: string[];
bus: { published: number; dropped: number; subscribers: number; buffered: number };
connections: Record<string, unknown>[];
}
export interface ProbeResult {
ok: boolean;
driver?: string;
detail?: Record<string, unknown>;
error?: string;
[key: string]: unknown;
}