Skip to content

Commit df7e731

Browse files
committed
Add payload
1 parent 4f4191f commit df7e731

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from '@/lib/copilot/chat-streaming'
1515
import { COPILOT_REQUEST_MODES } from '@/lib/copilot/models'
1616
import { orchestrateCopilotStream } from '@/lib/copilot/orchestrator'
17+
import { getUserEntityPermissions } from '@/lib/workspaces/permissions/utils'
1718
import {
1819
authenticateCopilotRequestSessionOnly,
1920
createBadRequestResponse,
@@ -218,6 +219,12 @@ export async function POST(req: NextRequest) {
218219

219220
const effectiveMode = mode === 'agent' ? 'build' : mode
220221

222+
const userPermission = resolvedWorkspaceId
223+
? await getUserEntityPermissions(authenticatedUserId, 'workspace', resolvedWorkspaceId).catch(
224+
() => null
225+
)
226+
: null
227+
221228
const requestPayload = await buildCopilotRequestPayload(
222229
{
223230
message,
@@ -236,6 +243,7 @@ export async function POST(req: NextRequest) {
236243
chatId: actualChatId,
237244
prefetch,
238245
implicitFeedback,
246+
userPermission: userPermission ?? undefined,
239247
},
240248
{
241249
selectedModel,

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { createSSEStream, SSE_RESPONSE_HEADERS } from '@/lib/copilot/chat-stream
1111
import type { OrchestratorResult } from '@/lib/copilot/orchestrator/types'
1212
import { createRequestTracker, createUnauthorizedResponse } from '@/lib/copilot/request-helpers'
1313
import { generateWorkspaceContext } from '@/lib/copilot/workspace-context'
14+
import { getUserEntityPermissions } from '@/lib/workspaces/permissions/utils'
1415

1516
const logger = createLogger('MothershipChatAPI')
1617

@@ -129,7 +130,10 @@ export async function POST(req: NextRequest) {
129130
.where(eq(copilotChats.id, actualChatId))
130131
}
131132

132-
const workspaceContext = await generateWorkspaceContext(workspaceId, authenticatedUserId)
133+
const [workspaceContext, userPermission] = await Promise.all([
134+
generateWorkspaceContext(workspaceId, authenticatedUserId),
135+
getUserEntityPermissions(authenticatedUserId, 'workspace', workspaceId).catch(() => null),
136+
])
133137

134138
const requestPayload = await buildCopilotRequestPayload(
135139
{
@@ -143,6 +147,7 @@ export async function POST(req: NextRequest) {
143147
contexts: agentContexts,
144148
fileAttachments,
145149
chatId: actualChatId,
150+
userPermission: userPermission ?? undefined,
146151
workspaceContext,
147152
},
148153
{ selectedModel: '' }

apps/sim/lib/copilot/chat-payload.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface BuildPayloadParams {
2626
prefetch?: boolean
2727
implicitFeedback?: string
2828
workspaceContext?: string
29+
userPermission?: string
2930
}
3031

3132
export interface ToolSchema {
@@ -164,6 +165,7 @@ export async function buildCopilotRequestPayload(
164165
...(integrationTools.length > 0 ? { integrationTools } : {}),
165166
...(commands && commands.length > 0 ? { commands } : {}),
166167
...(params.workspaceContext ? { workspaceContext: params.workspaceContext } : {}),
168+
...(params.userPermission ? { userPermission: params.userPermission } : {}),
167169
isHosted,
168170
}
169171
}

0 commit comments

Comments
 (0)