mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-29 23:56:43 +01:00
feat: return completed handoffs to Agent Chat (#14408)
Return completed Agent Chat handoffs through a durable outbox and scope each generated update to its supplied tasks. Add recovery, browser delivery, result access, and calibrated quality coverage. Validated with two consecutive ten-case Claude/Codex campaigns, all CI checks, and a 5/5 review. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
3b4b270650
commit
83076d7e7c
59 files changed
+2696
-83
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { recordChatHandoff, recordChatCompletion, existingChatCompletionReply, acknowledgeChatCompletionReply } from "./chat-completion-delivery.js";
|
||||
import { mirrorSlackBoardComment, slackBoardReplyBindings } from "./slack-board-messages.js";
|
||||
import { assertAgentRunWriteAllowed } from "../agent-run-cancellation.js";
|
||||
import { externalConversationStateSql, nonIdleSlackIssueCondition, resumeSlackConversation } from "./slack-conversation-state.js";
|
||||
@@ -9126,6 +9127,7 @@ export function issueService(db: Db) {
|
||||
.select({
|
||||
id: issues.id,
|
||||
conversationAgentId: issues.conversationAgentId,
|
||||
originKind: issues.originKind,
|
||||
assigneeAgentId: issues.assigneeAgentId,
|
||||
status: issues.status,
|
||||
companyId: issues.companyId,
|
||||
@@ -9133,7 +9135,8 @@ export function issueService(db: Db) {
|
||||
.from(issues)
|
||||
.where(eq(issues.id, parentIssueId))
|
||||
.then((rows) => rows[0] ?? null);
|
||||
if (!parent || parent.conversationAgentId || !parent.assigneeAgentId || ["backlog", "done", "cancelled"].includes(parent.status)) {
|
||||
if (!parent || parent.conversationAgentId || !parent.assigneeAgentId || ["backlog", "cancelled"].includes(parent.status) ||
|
||||
(parent.status === "done" && parent.originKind !== "onboarding_first_task")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -9205,6 +9208,7 @@ export function issueService(db: Db) {
|
||||
}));
|
||||
|
||||
return {
|
||||
onboardingCompletion: parent.originKind === "onboarding_first_task",
|
||||
id: parent.id,
|
||||
assigneeAgentId: parent.assigneeAgentId,
|
||||
childIssueIds: children.map((child) => child.id),
|
||||
@@ -10159,6 +10163,7 @@ export function issueService(db: Db) {
|
||||
);
|
||||
|
||||
const [issue] = await tx.insert(issues).values(values).returning();
|
||||
await recordChatHandoff(tx, issue, actorRunId);
|
||||
if (idempotencyKey) {
|
||||
await tx.insert(issueCreateIdempotencyKeys).values({
|
||||
companyId,
|
||||
@@ -10945,6 +10950,7 @@ export function issueService(db: Db) {
|
||||
.returning()
|
||||
.then((rows: Array<typeof issues.$inferSelect>) => rows[0] ?? null);
|
||||
if (!updated) return null;
|
||||
await recordChatCompletion(tx, receiptExisting, updated);
|
||||
// An operator explicitly choosing a disposition owns that decision,
|
||||
// including choosing In Review while the conversation is Idle.
|
||||
if (actorUserId && issueData.status !== undefined) {
|
||||
@@ -12114,6 +12120,8 @@ export function issueService(db: Db) {
|
||||
metadata?: IssueCommentMetadata | null;
|
||||
attachmentIds?: string[];
|
||||
authorizationReason?: string | null;
|
||||
/** Server-only final assistant response, never a tool/progress comment. */
|
||||
completionReply?: boolean;
|
||||
sourceTrust?: typeof issueComments.$inferInsert.sourceTrust;
|
||||
createdAt?: Date | string | null;
|
||||
clientRequestId?: string;
|
||||
@@ -12149,7 +12157,7 @@ export function issueService(db: Db) {
|
||||
.where(eq(issues.id, issueId));
|
||||
// Caller-owned transactions (including chat and review comments) must
|
||||
// serialize with question creation before inserting the human comment.
|
||||
const issue = await (actor.userId ? issueQuery.for("update") : issueQuery)
|
||||
const issue = await (actor.userId || (actor.runId && dbOrTx !== db) ? issueQuery.for("update") : issueQuery)
|
||||
.then((rows: Array<{ companyId: string; conversationAgentId: string | null }>) => rows[0] ?? null);
|
||||
|
||||
if (!issue) throw notFound("Issue not found");
|
||||
@@ -12181,6 +12189,10 @@ export function issueService(db: Db) {
|
||||
throw conflict("Conversation session changed; this reply belongs to an earlier session");
|
||||
}
|
||||
}
|
||||
if (options?.completionReply && actor.agentId && actor.runId) {
|
||||
const delivered = await existingChatCompletionReply(dbOrTx, actor.runId, issueId);
|
||||
if (delivered) return redactIssueComment(delivered, currentUserRedactionOptions.enabled);
|
||||
}
|
||||
const authorType = issueCommentAuthorTypeSchema.parse(
|
||||
options?.authorType ??
|
||||
(actor.agentId ? "agent" : actor.userId ? "user" : "system"),
|
||||
@@ -12355,6 +12367,7 @@ export function issueService(db: Db) {
|
||||
!shouldUpgradeAttachmentAuthorization &&
|
||||
!shouldBindAttachments
|
||||
) {
|
||||
if (options?.completionReply && actor.agentId && createdByRunId) await acknowledgeChatCompletionReply(dbOrTx, createdByRunId, existing.id);
|
||||
return redactIssueComment(
|
||||
existing,
|
||||
currentUserRedactionOptions.enabled,
|
||||
@@ -12413,6 +12426,7 @@ export function issueService(db: Db) {
|
||||
.returning();
|
||||
}
|
||||
if (!comment) throw new Error("Failed to create issue comment");
|
||||
if (options?.completionReply && actor.agentId && createdByRunId) await acknowledgeChatCompletionReply(dbOrTx, createdByRunId, comment.id);
|
||||
|
||||
const boundAttachments: Array<{
|
||||
id: string;
|
||||
|
||||
Reference in new issue
Block a user