From 01c471f292f6d735fa6d8f19d64e9609f2cf6ec7 Mon Sep 17 00:00:00 2001 From: yiling Date: Fri, 4 Dec 2026 19:15:58 +0800 Subject: [PATCH] fix(agents): guide Transcript Agent setup --- CHANGELOG.md | 1 + apps/web/e2e/serve.ts | 1 + packages/core/src/agent/agent.test.ts | 6 +- packages/core/src/agent/agent.ts | 2 +- packages/core/src/agent/system-agents.ts | 12 +- packages/core/src/search/embedding-server.ts | 16 ++- packages/core/src/team/team.test.ts | 29 ++++- packages/core/src/team/team.ts | 8 +- packages/dtos/src/team.ts | 1 + .../settings/AgentsSettings.test.tsx | 88 +++++++++++++ .../components/settings/AgentsSettings.tsx | 117 ++++++++++++------ packages/webui/messages/en.json | 2 + packages/webui/messages/ko.json | 2 + packages/webui/messages/zh.json | 2 + .../routes/teams/$teamId/settings.lazy.tsx | 4 + 15 files changed, 238 insertions(+), 53 deletions(-) create mode 100644 packages/webui/components/settings/AgentsSettings.test.tsx diff --git a/CHANGELOG.md b/CHANGELOG.md index 64e580af..c9789949 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Fixed - **storage**: Download HTML, SVG, and other unsupported preview formats when opened from local storage. +- **video**: The Transcript Agent settings guide you to set up an embedding server first. Automatically created Transcript Agents have their own default avatar. ### Changed diff --git a/apps/web/e2e/serve.ts b/apps/web/e2e/serve.ts index 33ae7e3c..3921701a 100644 --- a/apps/web/e2e/serve.ts +++ b/apps/web/e2e/serve.ts @@ -23,6 +23,7 @@ async function start() { process.env.NODE_ENV = 'development' process.env.SHUMAI_E2E = 'true' process.env.ENABLE_EMBEDDING_AGENT = 'false' + process.env.ENABLE_TRANSCRIPTION_AGENT = 'false' // Write variables to .env.e2e file so the teardown can load them const envContent = [ diff --git a/packages/core/src/agent/agent.test.ts b/packages/core/src/agent/agent.test.ts index 84df8c2e..e5ecfce5 100644 --- a/packages/core/src/agent/agent.test.ts +++ b/packages/core/src/agent/agent.test.ts @@ -1076,7 +1076,11 @@ describe('AgentService', () => { vi.stubEnv('ENABLE_TRANSCRIPTION_AGENT', 'true') await svc.ensureSystemAgents() const [agent] = await svc.listAgents({ teamId: team.id }) - expect(await svc.toAgentInfo(agent)).toMatchObject({ enabled: true, readOnly: true }) + expect(await svc.toAgentInfo(agent)).toMatchObject({ + enabled: true, + readOnly: true, + avatarPreset: 'avatar-2', + }) vi.stubEnv('ENABLE_TRANSCRIPTION_AGENT', 'false') await svc.ensureSystemAgentsForTeam(team.id) diff --git a/packages/core/src/agent/agent.ts b/packages/core/src/agent/agent.ts index 8d066db8..efcd26b8 100644 --- a/packages/core/src/agent/agent.ts +++ b/packages/core/src/agent/agent.ts @@ -679,7 +679,7 @@ export class AgentService { teamId, name: type === 'embedding' ? 'embedding-agent' : setting.name, type, - avatar: 'avatar-1', + avatar: setting.avatar, thinkingLevel: 'off', enabled: true, }) diff --git a/packages/core/src/agent/system-agents.ts b/packages/core/src/agent/system-agents.ts index 2c99a3dc..f2ba33a7 100644 --- a/packages/core/src/agent/system-agents.ts +++ b/packages/core/src/agent/system-agents.ts @@ -1,16 +1,20 @@ import type { AgentType } from '@shumai/dtos' const systemAgentSettings = { - embedding: { envKey: 'ENABLE_EMBEDDING_AGENT', name: 'Embedding agent' }, - transcription: { envKey: 'ENABLE_TRANSCRIPTION_AGENT', name: 'Transcript Agent' }, + embedding: { envKey: 'ENABLE_EMBEDDING_AGENT', name: 'Embedding agent', avatar: 'avatar-1' }, + transcription: { + envKey: 'ENABLE_TRANSCRIPTION_AGENT', + name: 'Transcript Agent', + avatar: 'avatar-2', + }, } as const export function getSystemAgentSetting(type: AgentType) { if (type !== 'embedding' && type !== 'transcription') return undefined - const { envKey, name } = systemAgentSettings[type] + const { envKey, name, avatar } = systemAgentSettings[type] const value = process.env[envKey] if (value !== 'true' && value !== 'false') return undefined - return { name, enabled: value === 'true' } + return { name, avatar, enabled: value === 'true' } } diff --git a/packages/core/src/search/embedding-server.ts b/packages/core/src/search/embedding-server.ts index fd708a3c..b96489ad 100644 --- a/packages/core/src/search/embedding-server.ts +++ b/packages/core/src/search/embedding-server.ts @@ -20,6 +20,17 @@ const integration: IntegrationDefinition<'embeddingServer'> = { export const LOCAL_EMBEDDING_PROVIDER = 'gemma-embedding-2-openai' const defaultLocalBaseUrl = 'http://localhost:9379/v1' +export function resolveEmbeddingProvider( + { url, isEnvConfigured }: EmbeddingServerSettingsResponse, + providerOverride?: string, +): string { + return ( + providerOverride || + process.env.EMBEDDING_PROVIDER || + (url && !isEnvConfigured ? LOCAL_EMBEDDING_PROVIDER : 'gemini-embedding-2') + ) +} + function getOpenAiBaseUrl(url: string): string { const baseUrl = url.replace(/\/embeddings$/, '') return baseUrl.endsWith('/v1') ? baseUrl : `${baseUrl}/v1` @@ -36,10 +47,7 @@ const modelListSchema = z.object({ export class EmbeddingServerService { async resolveRuntimeConfig(teamId?: string, providerOverride?: string) { const { url, isEnv } = await resolveIntegrationConfig(integration, teamId ?? null) - const provider = - providerOverride || - process.env.EMBEDDING_PROVIDER || - (url && !isEnv ? LOCAL_EMBEDDING_PROVIDER : 'gemini-embedding-2') + const provider = resolveEmbeddingProvider({ url, isEnvConfigured: isEnv }, providerOverride) const localUrl = url || defaultLocalBaseUrl return { provider, diff --git a/packages/core/src/team/team.test.ts b/packages/core/src/team/team.test.ts index 4b49f4f6..12058739 100644 --- a/packages/core/src/team/team.test.ts +++ b/packages/core/src/team/team.test.ts @@ -2,7 +2,7 @@ import * as path from 'path' import { prisma } from '@shumai/db' import { setupTestDbHooks } from '@shumai/db/test' import { teamService } from '@shumai/core/src/team/team' -import { describe, expect, it } from 'vitest' +import { describe, expect, it, vi } from 'vitest' import type { TeamSettingsResponse } from '@shumai/dtos' describe('TeamService', () => { @@ -357,6 +357,30 @@ describe('TeamService', () => { expect(pm1View.find((m) => m.id === projectMember2.id)?.scope).toBe('project') }) + it('reports whether the effective embedding provider supports the Transcript Agent', async () => { + const team = await prisma.team.create({ + data: { + name: 'Embedding settings', + settings: { embeddingServer: { url: 'http://embedding:9379/v1' } }, + }, + }) + vi.stubEnv('GEMMA_EMBEDDING_OPENAI_BASE_URL', undefined) + vi.stubEnv('EMBEDDING_PROVIDER', undefined) + try { + await expect(teamService.getSettings(team.id)).resolves.toMatchObject({ + localEmbeddingProviderConfigured: true, + transcriptionAgentManagedByEnv: false, + }) + + vi.stubEnv('EMBEDDING_PROVIDER', 'gemini-embedding-2') + await expect(teamService.getSettings(team.id)).resolves.toMatchObject({ + localEmbeddingProviderConfigured: false, + }) + } finally { + vi.unstubAllEnvs() + } + }) + it('should get and update settings', async () => { const user = await prisma.user.create({ data: { name: 'Test User', email: `test-${Date.now()}@example.com`, password: 'pw' }, @@ -368,6 +392,7 @@ describe('TeamService', () => { const settings = await teamService.getSettings(team.id) expect(settings).toEqual({ semanticSearchEnabled: false, + localEmbeddingProviderConfigured: false, transcriptionAgentManagedByEnv: false, embeddingServer: { url: undefined, isEnvConfigured: false }, transcode: { @@ -406,6 +431,7 @@ describe('TeamService', () => { expect(newSettings).toEqual({ theme: 'dark', semanticSearchEnabled: false, + localEmbeddingProviderConfigured: false, transcriptionAgentManagedByEnv: false, embeddingServer: { url: undefined, isEnvConfigured: false }, transcode: { @@ -453,6 +479,7 @@ describe('TeamService', () => { const finalSettings = await teamService.getSettings(team.id) expect(finalSettings).toEqual({ theme: 'dark', + localEmbeddingProviderConfigured: false, transcriptionAgentManagedByEnv: false, embeddingServer: { url: undefined, isEnvConfigured: false }, transcode: { diff --git a/packages/core/src/team/team.ts b/packages/core/src/team/team.ts index 2f79ad4e..6a3429eb 100644 --- a/packages/core/src/team/team.ts +++ b/packages/core/src/team/team.ts @@ -10,7 +10,11 @@ import { AgentService, agentService } from '@shumai/core/src/agent/agent' import { getSystemAgentSetting } from '@shumai/core/src/agent/system-agents' import { turntableService } from '@shumai/core/src/turntable/turntable' import { gotenbergService } from '@shumai/core/src/gotenberg/gotenberg' -import { embeddingServerService } from '@shumai/core/src/search/embedding-server' +import { + embeddingServerService, + LOCAL_EMBEDDING_PROVIDER, + resolveEmbeddingProvider, +} from '@shumai/core/src/search/embedding-server' import { getArchiveStorageConfig, isArchiveStorageEnabled, @@ -361,6 +365,8 @@ export class TeamService { settings.turntable = await turntableService.getSettings(teamId) settings.gotenberg = await gotenbergService.getSettings(teamId) settings.embeddingServer = await embeddingServerService.getSettings(teamId) + settings.localEmbeddingProviderConfigured = + resolveEmbeddingProvider(settings.embeddingServer) === LOCAL_EMBEDDING_PROVIDER settings.transcriptionAgentManagedByEnv = getSystemAgentSetting('transcription') !== undefined const archiveConfig = getArchiveStorageConfig() diff --git a/packages/dtos/src/team.ts b/packages/dtos/src/team.ts index 05900777..9fb76929 100644 --- a/packages/dtos/src/team.ts +++ b/packages/dtos/src/team.ts @@ -253,6 +253,7 @@ export interface TeamSettingsResponse { turntable?: TurntableSettingsResponse gotenberg?: GotenbergSettingsResponse embeddingServer?: EmbeddingServerSettingsResponse + localEmbeddingProviderConfigured?: boolean transcriptionAgentManagedByEnv?: boolean appearance?: TeamAppearanceSettings semanticSearchEnabled?: boolean diff --git a/packages/webui/components/settings/AgentsSettings.test.tsx b/packages/webui/components/settings/AgentsSettings.test.tsx new file mode 100644 index 00000000..e9ae036d --- /dev/null +++ b/packages/webui/components/settings/AgentsSettings.test.tsx @@ -0,0 +1,88 @@ +// @vitest-environment happy-dom +import { QueryClient, QueryClientProvider } from '@tanstack/react-query' +import { cleanup, fireEvent, render, screen } from '@testing-library/react' +import { afterEach, describe, expect, it, vi } from 'vitest' +import { AgentsSettings } from './AgentsSettings' + +const getAgents = vi.fn() + +vi.mock('@/ui/api/client', () => ({ + client: { + api: { + teams: { ':teamId': { agents: { $get: () => getAgents() } } }, + }, + }, +})) + +vi.mock('@/ui/hooks/use-permissions', () => ({ + usePermissions: () => ({ canAdmin: true }), +})) + +vi.mock('./AgentFormDialog', () => ({ + AgentFormDialog: ({ title }: { title: string }) =>
{title}
, +})) + +function renderSettings(initiallyConfigured: boolean) { + const queryClient = new QueryClient() + const onOpenIntegrations = vi.fn() + const view = (configured: boolean) => ( + + + + ) + + const { rerender } = render(view(initiallyConfigured)) + return { + onOpenIntegrations, + updateConfigured: (configured: boolean) => rerender(view(configured)), + } +} + +describe('Transcript Agent setup', () => { + afterEach(() => { + cleanup() + vi.resetAllMocks() + }) + + it('blocks creation and offers to open Integrations when setup is missing', async () => { + getAgents.mockResolvedValue(Response.json([])) + const { onOpenIntegrations, updateConfigured } = renderSettings(false) + + await screen.findByText('Set up a local embedding server to use the Transcript Agent.') + const create = screen.getByRole('button', { + name: 'Create Transcript Agent', + }) + expect(create.disabled).toBe(true) + fireEvent.click(screen.getByRole('button', { name: 'Open Integrations' })) + expect(onOpenIntegrations).toHaveBeenCalledOnce() + + updateConfigured(true) + expect(create.disabled).toBe(false) + fireEvent.click(create) + expect(screen.getByRole('dialog')).toBeTruthy() + }) + + it('keeps an existing Transcript Agent visible with its controls disabled', async () => { + getAgents.mockResolvedValue( + Response.json([ + { id: 'transcriber', name: 'Video Transcriber', type: 'transcription', enabled: true }, + ]), + ) + const { updateConfigured } = renderSettings(false) + + const transcriber = await screen.findByText('Video Transcriber') + const enabled = screen.getByRole('switch') + expect(enabled.disabled).toBe(true) + fireEvent.click(transcriber) + expect(screen.queryByRole('dialog')).toBeNull() + + updateConfigured(true) + expect(enabled.disabled).toBe(false) + fireEvent.click(transcriber) + expect(screen.getByRole('dialog')).toBeTruthy() + }) +}) diff --git a/packages/webui/components/settings/AgentsSettings.tsx b/packages/webui/components/settings/AgentsSettings.tsx index f2edbbdf..57f4990d 100644 --- a/packages/webui/components/settings/AgentsSettings.tsx +++ b/packages/webui/components/settings/AgentsSettings.tsx @@ -50,7 +50,9 @@ import { AgentFormDialog } from './AgentFormDialog' interface AgentsSettingsProps { teamId: string + localEmbeddingProviderConfigured: boolean transcriptionAgentManagedByEnv?: boolean + onOpenIntegrations: () => void } const AGENT_TYPES: { @@ -64,7 +66,12 @@ const AGENT_TYPES: { { type: 'transcription', title: m.transcript_agent, icon: Captions }, ] -export function AgentsSettings({ teamId, transcriptionAgentManagedByEnv }: AgentsSettingsProps) { +export function AgentsSettings({ + teamId, + localEmbeddingProviderConfigured, + transcriptionAgentManagedByEnv, + onOpenIntegrations, +}: AgentsSettingsProps) { const queryClient = useQueryClient() const { canAdmin } = usePermissions() const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false) @@ -265,8 +272,11 @@ export function AgentsSettings({ teamId, transcriptionAgentManagedByEnv }: Agent const typeAgents = agents.filter((a) => a.type === section.type) const Icon = section.icon const isSingleAgentType = section.type !== 'chat' - const isManagedTranscriptAgent = - section.type === 'transcription' && transcriptionAgentManagedByEnv + const isTranscriptSection = section.type === 'transcription' + const requiresEmbeddingServer = isTranscriptSection && !localEmbeddingProviderConfigured + const isManagedTranscriptAgent = isTranscriptSection && transcriptionAgentManagedByEnv + const canCreate = + canAdmin && !isManagedTranscriptAgent && !(isSingleAgentType && typeAgents.length > 0) return (
- {canAdmin && - !isManagedTranscriptAgent && - !(isSingleAgentType && typeAgents.length > 0) && ( - - )} + {canCreate && ( + + )} {!isSingleAgentType && ( - {section.type === 'transcription' && ( -

- {isManagedTranscriptAgent && typeAgents.length === 0 - ? m.agent_managed_by_system_hint() - : m.transcript_agent_description()} -

+ {requiresEmbeddingServer ? ( +
+

+ {m.transcript_agent_setup_required()} +

+ +
+ ) : ( + isTranscriptSection && ( +

+ {isManagedTranscriptAgent && typeAgents.length === 0 + ? m.agent_managed_by_system_hint() + : m.transcript_agent_description()} +

+ ) )}
{typeAgents.map((agent) => ( setAgentToEdit(agent)} + className={cn( + 'group relative overflow-hidden border-border pb-1 pt-1', + requiresEmbeddingServer + ? 'opacity-60' + : 'cursor-pointer transition-all duration-200 hover:border-primary/50', + )} + onClick={ + requiresEmbeddingServer ? undefined : () => setAgentToEdit(agent) + } >
@@ -372,6 +404,7 @@ export function AgentsSettings({ teamId, transcriptionAgentManagedByEnv }: Agent + {canCreate && ( + + )}
)}
diff --git a/packages/webui/messages/en.json b/packages/webui/messages/en.json index fdc17d8d..81d5fefc 100644 --- a/packages/webui/messages/en.json +++ b/packages/webui/messages/en.json @@ -284,6 +284,8 @@ "agent_type_transcription": "Transcript", "transcript_agent": "Transcript Agent", "transcript_agent_description": "Posts an internal comment when a video transcription job fails.", + "transcript_agent_setup_required": "Set up a local embedding server to use the Transcript Agent.", + "transcript_agent_open_integrations": "Open Integrations", "integrations": "Integrations", "integrations_settings_description": "Configure third-party service integrations for media rendering and document processing.", "storage": "Storage", diff --git a/packages/webui/messages/ko.json b/packages/webui/messages/ko.json index 7d5b6bc2..3692d8cb 100644 --- a/packages/webui/messages/ko.json +++ b/packages/webui/messages/ko.json @@ -273,6 +273,8 @@ "agent_type_transcription": "음성 기록", "transcript_agent": "음성 기록 에이전트", "transcript_agent_description": "동영상 음성 기록 작업이 실패하면 내부 댓글을 남깁니다.", + "transcript_agent_setup_required": "음성 기록 에이전트를 사용하려면 먼저 로컬 임베딩 서버를 설정하세요.", + "transcript_agent_open_integrations": "통합 설정 열기", "integrations": "연동", "integrations_settings_description": "미디어 렌더링과 문서 처리를 위한 외부 서비스 연동을 설정합니다.", "storage": "저장소", diff --git a/packages/webui/messages/zh.json b/packages/webui/messages/zh.json index 4e4eab06..b27484f4 100644 --- a/packages/webui/messages/zh.json +++ b/packages/webui/messages/zh.json @@ -284,6 +284,8 @@ "agent_type_transcription": "转录", "transcript_agent": "转录智能体", "transcript_agent_description": "视频转录失败时发布内部评论。", + "transcript_agent_setup_required": "请先配置本地向量模型服务,再使用转录智能体。", + "transcript_agent_open_integrations": "打开集成设置", "integrations": "集成", "integrations_settings_description": "配置用于媒体渲染与文档处理的第三方服务集成。", "storage": "存储", diff --git a/packages/webui/routes/teams/$teamId/settings.lazy.tsx b/packages/webui/routes/teams/$teamId/settings.lazy.tsx index 89a94472..c28dea55 100644 --- a/packages/webui/routes/teams/$teamId/settings.lazy.tsx +++ b/packages/webui/routes/teams/$teamId/settings.lazy.tsx @@ -1230,7 +1230,11 @@ export function TeamSettingsPage() {
handleTabChange('integrations')} />
)}