Skip to content

Commit 6bfce16

Browse files
committed
fix(mothership): stop duplicating chat resource tabs in workspace chats
1 parent 9a2b64d commit 6bfce16

7 files changed

Lines changed: 11 additions & 11 deletions

File tree

‎apps/sim/lib/api/contracts/mothership-resource-tools.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export const openResourceOutputSchema = z.object({
2929
type: z.enum(['workflow', 'table', 'knowledgebase', 'file', 'dashboard', 'log']),
3030
id: z.string(),
3131
title: z.string(),
32-
workspaceId: z.string(),
3332
viewId: z.string().optional(),
3433
executionId: z.string().optional(),
3534
})

‎apps/sim/lib/mothership/agent-cli/index.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ async function executeBoundAgentCliRequest(
177177
} else throw new Error('Service invocation must use the service bridge')
178178
if (resources.length)
179179
result = { ...result, resources: [...resources, ...(result.resources ?? [])] }
180-
if (result.resources?.length)
180+
// Only organization chats address a workspace; a workspace chat's resources leave it implicit.
181+
if (context.chatOrganizationId && result.resources?.length)
181182
result = {
182183
...result,
183184
resources: result.resources.map((effect) => {

‎apps/sim/lib/mothership/agent-cli/resource-owner.test.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ beforeEach(() => {
8585
})
8686

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

‎apps/sim/lib/mothership/request/tools/executor.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,9 @@ async function executeToolAndReportInner(
10401040
execContext.chatId,
10411041
options?.onEvent,
10421042
() => abortRequested(context, execContext, options),
1043-
toolCall.targetWorkspaceId ?? execContext.workspaceId,
1043+
execContext.organizationId
1044+
? (toolCall.targetWorkspaceId ?? execContext.workspaceId)
1045+
: undefined,
10441046
execContext.userId
10451047
)
10461048
}

‎apps/sim/lib/mothership/tools/registry/server-tool-adapter.test.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ describe('server tool adapter authority boundary', () => {
120120
})
121121

122122
it('forwards canonical open-resource effects without replacing target assertions or injecting a workflow', async () => {
123-
const resources = [
124-
{ type: 'workflow', id: 'flow', title: 'Canonical', workspaceId: 'workspace-1' },
125-
]
123+
const resources = [{ type: 'workflow', id: 'flow', title: 'Canonical' }]
126124
mocks.routeExecution.mockResolvedValue({ resources })
127125
const params = {
128126
workspaceId: 'asserted-workspace',

‎apps/sim/lib/mothership/tools/server/open-resource.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ describe('resource opening authorization boundary', () => {
8787
'Canonical knowledge',
8888
'Workflow run',
8989
])
90-
expect(result.resources.every((resource) => resource.workspaceId === 'ws-a')).toBe(true)
9190
for (const read of Object.values(mocks))
9291
expect(read).toHaveBeenCalledWith(
9392
expect.objectContaining({

‎apps/sim/lib/mothership/tools/server/open-resource.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const openResourceServerTool: BaseServerTool<OpenResourceInput, OpenResou
5656
assertServerToolNotAborted(context)
5757
if (resource.viewId && resource.type !== 'table')
5858
throw new OrchestrationError('validation', 'Saved views apply only to tables')
59-
const base = { type: resource.type, id: resource.id, workspaceId }
59+
const base = { type: resource.type, id: resource.id }
6060
switch (resource.type) {
6161
case 'workflow': {
6262
const { workflow } = await executeCopilotWorkflowUseCase(context, readWorkflowMetadata, {

0 commit comments

Comments
 (0)