Skip to content

feat(api): expose per-agent app connections via REST#7

Merged
matoushavlena merged 1 commit intomainfrom
feat/agent-connections-rest-endpoint
Apr 17, 2026
Merged

feat(api): expose per-agent app connections via REST#7
matoushavlena merged 1 commit intomainfrom
feat/agent-connections-rest-endpoint

Conversation

@matoushavlena
Copy link
Copy Markdown

Summary

Adds GET and PUT /api/agents/[agentId]/connections, mirroring the existing /api/agents/[agentId]/secrets route exactly. The underlying service functions (getAgentAppConnections, updateAgentAppConnections in apps/web/src/lib/services/agent-service.ts) already exist and are currently only reachable from Next.js server actions.

Motivation

The Humr agent platform (https://github.com/kagenti/humr) runs its own API server and wants to surface per-agent OAuth-app assignments to users — read-only first, then editable — without forcing them to context-switch to the OneCLI dashboard. That needs an HTTP surface, since Next.js server actions aren't callable from outside the Next.js process.

This mirrors the pattern the Humr team already uses for /api/agents/[agentId]/secrets — the only other "per-agent assignment" endpoint OneCLI exposes.

Changes

  • New apps/web/src/app/api/agents/[agentId]/connections/route.ts — GET returns a list of appConnectionId strings assigned to the agent; PUT replaces the assignment set. Both use resolveApiAuth, return 401 when unauthenticated, and delegate to the existing service functions. PUT invalidates the gateway cache, same as /secrets.
  • New updateAgentAppConnectionsSchema in apps/web/src/lib/validations/agent.ts — a zod schema for the PUT body ({ appConnectionIds: string[] }).

No schema changes, no service-layer changes — the service and its ServiceError("NOT_FOUND", ...) / ServiceError("BAD_REQUEST", ...) paths are already covered by handleServiceError.

Test plan

  • pnpm --filter @onecli/web run lint — clean
  • pnpm --filter @onecli/web run check-types — clean
  • pnpm exec prettier --check on both touched files — clean
  • Manual: GET /api/agents/{id}/connections with a valid API token returns [] for an agent with no apps assigned, then returns [...ids] after PUTing
  • Manual: PUT with an unknown appConnectionId returns 400 via the existing BAD_REQUEST service error
  • Manual: missing auth returns 401

Adds GET and PUT /api/agents/[agentId]/connections, mirroring the
existing /secrets route. The service-layer functions
(getAgentAppConnections, updateAgentAppConnections) already exist —
this just exposes them to cross-service consumers that can't call
Next.js server actions.

Motivation: the Humr agent platform needs to read (and eventually
write) per-agent app-connection assignments from its own API server.
The existing server-action surface is only reachable from inside
Next.js, so external integrators have no way to surface "which OAuth
apps does this agent have access to" without duplicating the DB.
@matoushavlena matoushavlena merged commit 1a519f4 into main Apr 17, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants