Skip to content

Commit b83d21b

Browse files
committed
fix(mothership): continue Sim Chat block conversations
1 parent 5c30d17 commit b83d21b

6 files changed

Lines changed: 35 additions & 1 deletion

File tree

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,32 @@ describe('mothership private trace provenance transport', () => {
207207
)
208208
})
209209

210+
it.each([true, false, undefined])(
211+
'forwards conversation replay opt-in: %s',
212+
async (useConversationHistory) => {
213+
mockRunHeadlessCopilotLifecycle.mockImplementation(
214+
async (payload: Record<string, unknown>) => {
215+
expect(payload.useConversationHistory).toBe(useConversationHistory)
216+
return successResult()
217+
}
218+
)
219+
const response = await POST(
220+
createMockRequest(
221+
'POST',
222+
{ ...requestBody, useConversationHistory },
223+
{
224+
'X-Sim-Mcp-Delegation': 'signed-block',
225+
Authorization: 'Bearer internal',
226+
'x-sim-billing-attribution': 'billing',
227+
},
228+
'http://localhost:3000/api/mothership/execute'
229+
),
230+
undefined
231+
)
232+
expect(response.status).toBe(200)
233+
}
234+
)
235+
210236
it('omits an absent response format from the headless lifecycle payload', async () => {
211237
mockRunHeadlessCopilotLifecycle.mockImplementation(async (payload: Record<string, unknown>) => {
212238
expect(payload).not.toHaveProperty('responseFormat')

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ export const POST = withRouteHandler(async (req: NextRequest) => {
148148
const {
149149
messages,
150150
responseFormat,
151+
useConversationHistory,
151152
modelSelection,
152153
effort,
153154
workspaceId,
@@ -301,6 +302,7 @@ export const POST = withRouteHandler(async (req: NextRequest) => {
301302
)
302303
const requestPayload: Record<string, unknown> = {
303304
messages: wireMessages,
305+
...(useConversationHistory !== undefined ? { useConversationHistory } : {}),
304306
...(modelSelection ? { modelSelection } : {}),
305307
...(effort ? { effort } : {}),
306308
...(responseFormat !== undefined ? { responseFormat } : {}),

‎apps/sim/executor/handlers/mothership/mothership-handler.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ describe('MothershipBlockHandler', () => {
794794
modelSelection: { model: 'gpt-6-astra', fastMode: false },
795795
effort: 'high',
796796
messages: [{ role: 'user', content: 'Hello from workflow' }],
797+
useConversationHistory: true,
797798
workspaceId: 'workspace-1',
798799
userId: 'user-1',
799800
chatId: resolveMothershipConversation('workspace-1', 'chat-uuid').chatId,
@@ -880,6 +881,7 @@ describe('MothershipBlockHandler', () => {
880881
modelSelection: { model: 'gpt-6-astra', fastMode: false },
881882
effort: 'high',
882883
messages: [{ role: 'user', content: 'Continue this thread' }],
884+
useConversationHistory: true,
883885
workspaceId: 'workspace-1',
884886
userId: 'user-1',
885887
chatId: resolveMothershipConversation('workspace-1', 'existing-chat-id').chatId,

‎apps/sim/executor/handlers/mothership/mothership-handler.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,7 @@ export class MothershipBlockHandler implements BlockHandler {
988988
const effort = ChatPayloadSchema.shape.effort.parse(inputs.effort ?? 'high')
989989
const body: Record<string, unknown> = {
990990
messages,
991+
useConversationHistory: true,
991992
modelSelection,
992993
effort,
993994
workspaceId: ctx.workspaceId || '',

‎apps/sim/lib/api/contracts/mothership-chats.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ const mothershipExecuteMcpToolSchema = z
116116
.passthrough()
117117

118118
export const mothershipExecuteBodySchema = z.object({
119+
useConversationHistory: z.boolean().optional(),
119120
effort: ChatPayloadSchema.shape.effort,
120121
modelSelection: ChatPayloadSchema.shape.modelSelection,
121122
messages: z.array(mothershipExecuteMessageSchema).min(1, 'At least one message is required'),

‎apps/sim/lib/mothership/generated/protocol.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ export interface ProtocolMismatch {
395395
}
396396

397397
/**
398-
* POST /api/mothership/execute — the one-shot headless surface used by Sim Chat blocks.
398+
* POST /api/mothership/execute — headless execution, with optional conversation replay.
399399
* The caller supplies the conversation and authorized catalog selectors. The worker
400400
* runs one bounded loop and streams mothership-stream-v1 frames. No skills or CLI;
401401
* discovery and execution resolve selected operations through Sim.
@@ -404,6 +404,8 @@ export interface ExecuteRequest extends StreamResponseReceipt {
404404
effort?: ChatRequest["effort"];
405405
modelSelection?: ModelSelection | undefined;
406406
messages: ExecuteMessage[];
407+
/** Replay stored turns before one new user message (optionally preceded by a system prompt). */
408+
useConversationHistory?: boolean | undefined;
407409
/** JSON schema for structured output; enforced by instruction + caller-side validation. */
408410
responseFormat?: unknown | undefined;
409411
userId: string;

0 commit comments

Comments
 (0)