Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/sim/app/api/admin/mothership/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { settings, user } from '@sim/db/schema'
import { getErrorMessage } from '@sim/utils/errors'
import { eq } from 'drizzle-orm'
import { type NextRequest, NextResponse } from 'next/server'
import { adminMothershipQuerySchema } from '@/lib/api/contracts/mothership-tasks'
import { adminMothershipQuerySchema } from '@/lib/api/contracts/mothership-chats'
import { mothershipEnvironmentSchema } from '@/lib/api/contracts/user'
import { searchParamsToObject, validationErrorResponse } from '@/lib/api/server'
import { getSession } from '@/lib/auth'
Expand Down
4 changes: 2 additions & 2 deletions apps/sim/app/api/copilot/chat/delete/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ vi.mock('@/lib/copilot/chat/lifecycle', () => ({
getAccessibleCopilotChatAuth: mockGetAccessibleCopilotChatAuth,
}))

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

import { DELETE } from './route'
Expand Down
4 changes: 2 additions & 2 deletions apps/sim/app/api/copilot/chat/delete/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { deleteCopilotChatContract } from '@/lib/api/contracts/copilot'
import { parseRequest } from '@/lib/api/server'
import { getSession } from '@/lib/auth'
import { getAccessibleCopilotChatAuth } from '@/lib/copilot/chat/lifecycle'
import { taskPubSub } from '@/lib/copilot/tasks'
import { chatPubSub } from '@/lib/copilot/chat-status'
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'

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

if (deleted.workspaceId) {
taskPubSub?.publishStatusChanged({
chatPubSub?.publishStatusChanged({
workspaceId: deleted.workspaceId,
chatId: parsed.chatId,
type: 'deleted',
Expand Down
4 changes: 2 additions & 2 deletions apps/sim/app/api/copilot/chat/rename/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { renameCopilotChatContract } from '@/lib/api/contracts/copilot'
import { parseRequest, validationErrorResponse } from '@/lib/api/server'
import { getSession } from '@/lib/auth'
import { getAccessibleCopilotChatAuth } from '@/lib/copilot/chat/lifecycle'
import { taskPubSub } from '@/lib/copilot/tasks'
import { chatPubSub } from '@/lib/copilot/chat-status'
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'

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

if (updated.workspaceId) {
taskPubSub?.publishStatusChanged({
chatPubSub?.publishStatusChanged({
workspaceId: updated.workspaceId,
chatId,
type: 'renamed',
Expand Down
4 changes: 2 additions & 2 deletions apps/sim/app/api/copilot/chat/stop/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ vi.mock('@/lib/copilot/chat/messages-store', () => ({
appendCopilotChatMessages: mockAppendCopilotChatMessages,
}))

vi.mock('@/lib/copilot/tasks', () => ({
taskPubSub: {
vi.mock('@/lib/copilot/chat-status', () => ({
chatPubSub: {
publishStatusChanged: mockPublishStatusChanged,
},
}))
Expand Down
4 changes: 2 additions & 2 deletions apps/sim/app/api/copilot/chat/stop/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import {
withStoppedContentBlock,
} from '@/lib/copilot/chat/persisted-message'
import { finalizeAssistantTurn } from '@/lib/copilot/chat/terminal-state'
import { chatPubSub } from '@/lib/copilot/chat-status'
import {
CopilotChatFinalizeOutcome,
CopilotStopOutcome,
} from '@/lib/copilot/generated/trace-attribute-values-v1'
import { TraceAttr } from '@/lib/copilot/generated/trace-attributes-v1'
import { TraceSpan } from '@/lib/copilot/generated/trace-spans-v1'
import { withIncomingGoSpan } from '@/lib/copilot/request/otel'
import { taskPubSub } from '@/lib/copilot/tasks'
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'

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

if (shouldPublishCompleted && result.workspaceId) {
taskPubSub?.publishStatusChanged({
chatPubSub?.publishStatusChanged({
workspaceId: result.workspaceId,
chatId,
type: 'completed',
Expand Down
4 changes: 2 additions & 2 deletions apps/sim/app/api/copilot/chats/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { type NextRequest, NextResponse } from 'next/server'
import { createWorkflowCopilotChatContract } from '@/lib/api/contracts/copilot'
import { parseRequest, validationErrorResponse } from '@/lib/api/server'
import { resolveOrCreateChat } from '@/lib/copilot/chat/lifecycle'
import { chatPubSub } from '@/lib/copilot/chat-status'
import {
authenticateCopilotRequestSessionOnly,
createBadRequestResponse,
createForbiddenResponse,
createInternalServerErrorResponse,
createUnauthorizedResponse,
} from '@/lib/copilot/request/http'
import { taskPubSub } from '@/lib/copilot/tasks'
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
import {
assertActiveWorkspaceAccess,
Expand Down Expand Up @@ -138,7 +138,7 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
return createInternalServerErrorResponse('Failed to create chat')
}

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

return NextResponse.json({ success: true, id: result.chatId })
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/mothership/chat/abort/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { NextRequest } from 'next/server'
import { mothershipChatAbortEnvelopeSchema } from '@/lib/api/contracts/mothership-tasks'
import { mothershipChatAbortEnvelopeSchema } from '@/lib/api/contracts/mothership-chats'
import { validationErrorResponse } from '@/lib/api/server'
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
import { POST as copilotAbortPost } from '@/app/api/copilot/chat/abort/route'
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/mothership/chat/resources/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { NextRequest, NextResponse } from 'next/server'
import { mothershipChatResourceEnvelopeSchema } from '@/lib/api/contracts/mothership-tasks'
import { mothershipChatResourceEnvelopeSchema } from '@/lib/api/contracts/mothership-chats'
import { validationErrorResponse } from '@/lib/api/server'
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
import {
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/mothership/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { type NextRequest, NextResponse } from 'next/server'
import {
mothershipChatGetQuerySchema,
mothershipChatPostEnvelopeSchema,
} from '@/lib/api/contracts/mothership-tasks'
} from '@/lib/api/contracts/mothership-chats'
import { validationErrorResponse } from '@/lib/api/server'
import { getSession } from '@/lib/auth'
import { handleUnifiedChatPost, maxDuration } from '@/lib/copilot/chat/post'
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/mothership/chat/stop/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { NextRequest } from 'next/server'
import { mothershipChatStopEnvelopeSchema } from '@/lib/api/contracts/mothership-tasks'
import { mothershipChatStopEnvelopeSchema } from '@/lib/api/contracts/mothership-chats'
import { validationErrorResponse } from '@/lib/api/server'
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
import { POST as copilotStopPost } from '@/app/api/copilot/chat/stop/route'
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/mothership/chat/stream/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { NextRequest } from 'next/server'
import { mothershipChatStreamQuerySchema } from '@/lib/api/contracts/mothership-tasks'
import { mothershipChatStreamQuerySchema } from '@/lib/api/contracts/mothership-chats'
import { validationErrorResponse } from '@/lib/api/server'
import { GET as copilotStreamGet, maxDuration } from '@/app/api/copilot/chat/stream/route'

Expand Down
6 changes: 3 additions & 3 deletions apps/sim/app/api/mothership/chats/[chatId]/fork/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { createLogger } from '@sim/logger'
import { generateId } from '@sim/utils/id'
import { eq } from 'drizzle-orm'
import { type NextRequest, NextResponse } from 'next/server'
import { forkMothershipChatContract } from '@/lib/api/contracts/mothership-tasks'
import { forkMothershipChatContract } from '@/lib/api/contracts/mothership-chats'
import { parseRequest } from '@/lib/api/server'
import { loadCopilotChatMessages } from '@/lib/copilot/chat/lifecycle'
import { appendCopilotChatMessages } from '@/lib/copilot/chat/messages-store'
import { chatPubSub } from '@/lib/copilot/chat-status'
import { fetchGo } from '@/lib/copilot/request/go/fetch'
import {
authenticateCopilotRequestSessionOnly,
Expand All @@ -19,7 +20,6 @@ import {
} from '@/lib/copilot/request/http'
import type { MothershipResource } from '@/lib/copilot/resources/types'
import { getMothershipBaseURL, getMothershipSourceEnvHeaders } from '@/lib/copilot/server/agent-url'
import { taskPubSub } from '@/lib/copilot/tasks'
import { env } from '@/lib/core/config/env'
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
import { captureServerEvent } from '@/lib/posthog/server'
Expand Down Expand Up @@ -154,7 +154,7 @@ export const POST = withRouteHandler(
}

if (newChat.workspaceId) {
taskPubSub?.publishStatusChanged({
chatPubSub?.publishStatusChanged({
workspaceId: newChat.workspaceId,
chatId: newId,
type: 'created',
Expand Down
4 changes: 2 additions & 2 deletions apps/sim/app/api/mothership/chats/[chatId]/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ vi.mock('@/lib/copilot/chat/persisted-message', () => ({
normalizeMessage: (m: unknown) => m,
}))

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

vi.mock('@/lib/posthog/server', () => ({
Expand Down
8 changes: 4 additions & 4 deletions apps/sim/app/api/mothership/chats/[chatId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
deleteMothershipChatContract,
getMothershipChatContract,
updateMothershipChatContract,
} from '@/lib/api/contracts/mothership-tasks'
} from '@/lib/api/contracts/mothership-chats'
import { parseRequest } from '@/lib/api/server'
import { getLatestRunForStream } from '@/lib/copilot/async-runs/repository'
import { buildEffectiveChatTranscript } from '@/lib/copilot/chat/effective-transcript'
Expand All @@ -18,6 +18,7 @@ import {
} from '@/lib/copilot/chat/lifecycle'
import { normalizeMessage } from '@/lib/copilot/chat/persisted-message'
import { reconcileChatStreamMarkers } from '@/lib/copilot/chat/stream-liveness'
import { chatPubSub } from '@/lib/copilot/chat-status'
import {
authenticateCopilotRequestSessionOnly,
createInternalServerErrorResponse,
Expand All @@ -27,7 +28,6 @@ import type { FilePreviewSession } from '@/lib/copilot/request/session'
import { readEvents } from '@/lib/copilot/request/session/buffer'
import { readFilePreviewSessions } from '@/lib/copilot/request/session/file-preview-session'
import { type StreamBatchEvent, toStreamBatchEvent } from '@/lib/copilot/request/session/types'
import { taskPubSub } from '@/lib/copilot/tasks'
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
import { captureServerEvent } from '@/lib/posthog/server'

Expand Down Expand Up @@ -185,7 +185,7 @@ export const PATCH = withRouteHandler(

if (updatedChat.workspaceId) {
if (title !== undefined) {
taskPubSub?.publishStatusChanged({
chatPubSub?.publishStatusChanged({
workspaceId: updatedChat.workspaceId,
chatId,
type: 'renamed',
Expand Down Expand Up @@ -264,7 +264,7 @@ export const DELETE = withRouteHandler(
}

if (deletedChat.workspaceId) {
taskPubSub?.publishStatusChanged({
chatPubSub?.publishStatusChanged({
workspaceId: deletedChat.workspaceId,
chatId,
type: 'deleted',
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/mothership/chats/read/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { copilotChats } from '@sim/db/schema'
import { createLogger } from '@sim/logger'
import { and, eq, sql } from 'drizzle-orm'
import { type NextRequest, NextResponse } from 'next/server'
import { markMothershipChatReadContract } from '@/lib/api/contracts/mothership-tasks'
import { markMothershipChatReadContract } from '@/lib/api/contracts/mothership-chats'
import { parseRequest } from '@/lib/api/server'
import {
authenticateCopilotRequestSessionOnly,
Expand Down
4 changes: 2 additions & 2 deletions apps/sim/app/api/mothership/chats/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ vi.mock('@/lib/copilot/chat/stream-liveness', () => ({
reconcileChatStreamMarkers: mockReconcileChatStreamMarkers,
}))

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

vi.mock('@/lib/posthog/server', () => ({
Expand Down
6 changes: 3 additions & 3 deletions apps/sim/app/api/mothership/chats/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import { type NextRequest, NextResponse } from 'next/server'
import {
createMothershipChatContract,
listMothershipChatsContract,
} from '@/lib/api/contracts/mothership-tasks'
} from '@/lib/api/contracts/mothership-chats'
import { parseRequest } from '@/lib/api/server'
import { reconcileChatStreamMarkers } from '@/lib/copilot/chat/stream-liveness'
import { chatPubSub } from '@/lib/copilot/chat-status'
import {
authenticateCopilotRequestSessionOnly,
createForbiddenResponse,
createInternalServerErrorResponse,
createUnauthorizedResponse,
} from '@/lib/copilot/request/http'
import { taskPubSub } from '@/lib/copilot/tasks'
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
import { captureServerEvent } from '@/lib/posthog/server'
import {
Expand Down Expand Up @@ -111,7 +111,7 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
})
.returning({ id: copilotChats.id })

taskPubSub?.publishStatusChanged({ workspaceId, chatId: chat.id, type: 'created' })
chatPubSub?.publishStatusChanged({ workspaceId, chatId: chat.id, type: 'created' })

captureServerEvent(
userId,
Expand Down
8 changes: 4 additions & 4 deletions apps/sim/app/api/mothership/events/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/

import type { NextRequest } from 'next/server'
import { mothershipEventsQuerySchema } from '@/lib/api/contracts/mothership-tasks'
import { mothershipEventsQuerySchema } from '@/lib/api/contracts/mothership-chats'
import { validationErrorResponse } from '@/lib/api/server'
import { taskPubSub } from '@/lib/copilot/tasks'
import { chatPubSub } from '@/lib/copilot/chat-status'
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
import { createWorkspaceSSE } from '@/lib/events/sse-endpoint'

Expand All @@ -21,8 +21,8 @@ const mothershipEventsHandler = createWorkspaceSSE({
subscriptions: [
{
subscribe: (workspaceId, send) => {
if (!taskPubSub) return () => {}
return taskPubSub.onStatusChanged((event) => {
if (!chatPubSub) return () => {}
return chatPubSub.onStatusChanged((event) => {
if (event.workspaceId !== workspaceId) return
send('task_status', {
chatId: event.chatId,
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/mothership/execute/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createLogger } from '@sim/logger'
import { getErrorMessage, toError } from '@sim/utils/errors'
import { generateId } from '@sim/utils/id'
import { type NextRequest, NextResponse } from 'next/server'
import { mothershipExecuteContract } from '@/lib/api/contracts/mothership-tasks'
import { mothershipExecuteContract } from '@/lib/api/contracts/mothership-chats'
import { parseRequest } from '@/lib/api/server'
import { checkInternalAuth } from '@/lib/auth/hybrid'
import { buildIntegrationToolSchemas } from '@/lib/copilot/chat/payload'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default function TaskLayout({ children }: { children: React.ReactNode }) {
export default function ChatLayout({ children }: { children: React.ReactNode }) {
return <div className='flex h-full flex-1 flex-col overflow-hidden'>{children}</div>
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ export const metadata: Metadata = {
title: 'Chat',
}

interface TaskPageProps {
interface ChatPageProps {
params: Promise<{
workspaceId: string
taskId: string
chatId: string
}>
searchParams: Promise<{ resource?: string }>
}

export default async function TaskPage({ params, searchParams }: TaskPageProps) {
const [{ taskId }, { resource }, session] = await Promise.all([
export default async function ChatPage({ params, searchParams }: ChatPageProps) {
const [{ chatId }, { resource }, session] = await Promise.all([
params,
searchParams,
getSession(),
])
return (
<Home
key={taskId}
chatId={taskId}
key={chatId}
chatId={chatId}
userName={session?.user?.name}
userId={session?.user?.id}
initialResourceId={resource ?? null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from '@/components/emcn'
import { cn } from '@/lib/core/utils/cn'
import { useSubmitCopilotFeedback } from '@/hooks/queries/copilot-feedback'
import { useForkTask } from '@/hooks/queries/tasks'
import { useForkMothershipChat } from '@/hooks/queries/mothership-chats'
import { useFolderStore } from '@/stores/folders/store'

const SPECIAL_TAGS = 'thinking|options|usage_upgrade|credential|mothership-error|file'
Expand Down Expand Up @@ -72,7 +72,7 @@ export const MessageActions = memo(function MessageActions({
const resetTimeoutRef = useRef<number | null>(null)
const requestIdTimeoutRef = useRef<number | null>(null)
const submitFeedback = useSubmitCopilotFeedback()
const forkTask = useForkTask(params.workspaceId)
const forkChat = useForkMothershipChat(params.workspaceId)

useEffect(() => {
return () => {
Expand Down Expand Up @@ -151,11 +151,11 @@ export const MessageActions = memo(function MessageActions({
}

const handleFork = async () => {
if (!chatId || !messageId || forkTask.isPending) return
if (!chatId || !messageId || forkChat.isPending) return
try {
const result = await forkTask.mutateAsync({ chatId, upToMessageId: messageId })
useFolderStore.getState().clearTaskSelection()
router.push(`/workspace/${params.workspaceId}/task/${result.id}`)
const result = await forkChat.mutateAsync({ chatId, upToMessageId: messageId })
useFolderStore.getState().clearChatSelection()
router.push(`/workspace/${params.workspaceId}/chat/${result.id}`)
} catch {
toast.error('Failed to fork chat')
}
Expand Down Expand Up @@ -223,8 +223,8 @@ export const MessageActions = memo(function MessageActions({
type='button'
aria-label='Fork from here'
onClick={handleFork}
disabled={forkTask.isPending}
className={cn(BUTTON_CLASS, forkTask.isPending && 'cursor-not-allowed opacity-50')}
disabled={forkChat.isPending}
className={cn(BUTTON_CLASS, forkChat.isPending && 'cursor-not-allowed opacity-50')}
>
<GitBranch className={ICON_CLASS} />
</button>
Expand Down
Loading
Loading