mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-15 10:30:37 +09:00
feat(inbox): add operator search and keyboard controls
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
36376968af
commit
3ab7d52f00
25 changed files with 1340 additions and 114 deletions
|
|
@ -2,7 +2,7 @@ import { Router, type Request } from "express";
|
|||
import { generateKeyPairSync, randomUUID } from "node:crypto";
|
||||
import path from "node:path";
|
||||
import type { Db } from "@paperclipai/db";
|
||||
import { agents as agentsTable, companies, heartbeatRuns } from "@paperclipai/db";
|
||||
import { agents as agentsTable, companies, heartbeatRuns, issues as issuesTable } from "@paperclipai/db";
|
||||
import { and, desc, eq, inArray, not, sql } from "drizzle-orm";
|
||||
import {
|
||||
agentSkillSyncSchema,
|
||||
|
|
@ -220,6 +220,73 @@ export function agentRoutes(db: Db) {
|
|||
return allowedByGrant || canCreateAgents(actorAgent);
|
||||
}
|
||||
|
||||
async function buildSkippedWakeupResponse(
|
||||
agent: NonNullable<Awaited<ReturnType<typeof svc.getById>>>,
|
||||
payload: Record<string, unknown> | null | undefined,
|
||||
) {
|
||||
const issueId = typeof payload?.issueId === "string" && payload.issueId.trim() ? payload.issueId : null;
|
||||
if (!issueId) {
|
||||
return {
|
||||
status: "skipped" as const,
|
||||
reason: "wakeup_skipped",
|
||||
message: "Wakeup was skipped.",
|
||||
issueId: null,
|
||||
executionRunId: null,
|
||||
executionAgentId: null,
|
||||
executionAgentName: null,
|
||||
};
|
||||
}
|
||||
|
||||
const issue = await db
|
||||
.select({
|
||||
id: issuesTable.id,
|
||||
executionRunId: issuesTable.executionRunId,
|
||||
})
|
||||
.from(issuesTable)
|
||||
.where(and(eq(issuesTable.id, issueId), eq(issuesTable.companyId, agent.companyId)))
|
||||
.then((rows) => rows[0] ?? null);
|
||||
|
||||
if (!issue?.executionRunId) {
|
||||
return {
|
||||
status: "skipped" as const,
|
||||
reason: "wakeup_skipped",
|
||||
message: "Wakeup was skipped.",
|
||||
issueId,
|
||||
executionRunId: null,
|
||||
executionAgentId: null,
|
||||
executionAgentName: null,
|
||||
};
|
||||
}
|
||||
|
||||
const executionRun = await heartbeat.getRun(issue.executionRunId);
|
||||
if (!executionRun || (executionRun.status !== "queued" && executionRun.status !== "running")) {
|
||||
return {
|
||||
status: "skipped" as const,
|
||||
reason: "wakeup_skipped",
|
||||
message: "Wakeup was skipped.",
|
||||
issueId,
|
||||
executionRunId: issue.executionRunId,
|
||||
executionAgentId: null,
|
||||
executionAgentName: null,
|
||||
};
|
||||
}
|
||||
|
||||
const executionAgent = await svc.getById(executionRun.agentId);
|
||||
const executionAgentName = executionAgent?.name ?? null;
|
||||
|
||||
return {
|
||||
status: "skipped" as const,
|
||||
reason: "issue_execution_deferred",
|
||||
message: executionAgentName
|
||||
? `Wakeup was deferred because this issue is already being executed by ${executionAgentName}.`
|
||||
: "Wakeup was deferred because this issue already has an active execution run.",
|
||||
issueId,
|
||||
executionRunId: executionRun.id,
|
||||
executionAgentId: executionRun.agentId,
|
||||
executionAgentName,
|
||||
};
|
||||
}
|
||||
|
||||
async function assertCanUpdateAgent(req: Request, targetAgent: { id: string; companyId: string }) {
|
||||
assertCompanyAccess(req, targetAgent.companyId);
|
||||
if (req.actor.type === "board") return;
|
||||
|
|
@ -532,8 +599,15 @@ export function agentRoutes(db: Db) {
|
|||
};
|
||||
}
|
||||
|
||||
const ADAPTERS_REQUIRING_MATERIALIZED_RUNTIME_SKILLS = new Set([
|
||||
"cursor",
|
||||
"gemini_local",
|
||||
"opencode_local",
|
||||
"pi_local",
|
||||
]);
|
||||
|
||||
function shouldMaterializeRuntimeSkillsForAdapter(adapterType: string) {
|
||||
return adapterType !== "claude_local";
|
||||
return ADAPTERS_REQUIRING_MATERIALIZED_RUNTIME_SKILLS.has(adapterType);
|
||||
}
|
||||
|
||||
async function buildRuntimeSkillConfig(
|
||||
|
|
@ -1001,6 +1075,7 @@ export function agentRoutes(db: Db) {
|
|||
projectId: issue.projectId,
|
||||
goalId: issue.goalId,
|
||||
parentId: issue.parentId,
|
||||
lastActivityAt: (issue as typeof issue & { lastActivityAt?: Date | null }).lastActivityAt ?? issue.updatedAt,
|
||||
updatedAt: issue.updatedAt,
|
||||
activeRun: issue.activeRun,
|
||||
})),
|
||||
|
|
@ -1994,7 +2069,7 @@ export function agentRoutes(db: Db) {
|
|||
});
|
||||
|
||||
if (!run) {
|
||||
res.status(202).json({ status: "skipped" });
|
||||
res.status(202).json(await buildSkippedWakeupResponse(agent, req.body.payload ?? null));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,11 @@ export function instanceSettingsRoutes(db: Db) {
|
|||
const svc = instanceSettingsService(db);
|
||||
|
||||
router.get("/instance/settings/general", async (req, res) => {
|
||||
assertCanManageInstanceSettings(req);
|
||||
// General settings (e.g. keyboardShortcuts) are readable by any
|
||||
// authenticated board user. Only PATCH requires instance-admin.
|
||||
if (req.actor.type !== "board") {
|
||||
throw forbidden("Board access required");
|
||||
}
|
||||
res.json(await svc.getGeneral());
|
||||
});
|
||||
|
||||
|
|
@ -56,7 +60,11 @@ export function instanceSettingsRoutes(db: Db) {
|
|||
);
|
||||
|
||||
router.get("/instance/settings/experimental", async (req, res) => {
|
||||
assertCanManageInstanceSettings(req);
|
||||
// Experimental settings are readable by any authenticated board user.
|
||||
// Only PATCH requires instance-admin.
|
||||
if (req.actor.type !== "board") {
|
||||
throw forbidden("Board access required");
|
||||
}
|
||||
res.json(await svc.getExperimental());
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue