mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-27 11:24:43 +00:00
feat(settings): add team appearance setting to hide agent features (#411)
* feat(settings): add team appearance setting to hide agent features Add an Appearance subpage under Team Settings allowing team owners to toggle appearance.hideAgent for the team. Return appearance.hideAgent in the user-metadata API, and conditionally hide the AGENTS.md button, agent chatbot sidebar, and chatbot trigger button in the WebUI. * refactor(settings): add strongly typed TeamSettingsResponse to remove explicit any Introduce TeamSettingsResponse and TeamAppearanceSettings in @shumai/dtos, type TeamService.getSettings and updateSettings, and eliminate the explicit any cast in AppearanceSettings.tsx.
This commit is contained in:
@@ -363,20 +363,26 @@ describe('TeamService', () => {
|
||||
})
|
||||
|
||||
const settings = await teamService.getSettings(team.id)
|
||||
expect(settings).toEqual({ semanticSearchEnabled: false })
|
||||
expect(settings).toEqual({ semanticSearchEnabled: false, appearance: { hideAgent: false } })
|
||||
|
||||
await teamService.updateSettings(team.id, 'theme', 'dark')
|
||||
|
||||
const newSettings = await teamService.getSettings(team.id)
|
||||
expect(newSettings).toEqual({ theme: 'dark', semanticSearchEnabled: false })
|
||||
expect(newSettings).toEqual({
|
||||
theme: 'dark',
|
||||
semanticSearchEnabled: false,
|
||||
appearance: { hideAgent: false },
|
||||
})
|
||||
|
||||
await teamService.updateSettings(team.id, 'transcode.videoStrategy', 'all')
|
||||
await teamService.updateSettings(team.id, 'transcode.hardwareAcceleration', 'auto')
|
||||
await teamService.updateSettings(team.id, 'appearance.hideAgent', true)
|
||||
|
||||
const finalSettings = await teamService.getSettings(team.id)
|
||||
expect(finalSettings).toEqual({
|
||||
theme: 'dark',
|
||||
transcode: { videoStrategy: 'all', hardwareAcceleration: 'auto' },
|
||||
appearance: { hideAgent: true },
|
||||
semanticSearchEnabled: false,
|
||||
})
|
||||
})
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
UserInfo,
|
||||
SandboxSettings,
|
||||
UpdateSandboxSettingsRequest,
|
||||
TeamSettingsResponse,
|
||||
} from '@shumai/dtos'
|
||||
|
||||
export class TeamService {
|
||||
@@ -288,53 +289,65 @@ export class TeamService {
|
||||
})
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
async getSettings(teamId: string): Promise<any> {
|
||||
async getSettings(teamId: string): Promise<TeamSettingsResponse> {
|
||||
const team = await prisma.team.findUnique({
|
||||
where: { id: teamId },
|
||||
})
|
||||
if (!team) throw new HTTPException(404, { message: 'team not found' })
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const settings = (team.settings || {}) as any
|
||||
const settings = (team.settings || {}) as TeamSettingsResponse
|
||||
|
||||
const embeddingAgent = await prisma.agent.findFirst({
|
||||
where: { teamId, type: 'embedding', enabled: true },
|
||||
})
|
||||
settings.semanticSearchEnabled = !!embeddingAgent
|
||||
|
||||
if (!settings.appearance) {
|
||||
settings.appearance = { hideAgent: false }
|
||||
} else if (settings.appearance.hideAgent === undefined) {
|
||||
settings.appearance.hideAgent = false
|
||||
}
|
||||
|
||||
return settings
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
async updateSettings(teamId: string, key: string, value: any): Promise<any> {
|
||||
async updateSettings(teamId: string, key: string, value: unknown): Promise<TeamSettingsResponse> {
|
||||
const team = await prisma.team.findUnique({ where: { id: teamId } })
|
||||
if (!team) throw new HTTPException(404, { message: 'team not found' })
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const settings = (team.settings || {}) as any
|
||||
const settings = (team.settings || {}) as TeamSettingsResponse
|
||||
|
||||
if (key === 'transcode.videoStrategy') {
|
||||
if (!settings.transcode) {
|
||||
settings.transcode = {}
|
||||
}
|
||||
settings.transcode.videoStrategy = value
|
||||
settings.transcode.videoStrategy = value as NonNullable<
|
||||
TeamSettingsResponse['transcode']
|
||||
>['videoStrategy']
|
||||
delete settings['transcode.videoStrategy']
|
||||
} else if (key === 'transcode.hardwareAcceleration') {
|
||||
if (!settings.transcode) {
|
||||
settings.transcode = {}
|
||||
}
|
||||
settings.transcode.hardwareAcceleration = value
|
||||
settings.transcode.hardwareAcceleration = value as NonNullable<
|
||||
TeamSettingsResponse['transcode']
|
||||
>['hardwareAcceleration']
|
||||
delete settings['transcode.hardwareAcceleration']
|
||||
} else if (key === 'appearance.hideAgent') {
|
||||
if (!settings.appearance) {
|
||||
settings.appearance = {}
|
||||
}
|
||||
settings.appearance.hideAgent = Boolean(value)
|
||||
delete settings['appearance.hideAgent']
|
||||
} else {
|
||||
settings[key] = value
|
||||
}
|
||||
|
||||
const updated = await prisma.team.update({
|
||||
where: { id: teamId },
|
||||
data: { settings },
|
||||
data: { settings: settings as unknown as PrismaJson.Settings },
|
||||
})
|
||||
|
||||
return updated.settings || {}
|
||||
return (updated.settings || {}) as TeamSettingsResponse
|
||||
}
|
||||
|
||||
async getSandboxSettings(teamId: string): Promise<SandboxSettings> {
|
||||
|
||||
@@ -45,13 +45,39 @@ describe('UserMetadataService', () => {
|
||||
await userMetadataService.upsertMetadata(user.id, team.id, 'key2', 'value2')
|
||||
|
||||
const list = await userMetadataService.listMetadata(user.id, team.id)
|
||||
expect(list).toHaveLength(2)
|
||||
expect(list).toHaveLength(3)
|
||||
expect(list).toEqual([
|
||||
{ key: 'key1', value: 'value1' },
|
||||
{ key: 'key2', value: 'value2' },
|
||||
{ key: 'appearance.hideAgent', value: false },
|
||||
])
|
||||
})
|
||||
|
||||
it('should return team appearance.hideAgent when configured', async () => {
|
||||
const user = await prisma.user.create({
|
||||
data: {
|
||||
name: 'Test User HideAgent',
|
||||
email: `testha-${Date.now()}@example.com`,
|
||||
password: 'pw',
|
||||
},
|
||||
})
|
||||
const team = await prisma.team.create({
|
||||
data: {
|
||||
name: 'Test Team HideAgent',
|
||||
settings: {
|
||||
transcode: { videoStrategy: 'best_match' },
|
||||
appearance: { hideAgent: true },
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const list = await userMetadataService.listMetadata(user.id, team.id)
|
||||
expect(list).toContainEqual({ key: 'appearance.hideAgent', value: true })
|
||||
|
||||
const meta = await userMetadataService.getMetadata(user.id, team.id, 'appearance.hideAgent')
|
||||
expect(meta).toEqual({ key: 'appearance.hideAgent', value: true })
|
||||
})
|
||||
|
||||
it('should return null if metadata not found', async () => {
|
||||
const user = await prisma.user.create({
|
||||
data: { name: 'Test User 3', email: `test3-${Date.now()}@example.com`, password: 'pw' },
|
||||
|
||||
@@ -24,23 +24,53 @@ export class UserMetadataService {
|
||||
}
|
||||
|
||||
async listMetadata(userId: string, teamId: string): Promise<UserMetadataItem[]> {
|
||||
const items = await prisma.userMetadata.findMany({
|
||||
where: {
|
||||
userId,
|
||||
teamId,
|
||||
},
|
||||
orderBy: {
|
||||
key: 'asc',
|
||||
},
|
||||
const [items, team] = await Promise.all([
|
||||
prisma.userMetadata.findMany({
|
||||
where: {
|
||||
userId,
|
||||
teamId,
|
||||
},
|
||||
orderBy: {
|
||||
key: 'asc',
|
||||
},
|
||||
}),
|
||||
prisma.team.findUnique({
|
||||
where: { id: teamId },
|
||||
select: { settings: true },
|
||||
}),
|
||||
])
|
||||
|
||||
const result: UserMetadataItem[] = items
|
||||
.filter((item) => item.key !== 'appearance.hideAgent')
|
||||
.map((item) => ({
|
||||
key: item.key,
|
||||
value: item.value,
|
||||
}))
|
||||
|
||||
const teamSettings = team?.settings as PrismaJson.Settings | null
|
||||
const hideAgent = teamSettings?.appearance?.hideAgent ?? false
|
||||
|
||||
result.push({
|
||||
key: 'appearance.hideAgent',
|
||||
value: hideAgent,
|
||||
})
|
||||
|
||||
return items.map((item) => ({
|
||||
key: item.key,
|
||||
value: item.value,
|
||||
}))
|
||||
return result
|
||||
}
|
||||
|
||||
async getMetadata(userId: string, teamId: string, key: string): Promise<UserMetadataItem | null> {
|
||||
if (key === 'appearance.hideAgent') {
|
||||
const team = await prisma.team.findUnique({
|
||||
where: { id: teamId },
|
||||
select: { settings: true },
|
||||
})
|
||||
const teamSettings = team?.settings as PrismaJson.Settings | null
|
||||
return {
|
||||
key: 'appearance.hideAgent',
|
||||
value: teamSettings?.appearance?.hideAgent ?? false,
|
||||
}
|
||||
}
|
||||
|
||||
const item = await prisma.userMetadata.findUnique({
|
||||
where: {
|
||||
userIdTeamIdKey: {
|
||||
|
||||
Reference in New Issue
Block a user