🤯 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(channel): always open a project's General channel (#22870)
Arvin Xu236361a6d760
diff --git a/apps/server/src/services/channel/defaultChannel.test.ts b/apps/server/src/services/channel/defaultChannel.test.tsindex 372ab25f226..8a32deb5f52 100644--- a/apps/server/src/services/channel/defaultChannel.test.ts+++ b/apps/server/src/services/channel/defaultChannel.test.ts@@ -32,12 +32,13 @@ describe('createDefaultChannel', () => {});it.each([false, undefined])(- 'creates nothing while `channel` is %s for the creator',+ 'still opens the project Channel while `channel` is %s for the creator',async (flag) => {getFlags.mockResolvedValue({ enableChannels: flag });await createDefaultChannel({ ...params, projectId: 'pro_1', workspaceId: 'ws_1' });- expect(getFlags).toHaveBeenCalledWith('owner');- expect(createDefault).not.toHaveBeenCalled();+ expect(createDefault).toHaveBeenCalledWith(+ expect.objectContaining({ projectId: 'pro_1', title: DEFAULT_CHANNEL_TITLE }),+ );},);@@ -63,9 +64,7 @@ describe('createDefaultChannel', () => {const error = vi.spyOn(console, 'error').mockImplementation(() => {});createDefault.mockRejectedValue(new Error('connection reset'));await expect(createDefaultChannel(params)).resolves.toBeUndefined();- getFlags.mockRejectedValue(new Error('config unavailable'));- await expect(createDefaultChannel(params)).resolves.toBeUndefined();- expect(error).toHaveBeenCalledTimes(2);+ expect(error).toHaveBeenCalledTimes(1);expect(error).toHaveBeenCalledWith(expect.any(String),expect.objectContaining({ agentId: 'agt_main', userId: 'owner' }),@@ -106,6 +105,9 @@ describe('createAgentDirectChannel', () => {const error = vi.spyOn(console, 'error').mockImplementation(() => {});createDirect.mockRejectedValue(new Error('connection reset'));await expect(createAgentDirectChannel(params)).resolves.toBeUndefined();+ getFlags.mockRejectedValue(new Error('config unavailable'));+ await expect(createAgentDirectChannel(params)).resolves.toBeUndefined();+ expect(error).toHaveBeenCalledTimes(2);expect(error).toHaveBeenCalledWith(expect.any(String),expect.objectContaining({ agentId: 'agt_main', userId: 'owner' }),diff --git a/apps/server/src/services/channel/defaultChannel.ts b/apps/server/src/services/channel/defaultChannel.tsindex eea2d072cc5..7623583cba3 100644--- a/apps/server/src/services/channel/defaultChannel.ts+++ b/apps/server/src/services/channel/defaultChannel.ts@@ -16,8 +16,8 @@ export interface DefaultChannelParams {}/**- * Runs `open` only while Channels are on for the creator. Best-effort: what it follows already- * exists, so a failure must not fail its creation.+ * Runs `open` best-effort: what it follows already exists, so a failure must not fail its+ * creation.*/const openForCreator = async (what: string,@@ -25,7 +25,6 @@ const openForCreator = async (open: () => Promise<unknown>,) => {try {- if (!(await isChannelEnabled(context.userId))) return;await open();} catch (error) {console.error(`[channel] Failed to create ${what}`, { ...context, error });@@ -34,7 +33,8 @@ const openForCreator = async (/*** Opens the Channel a new workspace or project starts with: its creator and its main Agent (the- * scope's LobeAI when that Agent needs a device).+ * scope's LobeAI when that Agent needs a device). Not gated by the `channel` flag: every project+ * starts with its General Channel, so turning Channels on later finds it already there.*/export const createDefaultChannel = async ({ db, ...context }: DefaultChannelParams) =>openForCreator('the default channel', context, () =>@@ -65,8 +65,12 @@ export const createAgentDirectChannel = async ({localDeviceId,...context}: AgentDirectChannelParams) =>- openForCreator('the direct channel of a new agent', context, () =>- new ChannelService(db, context.userId, context.workspaceId).createDirect(context.agentId, {- localDeviceId,- }),- );+ openForCreator('the direct channel of a new agent', context, async () => {+ if (!(await isChannelEnabled(context.userId))) return;+ await new ChannelService(db, context.userId, context.workspaceId).createDirect(+ context.agentId,+ {+ localDeviceId,+ },+ );+ });