dsh-data-domain-knowledge 0.1.1-alpha.2 → 0.1.1-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -16
- package/lib/client.js +1042 -2097
- package/lib/contract-refs.d.ts +0 -1
- package/lib/doc-page.js +1 -1
- package/lib/pages.js +2489 -1060
- package/lib/types/agent-behavior-rules.d.ts.map +1 -1
- package/lib/types/agent-behavior-rules.js +3 -2
- package/lib/types/agent-behavior-rules.js.map +1 -1
- package/lib/types/axis-contract.js +1 -1
- package/lib/types/axis-contract.js.map +1 -1
- package/lib/types/card-organize.d.ts +2 -1
- package/lib/types/card-organize.d.ts.map +1 -1
- package/lib/types/card-organize.js +5 -3
- package/lib/types/card-organize.js.map +1 -1
- package/lib/types/config-schema.d.ts +1 -1
- package/lib/types/config-schema.js +1 -1
- package/lib/types/convert/host.d.ts +2 -3
- package/lib/types/convert/host.d.ts.map +1 -1
- package/lib/types/convert/host.js +11 -2
- package/lib/types/convert/host.js.map +1 -1
- package/lib/types/convert/ingest.d.ts +14 -20
- package/lib/types/convert/ingest.d.ts.map +1 -1
- package/lib/types/convert/ingest.js +8 -5
- package/lib/types/convert/ingest.js.map +1 -1
- package/lib/types/diagnosis/store.d.ts +2 -2
- package/lib/types/diagnosis/store.d.ts.map +1 -1
- package/lib/types/diagnosis/store.js +10 -2
- package/lib/types/diagnosis/store.js.map +1 -1
- package/lib/types/diagnosis/types.d.ts +1 -1
- package/lib/types/diagnosis/types.js +1 -1
- package/lib/types/extract-model.d.ts +3 -0
- package/lib/types/extract-model.d.ts.map +1 -1
- package/lib/types/extract-model.js.map +1 -1
- package/lib/types/images.js +1 -1
- package/lib/types/index.d.ts +0 -4
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js +99 -91
- package/lib/types/index.js.map +1 -1
- package/lib/types/knowledge-bases.d.ts +3 -0
- package/lib/types/knowledge-bases.d.ts.map +1 -1
- package/lib/types/knowledge-bases.js +22 -2
- package/lib/types/knowledge-bases.js.map +1 -1
- package/lib/types/knowledge-contract.d.ts +6 -0
- package/lib/types/knowledge-contract.d.ts.map +1 -1
- package/lib/types/knowledge-contract.js +6 -2
- package/lib/types/knowledge-contract.js.map +1 -1
- package/lib/types/layout.d.ts +9 -26
- package/lib/types/layout.d.ts.map +1 -1
- package/lib/types/layout.js +10 -28
- package/lib/types/layout.js.map +1 -1
- package/lib/types/materialize-snapshot.d.ts +5 -0
- package/lib/types/materialize-snapshot.d.ts.map +1 -1
- package/lib/types/migrate.d.ts +3 -1
- package/lib/types/migrate.d.ts.map +1 -1
- package/lib/types/migrate.js +3 -1
- package/lib/types/migrate.js.map +1 -1
- package/lib/types/model-text.d.ts +7 -0
- package/lib/types/model-text.d.ts.map +1 -1
- package/lib/types/model-text.js +31 -9
- package/lib/types/model-text.js.map +1 -1
- package/lib/types/organize-contract.d.ts.map +1 -1
- package/lib/types/organize-contract.js +2 -1
- package/lib/types/organize-contract.js.map +1 -1
- package/lib/types/pipeline/engine.d.ts +28 -4
- package/lib/types/pipeline/engine.d.ts.map +1 -1
- package/lib/types/pipeline/engine.js +68 -15
- package/lib/types/pipeline/engine.js.map +1 -1
- package/lib/types/pipeline/progress.d.ts +12 -0
- package/lib/types/pipeline/progress.d.ts.map +1 -0
- package/lib/types/pipeline/progress.js +37 -0
- package/lib/types/pipeline/progress.js.map +1 -0
- package/lib/types/pipeline/resumable-extract.d.ts +45 -0
- package/lib/types/pipeline/resumable-extract.d.ts.map +1 -0
- package/lib/types/pipeline/resumable-extract.js +262 -0
- package/lib/types/pipeline/resumable-extract.js.map +1 -0
- package/lib/types/pipeline/store.d.ts +8 -2
- package/lib/types/pipeline/store.d.ts.map +1 -1
- package/lib/types/pipeline/store.js +27 -5
- package/lib/types/pipeline/store.js.map +1 -1
- package/lib/types/pipeline/types.d.ts +56 -0
- package/lib/types/pipeline/types.d.ts.map +1 -1
- package/lib/types/pipeline/types.js +18 -1
- package/lib/types/pipeline/types.js.map +1 -1
- package/lib/types/present.d.ts +1 -1
- package/lib/types/present.js +1 -1
- package/lib/types/preset-ids.d.ts +0 -1
- package/lib/types/preset-ids.d.ts.map +1 -1
- package/lib/types/preset-ids.js +0 -3
- package/lib/types/preset-ids.js.map +1 -1
- package/lib/types/query-analysis.d.ts +0 -5
- package/lib/types/query-analysis.d.ts.map +1 -1
- package/lib/types/query-analysis.js +0 -16
- package/lib/types/query-analysis.js.map +1 -1
- package/lib/types/recall-delivery.d.ts +36 -0
- package/lib/types/recall-delivery.d.ts.map +1 -0
- package/lib/types/recall-delivery.js +16 -0
- package/lib/types/recall-delivery.js.map +1 -0
- package/lib/types/retrieval/scope.d.ts +17 -0
- package/lib/types/retrieval/scope.d.ts.map +1 -0
- package/lib/types/retrieval/scope.js +11 -0
- package/lib/types/retrieval/scope.js.map +1 -0
- package/lib/types/runtime.d.ts +75 -14
- package/lib/types/runtime.d.ts.map +1 -1
- package/lib/types/runtime.js +454 -198
- package/lib/types/runtime.js.map +1 -1
- package/lib/types/settings-volatile.d.ts +0 -7
- package/lib/types/settings-volatile.d.ts.map +1 -1
- package/lib/types/settings-volatile.js +0 -7
- package/lib/types/settings-volatile.js.map +1 -1
- package/lib/types/source-identity.d.ts +34 -0
- package/lib/types/source-identity.d.ts.map +1 -0
- package/lib/types/source-identity.js +85 -0
- package/lib/types/source-identity.js.map +1 -0
- package/lib/types/source-read.d.ts +18 -0
- package/lib/types/source-read.d.ts.map +1 -0
- package/lib/types/source-read.js +49 -0
- package/lib/types/source-read.js.map +1 -0
- package/lib/types/store/axis-references.d.ts.map +1 -1
- package/lib/types/store/axis-references.js +5 -3
- package/lib/types/store/axis-references.js.map +1 -1
- package/lib/types/store/knowledge-db.d.ts +5 -29
- package/lib/types/store/knowledge-db.d.ts.map +1 -1
- package/lib/types/store/knowledge-db.js +57 -2
- package/lib/types/store/knowledge-db.js.map +1 -1
- package/lib/types/store/source-identity.d.ts +8 -0
- package/lib/types/store/source-identity.d.ts.map +1 -0
- package/lib/types/store/source-identity.js +56 -0
- package/lib/types/store/source-identity.js.map +1 -0
- package/lib/types/types.d.ts +46 -5
- package/lib/types/types.d.ts.map +1 -1
- package/lib/types/types.js +6 -3
- package/lib/types/types.js.map +1 -1
- package/lib/types/wiki-availability.d.ts +11 -0
- package/lib/types/wiki-availability.d.ts.map +1 -0
- package/lib/types/wiki-availability.js +39 -0
- package/lib/types/wiki-availability.js.map +1 -0
- package/lib/types/wiki-finalize.d.ts +4 -2
- package/lib/types/wiki-finalize.d.ts.map +1 -1
- package/lib/types/wiki-finalize.js +9 -27
- package/lib/types/wiki-finalize.js.map +1 -1
- package/lib/types/wiki-links.d.ts +35 -0
- package/lib/types/wiki-links.d.ts.map +1 -0
- package/lib/types/wiki-links.js +129 -0
- package/lib/types/wiki-links.js.map +1 -0
- package/lib/types/wiki-trial-types.d.ts +3 -0
- package/lib/types/wiki-trial-types.d.ts.map +1 -1
- package/lib/types/wiki-trial.d.ts +3 -3
- package/lib/types/wiki-trial.d.ts.map +1 -1
- package/lib/types/wiki-trial.js +14 -3
- package/lib/types/wiki-trial.js.map +1 -1
- package/package.json +16 -16
- package/scripts/doctor.mjs +0 -7
- package/scripts/setup-embedding.sh +0 -0
- package/src/agent-behavior-rules.ts +3 -2
- package/src/axis-contract.ts +1 -1
- package/src/card-organize.ts +5 -3
- package/src/client/AttributionEventGuide.tsx +3 -3
- package/src/client/AxisMatrix.tsx +86 -19
- package/src/client/AxisRegistrySection.tsx +1 -1
- package/src/client/CompileSettingsView.tsx +473 -0
- package/src/client/DirectoryPicker.tsx +0 -2
- package/src/client/ExtractionTasksPage.tsx +557 -423
- package/src/client/GuideArchitectureCanvas.tsx +5 -12
- package/src/client/ImportFilesDialog.tsx +1 -0
- package/src/client/InfoHint.tsx +1 -1
- package/src/client/KnowledgeBaseTab.tsx +141 -148
- package/src/client/KnowledgePanel.tsx +16 -9
- package/src/client/OperationLogTab.tsx +1 -1
- package/src/client/PipelineRunView.tsx +173 -0
- package/src/client/RecallPanel.tsx +5 -16
- package/src/client/TabGuide.tsx +3 -7
- package/src/client/WikiFlowPanel.tsx +10 -11
- package/src/client/arch/NodeLogicPanel.tsx +3 -3
- package/src/client/arch/model.ts +5 -113
- package/src/client/architecture.css +1 -1
- package/src/client/architecture.tsx +13 -27
- package/src/client/attribution/AttributionTab.tsx +141 -10
- package/src/client/pages.css +305 -180
- package/src/client/pages.tsx +7 -12
- package/src/client/styles.css +15 -96
- package/src/config-schema.ts +1 -1
- package/src/convert/host.ts +13 -5
- package/src/convert/ingest.ts +20 -7
- package/src/diagnosis/store.ts +7 -2
- package/src/diagnosis/types.ts +1 -1
- package/src/extract-model.ts +3 -0
- package/src/images.ts +1 -1
- package/src/index.ts +92 -97
- package/src/knowledge-bases.ts +23 -3
- package/src/knowledge-contract.ts +7 -2
- package/src/layout.ts +10 -32
- package/src/materialize-snapshot.ts +1 -0
- package/src/migrate.ts +3 -1
- package/src/model-text.ts +33 -11
- package/src/organize-contract.ts +2 -1
- package/src/pipeline/engine.ts +85 -22
- package/src/pipeline/progress.ts +40 -0
- package/src/pipeline/resumable-extract.ts +233 -0
- package/src/pipeline/store.ts +28 -6
- package/src/pipeline/types.ts +47 -2
- package/src/present.ts +1 -1
- package/src/preset-ids.ts +0 -4
- package/src/query-analysis.ts +0 -20
- package/src/recall-delivery.ts +19 -0
- package/src/retrieval/scope.ts +10 -0
- package/src/runtime.ts +412 -206
- package/src/settings-volatile.ts +0 -7
- package/src/source-identity.ts +85 -0
- package/src/source-read.ts +47 -0
- package/src/store/axis-references.ts +5 -3
- package/src/store/knowledge-db.ts +54 -2
- package/src/store/source-identity.ts +42 -0
- package/src/types.ts +18 -5
- package/src/wiki-availability.ts +37 -0
- package/src/wiki-finalize.ts +9 -25
- package/src/wiki-links.ts +120 -0
- package/src/wiki-trial-types.ts +3 -2
- package/src/wiki-trial.ts +17 -6
- package/lib/types/intent/engine.d.ts +0 -122
- package/lib/types/intent/engine.d.ts.map +0 -1
- package/lib/types/intent/engine.js +0 -488
- package/lib/types/intent/engine.js.map +0 -1
- package/lib/types/intent/host.d.ts +0 -68
- package/lib/types/intent/host.d.ts.map +0 -1
- package/lib/types/intent/host.js +0 -249
- package/lib/types/intent/host.js.map +0 -1
- package/lib/types/intent/scope.d.ts +0 -25
- package/lib/types/intent/scope.d.ts.map +0 -1
- package/lib/types/intent/scope.js +0 -116
- package/lib/types/intent/scope.js.map +0 -1
- package/lib/types/intent/store.d.ts +0 -33
- package/lib/types/intent/store.d.ts.map +0 -1
- package/lib/types/intent/store.js +0 -239
- package/lib/types/intent/store.js.map +0 -1
- package/lib/types/intent/tools.d.ts +0 -62
- package/lib/types/intent/tools.d.ts.map +0 -1
- package/lib/types/intent/tools.js +0 -130
- package/lib/types/intent/tools.js.map +0 -1
- package/lib/types/intent/types.d.ts +0 -170
- package/lib/types/intent/types.d.ts.map +0 -1
- package/lib/types/intent/types.js +0 -56
- package/lib/types/intent/types.js.map +0 -1
- package/src/client/IntentLogic.tsx +0 -192
- package/src/client/IntentTab.tsx +0 -343
- package/src/client/TypeDefinitionDrawer.tsx +0 -195
- package/src/intent/README.md +0 -42
- package/src/intent/engine.ts +0 -515
- package/src/intent/host.ts +0 -315
- package/src/intent/scope.ts +0 -125
- package/src/intent/store.ts +0 -218
- package/src/intent/tools.ts +0 -154
- package/src/intent/types.ts +0 -229
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { normalizeCandidateName } from './extract.js'
|
|
2
|
+
import type { KnowledgeCard } from './types.js'
|
|
3
|
+
|
|
4
|
+
export const WIKI_NAV_START = '<!-- compiled:wiki-links -->'
|
|
5
|
+
const WIKI_NAV_END = '<!-- /compiled:wiki-links -->'
|
|
6
|
+
export interface WikiObject { id: string; name: string; aliases: string[]; scopeId?: string }
|
|
7
|
+
export interface WikiReference { entityId: string; entityType: string; title: string; target: string; link: string }
|
|
8
|
+
|
|
9
|
+
export function stripWikiNavigation(content: string): string {
|
|
10
|
+
return content.replace(/\n*<!-- compiled:wiki-links -->\n[\s\S]*?\n<!-- \/compiled:wiki-links -->\s*$/, '').trim()
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Preserve offsets while excluding fenced code, inline code, URLs and ordinary Markdown links. */
|
|
14
|
+
function proseMask(content: string): string {
|
|
15
|
+
let fence: string | undefined
|
|
16
|
+
let result = content.split('\n').map(line => {
|
|
17
|
+
const match = line.match(/^\s*(?:(?:\d+[.)]|[-+*])\s+)?(`{3,}|~{3,})(.*)$/)
|
|
18
|
+
const wasCode = Boolean(fence)
|
|
19
|
+
if (match) {
|
|
20
|
+
if (!fence) fence = match[1]!
|
|
21
|
+
else if (match[1]![0] === fence[0] && match[1]!.length >= fence.length && !match[2]!.trim()) fence = undefined
|
|
22
|
+
}
|
|
23
|
+
return wasCode || match ? ' '.repeat(line.length) : line
|
|
24
|
+
}).join('\n')
|
|
25
|
+
result = result.replace(/(`+)[^\n]*?\1|!?\[[^\]\n]*\]\([^\n)]*\)|https?:\/\/[^\s<>]+/g, match => ' '.repeat(match.length))
|
|
26
|
+
return result
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function scanWikiLinks(content: string): Array<{ target: string; label: string; start: number; end: number }> {
|
|
30
|
+
return [...proseMask(content).matchAll(/\[\[([^\]|\n]+)(?:\|([^\]\n]*))?\]\]/g)].map(match => ({
|
|
31
|
+
target: match[1]!.trim(), label: match[2]?.trim() || match[1]!.trim(), start: match.index!, end: match.index! + match[0].length,
|
|
32
|
+
}))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function wikiReference(card: Pick<KnowledgeCard, 'entityId' | 'entityType' | 'title'>): WikiReference {
|
|
36
|
+
const target = `${card.entityType}/${card.entityId}`
|
|
37
|
+
const metadata = (card as KnowledgeCard).metadata
|
|
38
|
+
const labels = metadata?.wiki_coordinate_labels as { action?: string; scene?: string } | undefined
|
|
39
|
+
const details = metadata?.wiki_kind ? [metadata.wiki_kind === 'way' ? 'Wiki Way' : 'Wiki Fact', labels?.action, labels?.scene].filter((value): value is string => Boolean(value) && !card.title.includes(value!)) : []
|
|
40
|
+
const display = `${card.title}${details.length ? ` · ${details.join(' · ')}` : ''}`
|
|
41
|
+
const label = display.replace(/[\[\]|\r\n]/g, ' ').trim() || card.entityId
|
|
42
|
+
return { entityId: card.entityId, entityType: card.entityType, title: card.title, target, link: `[[${target}|${label}]]` }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Stable IDs take precedence. A title or alias must resolve uniquely; never pick an arbitrary match. */
|
|
46
|
+
export function wikiLinkCandidates(cards: KnowledgeCard[], raw: string): KnowledgeCard[] {
|
|
47
|
+
const target = raw.trim().replace(/^\[\[([^\]|]+)(?:\|[^\]]*)?\]\]$/, '$1').trim()
|
|
48
|
+
const exact = cards.filter(card => target === card.entityId || target === `${card.entityType}/${card.entityId}` || target === `${card.entityType}:${card.entityId}`)
|
|
49
|
+
if (exact.length) return exact
|
|
50
|
+
return cards.filter(card => {
|
|
51
|
+
const names = [card.title, ...(Array.isArray(card.metadata.aliases) ? card.metadata.aliases.filter((a): a is string => typeof a === 'string') : typeof card.metadata.aliases === 'string' ? [card.metadata.aliases] : [])]
|
|
52
|
+
return names.some(name => normalizeCandidateName(target) === normalizeCandidateName(name)
|
|
53
|
+
|| normalizeCandidateName(target) === normalizeCandidateName(`${card.entityType}/${name}`))
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Index labels, not storage IDs or navigation text. Code examples remain unchanged. */
|
|
58
|
+
export function wikiIndexContent(content: string): string {
|
|
59
|
+
let text = stripWikiNavigation(content)
|
|
60
|
+
for (const link of scanWikiLinks(text).reverse()) text = text.slice(0, link.start) + link.label + text.slice(link.end)
|
|
61
|
+
return text
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Link only registered Objects and real Wiki files. Sharing a Source alone is not a semantic link. */
|
|
65
|
+
export function compileWikiNavigation(card: KnowledgeCard, cards: KnowledgeCard[], objects: WikiObject[]): {
|
|
66
|
+
content: string; outgoing: WikiReference[]; inlineTargets: string[]; objectIds: string[]
|
|
67
|
+
} {
|
|
68
|
+
let body = stripWikiNavigation(card.content)
|
|
69
|
+
const previous = new Set(Array.isArray(card.metadata.wiki_inline_targets) ? card.metadata.wiki_inline_targets : [])
|
|
70
|
+
for (const link of scanWikiLinks(body).reverse()) if (previous.has(link.target)) body = body.slice(0, link.start) + link.label + body.slice(link.end)
|
|
71
|
+
const mask = proseMask(body)
|
|
72
|
+
const covered = scanWikiLinks(body)
|
|
73
|
+
const byName = new Map<string, Set<string>>()
|
|
74
|
+
for (const object of objects) for (const name of [object.name, ...object.aliases]) {
|
|
75
|
+
if (name.length < 2) continue
|
|
76
|
+
const key = name.toLocaleLowerCase()
|
|
77
|
+
const ids = byName.get(key) ?? new Set<string>(); ids.add(object.id); byName.set(key, ids)
|
|
78
|
+
}
|
|
79
|
+
const mentioned = new Set(card.coordinate?.objectId ? [card.coordinate.objectId] : [])
|
|
80
|
+
const edits: Array<{ start: number; end: number; value: string; target: string }> = []
|
|
81
|
+
const live = cards.filter(candidate => candidate.status !== 'deprecated' && candidate.entityId !== card.entityId)
|
|
82
|
+
for (const [name, ids] of [...byName].sort((a, b) => b[0].length - a[0].length)) {
|
|
83
|
+
if (ids.size !== 1) continue
|
|
84
|
+
const objectId = [...ids][0]!
|
|
85
|
+
const literal = new RegExp(name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'giu')
|
|
86
|
+
for (const match of mask.matchAll(literal)) {
|
|
87
|
+
const at = match.index!
|
|
88
|
+
const end = at + match[0].length
|
|
89
|
+
if (covered.some(link => at < link.end && end > link.start) || edits.some(edit => at < edit.end && end > edit.start)) continue
|
|
90
|
+
if (/^[a-z0-9_]+$/i.test(name) && (/[a-z0-9_]/i.test(mask[at - 1] ?? '') || /[a-z0-9_]/i.test(mask[end] ?? ''))) continue
|
|
91
|
+
mentioned.add(objectId)
|
|
92
|
+
const candidates = live.filter(candidate => candidate.coordinate?.objectId === objectId)
|
|
93
|
+
const preferred = candidates.filter(candidate => candidate.metadata.wiki_kind === 'fact'
|
|
94
|
+
&& candidate.coordinate?.actionId === card.coordinate?.actionId && candidate.coordinate?.sceneId === card.coordinate?.sceneId)
|
|
95
|
+
const general = candidates.filter(candidate => candidate.metadata.wiki_kind === 'fact' && !candidate.coordinate?.actionId && !candidate.coordinate?.sceneId)
|
|
96
|
+
const choices = preferred.length ? preferred : general.length ? general : candidates.length === 1 ? candidates : []
|
|
97
|
+
if (choices.length !== 1) continue
|
|
98
|
+
const target = wikiReference(choices[0]!).target
|
|
99
|
+
edits.push({ start: at, end, value: `[[${target}|${body.slice(at, end)}]]`, target })
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Registry scope is an established conceptual parent, not a guessed relationship.
|
|
103
|
+
const byId = new Map(objects.map(object => [object.id, object]))
|
|
104
|
+
for (const id of mentioned) {
|
|
105
|
+
const parent = byId.get(id)?.scopeId
|
|
106
|
+
if (parent && byId.has(parent)) mentioned.add(parent)
|
|
107
|
+
}
|
|
108
|
+
for (const edit of edits.sort((a, b) => b.start - a.start)) body = body.slice(0, edit.start) + edit.value + body.slice(edit.end)
|
|
109
|
+
const outgoing = new Map<string, WikiReference>()
|
|
110
|
+
for (const candidate of live) if (candidate.coordinate && mentioned.has(candidate.coordinate.objectId)) {
|
|
111
|
+
const reference = wikiReference(candidate); outgoing.set(reference.target, reference)
|
|
112
|
+
}
|
|
113
|
+
for (const link of scanWikiLinks(body)) {
|
|
114
|
+
const matches = wikiLinkCandidates(live, link.target)
|
|
115
|
+
if (matches.length === 1) { const reference = wikiReference(matches[0]!); outgoing.set(reference.target, reference) }
|
|
116
|
+
}
|
|
117
|
+
const references = [...outgoing.values()].sort((a, b) => a.target.localeCompare(b.target))
|
|
118
|
+
const navigation = references.length ? `\n\n${WIKI_NAV_START}\n## Wiki 导航\n\n${references.map(reference => `- ${reference.link}`).join('\n')}\n${WIKI_NAV_END}` : ''
|
|
119
|
+
return { content: body + navigation, outgoing: references, inlineTargets: [...new Set(edits.map(edit => edit.target))].sort(), objectIds: [...mentioned].sort() }
|
|
120
|
+
}
|
package/src/wiki-trial-types.ts
CHANGED
|
@@ -32,6 +32,7 @@ export type TrialPhase =
|
|
|
32
32
|
* 能不能在原文里逐字找到要**本地查**,那是引文核验。
|
|
33
33
|
*/
|
|
34
34
|
export interface TrialSource {
|
|
35
|
+
sourceVersion?: number
|
|
35
36
|
documentId: string
|
|
36
37
|
quote: string
|
|
37
38
|
/** 引文在原文里的起止字符偏移。找不到时没有这个字段。 */
|
|
@@ -312,7 +313,7 @@ export interface TrialTokenUsage {
|
|
|
312
313
|
export interface TrialModelCallTrace {
|
|
313
314
|
ok: boolean
|
|
314
315
|
why?: string
|
|
315
|
-
request?: { provider?: string; model?: string; reasoningEffort?: string; sessionId?: string }
|
|
316
|
+
request?: { provider?: string; model?: string; reasoningEffort?: string; maxTokens?: number; sessionId?: string }
|
|
316
317
|
prompt: { system: string; user: string }
|
|
317
318
|
response?: string
|
|
318
319
|
usage?: TrialTokenUsage
|
|
@@ -349,7 +350,7 @@ export interface TrialReport {
|
|
|
349
350
|
/** 解析失败时的短摘录,保留旧界面的错误提示。 */
|
|
350
351
|
raw?: string
|
|
351
352
|
/** 本次实际送出的模型路由与会话信息。 */
|
|
352
|
-
request?: { provider?: string; model?: string; reasoningEffort?: string; sessionId?: string }
|
|
353
|
+
request?: { provider?: string; model?: string; reasoningEffort?: string; maxTokens?: number; sessionId?: string }
|
|
353
354
|
/** 模型返回的完整原文,供抽取轨迹复核。 */
|
|
354
355
|
response?: string
|
|
355
356
|
/** 模型端返回的本次调用用量。 */
|
package/src/wiki-trial.ts
CHANGED
|
@@ -30,12 +30,12 @@ import { normalizeKnowledgeExtraction } from './knowledge-contract.js'
|
|
|
30
30
|
* 顺序里有一条硬规矩:**先把"知识是什么"搞清楚,再决定"这些知识怎么组织成 Wiki Card"。**
|
|
31
31
|
* Wiki Card 是组织结果,不是知识合并结果。
|
|
32
32
|
*
|
|
33
|
-
* ##
|
|
33
|
+
* ## 主抽取与执行分片
|
|
34
34
|
*
|
|
35
|
-
* 七步是给人 review
|
|
35
|
+
* 七步是给人 review 的,不是给模型分的工。本模块校验一次抽取返回,输出统一报告:
|
|
36
36
|
* `subject` / `knowledge` / `objects` / `actions` / `scenes` / `dropped`。
|
|
37
37
|
* 编译时若坐标不能直接命中,系统会把有候选的坐标合并成一次受约束的补判请求;没有候选时不补判。
|
|
38
|
-
*
|
|
38
|
+
* 主流水线由 resumable-extract 按自然边界分片,保存检查点;小文档使用单片。
|
|
39
39
|
*
|
|
40
40
|
* ## 对象 × 动作矩阵
|
|
41
41
|
*
|
|
@@ -357,6 +357,17 @@ export function locateQuote(text: string, quote: string): { found: boolean; loca
|
|
|
357
357
|
return { found: true, locator: { start, end: last + 1 } }
|
|
358
358
|
}
|
|
359
359
|
|
|
360
|
+
/** A compiler-supplied chunk range disambiguates repeated quotes; verify it against source text. */
|
|
361
|
+
function locateTrialQuote(text: string, quote: string, source: Record<string, unknown>): ReturnType<typeof locateQuote> {
|
|
362
|
+
const range = plainRecord(source.extraction_range)
|
|
363
|
+
const start = Number(range.start), end = Number(range.end)
|
|
364
|
+
if (Number.isInteger(start) && Number.isInteger(end) && start >= 0 && end > start && end <= text.length) {
|
|
365
|
+
const local = locateQuote(text.slice(start, end), quote)
|
|
366
|
+
if (local.locator) return { found: local.found, locator: { start: start + local.locator.start, end: start + local.locator.end } }
|
|
367
|
+
}
|
|
368
|
+
return locateQuote(text, quote)
|
|
369
|
+
}
|
|
370
|
+
|
|
360
371
|
/** 引文落在哪个标题下面,从外到内。找不到位置就返回空数组。 */
|
|
361
372
|
export function headingPathAt(text: string, offset: number): string[] {
|
|
362
373
|
const stack: string[] = []
|
|
@@ -510,7 +521,7 @@ function readKnowledge(raw: unknown, options: ReadKnowledgeOptions): { knowledge
|
|
|
510
521
|
const source = item as Record<string, unknown>
|
|
511
522
|
const quote = str(source.quote)
|
|
512
523
|
if (!quote) continue
|
|
513
|
-
const located =
|
|
524
|
+
const located = locateTrialQuote(options.text, quote, source)
|
|
514
525
|
sources.push({
|
|
515
526
|
documentId: options.documentId,
|
|
516
527
|
quote,
|
|
@@ -551,7 +562,7 @@ function readTrialSources(raw: unknown, options: Pick<ReadEventOptions, 'text' |
|
|
|
551
562
|
const source = item as Record<string, unknown>
|
|
552
563
|
const quote = str(source.quote)
|
|
553
564
|
if (!quote) continue
|
|
554
|
-
const located =
|
|
565
|
+
const located = locateTrialQuote(options.text, quote, source)
|
|
555
566
|
sources.push({
|
|
556
567
|
documentId: options.documentId,
|
|
557
568
|
quote,
|
|
@@ -1240,7 +1251,7 @@ export async function runWikiTrial(input: {
|
|
|
1240
1251
|
let raw = ''
|
|
1241
1252
|
let usage: TrialTokenUsage | undefined
|
|
1242
1253
|
try {
|
|
1243
|
-
raw = await input.call({ system, prompt: promptUser, sessionId, onUsage: value => { usage = value }, onDelta: text => { raw += text; input.onDelta?.(text) } })
|
|
1254
|
+
raw = await input.call({ system, prompt: promptUser, sessionId, ...(input.modelRequest?.maxTokens !== undefined ? { maxTokens: input.modelRequest.maxTokens } : {}), onUsage: value => { usage = value }, onDelta: text => { raw += text; input.onDelta?.(text) } })
|
|
1244
1255
|
} catch (cause) {
|
|
1245
1256
|
return emptyReport({
|
|
1246
1257
|
title: input.title, text: input.text, subject: subject || input.title, promptUser, system,
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { type IntentRecord, type IntentRecordInput, type IntentResult, type IntentSettings, type IntentSource, type IntentTaskSummary, type IntentTurnState } from './types.js';
|
|
2
|
-
import type { LineageContext } from '#contracts';
|
|
3
|
-
/**
|
|
4
|
-
* Bounded audit store: one record per session turn, expiring after the configured TTL.
|
|
5
|
-
*
|
|
6
|
-
* 0033 起它同时是**工作集**与**留痕的入口**,两者的分工要说清:
|
|
7
|
-
*
|
|
8
|
-
* - 内存里这份是有 TTL 的**工作集**(默认 600 秒):血缘判定只关心最近的轮次,
|
|
9
|
-
* 一个十轮之前就结束的会话不该让新的一轮接到它的 task 上。
|
|
10
|
-
* - 磁盘上那份(`intent/intent.db`)是**留痕**,当前版本便于读取,历史版本只追加、不随 TTL 消失。
|
|
11
|
-
* `sink` 在每次 `save` 时被调用,`hydrate` 在启动时把留痕读回工作集 ——
|
|
12
|
-
* 重启之后同一个会话的血缘因此还在(在 TTL 窗口内)。
|
|
13
|
-
*
|
|
14
|
-
* 为什么不干脆让 `records()` 直接读文件:那会让 TTL 名存实亡(文件永远有),
|
|
15
|
-
* 于是「工作集」这个概念消失,血缘会接到很久以前的 task 上。两件事分开,
|
|
16
|
-
* 各自的契约才都成立。
|
|
17
|
-
*/
|
|
18
|
-
export declare class IntentStore {
|
|
19
|
-
private ttlSeconds;
|
|
20
|
-
private readonly now;
|
|
21
|
-
private readonly sessions;
|
|
22
|
-
/**
|
|
23
|
-
* 每条被保存的记录都会经过它(落盘留痕)。
|
|
24
|
-
*
|
|
25
|
-
* 同步签名、由调用方自己吞异常:`save` 在记录路径的关键路径上,而留痕失败
|
|
26
|
-
* 不该让这一轮的意图记录失败 —— 「记录不拦截请求」这条契约对留痕也成立。
|
|
27
|
-
*/
|
|
28
|
-
private sink?;
|
|
29
|
-
constructor(ttlSeconds?: number, now?: () => number);
|
|
30
|
-
/** 装上一个留痕出口。多次调用以最后一次为准。 */
|
|
31
|
-
setSink(sink: (record: IntentRecord) => void): void;
|
|
32
|
-
/**
|
|
33
|
-
* 把留痕读回工作集(启动时调用一次)。
|
|
34
|
-
*
|
|
35
|
-
* `touched` 用记录自己的 `updatedAt`,于是「重启」不会把 TTL 归零:一份十小时
|
|
36
|
-
* 前的记录在 TTL 600 秒下本来就该过期,重启不该让它复活。
|
|
37
|
-
*/
|
|
38
|
-
hydrate(records: IntentRecord[]): number;
|
|
39
|
-
setTtl(seconds: number): void;
|
|
40
|
-
private entry;
|
|
41
|
-
/** Upsert by turn key so repeated records within one turn stay a single fact. */
|
|
42
|
-
save(record: IntentRecord): IntentRecord;
|
|
43
|
-
records(sessionKey: string): IntentRecord[];
|
|
44
|
-
last(sessionKey: string): IntentRecord | undefined;
|
|
45
|
-
findByTurn(sessionKey: string, turnKey: string): IntentRecord | undefined;
|
|
46
|
-
taskExists(sessionKey: string, taskId: string): boolean;
|
|
47
|
-
lastSubtaskOf(sessionKey: string, taskId: string): string | undefined;
|
|
48
|
-
expiresAt(sessionKey: string): string | undefined;
|
|
49
|
-
clear(sessionKey: string): void;
|
|
50
|
-
/** When the session was last touched (ms since epoch); 0 when unknown. */
|
|
51
|
-
touchedAt(sessionKey: string): number;
|
|
52
|
-
/** Live session keys, most recently touched first. Expired sessions are skipped. */
|
|
53
|
-
sessionKeys(): string[];
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Intent recorder. Every entry point is total: an unrecognized act, an unknown
|
|
57
|
-
* task reference, or a missing classification degrade into warnings on a stored
|
|
58
|
-
* record. Nothing here blocks, confirms, or rewrites the user's request.
|
|
59
|
-
*/
|
|
60
|
-
export declare class IntentEngine {
|
|
61
|
-
readonly store: IntentStore;
|
|
62
|
-
private settings;
|
|
63
|
-
private readonly turns;
|
|
64
|
-
constructor(settings?: Partial<IntentSettings>, store?: IntentStore);
|
|
65
|
-
setSettings(settings: Partial<IntentSettings>): void;
|
|
66
|
-
getSettings(): IntentSettings;
|
|
67
|
-
/**
|
|
68
|
-
* Open a turn and allocate its provisional ids before the model records.
|
|
69
|
-
* Downstream calls dispatched in parallel with the record can already carry
|
|
70
|
-
* an id; the record later commits the authoritative task binding.
|
|
71
|
-
*/
|
|
72
|
-
beginTurn(sessionKey: string, turn: number, userInput: string, eligible?: boolean): IntentTurnState;
|
|
73
|
-
/**
|
|
74
|
-
* 用户消息可能在 `turn/start` 之后才到达。
|
|
75
|
-
*
|
|
76
|
-
* 宿主事件顺序不是固定的:有些会话先发 `turn/start`,再发 `user/message`。如果只在
|
|
77
|
-
* `beginTurn` 读取一次原文,就会把整轮意图永久记录成空字符串。收到真实用户消息后,
|
|
78
|
-
* 只更新尚未提交的当前轮次;已经记录的判断不再被后来事件改写。
|
|
79
|
-
*/
|
|
80
|
-
updateTurnInput(sessionKey: string, userInput: string): boolean;
|
|
81
|
-
/** Mark the current turn as a data turn without classifying it. */
|
|
82
|
-
markDataIntent(sessionKey: string, turn?: number): boolean;
|
|
83
|
-
/** Mark the current turn as a data turn based on actual data-tool use. */
|
|
84
|
-
markDataToolUse(sessionKey: string, turn?: number): boolean;
|
|
85
|
-
/** Clear a text-only gate when the model explicitly identifies a non-data turn. */
|
|
86
|
-
clearDataIntent(sessionKey: string, turn?: number): boolean;
|
|
87
|
-
/** Whether the current turn is eligible for data intent recording. */
|
|
88
|
-
isDataIntentTurn(sessionKey: string, turn?: number): boolean;
|
|
89
|
-
/** Backfill one `unknown` record only when an eligible data turn has no model record. */
|
|
90
|
-
fallbackWhenMissing(sessionKey: string, turn: number): IntentResult | undefined;
|
|
91
|
-
/** Record the model's intent judgement. The host applies scope before calling this method. */
|
|
92
|
-
record(input: IntentRecordInput, source?: IntentSource): IntentResult;
|
|
93
|
-
/** Ids a downstream tool call in this session should carry. */
|
|
94
|
-
activeLineage(sessionKey: string): {
|
|
95
|
-
lineage: Partial<LineageContext>;
|
|
96
|
-
committed: boolean;
|
|
97
|
-
} | undefined;
|
|
98
|
-
tasks(sessionKey: string): IntentTaskSummary[];
|
|
99
|
-
view(sessionKey?: string, includePrompt?: boolean): IntentResult;
|
|
100
|
-
/**
|
|
101
|
-
* Session-level index for the 意图 panel: every live session with its last
|
|
102
|
-
* classification and active task ids. Records themselves stay per-session.
|
|
103
|
-
*/
|
|
104
|
-
overview(): {
|
|
105
|
-
sessions: Array<Record<string, unknown>>;
|
|
106
|
-
};
|
|
107
|
-
/**
|
|
108
|
-
* Model-facing contract: record first, then continue; the record never gates the request.
|
|
109
|
-
*
|
|
110
|
-
* 这段文本就是 `intent_record` 的**工具描述**(0023 起不再单独注入 system prompt 段),
|
|
111
|
-
* 分类规则固定随工具在场,不再通过设置或注册表变更。
|
|
112
|
-
*
|
|
113
|
-
* 分类判定是**两段式**的(issue 0023):
|
|
114
|
-
* 1. 先拿用户意思去比对预置分类的 `description` / `examples`,命中就**直接用该 id**;
|
|
115
|
-
* 2. 全不命中才允许自行判断(新起一个 id 或落 `unknown`)。
|
|
116
|
-
*
|
|
117
|
-
* 这样预置项就是"先验",而不是一份仅供参考的清单——模型不必每轮从零分类。
|
|
118
|
-
*/
|
|
119
|
-
routingPrompt(): string;
|
|
120
|
-
}
|
|
121
|
-
export declare function createIntentEngine(settings?: Partial<IntentSettings>): IntentEngine;
|
|
122
|
-
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../../src/intent/engine.ts"],"names":[],"mappings":"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"}
|