Files
PaperClipAI/server/src/routes/agent-profile-avatar.ts
T
DottaandPaperclip 2b4a1d7073 feat(dot): add guided invitations and persistent agent connections (#15581)
Add guided external-agent invitations with live Dot connection checks and ongoing access until revoked. Keep expired credentials invalid and enforce permissions for private avatar uploads. Preserve Runner recovery and remote launch boundaries.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-10-08 16:26:41 -05:00

37 lines
1.8 KiB
TypeScript

import { Router } from "express";
import type { Db } from "@paperclipai/db";
import { setAgentAvatarSchema } from "@paperclipai/shared";
import { z } from "zod";
import type { StorageService } from "../storage/types.js";
import { forbidden } from "../errors.js";
import { assertCompanyAccess, getActorInfo } from "./authz.js";
import { accessService } from "../services/access.js";
import { setAgentProfileAvatar } from "../services/agent-profile-avatar.js";
export function agentProfileAvatarRoutes(db: Db, storage: StorageService) {
const router = Router();
router.put("/companies/:companyId/agents/:agentId/avatar", async (req, res) => {
const companyId = z.uuid().parse(req.params.companyId);
const agentId = z.uuid().parse(req.params.agentId);
assertCompanyAccess(req, companyId);
if (req.actor.type === "agent") {
if (req.actor.keyScope?.kind === "task_bridge" || req.actor.keyScope?.kind === "skill_test") {
throw forbidden("Task-scoped credentials cannot update agent profiles");
}
if (req.actor.agentId !== agentId) throw forbidden("Agents can update only their own avatar");
} else if (req.actor.type !== "board" || req.actor.memberships?.find(m => m.companyId === companyId)?.membershipRole === "viewer") {
throw forbidden("Operator or agent access required");
}
if (req.actor.type === "board") {
const decision = await accessService(db).decide({
actor: req.actor, action: "agent_config:update",
resource: { type: "agent", companyId, agentId },
});
if (!decision.allowed) throw forbidden(decision.explanation);
}
const actor = getActorInfo(req);
res.json(await setAgentProfileAvatar(db, storage, companyId, agentId, setAgentAvatarSchema.parse(req.body), actor));
});
return router;
}