World's first open-source enterprise world model.
Rust agent-memorybitemporalgraphragknowledge-baseknowledge-graphllmontologypgvectorpostgresqlragrustself-hostedsemantic-searchtemporal-knowledge-graphworld-model
An answer without sources says so (#644)
WaylandYangef8f48a3d63d
diff --git a/web/src/i18n/en.ts b/web/src/i18n/en.tsindex 80a77b20..14fccb5b 100644--- a/web/src/i18n/en.ts+++ b/web/src/i18n/en.ts@@ -725,6 +725,8 @@ export const en = {`“${name}” and its messages will be permanently removed.`,deleteBtn: "Delete",cancel: "Cancel",+ // 这条回答背后一条来源都没有(#547)。是事实陈述,所以每条都挂,不猜哪条该挂+ noSources: "No sources consulted",},graph: {// 还没判出类型的实体(0009)。不是一个类,是"这一格还空着"diff --git a/web/src/i18n/zh.ts b/web/src/i18n/zh.tsindex 5bb8d910..d255560d 100644--- a/web/src/i18n/zh.ts+++ b/web/src/i18n/zh.ts@@ -666,6 +666,7 @@ export const zh: Strings = {deleteHint: (name: string) => `「${name}」及其消息将被永久移除。`,deleteBtn: "删除",cancel: "取消",+ noSources: "未引用任何来源",},graph: {untyped: "未分类",diff --git a/web/src/liveAnswer.test.ts b/web/src/liveAnswer.test.tsnew file mode 100644index 00000000..443f2def--- /dev/null+++ b/web/src/liveAnswer.test.ts@@ -0,0 +1,35 @@+import { describe, expect, it } from "vitest";+import type { Source } from "./api";+import { answeredWithoutSources, type Turn } from "./liveAnswer";++const answer = (over: Partial<Turn> = {}): Turn => ({+ role: "assistant",+ content: "以下是我找到的内容",+ ...over,+});+const source = { n: 1, kind: "chunk" } as unknown as Source;++describe("answeredWithoutSources (#547)", () => {+ it("marks a finished answer with no sources", () => {+ expect(answeredWithoutSources(answer({ sources: [] }), false)).toBe(true);+ });++ it("does not mark an answer that cites something", () => {+ expect(answeredWithoutSources(answer({ sources: [source] }), false)).toBe(false);+ });++ it("waits for the stream to finish before deciding", () => {+ expect(answeredWithoutSources(answer(), true)).toBe(false);+ expect(answeredWithoutSources(answer(), false)).toBe(true);+ });++ it("marks a replayed turn, whose empty sources are stored as undefined", () => {+ expect(answeredWithoutSources(answer({ sources: undefined }), false)).toBe(true);+ });++ it("leaves user turns and bare errors alone", () => {+ expect(answeredWithoutSources({ role: "user", content: "hi" }, false)).toBe(false);+ expect(answeredWithoutSources(answer({ content: "", error: "boom" }), false)).toBe(false);+ expect(answeredWithoutSources(answer({ error: "stopped" }), false)).toBe(true);+ });+});diff --git a/web/src/liveAnswer.ts b/web/src/liveAnswer.tsindex c6071f91..3501ed18 100644--- a/web/src/liveAnswer.ts+++ b/web/src/liveAnswer.ts@@ -28,6 +28,18 @@ export interface Turn {error?: string;}+/** 这条回答要不要挂「未引用任何来源」(#547)。+ *+ * 判据只看数据:说完了、背后一条来源都没有,就挂——招呼、拒答挂着无害,+ * 而「以下是我找到的内容」配零来源的那条,靠它露馅。还在流的不挂:来源是+ * 增量到的,挂上又撤下比晚一点出现更糟。只有报错、一个字没说的那条也不挂,+ * 它不是回答,红字已经交代了。回放时 `sources` 空数组存成 undefined,同样算零 */+export function answeredWithoutSources(turn: Turn, live: boolean): boolean {+ if (turn.role !== "assistant" || live) return false;+ if (turn.error && !turn.content) return false;+ return !turn.sources?.length;+}+/** 快照条目:纯数据,给渲染看。abort 不进快照——渲染不该顺手摸到它 */export interface Live {kbId: string;diff --git a/web/src/pages/Chat.tsx b/web/src/pages/Chat.tsxindex 539b2876..4c1eecc2 100644--- a/web/src/pages/Chat.tsx+++ b/web/src/pages/Chat.tsx@@ -57,7 +57,12 @@ import {Textarea,} from "../ui";import { convMarks, useLive, useUnread } from "../unread";-import { liveAnswer, type LiveHandle, type Turn } from "../liveAnswer";+import {+ answeredWithoutSources,+ liveAnswer,+ type LiveHandle,+ type Turn,+} from "../liveAnswer";import { NodCard } from "./PendingFacts";import { NextStep, nextStep, useReadiness } from "./NextStep";@@ -888,6 +893,11 @@ function TurnView({ turn, live }: { turn: Turn; live?: boolean }) {)}</div>)}+ {/* 没有引用时,引用那一格换成一句「未引用任何来源」(#547):+ 缺席没人读得出来,得写出来。判据见 answeredWithoutSources */}+ {answeredWithoutSources(turn, !!live) && (+ <div className="mt-2 text-small text-ink-2">{S.ask.noSources}</div>+ )}</div>);}