Skip to content

Commit 86427f8

Browse files
committed
fix(home): carry the Ask request mode through every send lane and refuse every non-server tool on an Ask turn
1 parent 4437b39 commit 86427f8

6 files changed

Lines changed: 20 additions & 4 deletions

File tree

apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4342,6 +4342,7 @@ export function useChat(
43424342
content: message,
43434343
fileAttachments,
43444344
contexts,
4345+
requestMode: options?.requestMode,
43454346
})
43464347
queueStore.setEditing(activeChatKey, null)
43474348
// Resume dispatch if it paused on this slot.
@@ -5009,6 +5010,7 @@ export function useChat(
50095010
content: dispatched.content,
50105011
fileAttachments: dispatched.fileAttachments,
50115012
contexts: dispatched.contexts,
5013+
...(dispatched.requestMode ? { requestMode: dispatched.requestMode } : {}),
50125014
userMessageId: withdrawnUserMessageId,
50135015
})
50145016
return

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/panel.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ export const Panel = memo(function Panel() {
512512
const handler = (e: Event) => {
513513
const detail = (e as CustomEvent<MothershipSendMessageDetail>).detail
514514
if (!detail?.message) return
515+
/** A mode-bearing send (Ask) belongs to the home chat, which has the mode; left unclaimed, it is stored for that surface. */
516+
if (detail.requestMode) return
515517
e.preventDefault()
516518
setActiveTab('copilot')
517519
copilotSendMessage(detail.message, detail.fileAttachments, detail.contexts, {

apps/sim/lib/copilot/tool-executor/executor.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,18 @@ export async function executeTool(
7878

7979
const normalizedParams = normalizeToolParams(toolId, params, context)
8080

81+
/**
82+
* An Ask turn reaches only Sim-executed server tools. An integration call and
83+
* a headless workflow run are both actions on a connected service or the
84+
* workspace, which an answer drawn from the knowledge bases never takes.
85+
*/
86+
if (context.requestMode === ASK_REQUEST_MODE && !(isKnownTool(toolId) && isSimExecuted(toolId))) {
87+
return { success: false, error: ASK_MODE_INTEGRATION_REFUSAL }
88+
}
89+
8190
const canUseRegisteredHandler =
8291
isKnownTool(toolId) && (isSimExecuted(toolId) || usesHeadlessClientFallback)
8392
if (!canUseRegisteredHandler) {
84-
if (context.requestMode === ASK_REQUEST_MODE) {
85-
return { success: false, error: ASK_MODE_INTEGRATION_REFUSAL }
86-
}
8793
const appParams = buildAppToolParams(normalizedParams, context)
8894
const options = {
8995
...(context.resolvedSecretTraceRegistry

apps/sim/lib/core/utils/browser-storage.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ export class MothershipHandoffStorage {
370370
: [...MothershipHandoffStorage.pendingContexts(workspaceId), ...contexts],
371371
...(handoff.fileAttachments?.length ? { fileAttachments: handoff.fileAttachments } : {}),
372372
...(handoff.resumeUserMessageId ? { resumeUserMessageId: handoff.resumeUserMessageId } : {}),
373+
...(handoff.requestMode ? { requestMode: handoff.requestMode } : {}),
373374
workspaceId,
374375
timestamp: Date.now(),
375376
})
@@ -429,6 +430,7 @@ export class MothershipHandoffStorage {
429430
return {
430431
...(data.message ? { message: data.message } : {}),
431432
contexts,
433+
...(data.requestMode === 'ask' ? { requestMode: 'ask' as const } : {}),
432434
...(Array.isArray(data.fileAttachments) && data.fileAttachments.length > 0
433435
? { fileAttachments: data.fileAttachments }
434436
: {}),

apps/sim/stores/mothership-queue/store.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export const useMothershipQueueStore = create<MothershipQueueState>()(
112112
content: patch.content,
113113
fileAttachments: patch.fileAttachments,
114114
contexts: patch.contexts,
115+
requestMode: patch.requestMode,
115116
}
116117
return { queues: setQueueForChat(state.queues, chatKey, next) }
117118
}),

apps/sim/stores/mothership-queue/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ export type QueuedMothershipMessage = QueuedMessage & {
2121
}
2222

2323
// Mutable fields an in-place edit overwrites; id and index are preserved by `replaceAt`.
24-
export type QueuedMessageEditPatch = Pick<QueuedMessage, 'content' | 'fileAttachments' | 'contexts'>
24+
export type QueuedMessageEditPatch = Pick<
25+
QueuedMessage,
26+
'content' | 'fileAttachments' | 'contexts' | 'requestMode'
27+
>
2528

2629
export interface MothershipQueueState {
2730
queues: Record<string, QueuedMothershipMessage[]>

0 commit comments

Comments
 (0)