Skip to content

Commit 528d8e7

Browse files
committed
Autoload
1 parent 04a6f9d commit 528d8e7

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/hooks/use-copilot-initialization.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ export function useCopilotInitialization(props: UseCopilotInitializationProps) {
105105
isSendingMessage,
106106
])
107107

108-
/** Load auto-allowed tools once on mount */
108+
/** Load auto-allowed tools once on mount - runs immediately, independent of workflow */
109109
const hasLoadedAutoAllowedToolsRef = useRef(false)
110110
useEffect(() => {
111-
if (hasMountedRef.current && !hasLoadedAutoAllowedToolsRef.current) {
111+
if (!hasLoadedAutoAllowedToolsRef.current) {
112112
hasLoadedAutoAllowedToolsRef.current = true
113113
loadAutoAllowedTools().catch((err) => {
114114
logger.warn('[Copilot] Failed to load auto-allowed tools', err)

apps/sim/stores/panel/copilot/store.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,10 @@ const sseHandlers: Record<string, SSEHandler> = {
14811481
// Check if tool is auto-allowed - if so, execute even if it has an interrupt
14821482
const { autoAllowedTools: classAutoAllowed } = get()
14831483
const isClassAutoAllowed = name ? classAutoAllowed.includes(name) : false
1484-
if ((!hasInterrupt || isClassAutoAllowed) && (typeof inst?.execute === 'function' || typeof inst?.handleAccept === 'function')) {
1484+
if (
1485+
(!hasInterrupt || isClassAutoAllowed) &&
1486+
(typeof inst?.execute === 'function' || typeof inst?.handleAccept === 'function')
1487+
) {
14851488
if (isClassAutoAllowed && hasInterrupt) {
14861489
logger.info('[toolCallsById] Auto-executing class tool with interrupt (auto-allowed)', {
14871490
id,
@@ -2719,6 +2722,9 @@ export const useCopilotStore = create<CopilotStore>()(
27192722
// Load sensitive credential IDs for masking before streaming starts
27202723
await get().loadSensitiveCredentialIds()
27212724

2725+
// Ensure auto-allowed tools are loaded before tool calls arrive
2726+
await get().loadAutoAllowedTools()
2727+
27222728
let newMessages: CopilotMessage[]
27232729
if (revertState) {
27242730
const currentMessages = get().messages
@@ -3782,10 +3788,7 @@ export const useCopilotStore = create<CopilotStore>()(
37823788
const { id, name, params } = toolCall
37833789

37843790
// Guard against double execution - skip if already executing or in terminal state
3785-
if (
3786-
toolCall.state === ClientToolCallState.executing ||
3787-
isTerminalState(toolCall.state)
3788-
) {
3791+
if (toolCall.state === ClientToolCallState.executing || isTerminalState(toolCall.state)) {
37893792
logger.info('[executeIntegrationTool] Skipping - already executing or terminal', {
37903793
id,
37913794
name,

0 commit comments

Comments
 (0)