mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-25 05:07:05 +00:00
feat(hub,web,cli): add Agent Team (sessions-as-teammates)
Hub
- independent teams.db (own user_version ladder); feature gate default OFF,
so a disabled hub never creates the file and team routes simply do not exist
- /api/teams: list/detail/by-session/memory/messages/spawn/tasks,
human message channel, team rename/archive/delete
- team runtime: spawn members via the existing runner RPC (worktree/yolo
options), peer message routing (mention/dm push, broadcast pull-only),
budgets (max members, message rate, reply chain depth), member-offline
announcements that wake the lead or escalate to the human
- team-attention notifications: in-app toast when visible, web push otherwise
- team memory dir {HAPI_HOME}/teams/<id>/ with charter.md template; read-only
browse API with path-traversal guards
CLI
- MCP tools: team_status / team_read / team_send / spawn_peer (claude, codex
bridge and ACP flavors); spawn_peer stays behind manual approval
- HAPI_TEAM_* env for spawned members; system-prompt block for Claude/Codex;
assignment brief carries team rules for flavors without prompt injection
- RUNNER_CAPABILITIES.agentTeam advertised to the hub
Web
- team group chat route with folded peer threads, key/task filters,
human composer, member/decision/system message cards
- side panel: live member status, interactive task board (create/status/
assignee), team memory browser, budget
- team create / add-member / settings dialogs; sidebar team section;
hub settings toggle for the feature (restart to apply)
- SSE team-updated invalidation
Zero impact when disabled: no teams.db, no routes, no tool or prompt changes.
This commit is contained in:
@@ -43,6 +43,7 @@ import type {
|
||||
SessionShareCreateResponse,
|
||||
SessionShareExchangeResponse
|
||||
} from '@/types/api'
|
||||
import type { TeamDetail, TeamMemoryFile, TeamMemoryFileContent, TeamMessage, TeamSummary, TeamTask } from '@/types/team'
|
||||
import type {
|
||||
AgentAvailabilityResponse,
|
||||
AgyModelsResponse,
|
||||
@@ -403,6 +404,113 @@ export class ApiClient {
|
||||
return await this.request<SessionResponse>(`/api/sessions/${encodeURIComponent(sessionId)}`)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------- Agent Team
|
||||
|
||||
async getTeams(): Promise<{ teams: TeamSummary[] }> {
|
||||
return await this.request<{ teams: TeamSummary[] }>('/api/teams')
|
||||
}
|
||||
|
||||
async getTeam(teamId: string): Promise<TeamDetail> {
|
||||
return await this.request<TeamDetail>(`/api/teams/${encodeURIComponent(teamId)}`)
|
||||
}
|
||||
|
||||
async getTeamMessages(
|
||||
teamId: string,
|
||||
options: { afterSeq?: number; limit?: number } = {}
|
||||
): Promise<{ messages: TeamMessage[] }> {
|
||||
const params = new URLSearchParams()
|
||||
if (options.afterSeq !== undefined) params.set('afterSeq', String(options.afterSeq))
|
||||
if (options.limit !== undefined) params.set('limit', String(options.limit))
|
||||
const query = params.toString()
|
||||
return await this.request<{ messages: TeamMessage[] }>(
|
||||
`/api/teams/${encodeURIComponent(teamId)}/messages${query ? `?${query}` : ''}`
|
||||
)
|
||||
}
|
||||
|
||||
async sendHumanTeamMessage(
|
||||
teamId: string,
|
||||
body: { text: string; to?: string; kind?: string }
|
||||
): Promise<{ message: TeamMessage }> {
|
||||
return await this.request<{ message: TeamMessage }>(
|
||||
`/api/teams/${encodeURIComponent(teamId)}/human-messages`,
|
||||
{ method: 'POST', body: JSON.stringify(body) }
|
||||
)
|
||||
}
|
||||
|
||||
async getTeamMemory(teamId: string): Promise<{ files: TeamMemoryFile[] }> {
|
||||
return await this.request<{ files: TeamMemoryFile[] }>(
|
||||
`/api/teams/${encodeURIComponent(teamId)}/memory`
|
||||
)
|
||||
}
|
||||
|
||||
async getTeamMemoryFile(teamId: string, path: string): Promise<TeamMemoryFileContent> {
|
||||
const params = new URLSearchParams({ path })
|
||||
return await this.request<TeamMemoryFileContent>(
|
||||
`/api/teams/${encodeURIComponent(teamId)}/memory/file?${params.toString()}`
|
||||
)
|
||||
}
|
||||
|
||||
async createTeamTask(
|
||||
teamId: string,
|
||||
body: { title: string; assigneeSessionId?: string | null }
|
||||
): Promise<{ task: TeamTask }> {
|
||||
return await this.request<{ task: TeamTask }>(
|
||||
`/api/teams/${encodeURIComponent(teamId)}/tasks`,
|
||||
{ method: 'POST', body: JSON.stringify(body) }
|
||||
)
|
||||
}
|
||||
|
||||
async updateTeamTask(
|
||||
teamId: string,
|
||||
taskId: string,
|
||||
body: { status?: string; assigneeSessionId?: string | null }
|
||||
): Promise<{ task: TeamTask }> {
|
||||
return await this.request<{ task: TeamTask }>(
|
||||
`/api/teams/${encodeURIComponent(teamId)}/tasks/${encodeURIComponent(taskId)}`,
|
||||
{ method: 'PATCH', body: JSON.stringify(body) }
|
||||
)
|
||||
}
|
||||
|
||||
async updateTeam(
|
||||
teamId: string,
|
||||
body: { name?: string; status?: 'active' | 'archived' }
|
||||
): Promise<{ team: TeamSummary }> {
|
||||
return await this.request<{ team: TeamSummary }>(
|
||||
`/api/teams/${encodeURIComponent(teamId)}`,
|
||||
{ method: 'PATCH', body: JSON.stringify(body) }
|
||||
)
|
||||
}
|
||||
|
||||
async deleteTeam(teamId: string): Promise<void> {
|
||||
await this.request(`/api/teams/${encodeURIComponent(teamId)}`, { method: 'DELETE' })
|
||||
}
|
||||
|
||||
async createTeam(body: { name: string; leadSessionId?: string }): Promise<{ team: TeamSummary }> {
|
||||
return await this.request<{ team: TeamSummary }>('/api/teams', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(body)
|
||||
})
|
||||
}
|
||||
|
||||
async spawnTeamMember(
|
||||
teamId: string,
|
||||
body: {
|
||||
fromSessionId: string
|
||||
role: string
|
||||
task?: string
|
||||
agent?: string
|
||||
model?: string
|
||||
sessionType?: 'simple' | 'worktree'
|
||||
worktreeName?: string
|
||||
yolo?: boolean
|
||||
}
|
||||
): Promise<{ teamId: string; sessionId: string; role: string; taskId: string | null }> {
|
||||
return await this.request(
|
||||
`/api/teams/${encodeURIComponent(teamId)}/spawn`,
|
||||
{ method: 'POST', body: JSON.stringify(body) }
|
||||
)
|
||||
}
|
||||
|
||||
async createSessionShare(sessionId: string): Promise<SessionShareCreateResponse> {
|
||||
return await this.request<SessionShareCreateResponse>('/api/session-shares', { method: 'POST', body: JSON.stringify({ sessionId }) })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user