Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion web-studio/src/components/connection-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function ConnectionDialog() {
}
}, [connection, isConnectionDialogOpen])

const isDevImplicit = serverMode === 'dev-implicit'
const isDevImplicit = serverMode === 'dev'
const showIdentityFields = !isDevImplicit || showAdvancedInDevMode

return (
Expand Down
2 changes: 1 addition & 1 deletion web-studio/src/hooks/use-app-connection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export function summarizeConnectionIdentity(
connection: ConnectionDraft,
serverMode: ServerMode,
): ConnectionIdentitySummary {
if (serverMode === 'dev-implicit') {
if (serverMode === 'dev') {
return { labelKey: 'identitySummary.devImplicit' }
}

Expand Down
44 changes: 31 additions & 13 deletions web-studio/src/hooks/use-server-mode.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { getHealth } from '#/lib/ov-client'

export type ServerMode =
| 'checking'
| 'dev-implicit'
| 'explicit-auth'
| 'offline'
export type BackendAuthMode = 'api_key' | 'trusted' | 'dev'

export type ServerMode = BackendAuthMode | 'checking' | 'offline'

export type ServerModeBadge = {
labelKey: string
Expand All @@ -15,6 +13,27 @@ export function normalizeBaseUrl(baseUrl: string): string {
return baseUrl.trim().replace(/\/+$/, '')
}

function isRecord(value: unknown): value is Record<string, unknown> {
return value !== null && typeof value === 'object' && !Array.isArray(value)
}

export function resolveServerModeFromHealthData(data: unknown): ServerMode {
if (!isRecord(data)) {
return 'offline'
}

switch (data.auth_mode) {
case 'api_key':
return 'api_key'
case 'dev':
return 'dev'
case 'trusted':
return 'trusted'
default:
return 'offline'
}
}

export async function detectServerMode(baseUrl: string): Promise<ServerMode> {
const normalizedBaseUrl = normalizeBaseUrl(baseUrl)
if (!normalizedBaseUrl) {
Expand All @@ -30,23 +49,22 @@ export async function detectServerMode(baseUrl: string): Promise<ServerMode> {
throwOnError: true,
})

const data = response.data as { user_id?: string }
return typeof data.user_id === 'string' && data.user_id.length > 0
? 'dev-implicit'
: 'explicit-auth'
return resolveServerModeFromHealthData(response.data)
} catch {
return 'offline'
}
}

export function describeServerMode(serverMode: ServerMode): ServerModeBadge {
switch (serverMode) {
case 'dev-implicit':
return { labelKey: 'serverMode.devImplicit', variant: 'secondary' }
case 'explicit-auth':
return { labelKey: 'serverMode.explicitAuth', variant: 'outline' }
case 'api_key':
return { labelKey: 'serverMode.apiKey', variant: 'outline' }
case 'dev':
return { labelKey: 'serverMode.dev', variant: 'secondary' }
case 'offline':
return { labelKey: 'serverMode.offline', variant: 'destructive' }
case 'trusted':
return { labelKey: 'serverMode.trusted', variant: 'outline' }
default:
return { labelKey: 'serverMode.checking', variant: 'outline' }
}
Expand Down
32 changes: 30 additions & 2 deletions web-studio/src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ const en = {
toggle: 'Toggle theme',
},
serverMode: {
apiKey: 'api_key',
checking: 'Detecting',
devImplicit: 'Server Identity',
explicitAuth: 'Explicit Auth',
dev: 'dev',
offline: 'Offline',
trusted: 'trusted',
},
},
connection: {
Expand Down Expand Up @@ -472,11 +473,38 @@ const en = {
},
filePreview: {
cancel: 'Cancel',
directoryLevels: {
abstract: {
label: 'Abstract',
title: 'Short semantic abstract',
},
overview: {
label: 'Overview',
title: 'Directory overview',
},
},
directoryNoSelection: 'Select a chip to show folder context.',
directoryNoSummary:
'No abstract or overview available for this folder.',
edit: 'Edit',
emptyFile: '(empty file)',
emptyPrompt: 'Select a file to preview it here',
folder: 'Folder',
imageFailed: 'Image failed to load.',
imageLoading: 'Loading image...',
jsonl: {
collapse: 'Collapse',
collapseRow: 'Collapse row {{index}}',
dialogMode: 'Dialog',
emptyJsonl: 'Empty JSONL.',
emptyMessage: 'Empty message',
expand: 'Expand',
expandRow: 'Expand row {{index}}',
noArguments: 'No arguments',
rawMode: 'JSONL',
recordCount: '{{count}} record(s)',
toolcall: 'toolcall',
},
largeFileSkipped: 'This file is large and was not loaded automatically.',
loadingContent: 'Reading content...',
loadingEditor: 'Loading editor...',
Expand Down
31 changes: 29 additions & 2 deletions web-studio/src/i18n/locales/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ const zhCN = {
toggle: '切换主题',
},
serverMode: {
apiKey: 'api_key',
checking: '检测中',
devImplicit: '服务端身份',
explicitAuth: '显式鉴权',
dev: 'dev',
offline: '未连接',
trusted: 'trusted',
},
},
connection: {
Expand Down Expand Up @@ -461,11 +462,37 @@ const zhCN = {
},
filePreview: {
cancel: '取消',
directoryLevels: {
abstract: {
label: '摘要',
title: '短语义摘要',
},
overview: {
label: '概览',
title: '目录概览',
},
},
directoryNoSelection: '选择一个标签以显示目录上下文。',
directoryNoSummary: '此文件夹暂无摘要或概览。',
edit: '编辑',
emptyFile: '(空文件)',
emptyPrompt: '选择文件后在这里预览',
folder: '文件夹',
imageFailed: '图片加载失败。',
imageLoading: '正在加载图片...',
jsonl: {
collapse: '收起',
collapseRow: '收起第 {{index}} 行',
dialogMode: '对话',
emptyJsonl: '空 JSONL。',
emptyMessage: '空消息',
expand: '展开',
expandRow: '展开第 {{index}} 行',
noArguments: '无参数',
rawMode: 'JSONL',
recordCount: '{{count}} 条记录',
toolcall: '工具调用',
},
largeFileSkipped: '文件较大,默认不自动加载。',
loadingContent: '正在读取内容...',
loadingEditor: '加载编辑器...',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export function AddResourceForm({
const buildCommonBody = () => {
const body: Record<string, unknown> = {
parent: targetUri.trim() || undefined,
create_parent: true,
strict,
telemetry: true,
wait: false,
Expand Down
Loading