Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(channel): name a reply's topic for the member who runs it (#23553)

Lobehub Coder5af9a2491346
diff --git a/packages/database/src/repositories/channel/__tests__/jobTopic.test.ts b/packages/database/src/repositories/channel/__tests__/jobTopic.test.ts
index 2c678186bdc..60e6e8702d5 100644
--- a/packages/database/src/repositories/channel/__tests__/jobTopic.test.ts
+++ b/packages/database/src/repositories/channel/__tests__/jobTopic.test.ts
@@ -26,9 +26,10 @@ const runningReply = async () => {
const [job] = await jobsOf(db, request.id);
const claimed = (await execution.claim(team.channel.id, job.id, lease))!;
await execution.accepted(team.channel.id, job.id);
- const jobTopic = async (repo: typeof team.asOwner) =>
- (await repo.detail(team.channel.id)).jobs.find((entry) => entry.id === job.id)!.topicId;
- return { ...team, jobTopic, topicId: claimed.topic.id };
+ const jobOf = async (repo: typeof team.asOwner) =>
+ (await repo.detail(team.channel.id)).jobs.find((entry) => entry.id === job.id)!;
+ const jobTopic = async (repo: typeof team.asOwner) => (await jobOf(repo)).topicId;
+ return { ...team, jobOf, jobTopic, topicId: claimed.topic.id };
};
describe('Channel job topic', () => {
@@ -38,10 +39,19 @@ describe('Channel job topic', () => {
expect(await state.jobTopic(state.asMember)).toBe(state.topicId);
});
+ it('names the topic for the member running the reply', async () => {
+ const state = await runningReply();
+ await db.update(topics).set({ title: 'Fix the login bug' }).where(eq(topics.id, state.topicId));
+
+ expect((await state.jobOf(state.asMember)).topicTitle).toBe('Fix the login bug');
+ });
+
it('hides the topic from other members, admins included', async () => {
const state = await runningReply();
+ await db.update(topics).set({ title: 'Fix the login bug' }).where(eq(topics.id, state.topicId));
expect(await state.jobTopic(state.asOwner)).toBeUndefined();
+ expect(await state.jobOf(state.asOwner)).not.toHaveProperty('topicTitle');
});
it('drops the link once the topic is trashed', async () => {
diff --git a/packages/database/src/repositories/channel/__tests__/projectAccess.test.ts b/packages/database/src/repositories/channel/__tests__/projectAccess.test.ts
index baded9667ef..84248b167c4 100644
--- a/packages/database/src/repositories/channel/__tests__/projectAccess.test.ts
+++ b/packages/database/src/repositories/channel/__tests__/projectAccess.test.ts
@@ -92,6 +92,7 @@ describe('open project Channels', () => {
expect(jobs).toEqual([expect.objectContaining({ canStop: false, id: job.id })]);
expect(jobs[0]).not.toHaveProperty('topicId');
+ expect(jobs[0]).not.toHaveProperty('topicTitle');
expect(jobs[0]).not.toHaveProperty('topicOwnerId');
});
diff --git a/packages/database/src/repositories/channel/__tests__/shareVisitors.test.ts b/packages/database/src/repositories/channel/__tests__/shareVisitors.test.ts
index 6e0a63a29a6..8d65b0aaad8 100644
--- a/packages/database/src/repositories/channel/__tests__/shareVisitors.test.ts
+++ b/packages/database/src/repositories/channel/__tests__/shareVisitors.test.ts
@@ -114,6 +114,7 @@ describe('share visitor conversations', () => {
expect(view.messages.every((message) => message.sourceTopicId === null)).toBe(true);
expect(view.jobs.length).toBeGreaterThan(0);
expect(view.jobs.every((job) => !('topicId' in job))).toBe(true);
+ expect(view.jobs.every((job) => !('topicTitle' in job))).toBe(true);
});
it('keep a Workspace member’s own conversation private, even after the Agent turns private', async () => {
diff --git a/packages/database/src/repositories/channel/__tests__/view.test.ts b/packages/database/src/repositories/channel/__tests__/view.test.ts
index 3b42e2bbd52..d6a50425eb2 100644
--- a/packages/database/src/repositories/channel/__tests__/view.test.ts
+++ b/packages/database/src/repositories/channel/__tests__/view.test.ts
@@ -64,6 +64,7 @@ describe('Channel public view', () => {
expect(view.hasMore).toBe(true);
expect(view.members.find((member) => member.id === agent.id)?.name).toBe('Researcher');
expect(view.jobs[0]).not.toHaveProperty('topicId');
+ expect(view.jobs[0]).not.toHaveProperty('topicTitle');
expect(view.jobs[0]).not.toHaveProperty('operationId');
expect(view.jobs[0]).not.toHaveProperty('executionConfig');
expect(view).not.toHaveProperty('member');
diff --git a/packages/database/src/repositories/channel/shareVisitors.ts b/packages/database/src/repositories/channel/shareVisitors.ts
index bbaa486dbe8..68b1fe7a30f 100644
--- a/packages/database/src/repositories/channel/shareVisitors.ts
+++ b/packages/database/src/repositories/channel/shareVisitors.ts
@@ -253,7 +253,9 @@ export const readShareVisitorChannel = (
joined: false,
readOnly: true as const,
...view,
- jobs: viewerJobs(view.jobs, viewerId, () => false).map(({ topicId: _, ...job }) => job),
+ jobs: viewerJobs(view.jobs, viewerId, () => false).map(
+ ({ topicId: _, topicTitle: __, ...job }) => job,
+ ),
messages: view.messages.map(withoutTopic),
rootMessage: view.rootMessage && withoutTopic(view.rootMessage),
};
diff --git a/packages/database/src/repositories/channel/view.ts b/packages/database/src/repositories/channel/view.ts
index 0784ea88eef..ff594fc4380 100644
--- a/packages/database/src/repositories/channel/view.ts
+++ b/packages/database/src/repositories/channel/view.ts
@@ -283,6 +283,8 @@ const publicJobColumns = {
WHERE ${channelMessages.channelId} = ${channelJobs.channelId}
AND ${channelMessages.requestKey} = 'opening:' || ${channelJobs.id}::text)`,
topicId: channelJobs.topicId,
+ // Its name, under the same owner-only rule as the id, so a reply at work says which topic it is.
+ topicTitle: topics.title,
// A trashed topic has no owner here, so its link goes with it.
topicOwnerId: sql<string | null>`CASE WHEN ${notTrashed(topics.isDeleted)}
THEN ${topics.userId} ELSE NULL END`,
@@ -494,18 +496,18 @@ const environmentViewer = async (
};
/**
- * A view's jobs as one viewer sees them: who may stop each, and the run's topic only for the
- * viewer who runs the reply; for anyone else the job carries no topic at all.
+ * A view's jobs as one viewer sees them: who may stop each, and the run's topic (id and title)
+ * only for the viewer who runs the reply; for anyone else the job carries no topic at all.
*/
export const viewerJobs = (
jobs: Awaited<ReturnType<typeof readChannelView>>['jobs'],
viewerUserId: string,
canStop: (requesterMemberId: string | null) => boolean,
) =>
- jobs.map(({ requesterMemberId, topicId, topicOwnerId, ...job }) => ({
+ jobs.map(({ requesterMemberId, topicId, topicOwnerId, topicTitle, ...job }) => ({
...job,
canStop: canStop(requesterMemberId),
- ...(topicId && topicOwnerId === viewerUserId ? { topicId } : {}),
+ ...(topicId && topicOwnerId === viewerUserId ? { topicId, topicTitle } : {}),
}));
export const readChannelView = async (
diff --git a/packages/types/src/channel.ts b/packages/types/src/channel.ts
index 9a6ba3aeaee..8639246f908 100644
--- a/packages/types/src/channel.ts
+++ b/packages/types/src/channel.ts
@@ -903,6 +903,8 @@ export interface ChannelPublicJob {
* `sourceTopicId` on replies), so they can follow a reply still at work.
*/
topicId?: string;
+ /** That topic's title, under the same rule as `topicId`; null while the topic is unnamed. */
+ topicTitle?: string | null;
/** Git branch of the worktree the run works in, instead of the member's own directory. */
worktreeBranch?: string | null;
writerHeld: boolean;