fix: keep question order and streamline contextual help
GoodBuddy Agents / Validate Agent source (push) Canceled after 0s
GoodBuddy Agents / Build darwin arm64 Agent (push) Canceled after 0s
GoodBuddy Agents / Build linux arm64 Agent (push) Canceled after 0s
GoodBuddy Agents / Build linux x64 Agent (push) Canceled after 0s
Cross-platform packages / Validate source (push) Canceled after 0s
Cross-platform packages / Authorize desktop packaging (push) Canceled after 0s
Cross-platform packages / linux arm64 (push) Canceled after 0s
Cross-platform packages / macos arm64 (push) Canceled after 0s
Cross-platform packages / windows arm64 (push) Canceled after 0s
Cross-platform packages / linux x64 (push) Canceled after 0s
Cross-platform packages / macos x64 (push) Canceled after 0s
Cross-platform packages / windows x64 (push) Canceled after 0s
Cross-platform packages / Publish GitHub and OSS release (push) Canceled after 0s
GoodBuddy Agents / Validate Agent source (push) Canceled after 0s
GoodBuddy Agents / Build darwin arm64 Agent (push) Canceled after 0s
GoodBuddy Agents / Build linux arm64 Agent (push) Canceled after 0s
GoodBuddy Agents / Build linux x64 Agent (push) Canceled after 0s
Cross-platform packages / Validate source (push) Canceled after 0s
Cross-platform packages / Authorize desktop packaging (push) Canceled after 0s
Cross-platform packages / linux arm64 (push) Canceled after 0s
Cross-platform packages / macos arm64 (push) Canceled after 0s
Cross-platform packages / windows arm64 (push) Canceled after 0s
Cross-platform packages / linux x64 (push) Canceled after 0s
Cross-platform packages / macos x64 (push) Canceled after 0s
Cross-platform packages / windows x64 (push) Canceled after 0s
Cross-platform packages / Publish GitHub and OSS release (push) Canceled after 0s
Keep interactive questions and answered cards at their original position in conversation history, including remote reception, recovery, and reopening. Preserve legacy history placement without a database migration. Move supplementary guidance into shared accessible contextual-help popovers across pages and settings. Add keyboard, modal, accessibility, and Electron regressions, plus bounded opt-in live canvas-analysis validation. Remove unused Agent, Runtime, and in-memory graph-search helpers, obsolete mocks and browser copy; reuse the existing package-size formatter. Keep production execution paths, protocol schemas, and released data migrations. Validation: targeted cleanup tests, typecheck, lint, shared Linux Host attach/read/re-attach, and added help/Electron checks passed. Final full-suite verification passed 4,858 tests with 67 skipped and zero failures (412 files passed, 9 skipped). Focused help checks passed 54 tests, including Electron style comparisons and Chromium accessibility descriptions. Details and validation boundaries are recorded in feature docs. Release note: 修复交互式问答在回答后排到后续输出末尾的问题,重新打开会话仍保留提问位置。页面和设置中的补充说明改为标题或字段旁的按需帮助,支持鼠标与键盘操作。
This commit is contained in:
@@ -7,7 +7,6 @@ import {
|
||||
extractKnowledgeGraph,
|
||||
mergeKnowledgeGraphs,
|
||||
normalizeEntityAlias,
|
||||
searchGraph,
|
||||
validateModelGraph,
|
||||
type GraphChunk,
|
||||
type KnowledgeGraph
|
||||
@@ -867,9 +866,9 @@ describe('extraction strategies', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('graph merge and search', () => {
|
||||
describe('graph merge', () => {
|
||||
const evidence = {
|
||||
chunkId: 'search',
|
||||
chunkId: 'merge',
|
||||
quote: 'evidence',
|
||||
start: 0,
|
||||
end: 8,
|
||||
@@ -883,27 +882,6 @@ describe('graph merge and search', () => {
|
||||
name: 'API Gateway',
|
||||
type: 'service',
|
||||
aliases: ['gateway'],
|
||||
evidence: [{ ...evidence, confidence: 0.9 }]
|
||||
},
|
||||
{
|
||||
id: 'users',
|
||||
name: 'User Service',
|
||||
type: 'service',
|
||||
aliases: [],
|
||||
evidence: [evidence]
|
||||
},
|
||||
{
|
||||
id: 'database',
|
||||
name: 'User Database',
|
||||
type: 'database',
|
||||
aliases: [],
|
||||
evidence: [{ ...evidence, confidence: 0.6 }]
|
||||
},
|
||||
{
|
||||
id: 'unrelated',
|
||||
name: 'Billing',
|
||||
type: 'service',
|
||||
aliases: [],
|
||||
evidence: [evidence]
|
||||
}
|
||||
],
|
||||
@@ -913,77 +891,11 @@ describe('graph merge and search', () => {
|
||||
sourceId: 'api',
|
||||
targetId: 'users',
|
||||
type: 'calls',
|
||||
evidence: [{ ...evidence, confidence: 0.95 }]
|
||||
},
|
||||
{
|
||||
id: 'users-db',
|
||||
sourceId: 'users',
|
||||
targetId: 'database',
|
||||
type: 'uses',
|
||||
evidence: [{ ...evidence, confidence: 0.8 }]
|
||||
},
|
||||
{
|
||||
id: 'orphan',
|
||||
sourceId: 'api',
|
||||
targetId: 'missing',
|
||||
type: 'calls',
|
||||
evidence: [evidence]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
it('ranks exact/alias matches, traverses adjacency, and returns a bounded subgraph', () => {
|
||||
const result = searchGraph(graph, 'gateway', {
|
||||
maximumEntities: 2,
|
||||
maximumRelations: 1,
|
||||
maximumDepth: 2
|
||||
})
|
||||
|
||||
expect(result.matchedEntityIds[0]).toBe('api')
|
||||
expect(result.entities.map((entity) => entity.id)).toEqual(['api', 'users'])
|
||||
expect(result.relations.map((relation) => relation.id)).toEqual([
|
||||
'api-users'
|
||||
])
|
||||
expect(searchGraph(graph, 'not found')).toEqual({
|
||||
entities: [],
|
||||
relations: [],
|
||||
matchedEntityIds: []
|
||||
})
|
||||
})
|
||||
|
||||
it('never exceeds global search limits even when callers request more', () => {
|
||||
const entities = Array.from(
|
||||
{ length: GRAPH_LIMITS.maximumSearchEntities + 10 },
|
||||
(_, index) => ({
|
||||
id: `node-${index}`,
|
||||
name: `node ${index}`,
|
||||
type: 'node',
|
||||
aliases: [],
|
||||
evidence: [evidence]
|
||||
})
|
||||
)
|
||||
const largeGraph: KnowledgeGraph = {
|
||||
entities,
|
||||
relations: entities.slice(1).map((entity, index) => ({
|
||||
id: `edge-${index}`,
|
||||
sourceId: entities[0]?.id ?? '',
|
||||
targetId: entity.id,
|
||||
type: 'links',
|
||||
evidence: [evidence]
|
||||
}))
|
||||
}
|
||||
const result = searchGraph(largeGraph, 'node', {
|
||||
maximumEntities: 10_000,
|
||||
maximumRelations: 10_000
|
||||
})
|
||||
expect(result.entities.length).toBeLessThanOrEqual(
|
||||
GRAPH_LIMITS.maximumSearchEntities
|
||||
)
|
||||
expect(result.relations.length).toBeLessThanOrEqual(
|
||||
GRAPH_LIMITS.maximumSearchRelations
|
||||
)
|
||||
})
|
||||
|
||||
it('discards relations whose endpoints disappear during merge', () => {
|
||||
const merged = mergeKnowledgeGraphs(
|
||||
{ entities: [graph.entities[0]!], relations: [graph.relations[0]!] },
|
||||
|
||||
@@ -21,8 +21,6 @@ export const GRAPH_LIMITS = {
|
||||
maximumRelations: 400,
|
||||
maximumFieldLength: 120,
|
||||
maximumQuoteLength: 500,
|
||||
maximumSearchEntities: 50,
|
||||
maximumSearchRelations: 100,
|
||||
maximumWarnings: 20,
|
||||
maximumWarningLength: 240
|
||||
} as const
|
||||
@@ -91,16 +89,6 @@ export interface ExtractKnowledgeGraphOptions {
|
||||
modelRetryBackoffMilliseconds?: number
|
||||
}
|
||||
|
||||
export interface GraphSearchOptions {
|
||||
maximumEntities?: number
|
||||
maximumRelations?: number
|
||||
maximumDepth?: number
|
||||
}
|
||||
|
||||
export interface GraphSearchResult extends KnowledgeGraph {
|
||||
matchedEntityIds: string[]
|
||||
}
|
||||
|
||||
const emptyGraph = (): KnowledgeGraph => ({ entities: [], relations: [] })
|
||||
|
||||
const modelEvidenceSchema = z
|
||||
@@ -1003,152 +991,3 @@ export async function extractKnowledgeGraph(
|
||||
warnings: [...context.warnings].slice(0, GRAPH_LIMITS.maximumWarnings)
|
||||
}
|
||||
}
|
||||
|
||||
function bestEvidenceConfidence(evidence: readonly GraphEvidence[]): number {
|
||||
return evidence.reduce(
|
||||
(maximum, item) => Math.max(maximum, item.confidence),
|
||||
0
|
||||
)
|
||||
}
|
||||
|
||||
function entityMatchScore(entity: GraphEntity, query: string): number {
|
||||
const key = normalizeEntityAlias(entity.name)
|
||||
const type = normalizeEntityAlias(entity.type)
|
||||
const aliases = entity.aliases.map(normalizeEntityAlias)
|
||||
if (key === query || aliases.includes(query)) {
|
||||
return 100
|
||||
}
|
||||
if (key.startsWith(query) || aliases.some((alias) => alias.startsWith(query))) {
|
||||
return 80
|
||||
}
|
||||
if (key.includes(query) || aliases.some((alias) => alias.includes(query))) {
|
||||
return 60
|
||||
}
|
||||
if (type.includes(query)) {
|
||||
return 30
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
export function searchGraph(
|
||||
graph: KnowledgeGraph,
|
||||
query: string,
|
||||
options: GraphSearchOptions = {}
|
||||
): GraphSearchResult {
|
||||
const normalizedQuery = normalizeEntityAlias(query)
|
||||
if (!normalizedQuery) {
|
||||
return { ...emptyGraph(), matchedEntityIds: [] }
|
||||
}
|
||||
const maximumEntities = Math.max(
|
||||
1,
|
||||
Math.min(
|
||||
options.maximumEntities ?? 20,
|
||||
GRAPH_LIMITS.maximumSearchEntities
|
||||
)
|
||||
)
|
||||
const maximumRelations = Math.max(
|
||||
0,
|
||||
Math.min(
|
||||
options.maximumRelations ?? 40,
|
||||
GRAPH_LIMITS.maximumSearchRelations
|
||||
)
|
||||
)
|
||||
const maximumDepth = Math.max(0, Math.min(options.maximumDepth ?? 1, 3))
|
||||
const entitiesById = new Map(
|
||||
graph.entities
|
||||
.slice(0, GRAPH_LIMITS.maximumEntities)
|
||||
.map((entity) => [entity.id, entity])
|
||||
)
|
||||
const validRelations = graph.relations
|
||||
.slice(0, GRAPH_LIMITS.maximumRelations)
|
||||
.filter(
|
||||
(relation) =>
|
||||
entitiesById.has(relation.sourceId) &&
|
||||
entitiesById.has(relation.targetId)
|
||||
)
|
||||
const scored = [...entitiesById.values()]
|
||||
.map((entity) => ({
|
||||
entity,
|
||||
score: entityMatchScore(entity, normalizedQuery)
|
||||
}))
|
||||
.filter((item) => item.score > 0)
|
||||
.sort(
|
||||
(left, right) =>
|
||||
right.score - left.score ||
|
||||
bestEvidenceConfidence(right.entity.evidence) -
|
||||
bestEvidenceConfidence(left.entity.evidence) ||
|
||||
left.entity.name.localeCompare(right.entity.name)
|
||||
)
|
||||
const matchedEntityIds = scored
|
||||
.slice(0, maximumEntities)
|
||||
.map((item) => item.entity.id)
|
||||
const selected = new Set(matchedEntityIds)
|
||||
let frontier = new Set(matchedEntityIds)
|
||||
for (
|
||||
let depth = 0;
|
||||
depth < maximumDepth && selected.size < maximumEntities;
|
||||
depth += 1
|
||||
) {
|
||||
const candidates = new Map<string, number>()
|
||||
for (const relation of validRelations) {
|
||||
const neighbor = frontier.has(relation.sourceId)
|
||||
? relation.targetId
|
||||
: frontier.has(relation.targetId)
|
||||
? relation.sourceId
|
||||
: undefined
|
||||
if (neighbor && !selected.has(neighbor)) {
|
||||
candidates.set(
|
||||
neighbor,
|
||||
Math.max(
|
||||
candidates.get(neighbor) ?? 0,
|
||||
bestEvidenceConfidence(relation.evidence)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
const next = [...candidates]
|
||||
.sort(
|
||||
([leftId, leftScore], [rightId, rightScore]) =>
|
||||
rightScore - leftScore ||
|
||||
(entitiesById.get(leftId)?.name ?? '').localeCompare(
|
||||
entitiesById.get(rightId)?.name ?? ''
|
||||
)
|
||||
)
|
||||
.slice(0, maximumEntities - selected.size)
|
||||
.map(([id]) => id)
|
||||
frontier = new Set(next)
|
||||
for (const id of next) {
|
||||
selected.add(id)
|
||||
}
|
||||
}
|
||||
const entities = [...selected]
|
||||
.map((id) => entitiesById.get(id))
|
||||
.filter((entity): entity is GraphEntity => entity !== undefined)
|
||||
const relations = validRelations
|
||||
.filter(
|
||||
(relation) =>
|
||||
selected.has(relation.sourceId) && selected.has(relation.targetId)
|
||||
)
|
||||
.sort(
|
||||
(left, right) =>
|
||||
Number(matchedEntityIds.includes(right.sourceId)) +
|
||||
Number(matchedEntityIds.includes(right.targetId)) -
|
||||
Number(matchedEntityIds.includes(left.sourceId)) -
|
||||
Number(matchedEntityIds.includes(left.targetId)) ||
|
||||
bestEvidenceConfidence(right.evidence) -
|
||||
bestEvidenceConfidence(left.evidence) ||
|
||||
left.id.localeCompare(right.id)
|
||||
)
|
||||
.slice(0, maximumRelations)
|
||||
const connected = new Set(
|
||||
relations.flatMap((relation) => [relation.sourceId, relation.targetId])
|
||||
)
|
||||
return {
|
||||
entities: entities.filter(
|
||||
(entity) =>
|
||||
matchedEntityIds.includes(entity.id) || connected.has(entity.id)
|
||||
),
|
||||
relations,
|
||||
matchedEntityIds
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user