Skip to content

Commit 9eeb1b2

Browse files
improvement(mothership): streaming state transitions (#4439)
* improvement(mothership): improve streaming state transitions * address comments
1 parent 1dc6f7d commit 9eeb1b2

10 files changed

Lines changed: 1931 additions & 447 deletions

File tree

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ const {
2929
mockSql: vi.fn((strings: TemplateStringsArray, ...values: unknown[]) => ({ strings, values })),
3030
}))
3131

32+
vi.mock('@sim/db/schema', () => ({
33+
copilotChats: {
34+
id: 'copilotChats.id',
35+
userId: 'copilotChats.userId',
36+
workspaceId: 'copilotChats.workspaceId',
37+
messages: 'copilotChats.messages',
38+
conversationId: 'copilotChats.conversationId',
39+
},
40+
}))
41+
3242
vi.mock('@sim/db', () => ({
3343
db: {
3444
select: mockSelect,
@@ -140,6 +150,7 @@ describe('copilot chat stop route', () => {
140150
workspaceId: 'ws-1',
141151
chatId: 'chat-1',
142152
type: 'completed',
153+
streamId: 'stream-1',
143154
})
144155
})
145156
})

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export const POST = withRouteHandler((req: NextRequest) =>
111111
workspaceId: updated.workspaceId,
112112
chatId,
113113
type: 'completed',
114+
streamId,
114115
})
115116
}
116117

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ async function handleResumeRequestBody({
248248
events: batchEvents,
249249
previewSessions,
250250
status: run.status,
251+
...(run.chatId ? { chatId: run.chatId } : {}),
251252
})
252253
}
253254

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const mothershipEventsHandler = createWorkspaceSSE({
2727
send('task_status', {
2828
chatId: event.chatId,
2929
type: event.type,
30+
...(event.streamId ? { streamId: event.streamId } : {}),
3031
timestamp: Date.now(),
3132
})
3233
})

0 commit comments

Comments
 (0)