66 lines
2.1 KiB
TypeScript
66 lines
2.1 KiB
TypeScript
import { apiFetchEnvelope } from '../../../services/api'
|
|
import type { ResourceOption } from '../types/chat'
|
|
import { listKnowledgeSpaces as listKnowledgeSpaceRecords } from '../../knowledge/api'
|
|
import { listDatasourceRecords, toResourceOption } from '../../databases/api'
|
|
|
|
export async function listModels(): Promise<string[]> {
|
|
try {
|
|
const data = await apiFetchEnvelope<{ [key: string]: unknown }>('/models')
|
|
if (Array.isArray(data)) return data as string[]
|
|
const models = (data as { models?: string[] })?.models
|
|
if (Array.isArray(models)) return models
|
|
return []
|
|
} catch {
|
|
return []
|
|
}
|
|
}
|
|
|
|
export async function listDatasources(): Promise<ResourceOption[]> {
|
|
try {
|
|
const rows = await listDatasourceRecords()
|
|
return rows.map(toResourceOption)
|
|
} catch {
|
|
return []
|
|
}
|
|
}
|
|
|
|
export async function listKnowledgeSpaces(): Promise<ResourceOption[]> {
|
|
try {
|
|
const spaces = await listKnowledgeSpaceRecords()
|
|
return spaces.map((space) => ({
|
|
id: space.id,
|
|
name: space.name,
|
|
description: space.description || '',
|
|
}))
|
|
} catch {
|
|
return []
|
|
}
|
|
}
|
|
|
|
export async function listSkills(): Promise<ResourceOption[]> {
|
|
try {
|
|
const data = await apiFetchEnvelope<unknown>('/skills')
|
|
const list = Array.isArray(data)
|
|
? data
|
|
: (data as { data?: unknown[]; skills?: unknown[] })?.skills ??
|
|
(data as { data?: unknown[] })?.data
|
|
if (!Array.isArray(list)) return []
|
|
return list.map((item, i) => {
|
|
const row = item as Record<string, unknown>
|
|
return {
|
|
id: String(row.id ?? row.name ?? i),
|
|
name: String(row.name ?? `skill-${i}`),
|
|
description: String(row.description ?? ''),
|
|
nameEn: row.name_en ? String(row.name_en) : undefined,
|
|
category: row.category ? String(row.category) : undefined,
|
|
categoryId: row.category_id ? String(row.category_id) : undefined,
|
|
domain: row.domain ? String(row.domain) : undefined,
|
|
icon: row.icon ? String(row.icon) : undefined,
|
|
settings: row.settings && typeof row.settings === 'object' ? (row.settings as ResourceOption['settings']) : undefined,
|
|
}
|
|
})
|
|
} catch {
|
|
return []
|
|
}
|
|
}
|