Source-only publication of reviewed commit 64e96a7f423673dc29ad56485be9fc79bce8af1c.
Passed in isolation: focused frontend/backend tests, race checks, TypeScript typecheck, lint, Go compilation, Flowgram build, and deterministic SDK build/tests.
Not accepted as a production release: Next.js export/native assembly remains blocked by environment memory limits; browser interaction and MySQL staging acceptance remain unverified. No production server, database/schema, runtime configuration, deployment, release tag, or workflow execution was performed.
Expected source tree: 0a4a7528e9.
84 lines
2.8 KiB
TypeScript
84 lines
2.8 KiB
TypeScript
// Modified in the independent AgentDesk fork: localized knowledge workflows and safe display errors.
|
|
type TFunction = (key: string, values?: Record<string, string | number>) => string
|
|
|
|
const CHANNEL_LABEL_KEYS: Record<string, string> = {
|
|
im: "knowledge.channelIM",
|
|
agent_assist: "knowledge.channelAgentAssist",
|
|
api: "knowledge.channelAPI",
|
|
debug: "knowledge.channelDebug",
|
|
}
|
|
|
|
const SCENE_LABEL_KEYS: Record<string, string> = {
|
|
first_response: "knowledge.sceneFirstResponse",
|
|
assist: "knowledge.sceneAssist",
|
|
qa: "knowledge.sceneQA",
|
|
}
|
|
|
|
const ANSWER_STATUS_LABEL_KEYS: Record<number, string> = {
|
|
1: "knowledge.answerNormal",
|
|
2: "knowledge.answerNoAnswer",
|
|
3: "knowledge.answerFallback",
|
|
4: "knowledge.answerBlocked",
|
|
}
|
|
|
|
const PROVIDER_LABEL_KEYS: Record<string, string> = {
|
|
fixed: "knowledge.chunkFixed",
|
|
structured: "knowledge.chunkStructured",
|
|
faq: "knowledge.chunkFAQ",
|
|
semantic: "knowledge.chunkSemantic",
|
|
}
|
|
|
|
export function getKnowledgeRetrieveChannelLabel(value: string, fallback: string, t: TFunction) {
|
|
return translateByKey(CHANNEL_LABEL_KEYS[value], fallback, t)
|
|
}
|
|
|
|
export function getKnowledgeRetrieveSceneLabel(value: string, fallback: string, t: TFunction) {
|
|
return translateByKey(SCENE_LABEL_KEYS[value], fallback, t)
|
|
}
|
|
|
|
export function getKnowledgeAnswerStatusLabel(value: number, fallback: string, t: TFunction) {
|
|
return translateByKey(ANSWER_STATUS_LABEL_KEYS[value], fallback, t)
|
|
}
|
|
|
|
export function getKnowledgeChunkProviderLabel(value: string, t: TFunction) {
|
|
return translateByKey(PROVIDER_LABEL_KEYS[value], value, t)
|
|
}
|
|
|
|
function translateByKey(key: string | undefined, fallback: string, t: TFunction) {
|
|
return key ? t(key) : fallback
|
|
}
|
|
|
|
const TYPE_LABEL_KEYS: Record<string, string> = {
|
|
document: "knowledge.typeDocument",
|
|
faq: "knowledge.typeFAQ",
|
|
}
|
|
|
|
const STATUS_LABEL_KEYS: Record<number, string> = {
|
|
0: "knowledge.statusOk",
|
|
1: "knowledge.statusDisabled",
|
|
2: "knowledge.statusDeleted",
|
|
}
|
|
|
|
const INDEX_STATUS_LABEL_KEYS: Record<string, string> = {
|
|
pending: "knowledge.indexPending",
|
|
indexed: "knowledge.indexIndexed",
|
|
failed: "knowledge.indexFailed",
|
|
}
|
|
|
|
export function getKnowledgeTypeLabel(value: string, t: TFunction) {
|
|
return translateByKey(TYPE_LABEL_KEYS[value], t("knowledge.unknownType"), t)
|
|
}
|
|
|
|
export function getKnowledgeStatusLabel(value: number, t: TFunction) {
|
|
return translateByKey(STATUS_LABEL_KEYS[value], t("knowledge.unknownStatus"), t)
|
|
}
|
|
|
|
export function getKnowledgeIndexStatusLabel(value: string, t: TFunction) {
|
|
return translateByKey(INDEX_STATUS_LABEL_KEYS[value], t("knowledge.unknownStatus"), t)
|
|
}
|
|
|
|
// Never expose a stored provider/SQL error, even when talking to an older server.
|
|
export function getKnowledgeIndexErrorLabel(error: string | undefined, t: TFunction) {
|
|
return error ? t("knowledge.indexFailureSummary") : ""
|
|
}
|