This commit is contained in:
馨冉 2026-09-13 17:20:41 +08:00 committed by GitHub
commit 4ae3a56e59
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 8 deletions

View File

@ -864,14 +864,24 @@ describeEmbeddedPostgres("issueService.list participantAgentId", () => {
});
});
it("resolves only structured same-company agent mentions", async () => {
it("resolves only structured same-company wakeable agent mentions", async () => {
const companyId = await seedAssignableAgentCompany();
const otherCompanyId = await seedAssignableAgentCompany();
const localAgentId = randomUUID();
const foreignAgentId = randomUUID();
const terminatedAgentId = randomUUID();
const pausedAgentId = randomUUID();
const pendingAgentId = randomUUID();
const invalidChainAgentId = randomUUID();
const terminatedManagerId = randomUUID();
await db.insert(agents).values([
agentRow(companyId, { id: localAgentId, name: "LocalAgent" }),
agentRow(companyId, { id: terminatedAgentId, name: "TerminatedAgent", status: "terminated" }),
agentRow(companyId, { id: pausedAgentId, name: "PausedAgent", status: "paused" }),
agentRow(companyId, { id: pendingAgentId, name: "PendingAgent", status: "pending_approval" }),
agentRow(companyId, { id: terminatedManagerId, name: "TerminatedManager", status: "terminated" }),
agentRow(companyId, { id: invalidChainAgentId, name: "InvalidChainAgent", reportsTo: terminatedManagerId }),
agentRow(otherCompanyId, { id: foreignAgentId, name: "ForeignAgent" }),
]);
@ -879,6 +889,10 @@ describeEmbeddedPostgres("issueService.list participantAgentId", () => {
companyId,
[
`hello [@LocalAgent](${buildAgentMentionHref(localAgentId)})`,
`skip [@TerminatedAgent](${buildAgentMentionHref(terminatedAgentId)})`,
`skip [@PausedAgent](${buildAgentMentionHref(pausedAgentId)})`,
`skip [@PendingAgent](${buildAgentMentionHref(pendingAgentId)})`,
`skip [@InvalidChainAgent](${buildAgentMentionHref(invalidChainAgentId)})`,
`and [@ForeignAgent](${buildAgentMentionHref(foreignAgentId)})`,
].join(" "),
);

View File

@ -93,6 +93,7 @@ import {
issueCommentAuthorTypeSchema,
issueCommentMetadataSchema,
issueCommentPresentationSchema,
isAgentInvokable,
isUuidLike,
normalizeIssueIdentifier as normalizeIssueReferenceIdentifier,
} from "@paperclipai/shared";
@ -12927,14 +12928,20 @@ export function issueService(db: Db) {
const explicitAgentMentionIds = extractAgentMentionIds(body);
if (explicitAgentMentionIds.length === 0) return [];
const rows = await db
.select({ id: agents.id })
.from(agents)
.where(eq(agents.companyId, companyId));
const companyAgentIds = new Set(rows.map((agent) => agent.id));
return explicitAgentMentionIds.filter((agentId) =>
companyAgentIds.has(agentId),
const rows = await db.select({
id: agents.id,
companyId: agents.companyId,
name: agents.name,
status: agents.status,
reportsTo: agents.reportsTo,
})
.from(agents).where(eq(agents.companyId, companyId));
const wakeableCompanyAgentIds = new Set(
rows
.filter((agent) => isAgentInvokable({ agent, agents: rows }))
.map((agent) => agent.id),
);
return explicitAgentMentionIds.filter((agentId) => wakeableCompanyAgentIds.has(agentId));
},
findMentionedProjectIds: async (