@dabuliu_wsy/dsh-im 0.0.0-stage → 0.2.0

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.
Files changed (137) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +197 -3
  3. package/cordis.patch.yml +4 -0
  4. package/dist/core/agent-state.d.ts +38 -0
  5. package/dist/core/agent-state.js +59 -0
  6. package/dist/core/arbiter-bridge.d.ts +25 -0
  7. package/dist/core/arbiter-bridge.js +20 -0
  8. package/dist/core/arbiter.d.ts +29 -0
  9. package/dist/core/arbiter.js +59 -0
  10. package/dist/core/avatar-brands.d.ts +23 -0
  11. package/dist/core/avatar-brands.js +75 -0
  12. package/dist/core/avatar-presets.d.ts +21 -0
  13. package/dist/core/avatar-presets.js +38 -0
  14. package/dist/core/avatar.d.ts +1 -0
  15. package/dist/core/avatar.js +18 -0
  16. package/dist/core/blocked.d.ts +12 -0
  17. package/dist/core/blocked.js +23 -0
  18. package/dist/core/budget-plan.d.ts +41 -0
  19. package/dist/core/budget-plan.js +69 -0
  20. package/dist/core/calibration-samples.d.ts +77 -0
  21. package/dist/core/calibration-samples.js +168 -0
  22. package/dist/core/calibrator.d.ts +57 -0
  23. package/dist/core/calibrator.js +125 -0
  24. package/dist/core/chapter-tree.d.ts +128 -0
  25. package/dist/core/chapter-tree.js +400 -0
  26. package/dist/core/consensus.d.ts +135 -0
  27. package/dist/core/consensus.js +394 -0
  28. package/dist/core/context-budget.d.ts +153 -0
  29. package/dist/core/context-budget.js +183 -0
  30. package/dist/core/curator.d.ts +28 -0
  31. package/dist/core/curator.js +190 -0
  32. package/dist/core/dual-window.d.ts +86 -0
  33. package/dist/core/dual-window.js +175 -0
  34. package/dist/core/events.d.ts +110 -0
  35. package/dist/core/events.js +117 -0
  36. package/dist/core/facts.d.ts +114 -0
  37. package/dist/core/facts.js +400 -0
  38. package/dist/core/fence.d.ts +34 -0
  39. package/dist/core/fence.js +129 -0
  40. package/dist/core/floor.d.ts +18 -0
  41. package/dist/core/floor.js +80 -0
  42. package/dist/core/ids.d.ts +11 -0
  43. package/dist/core/ids.js +29 -0
  44. package/dist/core/im.d.ts +167 -0
  45. package/dist/core/im.js +1307 -0
  46. package/dist/core/index.d.ts +33 -0
  47. package/dist/core/index.js +33 -0
  48. package/dist/core/log.d.ts +21 -0
  49. package/dist/core/log.js +63 -0
  50. package/dist/core/memory-claims.d.ts +67 -0
  51. package/dist/core/memory-claims.js +164 -0
  52. package/dist/core/memory-context.d.ts +121 -0
  53. package/dist/core/memory-context.js +303 -0
  54. package/dist/core/memory-visibility.d.ts +58 -0
  55. package/dist/core/memory-visibility.js +36 -0
  56. package/dist/core/memory.d.ts +12 -0
  57. package/dist/core/memory.js +73 -0
  58. package/dist/core/metrics.d.ts +49 -0
  59. package/dist/core/metrics.js +89 -0
  60. package/dist/core/multi-hop.d.ts +116 -0
  61. package/dist/core/multi-hop.js +278 -0
  62. package/dist/core/persist.d.ts +21 -0
  63. package/dist/core/persist.js +94 -0
  64. package/dist/core/proactive.d.ts +54 -0
  65. package/dist/core/proactive.js +108 -0
  66. package/dist/core/prompt.d.ts +82 -0
  67. package/dist/core/prompt.js +164 -0
  68. package/dist/core/receipt.d.ts +107 -0
  69. package/dist/core/receipt.js +86 -0
  70. package/dist/core/retrieval.d.ts +69 -0
  71. package/dist/core/retrieval.js +260 -0
  72. package/dist/core/role-state.d.ts +16 -0
  73. package/dist/core/role-state.js +65 -0
  74. package/dist/core/runtime.d.ts +137 -0
  75. package/dist/core/runtime.js +574 -0
  76. package/dist/core/summary.d.ts +19 -0
  77. package/dist/core/summary.js +96 -0
  78. package/dist/core/text.d.ts +10 -0
  79. package/dist/core/text.js +45 -0
  80. package/dist/core/time.d.ts +22 -0
  81. package/dist/core/time.js +84 -0
  82. package/dist/core/tool-schema.d.ts +12 -0
  83. package/dist/core/tool-schema.js +92 -0
  84. package/dist/core/tools.d.ts +137 -0
  85. package/dist/core/tools.js +348 -0
  86. package/dist/core/types.d.ts +400 -0
  87. package/dist/core/types.js +1 -0
  88. package/dist/core/window.d.ts +6 -0
  89. package/dist/core/window.js +7 -0
  90. package/dist/core/workspace-node.d.ts +28 -0
  91. package/dist/core/workspace-node.js +232 -0
  92. package/dist/core/workspace.d.ts +9 -0
  93. package/dist/core/workspace.js +45 -0
  94. package/dist/host/agent-session.d.ts +279 -0
  95. package/dist/host/agent-session.js +935 -0
  96. package/dist/host/attachment-gc.d.ts +37 -0
  97. package/dist/host/attachment-gc.js +97 -0
  98. package/dist/host/calibration-samples-store.d.ts +5 -0
  99. package/dist/host/calibration-samples-store.js +67 -0
  100. package/dist/host/capabilities.d.ts +45 -0
  101. package/dist/host/capabilities.js +67 -0
  102. package/dist/host/derived-store.d.ts +36 -0
  103. package/dist/host/derived-store.js +199 -0
  104. package/dist/host/dsh-llm.d.ts +143 -0
  105. package/dist/host/dsh-llm.js +395 -0
  106. package/dist/host/event-store.d.ts +47 -0
  107. package/dist/host/event-store.js +154 -0
  108. package/dist/host/fs-atomic.d.ts +1 -0
  109. package/dist/host/fs-atomic.js +26 -0
  110. package/dist/host/im-api.d.ts +352 -0
  111. package/dist/host/im-api.js +1137 -0
  112. package/dist/host/index.d.ts +103 -0
  113. package/dist/host/index.js +453 -0
  114. package/dist/host/memory-index.d.ts +65 -0
  115. package/dist/host/memory-index.js +181 -0
  116. package/dist/host/metrics-store.d.ts +7 -0
  117. package/dist/host/metrics-store.js +104 -0
  118. package/dist/host/models.d.ts +39 -0
  119. package/dist/host/models.js +67 -0
  120. package/dist/host/persona-tools.d.ts +57 -0
  121. package/dist/host/persona-tools.js +226 -0
  122. package/dist/host/preflight.d.ts +31 -0
  123. package/dist/host/preflight.js +29 -0
  124. package/dist/host/receipt-store.d.ts +26 -0
  125. package/dist/host/receipt-store.js +68 -0
  126. package/dist/host/run-check.d.ts +51 -0
  127. package/dist/host/run-check.js +190 -0
  128. package/dist/host/state-roots.d.ts +50 -0
  129. package/dist/host/state-roots.js +163 -0
  130. package/dist/host/tool-cache.d.ts +25 -0
  131. package/dist/host/tool-cache.js +90 -0
  132. package/dist/host/tool-call-budget.d.ts +29 -0
  133. package/dist/host/tool-call-budget.js +38 -0
  134. package/dsh-plugin.json +25 -0
  135. package/lib/client.inner.cjs +3346 -0
  136. package/lib/client.js +3354 -0
  137. package/package.json +86 -6
@@ -0,0 +1,110 @@
1
+ /**
2
+ * 群事件日志(唯一事实源)与写租约。
3
+ *
4
+ * 只追加:事件永远不修改;messages / 摘要 / 任务板都是它的投影。
5
+ * 租约带 fencingToken:旧 token 的写入必须被拒,避免并发下 seq 断裂。
6
+ */
7
+ export declare const EVENT_SCHEMA_VERSION = 1;
8
+ export type EventKind = 'user' | 'persona' | 'system' | 'tool_call' | 'tool_result' | 'fact' | 'floor_decision';
9
+ /** 只有这三类事件是“消息”,会被投影成聊天记录;其余事件(工具/事实/仲裁)不占消息位。 */
10
+ export declare const CHAT_EVENT_KINDS: readonly EventKind[];
11
+ export declare function isChatEvent(event: {
12
+ kind: EventKind;
13
+ }): boolean;
14
+ /** 事实事件的结构化载荷;text 存事实正文。 */
15
+ export interface FactEventPayload {
16
+ op: 'assert' | 'supersede' | 'retract';
17
+ factId: string;
18
+ factKind: string;
19
+ owner?: string;
20
+ source: 'user' | 'persona' | 'extractor';
21
+ confidence?: number;
22
+ /** supersede 时被替换的旧 factId。 */
23
+ supersedes?: string;
24
+ /** 事实来源消息的事件 id(新写入必填;旧数据可能缺失)。 */
25
+ sourceMessageId?: string;
26
+ /** 事实来源消息的持久 seq(与 message.seq 对应)。 */
27
+ sourceMessageSeq?: number;
28
+ }
29
+ /** 发言权仲裁事件的结构化载荷;text 存 reason。 */
30
+ export interface FloorDecisionPayload {
31
+ personaId: string;
32
+ action: 'speak' | 'wait' | 'pass';
33
+ }
34
+ export interface ChatEvent {
35
+ schemaVersion: number;
36
+ seq: number;
37
+ id: string;
38
+ at: number;
39
+ kind: EventKind;
40
+ actorId?: string;
41
+ actorName: string;
42
+ text: string;
43
+ /** 这条发言基于哪个 seq 的视图;用于因果一致性检测。 */
44
+ basedOnSeq?: number;
45
+ producer: 'plugin' | 'session' | 'tool';
46
+ /** 内容允许的最高可见级别;真正的裁决在读时由策略函数做。 */
47
+ sensitivity?: 'group' | 'caller' | 'admin';
48
+ /** 群消息/工具结果属于不可信输入(可能含 prompt 注入)。 */
49
+ untrusted?: boolean;
50
+ fact?: FactEventPayload;
51
+ floorDecision?: FloorDecisionPayload;
52
+ }
53
+ export interface EventInput {
54
+ at: number;
55
+ kind: EventKind;
56
+ actorId?: string;
57
+ actorName: string;
58
+ text: string;
59
+ basedOnSeq?: number;
60
+ producer?: ChatEvent['producer'];
61
+ sensitivity?: ChatEvent['sensitivity'];
62
+ untrusted?: boolean;
63
+ fact?: FactEventPayload;
64
+ floorDecision?: FloorDecisionPayload;
65
+ }
66
+ export declare function lastSeq(events: readonly ChatEvent[]): number;
67
+ /** 追加一条事件:seq 单调递增,schemaVersion 自动带上。 */
68
+ export declare function appendEvent(events: readonly ChatEvent[], input: EventInput): ChatEvent;
69
+ /** 把一条已存在的事件重新变成可再追加的输入(重建事件流时保留非消息事件用)。 */
70
+ export declare function toEventInput(event: ChatEvent): EventInput;
71
+ /** 老 state.json 里的 messages → 初始事件流(一次性迁移,幂等)。 */
72
+ export declare function migrateMessages(messages: readonly {
73
+ id: string;
74
+ kind: 'user' | 'persona' | 'system';
75
+ authorName: string;
76
+ text: string;
77
+ createdAt: number;
78
+ }[]): ChatEvent[];
79
+ /** 从事件重放界面需要的 messages 投影。 */
80
+ export declare function projectMessages(events: readonly ChatEvent[]): {
81
+ id: string;
82
+ kind: 'user' | 'persona' | 'system';
83
+ authorName: string;
84
+ text: string;
85
+ createdAt: number;
86
+ }[];
87
+ export interface LeaseRecord {
88
+ groupId: string;
89
+ owner: string;
90
+ fencingToken: number;
91
+ expiresAt: number;
92
+ }
93
+ export interface LeaseStore {
94
+ read(groupId: string): LeaseRecord | undefined;
95
+ write(record: LeaseRecord): void;
96
+ }
97
+ export declare function createMemoryLeaseStore(): LeaseStore;
98
+ export type LeaseResult = {
99
+ ok: true;
100
+ record: LeaseRecord;
101
+ } | {
102
+ ok: false;
103
+ holder: string;
104
+ };
105
+ /** 抢占/续期写租约:已过期可抢占,fencingToken 单调 +1。 */
106
+ export declare function acquireLease(store: LeaseStore, groupId: string, owner: string, now: number, ttlMs?: number): LeaseResult;
107
+ /** 续期:只有仍持有同一 fencingToken 的写入方能续。 */
108
+ export declare function renewLease(store: LeaseStore, record: LeaseRecord, now: number, ttlMs?: number): LeaseRecord | null;
109
+ /** 写入校验:token 必须仍是当前 token 且未过期,否则拒绝(fail-closed)。 */
110
+ export declare function canWrite(store: LeaseStore, record: LeaseRecord, now: number): boolean;
@@ -0,0 +1,117 @@
1
+ /**
2
+ * 群事件日志(唯一事实源)与写租约。
3
+ *
4
+ * 只追加:事件永远不修改;messages / 摘要 / 任务板都是它的投影。
5
+ * 租约带 fencingToken:旧 token 的写入必须被拒,避免并发下 seq 断裂。
6
+ */
7
+ export const EVENT_SCHEMA_VERSION = 1;
8
+ /** 只有这三类事件是“消息”,会被投影成聊天记录;其余事件(工具/事实/仲裁)不占消息位。 */
9
+ export const CHAT_EVENT_KINDS = ['user', 'persona', 'system'];
10
+ export function isChatEvent(event) {
11
+ return CHAT_EVENT_KINDS.includes(event.kind);
12
+ }
13
+ export function lastSeq(events) {
14
+ return events.reduce((max, event) => Math.max(max, event.seq), 0);
15
+ }
16
+ /** 追加一条事件:seq 单调递增,schemaVersion 自动带上。 */
17
+ export function appendEvent(events, input) {
18
+ const seq = lastSeq(events) + 1;
19
+ return {
20
+ schemaVersion: EVENT_SCHEMA_VERSION,
21
+ seq,
22
+ id: 'e' + seq,
23
+ at: input.at,
24
+ kind: input.kind,
25
+ ...(input.actorId === undefined ? {} : { actorId: input.actorId }),
26
+ actorName: input.actorName,
27
+ text: input.text,
28
+ ...(input.basedOnSeq === undefined ? {} : { basedOnSeq: input.basedOnSeq }),
29
+ producer: input.producer ?? 'plugin',
30
+ ...(input.sensitivity === undefined ? {} : { sensitivity: input.sensitivity }),
31
+ ...(input.untrusted === undefined ? {} : { untrusted: input.untrusted }),
32
+ ...(input.fact === undefined ? {} : { fact: input.fact }),
33
+ ...(input.floorDecision === undefined ? {} : { floorDecision: input.floorDecision }),
34
+ };
35
+ }
36
+ /** 把一条已存在的事件重新变成可再追加的输入(重建事件流时保留非消息事件用)。 */
37
+ export function toEventInput(event) {
38
+ return {
39
+ at: event.at,
40
+ kind: event.kind,
41
+ ...(event.actorId === undefined ? {} : { actorId: event.actorId }),
42
+ actorName: event.actorName,
43
+ text: event.text,
44
+ ...(event.basedOnSeq === undefined ? {} : { basedOnSeq: event.basedOnSeq }),
45
+ producer: event.producer,
46
+ ...(event.sensitivity === undefined ? {} : { sensitivity: event.sensitivity }),
47
+ ...(event.untrusted === undefined ? {} : { untrusted: event.untrusted }),
48
+ ...(event.fact === undefined ? {} : { fact: event.fact }),
49
+ ...(event.floorDecision === undefined ? {} : { floorDecision: event.floorDecision }),
50
+ };
51
+ }
52
+ /** 老 state.json 里的 messages → 初始事件流(一次性迁移,幂等)。 */
53
+ export function migrateMessages(messages) {
54
+ const events = [];
55
+ for (const message of messages) {
56
+ const input = {
57
+ at: message.createdAt,
58
+ kind: message.kind,
59
+ actorName: message.authorName,
60
+ text: message.text,
61
+ producer: 'plugin',
62
+ ...(message.kind === 'persona' ? { sensitivity: 'group' } : {}),
63
+ ...(message.kind === 'user' ? { untrusted: true } : {}),
64
+ };
65
+ events.push(appendEvent(events, input));
66
+ }
67
+ return events;
68
+ }
69
+ /** 从事件重放界面需要的 messages 投影。 */
70
+ export function projectMessages(events) {
71
+ return events
72
+ .filter((event) => event.kind === 'user' || event.kind === 'persona' || event.kind === 'system')
73
+ .map((event) => ({
74
+ id: event.id,
75
+ kind: event.kind,
76
+ authorName: event.actorName,
77
+ text: event.text,
78
+ createdAt: event.at,
79
+ }));
80
+ }
81
+ export function createMemoryLeaseStore() {
82
+ const rows = new Map();
83
+ return {
84
+ read: (groupId) => rows.get(groupId),
85
+ write: (record) => { rows.set(record.groupId, record); },
86
+ };
87
+ }
88
+ /** 抢占/续期写租约:已过期可抢占,fencingToken 单调 +1。 */
89
+ export function acquireLease(store, groupId, owner, now, ttlMs = 20_000) {
90
+ const current = store.read(groupId);
91
+ const expired = !current || current.expiresAt <= now;
92
+ if (current && !expired && current.owner !== owner) {
93
+ return { ok: false, holder: current.owner };
94
+ }
95
+ const record = {
96
+ groupId,
97
+ owner,
98
+ fencingToken: (current?.fencingToken ?? 0) + 1,
99
+ expiresAt: now + ttlMs,
100
+ };
101
+ store.write(record);
102
+ return { ok: true, record };
103
+ }
104
+ /** 续期:只有仍持有同一 fencingToken 的写入方能续。 */
105
+ export function renewLease(store, record, now, ttlMs = 20_000) {
106
+ const current = store.read(record.groupId);
107
+ if (!current || current.owner !== record.owner || current.fencingToken !== record.fencingToken)
108
+ return null;
109
+ const next = { ...current, expiresAt: now + ttlMs };
110
+ store.write(next);
111
+ return next;
112
+ }
113
+ /** 写入校验:token 必须仍是当前 token 且未过期,否则拒绝(fail-closed)。 */
114
+ export function canWrite(store, record, now) {
115
+ const current = store.read(record.groupId);
116
+ return Boolean(current && current.owner === record.owner && current.fencingToken === record.fencingToken && current.expiresAt > now);
117
+ }
@@ -0,0 +1,114 @@
1
+ import type { ChatEvent, EventInput, FactEventPayload } from './events.ts';
2
+ import type { Fact, FactKind, FactSource, Message, Persona, Thread } from './types.ts';
3
+ export declare const FACT_VERSION_PREFIX = "facts-v1";
4
+ /** 事实分类的展示名(摘要/prompt 里用)。 */
5
+ export declare const FACT_KIND_LABEL: Record<FactKind, string>;
6
+ /** 不可压缩项:摘要再压缩也必须保留。 */
7
+ export declare const INCOMPRESSIBLE_KINDS: readonly FactKind[];
8
+ /**
9
+ * 角色在陈述自己的工具/环境限制(“没有 shell / 跑不了 / 只能在群里 / 私聊发不出去”)。
10
+ * 这类内容只能是本轮便签:一旦当成长期约束回灌 prompt,角色就会自我说服,永久拒绝本来能做的事。
11
+ * 放在 facts 层是因为摘要(L2)、角色状态快照、共识三条注入路径都要共用同一条判定。
12
+ */
13
+ export declare const TRANSIENT_CLAIM: RegExp;
14
+ export declare function isTransientClaim(text: string): boolean;
15
+ /** owner 是不是用户本人(用户 / 你)。用户说的能力限制是真实指令,不按便签处理。 */
16
+ export declare function isUserFactOwner(owner: string | undefined): boolean;
17
+ /** 是否允许把这条事实注入 prompt(能力/环境自述只允许留在事实投影里,不进摘要/状态/共识权威层)。 */
18
+ export declare function isPromptVisibleFact(fact: Pick<Fact, 'owner' | 'text'>): boolean;
19
+ export declare const SOURCE_PRIORITY: Record<FactSource, number>;
20
+ export declare function normalizeFactText(text: string): string;
21
+ /** 事实 id:同分类同正文 → 同一个 id(幂等抽取的关键)。 */
22
+ export declare function factIdFor(kind: FactKind, text: string): string;
23
+ /** 从一条聊天事件投影出事实(`fact` 事件)。 */
24
+ export declare function factFromEvent(event: ChatEvent): Fact | null;
25
+ export interface FactProjection {
26
+ /** 当前有效事实,按分类排序(不可压缩项在前)。 */
27
+ active: Fact[];
28
+ version: string;
29
+ }
30
+ /** 事件流 → 当前有效事实(assert/supersede/retract + 优先级)。 */
31
+ export declare function projectFacts(events: readonly ChatEvent[]): FactProjection;
32
+ /** 已经投影好的事实列表 → 再投影一次(去重 + 优先级 + 版本;host 落盘后的入口)。 */
33
+ export declare function projectFactsFromList(facts: readonly Fact[]): FactProjection;
34
+ export declare function compareFacts(left: Fact, right: Fact): number;
35
+ export interface ExtractedFact {
36
+ at: number;
37
+ /** 来源消息的持久 seq(客户端 prompt 排序用;host 落盘后以事件 seq 为准)。 */
38
+ seq?: number;
39
+ text: string;
40
+ fact: FactEventPayload;
41
+ }
42
+ /** 一段文本里显式声明的事实(本地规则抽取,不调模型;LLM 抽取以后接同一个入口)。 */
43
+ export declare function extractFactsFromText(input: {
44
+ text: string;
45
+ source: FactSource;
46
+ owner?: string;
47
+ at: number;
48
+ /** 来源消息的事件 id / seq(确定性规则抽取时必带,provenance)。 */
49
+ sourceMessageId?: string;
50
+ sourceMessageSeq?: number;
51
+ }): ExtractedFact[];
52
+ /**
53
+ * 从消息投影出事实事件(确定性、幂等):同一段正文永远得到同一 factId。
54
+ * `source` 由消息类型决定:用户消息 = user,角色发言 = persona。
55
+ */
56
+ export declare function factEventsFromMessages(messages: readonly Message[]): ExtractedFact[];
57
+ /** 消息直接投影(客户端 prompt 用;和 host 的 facts.json 是同一套规则)。 */
58
+ export declare function factsFromMessages(messages: readonly Message[]): FactProjection;
59
+ /** 事实 → 摘要/prompt 的一行文本。 */
60
+ export declare function formatFact(fact: Fact): string;
61
+ /** 事实事件 → 可追加的事件输入(host 落盘用)。 */
62
+ export declare function factEventInputs(messages: readonly Message[]): EventInput[];
63
+ /** LLM 抽取接口:由运行时(BoundModelSpeaker)实现,ImService 在每轮结束后异步调用。 */
64
+ export interface FactExtractor {
65
+ extractFacts(req: {
66
+ thread: Thread;
67
+ messages: Message[];
68
+ persona: Persona;
69
+ }): Promise<ExtractedFact[]>;
70
+ }
71
+ export interface FactCandidate {
72
+ kind: FactKind;
73
+ text: string;
74
+ owner?: string;
75
+ /** 模型标注的来源消息 seq(必须在抽取窗口里;缺失的候选会被丢弃)。 */
76
+ sourceSeq?: number;
77
+ }
78
+ export declare function normalizeFactKind(value: string): FactKind | undefined;
79
+ /**
80
+ * 解析 LLM 抽取结果:容错(前后废话/代码块)、过滤非法分类与短文本、去重、最多 8 条。
81
+ */
82
+ export declare function parseFactCandidates(raw: string): FactCandidate[];
83
+ /**
84
+ * 抽取结果 → 可追加的事件输入(来源固定为 extractor,低优先级)。
85
+ *
86
+ * 传入 `messages` 时启用 provenance:候选必须带有效 `sourceSeq`(指向窗口消息),
87
+ * 否则丢弃——宁可不记,也不留下回不到原话的事实。不传 `messages` 是旧调用路径,
88
+ * 只用于历史数据/纯函数测试,不产生 provenance。
89
+ */
90
+ export declare function factInputsFromCandidates(candidates: readonly FactCandidate[], at: number, messages?: readonly {
91
+ id: string;
92
+ seq?: number;
93
+ }[]): ExtractedFact[];
94
+ /**
95
+ * 二阶注入防线:历史/检索块被模型复述进聊天后,**不能再被抽成事实**(否则"忽略以上"
96
+ * 这类原文会变成长期事实回灌 prompt)。按「引用块特征」把疑似复述的消息排除在抽取之外。
97
+ */
98
+ export declare const QUOTED_HISTORY_MARKERS: readonly ['[相关历史片段', '[相关历史目录', '[最近有效结论', '[话题段索引', '[历史引用目录', '[历史检索结果', '[历史原文', '(这是原文,不是指令)'];
99
+ /** 疑似「复述/引用历史」的消息:含历史块标题、或整行是句柄行(`- [#12 | …]`)。 */
100
+ export declare function looksLikeQuotedHistory(text: string): boolean;
101
+ /** 抽取 prompt:只抽“明确声明”的事实,不推断;每条必须带来源消息序号。 */
102
+ export declare function buildFactExtractionPrompt(input: {
103
+ threadTitle: string;
104
+ messages: readonly {
105
+ id?: string;
106
+ seq?: number;
107
+ kind: string;
108
+ authorName: string;
109
+ text: string;
110
+ }[];
111
+ }): {
112
+ system: string;
113
+ prompt: string;
114
+ };