fix(mothership): stop duplicating chat resource tabs in workspace chats by waleedlatif1 · Pull Request #8537 · simstudioai/sim · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion apps/sim/lib/api/contracts/mothership-resource-tools.ts
3 changes: 2 additions & 1 deletion apps/sim/lib/mothership/agent-cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ async function executeBoundAgentCliRequest(
} else throw new Error('Service invocation must use the service bridge')
if (resources.length)
result = { ...result, resources: [...resources, ...(result.resources ?? [])] }
if (result.resources?.length)
// Only organization chats address a workspace; a workspace chat's resources leave it implicit.
if (context.chatOrganizationId && result.resources?.length)
result = {
...result,
resources: result.resources.map((effect) => {
Expand Down
7 changes: 4 additions & 3 deletions apps/sim/lib/mothership/agent-cli/resource-owner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ beforeEach(() => {
})

describe('scoped CLI resource ownership', () => {
it('gives a workspace upload completion and explicit open the same resource identity', async () => {
it('gives a workspace upload completion, explicit open, and an open tab one identity', async () => {
const upload = await executeAgentCliRequest(
{ invocation: { kind: 'cli', argv: ['files', 'upload', '@/tmp/upload-acceptance.txt'] } },
context
Expand All @@ -102,9 +102,10 @@ describe('scoped CLI resource ownership', () => {
id: fileId,
title: file.name,
path: 'files/upload-acceptance.txt',
workspaceId: first,
})
expect(getChatResourceKey(resource)).toBe(getChatResourceKey(opened.resources[0]))
const openTab = getChatResourceKey({ type: 'file', id: fileId })
expect(getChatResourceKey(resource)).toBe(openTab)
expect(getChatResourceKey(opened.resources[0])).toBe(openTab)
expect(mocks.transport).toHaveBeenCalledTimes(1)
})

Expand Down
4 changes: 3 additions & 1 deletion apps/sim/lib/mothership/request/tools/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,9 @@ async function executeToolAndReportInner(
execContext.chatId,
options?.onEvent,
() => abortRequested(context, execContext, options),
toolCall.targetWorkspaceId ?? execContext.workspaceId,
execContext.organizationId
? (toolCall.targetWorkspaceId ?? execContext.workspaceId)
: undefined,
Comment thread
waleedlatif1 marked this conversation as resolved.
Outdated
execContext.userId
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ describe('server tool adapter authority boundary', () => {
})

it('forwards canonical open-resource effects without replacing target assertions or injecting a workflow', async () => {
const resources = [
{ type: 'workflow', id: 'flow', title: 'Canonical', workspaceId: 'workspace-1' },
]
const resources = [{ type: 'workflow', id: 'flow', title: 'Canonical' }]
mocks.routeExecution.mockResolvedValue({ resources })
const params = {
workspaceId: 'asserted-workspace',
Expand Down
1 change: 0 additions & 1 deletion apps/sim/lib/mothership/tools/server/open-resource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ describe('resource opening authorization boundary', () => {
'Canonical knowledge',
'Workflow run',
])
expect(result.resources.every((resource) => resource.workspaceId === 'ws-a')).toBe(true)
for (const read of Object.values(mocks))
expect(read).toHaveBeenCalledWith(
expect.objectContaining({
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/lib/mothership/tools/server/open-resource.ts
Loading