Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(studio): localize the task detail pipeline instead of branching on language (#5116)

Alec Chend61ffb0d0366
diff --git a/web-studio/src/i18n/locales/en/workspace.ts b/web-studio/src/i18n/locales/en/workspace.ts
index 0490d43be..cde5ef7e8 100644
--- a/web-studio/src/i18n/locales/en/workspace.ts
+++ b/web-studio/src/i18n/locales/en/workspace.ts
@@ -460,6 +460,29 @@ const workspace = {
allStatuses: 'All statuses',
clear: 'Clear filters',
},
+ actions: {
+ retrigger: 'Re-trigger Task',
+ },
+ pipeline: {
+ steps: 'Pipeline Steps',
+ duration: 'Duration',
+ count: '{{count}} items',
+ status: {
+ completed: 'Completed',
+ running: 'Running',
+ failed: 'Failed',
+ pending: 'Pending',
+ },
+ step: {
+ sessionPersistence: 'Session Persistence',
+ sessionCommit: 'Session Commit',
+ connectorAuth: 'Connector Auth',
+ resourceFetching: 'Resource Fetching',
+ externalParse: 'Document Parsing',
+ semantic: 'Semantic Processing',
+ embedding: 'Vector Embedding',
+ },
+ },
pagination: {
next: 'Next',
page: 'Page {{page}}',
diff --git a/web-studio/src/i18n/locales/zh-CN/workspace.ts b/web-studio/src/i18n/locales/zh-CN/workspace.ts
index 41f4e6fcb..0d151704e 100644
--- a/web-studio/src/i18n/locales/zh-CN/workspace.ts
+++ b/web-studio/src/i18n/locales/zh-CN/workspace.ts
@@ -441,6 +441,29 @@ const workspace = {
allStatuses: '全部状态',
clear: '清除筛选',
},
+ actions: {
+ retrigger: '重新发起任务',
+ },
+ pipeline: {
+ steps: '工序进度',
+ duration: '执行耗时 / 已用时长',
+ count: '{{count}} 项',
+ status: {
+ completed: '已完成',
+ running: '进行中',
+ failed: '失败',
+ pending: '等待中',
+ },
+ step: {
+ sessionPersistence: '会话状态持久化',
+ sessionCommit: '会话提交',
+ connectorAuth: '连接器鉴权',
+ resourceFetching: '资源拉取',
+ externalParse: '外部解析',
+ semantic: '语义处理',
+ embedding: '嵌入向量',
+ },
+ },
pagination: {
next: '下一页',
page: '第 {{page}} 页',
diff --git a/web-studio/src/routes/tasks/-components/task-detail-sheet.tsx b/web-studio/src/routes/tasks/-components/task-detail-sheet.tsx
index 93f730f7d..7321bf036 100644
--- a/web-studio/src/routes/tasks/-components/task-detail-sheet.tsx
+++ b/web-studio/src/routes/tasks/-components/task-detail-sheet.tsx
@@ -204,30 +204,19 @@ export function TaskDetailSheet({
<DetailField
className="col-span-2"
icon={<TimerResetIcon />}
- label={
- i18n.language.startsWith('zh')
- ? '执行耗时 / 已用时长'
- : 'Duration'
- }
- value={formatTaskDuration(
- task,
- i18n.language.startsWith('zh'),
- )}
+ label={t('pipeline.duration')}
+ value={formatTaskDuration(task)}
mono
/>
</div>
{/* Worker Sub-Queue Pipeline Diagram (Type-Aware) */}
{(() => {
- const steps = getTaskPipelineSteps(task, i18n.language)
+ const steps = getTaskPipelineSteps(task, t)
return (
<DetailSection
- title={
- i18n.language.startsWith('zh')
- ? '工序进度'
- : 'Pipeline Steps'
- }
+ title={t('pipeline.steps')}
>
<div className="rounded-xl border bg-muted/20 p-3 text-xs">
<div className="grid gap-1.5">
@@ -246,7 +235,9 @@ export function TaskDetailSheet({
<span className="flex items-center gap-2 text-[11px]">
{st.count !== undefined && (
<span className="font-mono text-muted-foreground">
- {st.count} 项
+ {t('pipeline.count', {
+ count: st.count,
+ })}
</span>
)}
<span
@@ -259,12 +250,12 @@ export function TaskDetailSheet({
}
>
{isDone
- ? '已完成'
+ ? t('pipeline.status.completed')
: isRun
- ? '进行中'
+ ? t('pipeline.status.running')
: isFail
- ? '失败'
- : '等待中'}
+ ? t('pipeline.status.failed')
+ : t('pipeline.status.pending')}
</span>
</span>
</div>
diff --git a/web-studio/src/routes/tasks/-lib/task-pipeline.test.ts b/web-studio/src/routes/tasks/-lib/task-pipeline.test.ts
new file mode 100644
index 000000000..bf62ced34
--- /dev/null
+++ b/web-studio/src/routes/tasks/-lib/task-pipeline.test.ts
@@ -0,0 +1,55 @@
+import { describe, expect, it } from 'vitest'
+
+import en from '#/i18n/locales/en/workspace'
+import zh from '#/i18n/locales/zh-CN/workspace'
+import { getTaskPipelineGroups, getTaskPipelineSteps } from './task-pipeline'
+import type { PipelineTranslate } from './task-pipeline'
+import type { TaskRecord } from './task-record'
+
+const TYPES = [
+ 'session_commit',
+ 'admin_reindex',
+ 'snapshot_restore_reindex',
+ 'connector_import',
+ 'add_resource',
+ 'add_skill',
+]
+
+function taskOf(task_type: string): TaskRecord {
+ return {
+ task_id: 't',
+ task_type,
+ status: 'running',
+ result: {},
+ } as TaskRecord
+}
+
+function namesOf(task: TaskRecord, t?: PipelineTranslate): string[] {
+ const steps = getTaskPipelineSteps(task, t).map((s) => s.name)
+ const groups = getTaskPipelineGroups(task, t).flatMap((g) =>
+ g.type === 'serial' ? [g.step.name] : g.steps.map((s) => s.name),
+ )
+ return [...steps, ...groups]
+}
+
+describe('task pipeline labels', () => {
+ it.each([
+ ['en', en.tasksPage],
+ ['zh-CN', zh.tasksPage],
+ ])('resolves every step key to %s text', (_lng, namespace) => {
+ const t = (key: string) =>
+ key.split('.').reduce<any>((node, part) => node?.[part], namespace) ?? key
+
+ for (const type of TYPES) {
+ for (const name of namesOf(taskOf(type), t)) {
+ // A key missing from the namespace comes back unresolved as "pipeline.step.<key>".
+ expect(name).not.toMatch(/^pipeline\./)
+ expect(name).not.toBe('')
+ }
+ }
+ })
+
+ it('falls back to the raw key when no translator is supplied', () => {
+ expect(namesOf(taskOf('session_commit'))).toContain('sessionCommit')
+ })
+})
diff --git a/web-studio/src/routes/tasks/-lib/task-pipeline.ts b/web-studio/src/routes/tasks/-lib/task-pipeline.ts
index d301c35b5..e765448eb 100644
--- a/web-studio/src/routes/tasks/-lib/task-pipeline.ts
+++ b/web-studio/src/routes/tasks/-lib/task-pipeline.ts
@@ -2,12 +2,18 @@ import type { TaskRecord } from './task-record'
export type StepState = 'completed' | 'running' | 'pending' | 'failed'
+export type PipelineTranslate = (key: string) => string
+
export type PipelineStep = {
name: string
state: StepState
count?: number
}
+function resolve(key: string, t?: PipelineTranslate): string {
+ return t ? t(`pipeline.step.${key}`) : key
+}
+
export type PipelineGroup =
| { type: 'serial'; step: PipelineStep }
| { type: 'parallel'; steps: PipelineStep[] }
@@ -34,9 +40,8 @@ function inferState(
*/
export function getTaskPipelineSteps(
task: TaskRecord,
- language: string = 'zh',
+ t?: PipelineTranslate,
): PipelineStep[] {
- const isZh = language.startsWith('zh')
const type = task.task_type
const status = task.status
const resObj = (task.result || {}) as Record<string, any>
@@ -45,7 +50,7 @@ export function getTaskPipelineSteps(
if (type === 'session_commit') {
return [
{
- name: isZh ? '会话状态持久化' : 'Session Persistence',
+ name: resolve('sessionPersistence', t),
state: status === 'completed' ? 'completed' : (status as StepState),
},
]
@@ -54,11 +59,11 @@ export function getTaskPipelineSteps(
if (type === 'admin_reindex' || type === 'snapshot_restore_reindex') {
return [
{
- name: isZh ? '外部解析' : 'Document Parsing',
+ name: resolve('externalParse', t),
state: status === 'pending' ? 'pending' : 'completed',
},
{
- name: isZh ? '嵌入向量' : 'Vector Embedding',
+ name: resolve('embedding', t),
state: inferState('Embedding', status === 'completed' ? 'completed' : (status as StepState), status, qStatus),
count: resObj.reindexed_items,
},
@@ -68,26 +73,26 @@ export function getTaskPipelineSteps(
if (type === 'connector_import') {
const preState: StepState = status === 'pending' ? 'pending' : 'completed'
return [
- { name: isZh ? '连接器鉴权' : 'Connector Auth', state: preState },
- { name: isZh ? '资源拉取' : 'Resource Fetching', state: preState, count: resObj.downloaded_files },
- { name: isZh ? '外部解析' : 'Document Parsing', state: inferState('Semantic', status === 'completed' ? 'completed' : (status as StepState), status, qStatus) },
- { name: isZh ? '嵌入向量' : 'Vector Embedding', state: inferState('Embedding', status === 'completed' ? 'completed' : (status as StepState), status, qStatus) },
+ { name: resolve('connectorAuth', t), state: preState },
+ { name: resolve('resourceFetching', t), state: preState, count: resObj.downloaded_files },
+ { name: resolve('externalParse', t), state: inferState('Semantic', status === 'completed' ? 'completed' : (status as StepState), status, qStatus) },
+ { name: resolve('embedding', t), state: inferState('Embedding', status === 'completed' ? 'completed' : (status as StepState), status, qStatus) },
]
}
// Default resource ingestion pipeline: 外部解析 -> 语义处理 -> 嵌入向量
return [
{
- name: isZh ? '外部解析' : 'Document Parsing',
+ name: resolve('externalParse', t),
state: status === 'pending' ? 'pending' : 'completed',
},
{
- name: isZh ? '语义处理' : 'Semantic Processing',
+ name: resolve('semantic', t),
state: inferState('Semantic', status === 'completed' ? 'completed' : (status as StepState), status, qStatus),
count: qStatus?.Semantic?.processed,
},
{
- name: isZh ? '嵌入向量' : 'Vector Embedding',
+ name: resolve('embedding', t),
state: inferState('Embedding', status === 'completed' ? 'completed' : (status as StepState), status, qStatus),
count: qStatus?.Embedding?.processed,
},
@@ -100,9 +105,8 @@ export function getTaskPipelineSteps(
*/
export function getTaskPipelineGroups(
task: TaskRecord,
- language: string = 'zh',
+ t?: PipelineTranslate,
): PipelineGroup[] {
- const isZh = language.startsWith('zh')
const type = task.task_type
const status = task.status
const resObj = (task.result || {}) as Record<string, any>
@@ -113,7 +117,7 @@ export function getTaskPipelineGroups(
{
type: 'serial',
step: {
- name: isZh ? '会话提交' : 'Session Commit',
+ name: resolve('sessionCommit', t),
state: status === 'completed' ? 'completed' : (status as StepState),
},
},
@@ -124,8 +128,8 @@ export function getTaskPipelineGroups(
const purgeState: StepState = status === 'pending' ? 'pending' : 'completed'
const rebuildState = inferState('Embedding', status === 'completed' ? 'completed' : (status as StepState), status, qStatus)
return [
- { type: 'serial', step: { name: isZh ? '外部解析' : 'Document Parsing', state: purgeState } },
- { type: 'serial', step: { name: isZh ? '嵌入向量' : 'Vector Embedding', state: rebuildState } },
+ { type: 'serial', step: { name: resolve('externalParse', t), state: purgeState } },
+ { type: 'serial', step: { name: resolve('embedding', t), state: rebuildState } },
]
}
@@ -134,12 +138,12 @@ export function getTaskPipelineGroups(
const semState = inferState('Semantic', status === 'completed' ? 'completed' : status === 'running' ? 'running' : status === 'failed' ? 'failed' : 'pending', status, qStatus)
const embState = inferState('Embedding', status === 'completed' ? 'completed' : status === 'running' ? 'running' : status === 'failed' ? 'failed' : 'pending', status, qStatus)
return [
- { type: 'serial', step: { name: isZh ? '外部解析' : 'Document Parsing', state: preState } },
+ { type: 'serial', step: { name: resolve('externalParse', t), state: preState } },
{
type: 'parallel',
steps: [
- { name: isZh ? '语义处理' : 'Semantic Processing', state: semState },
- { name: isZh ? '嵌入向量' : 'Vector Embedding', state: embState },
+ { name: resolve('semantic', t), state: semState },
+ { name: resolve('embedding', t), state: embState },
],
},
]
@@ -150,12 +154,12 @@ export function getTaskPipelineGroups(
const semState = inferState('Semantic', status === 'completed' ? 'completed' : status === 'running' ? 'running' : status === 'failed' ? 'failed' : 'pending', status, qStatus)
const embState = inferState('Embedding', status === 'completed' ? 'completed' : status === 'running' ? 'running' : status === 'failed' ? 'failed' : 'pending', status, qStatus)
return [
- { type: 'serial', step: { name: isZh ? '外部解析' : 'Document Parsing', state: parseState } },
+ { type: 'serial', step: { name: resolve('externalParse', t), state: parseState } },
{
type: 'parallel',
steps: [
- { name: isZh ? '语义处理' : 'Semantic Processing', state: semState },
- { name: isZh ? '嵌入向量' : 'Vector Embedding', state: embState },
+ { name: resolve('semantic', t), state: semState },
+ { name: resolve('embedding', t), state: embState },
],
},
]
diff --git a/web-studio/src/routes/tasks/-lib/task-time.ts b/web-studio/src/routes/tasks/-lib/task-time.ts
index 981a756ad..2b3b96471 100644
--- a/web-studio/src/routes/tasks/-lib/task-time.ts
+++ b/web-studio/src/routes/tasks/-lib/task-time.ts
@@ -30,10 +30,7 @@ export function getTaskDate(task: TaskTimestamp): Date | undefined {
return Number.isNaN(date.getTime()) ? undefined : date
}
-export function formatTaskDuration(
- task: TaskTimestamp,
- _isZh: boolean = true,
-): string {
+export function formatTaskDuration(task: TaskTimestamp): string {
const status = task.status || 'unknown'
// Pending tasks have not started execution yet
diff --git a/web-studio/src/routes/tasks/route.tsx b/web-studio/src/routes/tasks/route.tsx
index 74389952a..b4ba8e560 100644
--- a/web-studio/src/routes/tasks/route.tsx
+++ b/web-studio/src/routes/tasks/route.tsx
@@ -308,7 +308,7 @@ function TasksRoute() {
type="button"
disabled={isRetrying}
className="ml-1 inline-flex items-center justify-center rounded p-0.5 hover:bg-white/25 active:scale-95 transition-all cursor-pointer text-destructive-foreground disabled:opacity-50"
- title={i18n.language.startsWith('zh') ? '重新发起任务' : 'Re-trigger Task'}
+ title={t('actions.retrigger')}
onClick={(e) => {
e.stopPropagation()
retryMutation.mutate(task)
@@ -338,7 +338,7 @@ function TasksRoute() {
| { type: 'serial'; step: StepItem }
| { type: 'parallel'; steps: StepItem[] }
- const groups = getTaskPipelineGroups(task, i18n.language)
+ const groups = getTaskPipelineGroups(task, t)
return (
<div className="flex items-center gap-1.5 overflow-x-auto py-0.5 min-w-[210px]">
@@ -909,7 +909,7 @@ function TasksRoute() {
<TableCell>{renderQueuePipeline(task)}</TableCell>
<TableCell>{renderStatus(task)}</TableCell>
<TableCell className="whitespace-nowrap font-mono text-xs text-muted-foreground">
- {formatTaskDuration(task, i18n.language.startsWith('zh'))}
+ {formatTaskDuration(task)}
</TableCell>
<TableCell className="whitespace-nowrap text-right text-muted-foreground">
{formatTime(task)}