Skip to content

World's first open-source enterprise world model.

The new knowledge base dialog offers the packs

WaylandYang08ee3d2f647c
diff --git a/web/src/api.ts b/web/src/api.ts
index 0b6800b4..5d16c934 100644
--- a/web/src/api.ts
+++ b/web/src/api.ts
@@ -64,6 +64,17 @@ export interface Workspace {
created_at: string;
}
+/** 建库时可选的起点本体包(`GET /ontology-packs`)。 */
+export type OntologyPack = {
+ id: string;
+ name: string;
+ summary: string;
+ classes: number;
+ properties: number;
+ /** 与已有包重叠时的提示;null = 基本不重叠 */
+ overlaps: string | null;
+};
+
export interface Kb {
id: string;
workspace_id: string;
@@ -642,13 +653,22 @@ export const api = {
request<{ kbs: MyKb[] }>(`/api/v1/workspaces/${workspaceId}/my-kbs`),
createKb: (
workspaceId: string,
- body: { name: string; description?: string | null; visibility?: string },
+ body: {
+ name: string;
+ description?: string | null;
+ visibility?: string;
+ /** 起点本体包 id,顺序有意义:第一个会认领同名的种子类 */
+ ontology_packs?: string[];
+ },
) =>
request<Kb>(`/api/v1/workspaces/${workspaceId}/kbs`, {
method: "POST",
body: JSON.stringify(body),
}),
+ ontologyPacks: () =>
+ request<{ packs: OntologyPack[] }>("/api/v1/ontology-packs"),
+
kbDetail: (kbId: string) => request<Kb>(`/api/v1/kbs/${kbId}`),
updateKb: (kbId: string, body: Record<string, unknown>) =>
request<Kb>(`/api/v1/kbs/${kbId}`, {
diff --git a/web/src/i18n/en.ts b/web/src/i18n/en.ts
index a46c3b4b..c8507dcb 100644
--- a/web/src/i18n/en.ts
+++ b/web/src/i18n/en.ts
@@ -658,6 +658,10 @@ export const en = {
"members switch between them from the top bar.",
defaultChip: "Default",
newKb: "New knowledge base",
+ packsLabel: "Starting ontology",
+ packsHint: "Optional — packs bring declared direction, so subject and object cannot come out reversed.",
+ packsNone: "None — start from the ten seed relations",
+ packsCount: (c: number, p: number) => `${c} classes · ${p} properties`,
name: "Name",
description: "Description",
visibility: "Visibility",
diff --git a/web/src/i18n/zh.ts b/web/src/i18n/zh.ts
index a55b7f29..371e4d23 100644
--- a/web/src/i18n/zh.ts
+++ b/web/src/i18n/zh.ts
@@ -601,6 +601,10 @@ export const zh: Strings = {
"创建知识库是管理员动作——成员在顶栏切换。",
defaultChip: "默认",
newKb: "新建知识库",
+ packsLabel: "起点本体",
+ packsHint: "可不选。包里的谓语带方向声明,主宾颠倒进不来。",
+ packsNone: "不选 —— 从十个种子关系起步",
+ packsCount: (c: number, p: number) => `${c} 个类 · ${p} 个属性`,
name: "名称",
description: "描述",
visibility: "可见性",
diff --git a/web/src/pages/Settings.tsx b/web/src/pages/Settings.tsx
index 43492cd1..2abc6e9c 100644
--- a/web/src/pages/Settings.tsx
+++ b/web/src/pages/Settings.tsx
@@ -357,6 +357,19 @@ function NewKbModal({
const [name, setName] = useState("");
const [desc, setDesc] = useState("");
const [restricted, setRestricted] = useState(true);
+ const [packs, setPacks] = useState<string[]>([]);
+
+ const available = useQuery({
+ queryKey: ["ontologyPacks"],
+ queryFn: api.ontologyPacks,
+ });
+
+ // 勾选顺序即安装顺序:第一个包的类会认领同名的种子类,
+ // 后面的撞名才查得到对齐表。所以取消再勾会排到末尾——这是对的
+ const toggle = (id: string) =>
+ setPacks((prev) =>
+ prev.includes(id) ? prev.filter((p) => p !== id) : [...prev, id],
+ );
const create = useMutation({
mutationFn: () =>
@@ -364,6 +377,7 @@ function NewKbModal({
name: name.trim(),
description: desc.trim() || null,
visibility: restricted ? "restricted" : "open",
+ ontology_packs: packs,
}),
onSuccess: (kb) => onDone(kb.id),
});
@@ -406,6 +420,53 @@ function NewKbModal({
/>
{S.settings.kbs.visRestricted}
</label>
+
+ <div className="mb-4">
+ <div className="text-xs text-neutral-300 mb-1">
+ {S.settings.kbs.packsLabel}
+ </div>
+ <p className="text-[11px] leading-relaxed text-neutral-500 mb-2">
+ {S.settings.kbs.packsHint}
+ </p>
+ <div className="max-h-56 overflow-y-auto rounded-lg border border-white/10 divide-y divide-white/5">
+ {available.data?.packs.map((p) => {
+ const on = packs.includes(p.id);
+ return (
+ <label
+ key={p.id}
+ className="flex gap-2.5 px-3 py-2 cursor-pointer hover:bg-white/5"
+ >
+ <input
+ type="checkbox"
+ className="mt-0.5"
+ checked={on}
+ onChange={() => toggle(p.id)}
+ />
+ <span className="min-w-0">
+ <span className="block text-xs text-neutral-200">{p.name}</span>
+ <span className="block text-[11px] leading-snug text-neutral-500">
+ {p.summary}
+ <span className="text-neutral-600">
+ {" · "}
+ {S.settings.kbs.packsCount(p.classes, p.properties)}
+ </span>
+ </span>
+ {p.overlaps && (
+ <span className="block text-[11px] text-amber-500/80">
+ {p.overlaps}
+ </span>
+ )}
+ </span>
+ </label>
+ );
+ })}
+ </div>
+ {packs.length === 0 && (
+ <p className="text-[11px] text-neutral-500 mt-1.5">
+ {S.settings.kbs.packsNone}
+ </p>
+ )}
+ </div>
{create.isError && (
<p className="text-xs text-rose-400 mb-2">
{(create.error as Error).message}