Skip to content

Commit 0a0b72a

Browse files
committed
fix(copilot): preserve view pin clear requests
1 parent e2d2284 commit 0a0b72a

2 files changed

Lines changed: 46 additions & 4 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @vitest-environment node
3+
*/
4+
import { describe, expect, it } from 'vitest'
5+
import { addMothershipChatResourceBodySchema } from '@/lib/api/contracts/mothership-chats'
6+
7+
const TABLE_RESOURCE = {
8+
type: 'table' as const,
9+
id: 'table-1',
10+
title: 'Accounts',
11+
}
12+
13+
describe('addMothershipChatResourceBodySchema', () => {
14+
it('preserves an explicit saved-view pin clear through outbound parsing', () => {
15+
expect(
16+
addMothershipChatResourceBodySchema.parse({
17+
chatId: 'chat-1',
18+
resource: TABLE_RESOURCE,
19+
clearViewId: true,
20+
})
21+
).toEqual({ chatId: 'chat-1', resource: TABLE_RESOURCE, clearViewId: true })
22+
})
23+
24+
it('rejects a clear directive for a non-table resource', () => {
25+
expect(
26+
addMothershipChatResourceBodySchema.safeParse({
27+
chatId: 'chat-1',
28+
resource: { type: 'file', id: 'file-1', title: 'Accounts.csv' },
29+
clearViewId: true,
30+
}).success
31+
).toBe(false)
32+
})
33+
34+
it('rejects a clear directive paired with a replacement pin', () => {
35+
expect(
36+
addMothershipChatResourceBodySchema.safeParse({
37+
chatId: 'chat-1',
38+
resource: { ...TABLE_RESOURCE, viewId: 'view-1' },
39+
clearViewId: true,
40+
}).success
41+
).toBe(false)
42+
})
43+
})

apps/sim/lib/api/contracts/mothership-chats.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { z } from 'zod'
2+
import { addCopilotChatResourceBodySchema } from '@/lib/api/contracts/copilot'
23
import { scheduleContextSchema } from '@/lib/api/contracts/schedules'
34
import {
45
mountedSecretNamesSchema,
@@ -210,10 +211,8 @@ const mothershipChatResourcesResponseSchema = z.object({
210211
resources: z.array(mothershipChatResourceItemSchema),
211212
})
212213

213-
const addMothershipChatResourceBodySchema = z.object({
214-
chatId: z.string().min(1),
215-
resource: mothershipChatResourceItemSchema,
216-
})
214+
export const addMothershipChatResourceBodySchema = addCopilotChatResourceBodySchema
215+
export type AddMothershipChatResourceBody = z.input<typeof addMothershipChatResourceBodySchema>
217216

218217
const reorderMothershipChatResourcesBodySchema = z.object({
219218
chatId: z.string().min(1),

0 commit comments

Comments
 (0)