mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-20 00:53:46 +01:00
Keep standing chats out of the execution task sequence
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
94020ae8ad
commit
da00e353f4
5 files changed
+66
-28
No files matched your search
@@ -155,7 +155,7 @@ import {
|
||||
).toBe(false);
|
||||
expect(
|
||||
(
|
||||
await issueService(db).list(companyId, { q: results[0].identifier! })
|
||||
await issueService(db).list(companyId, { q: results[0].title })
|
||||
).some((issue) => issue.id === results[0].id),
|
||||
).toBe(true);
|
||||
expect(
|
||||
@@ -1053,6 +1053,13 @@ describe("chat prompt policy", () => {
|
||||
expect(AGENT_CHAT_DIRECTIVE).toContain("say plainly that no earlier version was saved, and ask the person for the text they want");
|
||||
});
|
||||
|
||||
it("uses the company prefix for links in an unnumbered standing chat", () => {
|
||||
const prompt = buildPaperclipTaskMarkdown({ companyPrefix: "BOB", coordinatorWorkspace: true,
|
||||
issue: { id: "chat", identifier: null, title: "Chat", workMode: "standard", conversationAgentId: "agent" } });
|
||||
expect(prompt).toContain("/BOB/agents/");
|
||||
expect(prompt).not.toContain("/<prefix>/");
|
||||
});
|
||||
|
||||
it("points chat at the teams catalog for ready-made teams and stops the search there", () => {
|
||||
expect(AGENT_CHAT_DIRECTIVE).toContain("Ready-made teams are installable packages in Paperclip's teams catalog");
|
||||
expect(AGENT_CHAT_DIRECTIVE).toContain("list the catalog with GET /api/teams/catalog");
|
||||
|
||||
@@ -3,7 +3,7 @@ import express from "express";
|
||||
import request from "supertest";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { expect, it, vi } from "vitest";
|
||||
import { agents, agentWakeupRequests, authUsers, companyOnboardingSeeds, goals, heartbeatRuns, issues, projects } from "@paperclipai/db";
|
||||
import { agents, agentWakeupRequests, authUsers, companies, companyOnboardingSeeds, goals, heartbeatRuns, issues, projects } from "@paperclipai/db";
|
||||
import { onboardingChatRoutes } from "../routes/onboarding-chat.js";
|
||||
import { issueService } from "../services/issues.js";
|
||||
import { issueThreadInteractionService } from "../services/issue-thread-interactions.js";
|
||||
@@ -30,6 +30,26 @@ describeEmbeddedPostgres("onboarding chat", () => {
|
||||
return { ...owner, agent, wakeup, app, path };
|
||||
}
|
||||
|
||||
it("keeps chats out of the task sequence, including repeated and concurrent onboarding opens", async () => {
|
||||
const { companyId, app, path } = await setup();
|
||||
const opened = await Promise.all([request(app).post(path), request(app).post(path)]);
|
||||
for (const response of opened) {
|
||||
expect(response.status).toBe(200);
|
||||
expect(response.body).toMatchObject({ identifier: null, issueNumber: null });
|
||||
}
|
||||
const [colleague] = await ctx.db.insert(agents).values({ companyId, name: "Grace", role: "engineer", status: "idle", adapterType: "process" }).returning();
|
||||
const secondChat = await request(app).post(`/api/companies/${companyId}/chats/${colleague.id}/onboarding`);
|
||||
expect(secondChat.status).toBe(200);
|
||||
expect(secondChat.body).toMatchObject({ identifier: null, issueNumber: null });
|
||||
const [company] = await ctx.db.select().from(companies).where(eq(companies.id, companyId));
|
||||
expect(company.issueCounter).toBe(0);
|
||||
const tasks = await Promise.all(Array.from({ length: 3 }, (_, index) =>
|
||||
issueService(ctx.db).create(companyId, { title: `Accepted task ${index}`, status: "backlog" }),
|
||||
));
|
||||
expect(tasks.map(task => task.issueNumber).sort()).toEqual([1, 2, 3]);
|
||||
expect(tasks.map(task => task.identifier).sort()).toEqual([1, 2, 3].map(number => `${company.issuePrefix}-${number}`));
|
||||
});
|
||||
|
||||
it("opens one owner-bound chat with signup context, zero execution tasks, zero projects, and no early wake", async () => {
|
||||
const { companyId, userId, agent, app, path, wakeup } = await setup();
|
||||
await ctx.db.insert(goals).values({ companyId, title: "Launch a robotics newsletter", level: "company", status: "active" });
|
||||
@@ -124,7 +144,7 @@ describeEmbeddedPostgres("onboarding chat", () => {
|
||||
const accepted = await interactions.acceptInteraction(chat, proposal.id, {}, { userId });
|
||||
expect(accepted.createdIssues).toHaveLength(1);
|
||||
const [task] = await issueService(ctx.db).list(companyId);
|
||||
expect(task).toMatchObject({ title: "Draft the editorial plan", parentId: null, assigneeAgentId: agent.id });
|
||||
expect(task).toMatchObject({ title: "Draft the editorial plan", parentId: null, assigneeAgentId: agent.id, issueNumber: 1 });
|
||||
expect((await documentService(ctx.db).getIssueDocumentByKey(task.id, "plan"))?.body).toBe(plan);
|
||||
await expect(interactions.acceptInteraction(chat, proposal.id, {}, { userId })).rejects.toThrow("already been resolved");
|
||||
expect(await issueService(ctx.db).list(companyId)).toHaveLength(1);
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { companies } from "@paperclipai/db";
|
||||
import type { Db, agents, agentTaskSessions, heartbeatRuns } from "@paperclipai/db";
|
||||
import { FAST_RESPONSE_AGENT_GUIDANCE, fastResponseHistoryBody, isValidIanaTimeZone } from "@paperclipai/shared";
|
||||
import type { PaperclipTurnContext } from "@paperclipai/adapter-utils/server-utils";
|
||||
@@ -252,7 +254,11 @@ export async function prepareHeartbeatTaskContext(db: Db, input: HeartbeatTaskCo
|
||||
: null;
|
||||
if (personTimeZone) context.paperclipConversationTimeZone = personTimeZone;
|
||||
else delete context.paperclipConversationTimeZone;
|
||||
const [chatCompany] = issueRef?.conversationAgentId && !issueRef.identifier
|
||||
? await db.select({ issuePrefix: companies.issuePrefix }).from(companies).where(eq(companies.id, agent.companyId))
|
||||
: [];
|
||||
const taskMarkdownInput = {
|
||||
companyPrefix: chatCompany?.issuePrefix,
|
||||
coordinatorWorkspace: Boolean(coordinatorWorkspace),
|
||||
personTimeZone,
|
||||
conferenceRoomEnabled: experimentalInstanceSettings.enableConferenceRoomChat === true,
|
||||
|
||||
@@ -7,6 +7,7 @@ import { TASK_QUESTION_GUIDANCE } from "../issue-question-context.js";
|
||||
import { ONBOARDING_CHAT_DIRECTIVE, ONBOARDING_CHAT_GREETING_DIRECTIVE } from "../onboarding-chat-prompt.js";
|
||||
|
||||
export function buildPaperclipTaskMarkdown(input: {
|
||||
companyPrefix?: string | null;
|
||||
onboardingChat?: boolean;
|
||||
onboardingGreeting?: boolean;
|
||||
issue: {
|
||||
@@ -92,10 +93,9 @@ export function buildPaperclipTaskMarkdown(input: {
|
||||
return [fence + "text", value, fence].join("\n");
|
||||
};
|
||||
const issue = input.issue;
|
||||
// Chat guidance names company pages as /<prefix>/...; a model can copy that
|
||||
// placeholder verbatim into a link the person clicks. The conversation's own
|
||||
// identifier (COM-1 -> COM) is the company prefix, so hand the agent real paths.
|
||||
const companyPagePrefix = /^(.+)-\d+$/.exec(issue?.identifier ?? "")?.[1] ?? null;
|
||||
// Unnumbered chats get the company's prefix directly. Legacy numbered chats
|
||||
// can fall back to their identifier so guidance always names real page paths.
|
||||
const companyPagePrefix = input.companyPrefix ?? /^(.+)-\d+$/.exec(issue?.identifier ?? "")?.[1] ?? null;
|
||||
const companyPages = (text: string) =>
|
||||
companyPagePrefix ? text.replaceAll("/<prefix>/", `/${companyPagePrefix}/`) : text;
|
||||
const ancestors = (input.ancestors ?? []).slice(0, 6);
|
||||
|
||||
@@ -11023,29 +11023,34 @@ export function issueService(db: Db) {
|
||||
executionWorkspaceSettings: issueData.executionWorkspaceSettings,
|
||||
});
|
||||
}
|
||||
// Self-correcting counter: use MAX(issue_number) + 1 if the counter
|
||||
// has drifted below the actual max, preventing identifier collisions.
|
||||
const [maxRow] = await tx
|
||||
.select({
|
||||
maxNum: sql<number>`coalesce(max(${issues.issueNumber}), 0)`,
|
||||
})
|
||||
.from(issues)
|
||||
.where(eq(issues.companyId, companyId));
|
||||
const currentMax = maxRow?.maxNum ?? 0;
|
||||
// Standing chats use UUIDs and do not consume execution task numbers.
|
||||
let issueNumber: number | null = null;
|
||||
let identifier: string | null = null;
|
||||
if (!issueData.conversationAgentId) {
|
||||
// Self-correcting counter: use MAX(issue_number) + 1 if the counter
|
||||
// has drifted below the actual max, preventing identifier collisions.
|
||||
const [maxRow] = await tx
|
||||
.select({
|
||||
maxNum: sql<number>`coalesce(max(${issues.issueNumber}), 0)`,
|
||||
})
|
||||
.from(issues)
|
||||
.where(eq(issues.companyId, companyId));
|
||||
const currentMax = maxRow?.maxNum ?? 0;
|
||||
|
||||
const [company] = await tx
|
||||
.update(companies)
|
||||
.set({
|
||||
issueCounter: sql`greatest(${companies.issueCounter}, ${currentMax}) + 1`,
|
||||
})
|
||||
.where(eq(companies.id, companyId))
|
||||
.returning({
|
||||
issueCounter: companies.issueCounter,
|
||||
issuePrefix: companies.issuePrefix,
|
||||
});
|
||||
const [company] = await tx
|
||||
.update(companies)
|
||||
.set({
|
||||
issueCounter: sql`greatest(${companies.issueCounter}, ${currentMax}) + 1`,
|
||||
})
|
||||
.where(eq(companies.id, companyId))
|
||||
.returning({
|
||||
issueCounter: companies.issueCounter,
|
||||
issuePrefix: companies.issuePrefix,
|
||||
});
|
||||
|
||||
const issueNumber = company.issueCounter;
|
||||
const identifier = `${company.issuePrefix}-${issueNumber}`;
|
||||
issueNumber = company.issueCounter;
|
||||
identifier = `${company.issuePrefix}-${issueNumber}`;
|
||||
}
|
||||
const responsibleUserId = await resolveResponsibleUserIdForIssueCreate(
|
||||
tx,
|
||||
companyId,
|
||||
|
||||
Reference in new issue
Block a user