Skip to content

Commit ebf687c

Browse files
committed
fix headless path
1 parent 8ef37a4 commit ebf687c

File tree

7 files changed

+84
-0
lines changed

7 files changed

+84
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { and, desc, eq, sql } from 'drizzle-orm'
55
import { type NextRequest, NextResponse } from 'next/server'
66
import { z } from 'zod'
77
import { getSession } from '@/lib/auth'
8+
import { createRunSegment } from '@/lib/copilot/async-runs/repository'
89
import { getAccessibleCopilotChat, resolveOrCreateChat } from '@/lib/copilot/chat-lifecycle'
910
import { buildCopilotRequestPayload } from '@/lib/copilot/chat-payload'
1011
import {
@@ -539,10 +540,26 @@ export async function POST(req: NextRequest) {
539540
return new Response(sseStream, { headers: SSE_RESPONSE_HEADERS })
540541
}
541542

543+
const nsExecutionId = crypto.randomUUID()
544+
const nsRunId = crypto.randomUUID()
545+
546+
if (actualChatId) {
547+
await createRunSegment({
548+
id: nsRunId,
549+
executionId: nsExecutionId,
550+
chatId: actualChatId,
551+
userId: authenticatedUserId,
552+
workflowId,
553+
streamId: userMessageIdToUse,
554+
}).catch(() => {})
555+
}
556+
542557
const nonStreamingResult = await orchestrateCopilotStream(requestPayload, {
543558
userId: authenticatedUserId,
544559
workflowId,
545560
chatId: actualChatId,
561+
executionId: nsExecutionId,
562+
runId: nsRunId,
546563
goRoute: '/api/copilot',
547564
autoExecuteTools: true,
548565
interactive: true,

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { eq, sql } from 'drizzle-orm'
1818
import { type NextRequest, NextResponse } from 'next/server'
1919
import { validateOAuthAccessToken } from '@/lib/auth/oauth-token'
2020
import { getHighestPrioritySubscription } from '@/lib/billing/core/subscription'
21+
import { createRunSegment } from '@/lib/copilot/async-runs/repository'
2122
import { ORCHESTRATION_TIMEOUT_MS, SIM_AGENT_API_URL } from '@/lib/copilot/constants'
2223
import { orchestrateCopilotStream } from '@/lib/copilot/orchestrator'
2324
import { orchestrateSubagentStream } from '@/lib/copilot/orchestrator/subagent'
@@ -727,10 +728,25 @@ async function handleBuildToolCall(
727728
chatId,
728729
}
729730

731+
const executionId = crypto.randomUUID()
732+
const runId = crypto.randomUUID()
733+
const messageId = requestPayload.messageId as string
734+
735+
await createRunSegment({
736+
id: runId,
737+
executionId,
738+
chatId,
739+
userId,
740+
workflowId: resolved.workflowId,
741+
streamId: messageId,
742+
}).catch(() => {})
743+
730744
const result = await orchestrateCopilotStream(requestPayload, {
731745
userId,
732746
workflowId: resolved.workflowId,
733747
chatId,
748+
executionId,
749+
runId,
734750
goRoute: '/api/mcp',
735751
autoExecuteTools: true,
736752
timeout: ORCHESTRATION_TIMEOUT_MS,

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createLogger } from '@sim/logger'
22
import { type NextRequest, NextResponse } from 'next/server'
33
import { z } from 'zod'
44
import { checkInternalAuth } from '@/lib/auth/hybrid'
5+
import { createRunSegment } from '@/lib/copilot/async-runs/repository'
56
import { buildIntegrationToolSchemas } from '@/lib/copilot/chat-payload'
67
import { appendCopilotLogContext } from '@/lib/copilot/logging'
78
import { orchestrateCopilotStream } from '@/lib/copilot/orchestrator'
@@ -71,10 +72,24 @@ export async function POST(req: NextRequest) {
7172
...(userPermission ? { userPermission } : {}),
7273
}
7374

75+
const executionId = crypto.randomUUID()
76+
const runId = crypto.randomUUID()
77+
78+
await createRunSegment({
79+
id: runId,
80+
executionId,
81+
chatId: effectiveChatId,
82+
userId,
83+
workspaceId,
84+
streamId: messageId,
85+
}).catch(() => {})
86+
7487
const result = await orchestrateCopilotStream(requestPayload, {
7588
userId,
7689
workspaceId,
7790
chatId: effectiveChatId,
91+
executionId,
92+
runId,
7893
goRoute: '/api/mothership/execute',
7994
autoExecuteTools: true,
8095
interactive: false,

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createLogger } from '@sim/logger'
22
import { type NextRequest, NextResponse } from 'next/server'
33
import { z } from 'zod'
4+
import { createRunSegment } from '@/lib/copilot/async-runs/repository'
45
import { appendCopilotLogContext } from '@/lib/copilot/logging'
56
import { COPILOT_REQUEST_MODES } from '@/lib/copilot/models'
67
import { orchestrateCopilotStream } from '@/lib/copilot/orchestrator'
@@ -104,10 +105,24 @@ export async function POST(req: NextRequest) {
104105
chatId,
105106
}
106107

108+
const executionId = crypto.randomUUID()
109+
const runId = crypto.randomUUID()
110+
111+
await createRunSegment({
112+
id: runId,
113+
executionId,
114+
chatId,
115+
userId: auth.userId,
116+
workflowId: resolved.workflowId,
117+
streamId: messageId,
118+
}).catch(() => {})
119+
107120
const result = await orchestrateCopilotStream(requestPayload, {
108121
userId: auth.userId,
109122
workflowId: resolved.workflowId,
110123
chatId,
124+
executionId,
125+
runId,
111126
goRoute: '/api/mcp',
112127
autoExecuteTools: parsed.autoExecuteTools,
113128
timeout: parsed.timeout,

apps/sim/app/workspace/[workspaceId]/home/components/message-content/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ const TOOL_ICONS: Record<MothershipToolName | SubagentName | 'mothership', IconC
8282
create_job: Calendar,
8383
manage_job: Calendar,
8484
update_job_history: Calendar,
85+
job_respond: Calendar,
8586
// Management
8687
manage_mcp_tool: Settings,
8788
manage_skill: Asterisk,

apps/sim/app/workspace/[workspaceId]/home/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export type MothershipToolName =
9898
| 'create_job'
9999
| 'complete_job'
100100
| 'update_job_history'
101+
| 'job_respond'
101102
| 'download_to_workspace_file'
102103
| 'materialize_file'
103104
| 'context_write'
@@ -377,6 +378,7 @@ export const TOOL_UI_METADATA: Record<MothershipToolName, ToolUIMetadata> = {
377378
create_job: { title: 'Creating job', phaseLabel: 'Resource', phase: 'resource' },
378379
manage_job: { title: 'Updating job', phaseLabel: 'Management', phase: 'management' },
379380
update_job_history: { title: 'Updating job', phaseLabel: 'Management', phase: 'management' },
381+
job_respond: { title: 'Explaining job scheduled', phaseLabel: 'Execution', phase: 'execution' },
380382
// Management
381383
manage_mcp_tool: { title: 'Updating integration', phaseLabel: 'Management', phase: 'management' },
382384
manage_skill: { title: 'Updating skill', phaseLabel: 'Management', phase: 'management' },

apps/sim/lib/mothership/inbox/executor.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { copilotChats, db, mothershipInboxTask, permissions, user, workspace } from '@sim/db'
22
import { createLogger } from '@sim/logger'
33
import { and, eq, sql } from 'drizzle-orm'
4+
import { createRunSegment } from '@/lib/copilot/async-runs/repository'
45
import { resolveOrCreateChat } from '@/lib/copilot/chat-lifecycle'
56
import { buildIntegrationToolSchemas } from '@/lib/copilot/chat-payload'
67
import { requestChatTitle } from '@/lib/copilot/chat-streaming'
@@ -187,10 +188,27 @@ export async function executeInboxTask(taskId: string): Promise<void> {
187188
...(fileAttachments.length > 0 ? { fileAttachments } : {}),
188189
}
189190

191+
const executionId = crypto.randomUUID()
192+
const runId = crypto.randomUUID()
193+
const runStreamId = crypto.randomUUID()
194+
195+
if (chatId) {
196+
await createRunSegment({
197+
id: runId,
198+
executionId,
199+
chatId,
200+
userId,
201+
workspaceId: ws.id,
202+
streamId: runStreamId,
203+
}).catch(() => {})
204+
}
205+
190206
const result = await orchestrateCopilotStream(requestPayload, {
191207
userId,
192208
workspaceId: ws.id,
193209
chatId: chatId ?? undefined,
210+
executionId,
211+
runId,
194212
goRoute: '/api/mothership/execute',
195213
autoExecuteTools: true,
196214
interactive: false,

0 commit comments

Comments
 (0)