Skip to content

Commit d54596a

Browse files
committed
fix(chat): scope the managed-credential listing to the group's workspace and carry only chat params on the handoff
1 parent cb68ed3 commit d54596a

3 files changed

Lines changed: 47 additions & 5 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
import { describe, expect, it } from 'vitest'
5+
import { chatUrl } from '@/app/workspace/[workspaceId]/home/hooks/chat-url'
6+
7+
function withSearch(search: string) {
8+
window.history.replaceState(null, '', `/workspace/ws-1/home${search}`)
9+
}
10+
11+
describe('chatUrl', () => {
12+
it('carries the mode and the open resource onto the chat path', () => {
13+
withSearch('?mode=assistant&resource=res-1')
14+
expect(chatUrl('ws-1', 'chat-1')).toBe(
15+
'/workspace/ws-1/chat/chat-1?mode=assistant&resource=res-1'
16+
)
17+
})
18+
19+
it('leaves a search query and its filters behind', () => {
20+
withSearch('?q=volvo&source=gmail&updated=7d&mode=assistant')
21+
expect(chatUrl('ws-1', 'chat-1')).toBe('/workspace/ws-1/chat/chat-1?mode=assistant')
22+
})
23+
24+
it('produces a clean path when nothing belongs on the chat', () => {
25+
withSearch('?q=volvo')
26+
expect(chatUrl('ws-1', 'chat-1')).toBe('/workspace/ws-1/chat/chat-1')
27+
})
28+
})
Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1+
import { modeParam, resourceParam } from '@/app/workspace/[workspaceId]/home/search-params'
2+
3+
/** The composer's URL state that belongs on a chat page: the mode and the open resource. */
4+
const CHAT_URL_PARAMS = [modeParam.key, resourceParam.key] as const
5+
16
/**
2-
* The URL a new chat is handed off to once the server names it. The current
3-
* query string rides along so the composer's URL-backed state, the mode above
4-
* all, survives the path swap: the first Assistant message must not bounce the
5-
* person back to Build.
7+
* The URL a new chat is handed off to once the server names it. Only the
8+
* params that belong on a chat ride along, so the mode survives the path swap
9+
* (the first Assistant message must not bounce the person back to Build) while
10+
* a search's `q` and filters, which never join a transcript, are left behind
11+
* whatever the URL held at that instant.
612
*/
713
export function chatUrl(workspaceId: string, chatId: string): string {
8-
return `/workspace/${workspaceId}/chat/${chatId}${window.location.search}`
14+
const current = new URLSearchParams(window.location.search)
15+
const carried = new URLSearchParams()
16+
for (const key of CHAT_URL_PARAMS) {
17+
const value = current.get(key)
18+
if (value) carried.set(key, value)
19+
}
20+
const search = carried.toString()
21+
return `/workspace/${workspaceId}/chat/${chatId}${search ? `?${search}` : ''}`
922
}

apps/sim/lib/credentials/environment.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ export async function getEnrolledManagedOAuthCredentials(
876876
.where(
877877
and(
878878
eq(credential.workspaceId, workspaceId),
879+
eq(credentialGroup.workspaceId, workspaceId),
879880
eq(credential.type, 'managed_oauth'),
880881
eq(user.id, userId),
881882
eq(user.emailVerified, true)

0 commit comments

Comments
 (0)