Skip to content

Commit b28b2a3

Browse files
committed
simplify event
1 parent 21da67d commit b28b2a3

13 files changed

Lines changed: 30 additions & 60 deletions

File tree

apps/sim/app/api/copilot/chat/delete/route.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ vi.mock('@/lib/copilot/chat/lifecycle', () => ({
4141
}))
4242

4343
vi.mock('@/lib/copilot/tasks', () => ({
44-
taskPubSub: { publishStatusChanged: vi.fn() },
44+
taskPubSub: { publishTaskListChanged: vi.fn() },
4545
}))
4646

4747
import { DELETE } from './route'

apps/sim/app/api/copilot/chat/delete/route.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ export async function DELETE(request: NextRequest) {
4141
logger.info('Chat deleted', { chatId: parsed.chatId })
4242

4343
if (deleted.workspaceId) {
44-
taskPubSub?.publishStatusChanged({
44+
taskPubSub?.publishTaskListChanged({
4545
workspaceId: deleted.workspaceId,
46-
chatId: parsed.chatId,
47-
type: 'deleted',
4846
})
4947
}
5048

apps/sim/app/api/copilot/chat/rename/route.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@ export async function PATCH(request: NextRequest) {
4444
logger.info('Chat renamed', { chatId, title })
4545

4646
if (updated.workspaceId) {
47-
taskPubSub?.publishStatusChanged({
47+
taskPubSub?.publishTaskListChanged({
4848
workspaceId: updated.workspaceId,
49-
chatId,
50-
type: 'renamed',
5149
})
5250
}
5351

apps/sim/app/api/copilot/chat/stop/route.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,8 @@ export async function POST(req: NextRequest) {
126126
.returning({ workspaceId: copilotChats.workspaceId })
127127

128128
if (updated?.workspaceId) {
129-
taskPubSub?.publishStatusChanged({
129+
taskPubSub?.publishTaskListChanged({
130130
workspaceId: updated.workspaceId,
131-
chatId,
132-
type: 'completed',
133131
})
134132
}
135133

apps/sim/app/api/copilot/chats/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export async function POST(request: NextRequest) {
128128
return createInternalServerErrorResponse('Failed to create chat')
129129
}
130130

131-
taskPubSub?.publishStatusChanged({ workspaceId, chatId: result.chatId, type: 'created' })
131+
taskPubSub?.publishTaskListChanged({ workspaceId })
132132

133133
return NextResponse.json({ success: true, id: result.chatId })
134134
} catch (error) {

apps/sim/app/api/mothership/chats/[chatId]/route.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,8 @@ export async function PATCH(
165165

166166
if (updatedChat.workspaceId) {
167167
if (title !== undefined) {
168-
taskPubSub?.publishStatusChanged({
168+
taskPubSub?.publishTaskListChanged({
169169
workspaceId: updatedChat.workspaceId,
170-
chatId,
171-
type: 'renamed',
172170
})
173171
captureServerEvent(
174172
userId,
@@ -239,10 +237,8 @@ export async function DELETE(
239237
}
240238

241239
if (deletedChat.workspaceId) {
242-
taskPubSub?.publishStatusChanged({
240+
taskPubSub?.publishTaskListChanged({
243241
workspaceId: deletedChat.workspaceId,
244-
chatId,
245-
type: 'deleted',
246242
})
247243
captureServerEvent(
248244
userId,

apps/sim/app/api/mothership/chats/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export async function POST(request: NextRequest) {
9494
})
9595
.returning({ id: copilotChats.id })
9696

97-
taskPubSub?.publishStatusChanged({ workspaceId, chatId: chat.id, type: 'created' })
97+
taskPubSub?.publishTaskListChanged({ workspaceId })
9898

9999
captureServerEvent(
100100
userId,

apps/sim/app/api/mothership/events/route.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
22
* SSE endpoint for task status events.
33
*
4-
* Pushes `task_status` events to the browser when tasks are
5-
* started, completed, created, deleted, or renamed.
4+
* Pushes `task_status` events to the browser when the workspace task list
5+
* changes.
66
*
77
* Auth is handled via session cookies (EventSource sends cookies automatically).
88
*/
@@ -18,13 +18,9 @@ export const GET = createWorkspaceSSE({
1818
{
1919
subscribe: (workspaceId, send) => {
2020
if (!taskPubSub) return () => {}
21-
return taskPubSub.onStatusChanged((event) => {
21+
return taskPubSub.onTaskListChanged((event) => {
2222
if (event.workspaceId !== workspaceId) return
23-
send('task_status', {
24-
chatId: event.chatId,
25-
type: event.type,
26-
timestamp: Date.now(),
27-
})
23+
send('task_status', {})
2824
})
2925
},
3026
},

apps/sim/lib/copilot/chat/post.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ vi.mock('@/lib/copilot/chat/lifecycle', () => ({
8484

8585
vi.mock('@/lib/copilot/tasks', () => ({
8686
taskPubSub: {
87-
publishStatusChanged: vi.fn(),
87+
publishTaskListChanged: vi.fn(),
8888
},
8989
}))
9090

apps/sim/lib/copilot/chat/post.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ async function persistUserMessage(params: {
284284
.returning({ messages: copilotChats.messages })
285285

286286
if (notifyWorkspaceStatus && updated && workspaceId) {
287-
taskPubSub?.publishStatusChanged({ workspaceId, chatId, type: 'started' })
287+
taskPubSub?.publishTaskListChanged({ workspaceId })
288288
}
289289

290290
return Array.isArray(updated?.messages) ? updated.messages : undefined
@@ -348,11 +348,7 @@ function buildOnComplete(params: {
348348
})
349349

350350
if (notifyWorkspaceStatus && workspaceId) {
351-
taskPubSub?.publishStatusChanged({
352-
workspaceId,
353-
chatId,
354-
type: 'completed',
355-
})
351+
taskPubSub?.publishTaskListChanged({ workspaceId })
356352
}
357353
} catch (error) {
358354
logger.error(`[${requestId}] Failed to persist chat messages`, {
@@ -379,11 +375,7 @@ function buildOnError(params: {
379375
await finalizeAssistantTurn({ chatId, userMessageId })
380376

381377
if (notifyWorkspaceStatus && workspaceId) {
382-
taskPubSub?.publishStatusChanged({
383-
workspaceId,
384-
chatId,
385-
type: 'completed',
386-
})
378+
taskPubSub?.publishTaskListChanged({ workspaceId })
387379
}
388380
} catch (error) {
389381
logger.error(`[${requestId}] Failed to finalize errored chat stream`, {

0 commit comments

Comments
 (0)