Skip to content

Commit 62f063f

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(mothership): adapt editable panels to native resource events
1 parent b96af0e commit 62f063f

15 files changed

Lines changed: 83 additions & 30 deletions

File tree

‎apps/sim/app/workspace/[workspaceId]/home/components/chat-resource-panel.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use client'
22

33
import { lazy, type ReactNode, Suspense, useCallback } from 'react'
4-
import { UnsavedChangesModal } from '@/app/workspace/[workspaceId]/components/credential-detail'
54
import type { WorkspaceSearchFilters } from '@/lib/api/contracts/knowledge'
5+
import { UnsavedChangesModal } from '@/app/workspace/[workspaceId]/components/credential-detail'
66
import { ChatPanelLayout } from '@/app/workspace/[workspaceId]/home/components/chat-panel-layout'
77
import { MothershipResourcesProvider } from '@/app/workspace/[workspaceId]/home/components/mothership-resources-context'
88
import { useBrowserTabResources } from '@/app/workspace/[workspaceId]/home/hooks/use-browser-tab-resources'

‎apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/add-resource-dropdown/available-resources.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import { formatDate } from '@/app/workspace/[workspaceId]/logs/utils'
1212
import { useFeatureFlag } from '@/app/workspace/[workspaceId]/providers/feature-flags-provider'
1313
import { listIntegrationsByPopularity } from '@/blocks/integration-matcher'
1414
import { useCustomTools } from '@/hooks/queries/custom-tools'
15-
import { useMcpServers } from '@/hooks/queries/mcp'
16-
import { useSkills } from '@/hooks/queries/skills'
1715
import { useWorkspaceDashboard } from '@/hooks/queries/dashboards'
1816
import { useFolders } from '@/hooks/queries/folders'
1917
import { useKnowledgeBasesQuery } from '@/hooks/queries/kb/knowledge'
2018
import { useLogsList } from '@/hooks/queries/logs'
19+
import { useMcpServers } from '@/hooks/queries/mcp'
2120
import { useMothershipChats } from '@/hooks/queries/mothership-chats'
21+
import { useSkills } from '@/hooks/queries/skills'
2222
import { useTablesList } from '@/hooks/queries/tables'
2323
import { useWorkflows } from '@/hooks/queries/workflows'
2424
import { useWorkspaceFileFolders } from '@/hooks/queries/workspace-file-folders'
@@ -159,7 +159,8 @@ export function useAvailableResources(
159159
{ enabled: enabled && Boolean(workspaceId) }
160160
)
161161
const skillsEnabled = enabled && Boolean(workspaceId) && !excludeTypes?.includes('skill')
162-
const customToolsEnabled = enabled && Boolean(workspaceId) && !excludeTypes?.includes('custom_tool')
162+
const customToolsEnabled =
163+
enabled && Boolean(workspaceId) && !excludeTypes?.includes('custom_tool')
163164
const mcpServersEnabled = enabled && Boolean(workspaceId) && !excludeTypes?.includes('mcp_server')
164165
const { data: skills, isPending: skillsPending } = useSkills(workspaceId, {
165166
enabled: skillsEnabled,

‎apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/add-resource-dropdown/organization-resource-inventory.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export function OrganizationResourceInventory({
1515
excludeTypes?: readonly MothershipResourceType[]
1616
onChange: (workspaceId: string, inventory: AvailableResources) => void
1717
}) {
18-
const inventory = useAvailableResources(workspaceId, { includeFolderMentions: true, excludeTypes })
18+
const inventory = useAvailableResources(workspaceId, {
19+
includeFolderMentions: true,
20+
excludeTypes,
21+
})
1922
useEffect(() => {
2023
onChange(workspaceId, inventory)
2124
}, [workspaceId, inventory, onChange])

‎apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/resource-content.tsx‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -578,11 +578,7 @@ function EmbeddedResourceEditorAction({ href, label }: { href: string; label: st
578578
return (
579579
<Tooltip.Root>
580580
<Tooltip.Trigger asChild>
581-
<TabStripAction
582-
variant='subtle'
583-
onClick={handleOpen}
584-
aria-label={label}
585-
>
581+
<TabStripAction variant='subtle' onClick={handleOpen} aria-label={label}>
586582
<SquareArrowUpRight className={RESOURCE_TAB_ICON_CLASS} />
587583
</TabStripAction>
588584
</Tooltip.Trigger>

‎apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-registry/resource-invalidation.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import type { MothershipResourceType } from '@/lib/mothership/resources/types'
33
import { dashboardKeys } from '@/hooks/queries/dashboards'
44
import { deploymentKeys, invalidateDeploymentQueries } from '@/hooks/queries/deployments'
55
import { logKeys } from '@/hooks/queries/logs'
6+
import { mothershipChatKeys } from '@/hooks/queries/mothership-chats'
67
import { skillsKeys } from '@/hooks/queries/skills'
78
import { customToolsKeys } from '@/hooks/queries/utils/custom-tool-keys'
8-
import { mcpKeys } from '@/hooks/queries/utils/mcp-keys'
9-
import { mothershipChatKeys } from '@/hooks/queries/mothership-chats'
109
import { folderKeys } from '@/hooks/queries/utils/folder-keys'
1110
import { invalidateWorkflowLists } from '@/hooks/queries/utils/invalidate-workflow-lists'
1211
import { knowledgeKeys } from '@/hooks/queries/utils/knowledge-keys'
12+
import { mcpKeys } from '@/hooks/queries/utils/mcp-keys'
1313
import { tableKeys } from '@/hooks/queries/utils/table-keys'
1414
import { workflowKeys } from '@/hooks/queries/utils/workflow-keys'
1515
import { workspaceFileFolderKeys } from '@/hooks/queries/workspace-file-folders'

‎apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-registry/resource-registry.test.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import { QueryClient } from '@tanstack/react-query'
55
import { describe, expect, it, vi } from 'vitest'
66
import { invalidateResourceQueries } from '@/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-registry'
7-
import { mcpKeys } from '@/hooks/queries/utils/mcp-keys'
87
import { skillsKeys } from '@/hooks/queries/skills'
98
import { customToolsKeys } from '@/hooks/queries/utils/custom-tool-keys'
9+
import { mcpKeys } from '@/hooks/queries/utils/mcp-keys'
1010

1111
describe('panel resource invalidation', () => {
1212
it('refreshes the Skill and Custom Tool lists', () => {

‎apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-tabs/resource-tabs.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ import type {
5050
MothershipResourceType,
5151
} from '@/app/workspace/[workspaceId]/home/types'
5252
import { customToolsQueryOptions, useCustomTools } from '@/hooks/queries/custom-tools'
53-
import { mcpServersQueryOptions, useMcpServers } from '@/hooks/queries/mcp'
54-
import { getSkillsQueryOptions, useSkills } from '@/hooks/queries/skills'
5553
import { useFolders } from '@/hooks/queries/folders'
5654
import { useKnowledgeBasesQuery } from '@/hooks/queries/kb/knowledge'
55+
import { mcpServersQueryOptions, useMcpServers } from '@/hooks/queries/mcp'
56+
import { getSkillsQueryOptions, useSkills } from '@/hooks/queries/skills'
5757
import { useTablesList } from '@/hooks/queries/tables'
5858
import { getWorkflowListQueryOptions } from '@/hooks/queries/utils/workflow-list-query'
5959
import { useWorkflows } from '@/hooks/queries/workflows'

‎apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/mothership-view.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,9 @@ export const MothershipView = memo(
318318
isAgentResponding={isAgentResponding}
319319
genericResourceData={active.type === 'generic' ? genericResourceData : undefined}
320320
previewContextKey={chatId}
321-
onNotFound={(resourceId) => removeResource(active.type, resourceId, active.workspaceId)}
321+
onNotFound={(resourceId) =>
322+
removeResource(active.type, resourceId, active.workspaceId)
323+
}
322324
/>
323325
)}
324326
{!active && (

‎apps/sim/app/workspace/[workspaceId]/home/hooks/stream/handle-resource-event.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function handleResourceEvent(ctx: StreamLoopContext, parsed: ResourceEven
7070
(!settings.workspaceId || (chatWorkspaceId && settings.workspaceId !== chatWorkspaceId))
7171
)
7272
return
73-
refreshSettings(queryClient, settings)
73+
refreshSettings(queryClient, settings, ctx.deps.chatIdRef.current ?? undefined)
7474
if (settings.scope !== 'account' || settings.id === 'profile') ctx.deps.refreshRoute?.()
7575
return
7676
}

‎apps/sim/app/workspace/[workspaceId]/home/hooks/stream/refresh-settings.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import { refreshGeneralSettings } from '@/hooks/queries/general-settings'
55
import { mothershipChatKeys } from '@/hooks/queries/mothership-chats'
66

77
/** Read canonical settings again; replay must never restore a historical setting value. */
8-
export function refreshSettings(queryClient: QueryClient, settings: SettingsRefresh): void {
8+
export function refreshSettings(
9+
queryClient: QueryClient,
10+
settings: SettingsRefresh,
11+
chatId?: string
12+
): void {
913
if (settings.scope === 'account' && settings.id === 'preferences') {
1014
void refreshGeneralSettings(queryClient)
1115
return
@@ -14,6 +18,13 @@ export function refreshSettings(queryClient: QueryClient, settings: SettingsRefr
1418
void queryClient.invalidateQueries({ queryKey: userProfileKeys.all })
1519
return
1620
}
21+
if (
22+
chatId &&
23+
settings.scope === 'workspace' &&
24+
['skills', 'custom-tools', 'mcp'].includes(settings.id)
25+
) {
26+
void queryClient.invalidateQueries({ queryKey: mothershipChatKeys.detail(chatId) })
27+
}
1728
// Access, billing and integration policies affect resources beyond the Settings screen.
1829
// Keep live chat history stable while revalidating the rest of the current viewer's cache.
1930
void queryClient.invalidateQueries({

0 commit comments

Comments
 (0)