Skip to content

Commit 8e3c69c

Browse files
committed
refactor(mothership-chats): rename task feature to chat, move route, add redirect
- Move workspace route /task/[taskId] -> /chat/[chatId] and add a permanent redirect in next.config so existing bookmarks/deeplinks keep working - Rename client hooks queries/tasks.ts -> queries/mothership-chats.ts with the mothership-chat-prefixed family (distinct from the existing deployed-chat hooks in queries/chats.ts to avoid query-key collisions) - Rename contract mothership-tasks.ts -> mothership-chats.ts (MothershipChat) - Rename lib/copilot/tasks.ts -> chat-status.ts (chatPubSub, ChatStatusEvent) - Rename use-task-events -> use-mothership-chat-events, use-task-selection -> use-chat-selection, and folder-store chat-selection methods - Update server-generated deeplinks (oauth callback, inbox response, inbox list) - Preserve wire/persisted/analytics values that cross process or deploy boundaries: Redis channel task:status_changed, SSE event task_status, MothershipResourceType 'task', posthog event names, drag/itemType discriminants. Unrelated scheduled-tasks and email-inbox tasks untouched
1 parent c90a1eb commit 8e3c69c

57 files changed

Lines changed: 803 additions & 743 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { settings, user } from '@sim/db/schema'
33
import { getErrorMessage } from '@sim/utils/errors'
44
import { eq } from 'drizzle-orm'
55
import { type NextRequest, NextResponse } from 'next/server'
6-
import { adminMothershipQuerySchema } from '@/lib/api/contracts/mothership-tasks'
6+
import { adminMothershipQuerySchema } from '@/lib/api/contracts/mothership-chats'
77
import { mothershipEnvironmentSchema } from '@/lib/api/contracts/user'
88
import { searchParamsToObject, validationErrorResponse } from '@/lib/api/server'
99
import { getSession } from '@/lib/auth'

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ vi.mock('@/lib/copilot/chat/lifecycle', () => ({
1919
getAccessibleCopilotChatAuth: mockGetAccessibleCopilotChatAuth,
2020
}))
2121

22-
vi.mock('@/lib/copilot/tasks', () => ({
23-
taskPubSub: { publishStatusChanged: vi.fn() },
22+
vi.mock('@/lib/copilot/chat-status', () => ({
23+
chatPubSub: { publishStatusChanged: vi.fn() },
2424
}))
2525

2626
import { DELETE } from './route'

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { deleteCopilotChatContract } from '@/lib/api/contracts/copilot'
77
import { parseRequest } from '@/lib/api/server'
88
import { getSession } from '@/lib/auth'
99
import { getAccessibleCopilotChatAuth } from '@/lib/copilot/chat/lifecycle'
10-
import { taskPubSub } from '@/lib/copilot/tasks'
10+
import { chatPubSub } from '@/lib/copilot/chat-status'
1111
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
1212

1313
const logger = createLogger('DeleteChatAPI')
@@ -47,7 +47,7 @@ export const DELETE = withRouteHandler(async (request: NextRequest) => {
4747
logger.info('Chat deleted', { chatId: parsed.chatId })
4848

4949
if (deleted.workspaceId) {
50-
taskPubSub?.publishStatusChanged({
50+
chatPubSub?.publishStatusChanged({
5151
workspaceId: deleted.workspaceId,
5252
chatId: parsed.chatId,
5353
type: 'deleted',

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { renameCopilotChatContract } from '@/lib/api/contracts/copilot'
77
import { parseRequest, validationErrorResponse } from '@/lib/api/server'
88
import { getSession } from '@/lib/auth'
99
import { getAccessibleCopilotChatAuth } from '@/lib/copilot/chat/lifecycle'
10-
import { taskPubSub } from '@/lib/copilot/tasks'
10+
import { chatPubSub } from '@/lib/copilot/chat-status'
1111
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
1212

1313
const logger = createLogger('RenameChatAPI')
@@ -49,7 +49,7 @@ export const PATCH = withRouteHandler(async (request: NextRequest) => {
4949
logger.info('Chat renamed', { chatId, title })
5050

5151
if (updated.workspaceId) {
52-
taskPubSub?.publishStatusChanged({
52+
chatPubSub?.publishStatusChanged({
5353
workspaceId: updated.workspaceId,
5454
chatId,
5555
type: 'renamed',

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ vi.mock('@/lib/copilot/chat/messages-store', () => ({
1616
appendCopilotChatMessages: mockAppendCopilotChatMessages,
1717
}))
1818

19-
vi.mock('@/lib/copilot/tasks', () => ({
20-
taskPubSub: {
19+
vi.mock('@/lib/copilot/chat-status', () => ({
20+
chatPubSub: {
2121
publishStatusChanged: mockPublishStatusChanged,
2222
},
2323
}))

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import {
1010
withStoppedContentBlock,
1111
} from '@/lib/copilot/chat/persisted-message'
1212
import { finalizeAssistantTurn } from '@/lib/copilot/chat/terminal-state'
13+
import { chatPubSub } from '@/lib/copilot/chat-status'
1314
import {
1415
CopilotChatFinalizeOutcome,
1516
CopilotStopOutcome,
1617
} from '@/lib/copilot/generated/trace-attribute-values-v1'
1718
import { TraceAttr } from '@/lib/copilot/generated/trace-attributes-v1'
1819
import { TraceSpan } from '@/lib/copilot/generated/trace-spans-v1'
1920
import { withIncomingGoSpan } from '@/lib/copilot/request/otel'
20-
import { taskPubSub } from '@/lib/copilot/tasks'
2121
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
2222

2323
const logger = createLogger('CopilotChatStopAPI')
@@ -83,7 +83,7 @@ export const POST = withRouteHandler((req: NextRequest) =>
8383
result.updated || result.outcome === CopilotChatFinalizeOutcome.AssistantAlreadyPersisted
8484

8585
if (shouldPublishCompleted && result.workspaceId) {
86-
taskPubSub?.publishStatusChanged({
86+
chatPubSub?.publishStatusChanged({
8787
workspaceId: result.workspaceId,
8888
chatId,
8989
type: 'completed',

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import { type NextRequest, NextResponse } from 'next/server'
77
import { createWorkflowCopilotChatContract } from '@/lib/api/contracts/copilot'
88
import { parseRequest, validationErrorResponse } from '@/lib/api/server'
99
import { resolveOrCreateChat } from '@/lib/copilot/chat/lifecycle'
10+
import { chatPubSub } from '@/lib/copilot/chat-status'
1011
import {
1112
authenticateCopilotRequestSessionOnly,
1213
createBadRequestResponse,
1314
createForbiddenResponse,
1415
createInternalServerErrorResponse,
1516
createUnauthorizedResponse,
1617
} from '@/lib/copilot/request/http'
17-
import { taskPubSub } from '@/lib/copilot/tasks'
1818
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
1919
import {
2020
assertActiveWorkspaceAccess,
@@ -138,7 +138,7 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
138138
return createInternalServerErrorResponse('Failed to create chat')
139139
}
140140

141-
taskPubSub?.publishStatusChanged({ workspaceId, chatId: result.chatId, type: 'created' })
141+
chatPubSub?.publishStatusChanged({ workspaceId, chatId: result.chatId, type: 'created' })
142142

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

apps/sim/app/api/mothership/chat/abort/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { NextRequest } from 'next/server'
2-
import { mothershipChatAbortEnvelopeSchema } from '@/lib/api/contracts/mothership-tasks'
2+
import { mothershipChatAbortEnvelopeSchema } from '@/lib/api/contracts/mothership-chats'
33
import { validationErrorResponse } from '@/lib/api/server'
44
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
55
import { POST as copilotAbortPost } from '@/app/api/copilot/chat/abort/route'

apps/sim/app/api/mothership/chat/resources/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { NextRequest, NextResponse } from 'next/server'
2-
import { mothershipChatResourceEnvelopeSchema } from '@/lib/api/contracts/mothership-tasks'
2+
import { mothershipChatResourceEnvelopeSchema } from '@/lib/api/contracts/mothership-chats'
33
import { validationErrorResponse } from '@/lib/api/server'
44
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
55
import {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { type NextRequest, NextResponse } from 'next/server'
22
import {
33
mothershipChatGetQuerySchema,
44
mothershipChatPostEnvelopeSchema,
5-
} from '@/lib/api/contracts/mothership-tasks'
5+
} from '@/lib/api/contracts/mothership-chats'
66
import { validationErrorResponse } from '@/lib/api/server'
77
import { getSession } from '@/lib/auth'
88
import { handleUnifiedChatPost, maxDuration } from '@/lib/copilot/chat/post'

0 commit comments

Comments
 (0)