mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
F003/F014: /api/v1/do/* only required X-Agent-ID (UUID) — no token check, unlike the flow routers' role guards. A forged X-Agent-ID passed. Added require_any_authenticated_agent (token-only; do router serves all roles) and applied it as a router-level dependency. Binds X-Agent-ID to a verified HMAC token when ROBOCO_AGENT_AUTH_REQUIRED=true; rejects a forged token even in dev mode. F004: /ws/* per-agent streams (channels/agents/sessions/notifications) never read the nginx-injected X-Agent-Token, so in strict mode an agent on the Docker network could subscribe to another agent's notifications with no auth. Added _require_panel_token verifying the CEO panel token against the CEO identity; wired into all four per-agent streams (system stream stays operator-only per its docstring). Same strict/dev contract. TDD: RED tests watched fail (no gate -> 200/accept), then GREEN. ruff+mypy clean; 399 api/mcp + 29 WS tests green, no regressions.
371 lines
9.4 KiB
Python
371 lines
9.4 KiB
Python
"""Content-tool HTTP endpoints. Thin handlers; delegate to ContentActions."""
|
|
|
|
from typing import Annotated
|
|
from uuid import UUID
|
|
|
|
from fastapi import APIRouter, Depends, Header, Request
|
|
|
|
from roboco.api.deps import get_content_actions
|
|
from roboco.api.routes.v1._role_dep import (
|
|
envelope_to_response,
|
|
require_any_authenticated_agent,
|
|
)
|
|
from roboco.api.schemas.v1.do import (
|
|
ApprovePlaybookRequest,
|
|
ArchivePlaybookRequest,
|
|
ChannelsRequest,
|
|
CommitRequest,
|
|
DmRequest,
|
|
DraftPlaybookRequest,
|
|
EvidenceRequest,
|
|
LinkSessionRequest,
|
|
NoteRequest,
|
|
NotifyAckRequest,
|
|
NotifyGetRequest,
|
|
NotifyListRequest,
|
|
NotifyRequest,
|
|
OpenSessionRequest,
|
|
PitchRequest,
|
|
ProgressRequest,
|
|
PRUpdateRequest,
|
|
ReadMessagesRequest,
|
|
RejectPlaybookRequest,
|
|
SayRequest,
|
|
)
|
|
from roboco.services.gateway.content_actions import ContentActions
|
|
|
|
router = APIRouter(
|
|
prefix="/api/v1/do",
|
|
tags=["v1-do"],
|
|
# F003/F014: bind X-Agent-ID to a verified HMAC token — same gate the
|
|
# flow routers enforce via their role guards. The do router serves all
|
|
# roles, so this is token-only (no role assertion).
|
|
dependencies=[require_any_authenticated_agent],
|
|
)
|
|
|
|
_AgentIdHeader = Annotated[UUID, Header(alias="X-Agent-ID")]
|
|
_ContentActionsDep = Annotated[ContentActions, Depends(get_content_actions)]
|
|
|
|
|
|
@router.post("/commit")
|
|
async def do_commit(
|
|
request: Request,
|
|
body: CommitRequest,
|
|
x_agent_id: _AgentIdHeader,
|
|
actions: _ContentActionsDep,
|
|
) -> dict:
|
|
env = await actions.commit(
|
|
agent_id=x_agent_id,
|
|
message=body.message,
|
|
files=body.files,
|
|
)
|
|
return envelope_to_response(env, request)
|
|
|
|
|
|
@router.post("/note")
|
|
async def do_note(
|
|
request: Request,
|
|
body: NoteRequest,
|
|
x_agent_id: _AgentIdHeader,
|
|
actions: _ContentActionsDep,
|
|
) -> dict:
|
|
env = await actions.note(
|
|
agent_id=x_agent_id,
|
|
text=body.text,
|
|
scope=body.scope,
|
|
task_id=body.task_id,
|
|
structured={
|
|
"title": body.title,
|
|
"context": body.context,
|
|
"options": body.options,
|
|
"chosen": body.chosen,
|
|
"rationale": body.rationale,
|
|
"consequences": body.consequences,
|
|
"what_done": body.what_done,
|
|
"what_learned": body.what_learned,
|
|
"what_struggled": body.what_struggled,
|
|
"next_steps": body.next_steps,
|
|
},
|
|
section=body.section,
|
|
done=body.done,
|
|
next=body.next,
|
|
where_to_look=body.where_to_look,
|
|
)
|
|
return envelope_to_response(env, request)
|
|
|
|
|
|
@router.post("/pitch")
|
|
async def do_pitch(
|
|
request: Request,
|
|
body: PitchRequest,
|
|
x_agent_id: _AgentIdHeader,
|
|
actions: _ContentActionsDep,
|
|
) -> dict:
|
|
env = await actions.pitch(
|
|
agent_id=x_agent_id,
|
|
title=body.title,
|
|
slug=body.slug,
|
|
problem=body.problem,
|
|
proposed_solution=body.proposed_solution,
|
|
target_cells=body.target_cells,
|
|
)
|
|
return envelope_to_response(env, request)
|
|
|
|
|
|
@router.post("/say")
|
|
async def do_say(
|
|
request: Request,
|
|
body: SayRequest,
|
|
x_agent_id: _AgentIdHeader,
|
|
actions: _ContentActionsDep,
|
|
) -> dict:
|
|
env = await actions.say(
|
|
agent_id=x_agent_id,
|
|
channel=body.channel,
|
|
text=body.text,
|
|
task_id=body.task_id,
|
|
)
|
|
return envelope_to_response(env, request)
|
|
|
|
|
|
@router.post("/dm")
|
|
async def do_dm(
|
|
request: Request,
|
|
body: DmRequest,
|
|
x_agent_id: _AgentIdHeader,
|
|
actions: _ContentActionsDep,
|
|
) -> dict:
|
|
env = await actions.dm(
|
|
agent_id=x_agent_id,
|
|
recipient=body.recipient,
|
|
text=body.text,
|
|
task_id=body.task_id,
|
|
skill=body.skill,
|
|
)
|
|
return envelope_to_response(env, request)
|
|
|
|
|
|
@router.post("/notify")
|
|
async def do_notify(
|
|
request: Request,
|
|
body: NotifyRequest,
|
|
x_agent_id: _AgentIdHeader,
|
|
actions: _ContentActionsDep,
|
|
) -> dict:
|
|
env = await actions.notify(
|
|
agent_id=x_agent_id,
|
|
target=body.target,
|
|
text=body.text,
|
|
priority=body.priority,
|
|
task_id=body.task_id,
|
|
)
|
|
return envelope_to_response(env, request)
|
|
|
|
|
|
@router.post("/evidence")
|
|
async def do_evidence(
|
|
request: Request,
|
|
body: EvidenceRequest,
|
|
x_agent_id: _AgentIdHeader,
|
|
actions: _ContentActionsDep,
|
|
) -> dict:
|
|
env = await actions.evidence(agent_id=x_agent_id, task_id=body.task_id)
|
|
return envelope_to_response(env, request)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Wave 1 — pre-gateway parity
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
@router.post("/progress")
|
|
async def do_progress(
|
|
request: Request,
|
|
body: ProgressRequest,
|
|
x_agent_id: _AgentIdHeader,
|
|
actions: _ContentActionsDep,
|
|
) -> dict:
|
|
env = await actions.progress(
|
|
agent_id=x_agent_id,
|
|
task_id=body.task_id,
|
|
message=body.message,
|
|
plan_step=body.plan_step,
|
|
percentage=body.percentage,
|
|
)
|
|
return envelope_to_response(env, request)
|
|
|
|
|
|
@router.post("/open_session")
|
|
async def do_open_session(
|
|
request: Request,
|
|
body: OpenSessionRequest,
|
|
x_agent_id: _AgentIdHeader,
|
|
actions: _ContentActionsDep,
|
|
) -> dict:
|
|
env = await actions.open_session(
|
|
agent_id=x_agent_id,
|
|
task_id=body.task_id,
|
|
channel=body.channel,
|
|
topic=body.topic,
|
|
relationship_type=body.relationship_type,
|
|
group_id=body.group_id,
|
|
)
|
|
return envelope_to_response(env, request)
|
|
|
|
|
|
@router.post("/link_session")
|
|
async def do_link_session(
|
|
request: Request,
|
|
body: LinkSessionRequest,
|
|
x_agent_id: _AgentIdHeader,
|
|
actions: _ContentActionsDep,
|
|
) -> dict:
|
|
env = await actions.link_session(
|
|
agent_id=x_agent_id,
|
|
session_id=body.session_id,
|
|
task_id=body.task_id,
|
|
is_primary=body.is_primary,
|
|
relationship_type=body.relationship_type,
|
|
)
|
|
return envelope_to_response(env, request)
|
|
|
|
|
|
@router.post("/notify_list")
|
|
async def do_notify_list(
|
|
request: Request,
|
|
body: NotifyListRequest,
|
|
x_agent_id: _AgentIdHeader,
|
|
actions: _ContentActionsDep,
|
|
) -> dict:
|
|
env = await actions.notify_list(
|
|
agent_id=x_agent_id,
|
|
unread_only=body.unread_only,
|
|
pending_ack_only=body.pending_ack_only,
|
|
limit=body.limit,
|
|
)
|
|
return envelope_to_response(env, request)
|
|
|
|
|
|
@router.post("/notify_get")
|
|
async def do_notify_get(
|
|
request: Request,
|
|
body: NotifyGetRequest,
|
|
x_agent_id: _AgentIdHeader,
|
|
actions: _ContentActionsDep,
|
|
) -> dict:
|
|
env = await actions.notify_get(
|
|
agent_id=x_agent_id,
|
|
notification_id=body.notification_id,
|
|
)
|
|
return envelope_to_response(env, request)
|
|
|
|
|
|
@router.post("/notify_ack")
|
|
async def do_notify_ack(
|
|
request: Request,
|
|
body: NotifyAckRequest,
|
|
x_agent_id: _AgentIdHeader,
|
|
actions: _ContentActionsDep,
|
|
) -> dict:
|
|
env = await actions.notify_ack(
|
|
agent_id=x_agent_id,
|
|
notification_id=body.notification_id,
|
|
)
|
|
return envelope_to_response(env, request)
|
|
|
|
|
|
@router.post("/read_messages")
|
|
async def do_read_messages(
|
|
request: Request,
|
|
_body: ReadMessagesRequest,
|
|
x_agent_id: _AgentIdHeader,
|
|
actions: _ContentActionsDep,
|
|
) -> dict:
|
|
env = await actions.read_messages(agent_id=x_agent_id)
|
|
return envelope_to_response(env, request)
|
|
|
|
|
|
@router.post("/channels")
|
|
async def do_channels(
|
|
request: Request,
|
|
_body: ChannelsRequest,
|
|
x_agent_id: _AgentIdHeader,
|
|
actions: _ContentActionsDep,
|
|
) -> dict:
|
|
env = await actions.channels(agent_id=x_agent_id)
|
|
return envelope_to_response(env, request)
|
|
|
|
|
|
@router.post("/pr_update")
|
|
async def do_pr_update(
|
|
request: Request,
|
|
body: PRUpdateRequest,
|
|
x_agent_id: _AgentIdHeader,
|
|
actions: _ContentActionsDep,
|
|
) -> dict:
|
|
env = await actions.pr_update(
|
|
agent_id=x_agent_id,
|
|
task_id=body.task_id,
|
|
title=body.title,
|
|
body=body.body,
|
|
reviewers=body.reviewers,
|
|
)
|
|
return envelope_to_response(env, request)
|
|
|
|
|
|
@router.post("/draft_playbook")
|
|
async def do_draft_playbook(
|
|
request: Request,
|
|
body: DraftPlaybookRequest,
|
|
x_agent_id: _AgentIdHeader,
|
|
actions: _ContentActionsDep,
|
|
) -> dict:
|
|
env = await actions.draft_playbook(
|
|
agent_id=x_agent_id,
|
|
title=body.title,
|
|
problem=body.problem,
|
|
procedure=body.procedure,
|
|
tags=body.tags,
|
|
source_task_id=body.source_task_id,
|
|
)
|
|
return envelope_to_response(env, request)
|
|
|
|
|
|
@router.post("/approve_playbook")
|
|
async def do_approve_playbook(
|
|
request: Request,
|
|
body: ApprovePlaybookRequest,
|
|
x_agent_id: _AgentIdHeader,
|
|
actions: _ContentActionsDep,
|
|
) -> dict:
|
|
env = await actions.approve_playbook(
|
|
agent_id=x_agent_id, playbook_id=body.playbook_id
|
|
)
|
|
return envelope_to_response(env, request)
|
|
|
|
|
|
@router.post("/reject_playbook")
|
|
async def do_reject_playbook(
|
|
request: Request,
|
|
body: RejectPlaybookRequest,
|
|
x_agent_id: _AgentIdHeader,
|
|
actions: _ContentActionsDep,
|
|
) -> dict:
|
|
env = await actions.reject_playbook(
|
|
agent_id=x_agent_id, playbook_id=body.playbook_id, reason=body.reason
|
|
)
|
|
return envelope_to_response(env, request)
|
|
|
|
|
|
@router.post("/archive_playbook")
|
|
async def do_archive_playbook(
|
|
request: Request,
|
|
body: ArchivePlaybookRequest,
|
|
x_agent_id: _AgentIdHeader,
|
|
actions: _ContentActionsDep,
|
|
) -> dict:
|
|
env = await actions.archive_playbook(
|
|
agent_id=x_agent_id, playbook_id=body.playbook_id
|
|
)
|
|
return envelope_to_response(env, request)
|