dsh-data-domain-knowledge 0.1.1-alpha.2 → 0.1.1-alpha.3

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 (189) hide show
  1. package/README.md +23 -16
  2. package/lib/client.js +596 -841
  3. package/lib/contract-refs.d.ts +0 -1
  4. package/lib/doc-page.js +7 -7
  5. package/lib/pages.js +928 -1145
  6. package/lib/types/agent-behavior-rules.d.ts.map +1 -1
  7. package/lib/types/agent-behavior-rules.js +1 -2
  8. package/lib/types/agent-behavior-rules.js.map +1 -1
  9. package/lib/types/axis-contract.js +1 -1
  10. package/lib/types/axis-contract.js.map +1 -1
  11. package/lib/types/card-organize.d.ts +2 -1
  12. package/lib/types/card-organize.d.ts.map +1 -1
  13. package/lib/types/card-organize.js +5 -3
  14. package/lib/types/card-organize.js.map +1 -1
  15. package/lib/types/config-schema.d.ts +1 -1
  16. package/lib/types/config-schema.js +1 -1
  17. package/lib/types/convert/host.d.ts +2 -3
  18. package/lib/types/convert/host.d.ts.map +1 -1
  19. package/lib/types/convert/host.js +5 -2
  20. package/lib/types/convert/host.js.map +1 -1
  21. package/lib/types/convert/ingest.d.ts +2 -0
  22. package/lib/types/convert/ingest.d.ts.map +1 -1
  23. package/lib/types/convert/ingest.js +1 -0
  24. package/lib/types/convert/ingest.js.map +1 -1
  25. package/lib/types/diagnosis/types.d.ts +1 -1
  26. package/lib/types/diagnosis/types.js +1 -1
  27. package/lib/types/images.js +1 -1
  28. package/lib/types/index.d.ts +0 -4
  29. package/lib/types/index.d.ts.map +1 -1
  30. package/lib/types/index.js +30 -41
  31. package/lib/types/index.js.map +1 -1
  32. package/lib/types/knowledge-contract.d.ts +6 -0
  33. package/lib/types/knowledge-contract.d.ts.map +1 -1
  34. package/lib/types/knowledge-contract.js +6 -2
  35. package/lib/types/knowledge-contract.js.map +1 -1
  36. package/lib/types/layout.d.ts +9 -26
  37. package/lib/types/layout.d.ts.map +1 -1
  38. package/lib/types/layout.js +10 -28
  39. package/lib/types/layout.js.map +1 -1
  40. package/lib/types/materialize-snapshot.d.ts +5 -0
  41. package/lib/types/materialize-snapshot.d.ts.map +1 -1
  42. package/lib/types/migrate.d.ts +3 -1
  43. package/lib/types/migrate.d.ts.map +1 -1
  44. package/lib/types/migrate.js +3 -1
  45. package/lib/types/migrate.js.map +1 -1
  46. package/lib/types/organize-contract.d.ts.map +1 -1
  47. package/lib/types/organize-contract.js +2 -1
  48. package/lib/types/organize-contract.js.map +1 -1
  49. package/lib/types/pipeline/engine.d.ts +1 -0
  50. package/lib/types/pipeline/engine.d.ts.map +1 -1
  51. package/lib/types/pipeline/engine.js +9 -3
  52. package/lib/types/pipeline/engine.js.map +1 -1
  53. package/lib/types/pipeline/types.d.ts +6 -0
  54. package/lib/types/pipeline/types.d.ts.map +1 -1
  55. package/lib/types/pipeline/types.js.map +1 -1
  56. package/lib/types/present.d.ts +1 -1
  57. package/lib/types/present.js +1 -1
  58. package/lib/types/preset-ids.d.ts +0 -1
  59. package/lib/types/preset-ids.d.ts.map +1 -1
  60. package/lib/types/preset-ids.js +0 -3
  61. package/lib/types/preset-ids.js.map +1 -1
  62. package/lib/types/query-analysis.d.ts +0 -5
  63. package/lib/types/query-analysis.d.ts.map +1 -1
  64. package/lib/types/query-analysis.js +0 -16
  65. package/lib/types/query-analysis.js.map +1 -1
  66. package/lib/types/recall-delivery.d.ts +36 -0
  67. package/lib/types/recall-delivery.d.ts.map +1 -0
  68. package/lib/types/recall-delivery.js +16 -0
  69. package/lib/types/recall-delivery.js.map +1 -0
  70. package/lib/types/runtime.d.ts +26 -12
  71. package/lib/types/runtime.d.ts.map +1 -1
  72. package/lib/types/runtime.js +231 -106
  73. package/lib/types/runtime.js.map +1 -1
  74. package/lib/types/settings-volatile.d.ts +0 -7
  75. package/lib/types/settings-volatile.d.ts.map +1 -1
  76. package/lib/types/settings-volatile.js +0 -7
  77. package/lib/types/settings-volatile.js.map +1 -1
  78. package/lib/types/source-identity.d.ts +3 -0
  79. package/lib/types/source-identity.d.ts.map +1 -0
  80. package/lib/types/source-identity.js +5 -0
  81. package/lib/types/source-identity.js.map +1 -0
  82. package/lib/types/store/axis-references.d.ts.map +1 -1
  83. package/lib/types/store/axis-references.js +5 -3
  84. package/lib/types/store/axis-references.js.map +1 -1
  85. package/lib/types/store/knowledge-db.d.ts +1 -1
  86. package/lib/types/store/knowledge-db.d.ts.map +1 -1
  87. package/lib/types/store/knowledge-db.js +16 -2
  88. package/lib/types/store/knowledge-db.js.map +1 -1
  89. package/lib/types/types.d.ts +5 -4
  90. package/lib/types/types.d.ts.map +1 -1
  91. package/lib/types/types.js +6 -3
  92. package/lib/types/types.js.map +1 -1
  93. package/lib/types/wiki-availability.d.ts +11 -0
  94. package/lib/types/wiki-availability.d.ts.map +1 -0
  95. package/lib/types/wiki-availability.js +39 -0
  96. package/lib/types/wiki-availability.js.map +1 -0
  97. package/lib/types/wiki-finalize.d.ts +4 -2
  98. package/lib/types/wiki-finalize.d.ts.map +1 -1
  99. package/lib/types/wiki-finalize.js +9 -27
  100. package/lib/types/wiki-finalize.js.map +1 -1
  101. package/lib/types/wiki-links.d.ts +35 -0
  102. package/lib/types/wiki-links.d.ts.map +1 -0
  103. package/lib/types/wiki-links.js +129 -0
  104. package/lib/types/wiki-links.js.map +1 -0
  105. package/package.json +16 -16
  106. package/scripts/doctor.mjs +0 -7
  107. package/scripts/setup-embedding.sh +0 -0
  108. package/src/agent-behavior-rules.ts +1 -2
  109. package/src/axis-contract.ts +1 -1
  110. package/src/card-organize.ts +5 -3
  111. package/src/client/AttributionEventGuide.tsx +3 -3
  112. package/src/client/AxisMatrix.tsx +86 -19
  113. package/src/client/DirectoryPicker.tsx +0 -2
  114. package/src/client/GuideArchitectureCanvas.tsx +5 -12
  115. package/src/client/ImportFilesDialog.tsx +1 -0
  116. package/src/client/InfoHint.tsx +1 -1
  117. package/src/client/KnowledgeBaseTab.tsx +113 -39
  118. package/src/client/KnowledgePanel.tsx +16 -9
  119. package/src/client/OperationLogTab.tsx +1 -1
  120. package/src/client/RecallPanel.tsx +5 -16
  121. package/src/client/TabGuide.tsx +3 -7
  122. package/src/client/WikiFlowPanel.tsx +10 -11
  123. package/src/client/arch/NodeLogicPanel.tsx +3 -3
  124. package/src/client/arch/model.ts +5 -113
  125. package/src/client/architecture.css +1 -1
  126. package/src/client/architecture.tsx +13 -27
  127. package/src/client/attribution/AttributionTab.tsx +141 -10
  128. package/src/client/pages.css +2 -2
  129. package/src/client/pages.tsx +4 -11
  130. package/src/client/styles.css +15 -96
  131. package/src/config-schema.ts +1 -1
  132. package/src/convert/host.ts +7 -5
  133. package/src/convert/ingest.ts +3 -0
  134. package/src/diagnosis/types.ts +1 -1
  135. package/src/images.ts +1 -1
  136. package/src/index.ts +27 -49
  137. package/src/knowledge-contract.ts +7 -2
  138. package/src/layout.ts +10 -32
  139. package/src/materialize-snapshot.ts +1 -0
  140. package/src/migrate.ts +3 -1
  141. package/src/organize-contract.ts +2 -1
  142. package/src/pipeline/engine.ts +9 -3
  143. package/src/pipeline/types.ts +2 -0
  144. package/src/present.ts +1 -1
  145. package/src/preset-ids.ts +0 -4
  146. package/src/query-analysis.ts +0 -20
  147. package/src/recall-delivery.ts +19 -0
  148. package/src/runtime.ts +220 -102
  149. package/src/settings-volatile.ts +0 -7
  150. package/src/source-identity.ts +4 -0
  151. package/src/store/axis-references.ts +5 -3
  152. package/src/store/knowledge-db.ts +14 -2
  153. package/src/types.ts +6 -4
  154. package/src/wiki-availability.ts +37 -0
  155. package/src/wiki-finalize.ts +9 -25
  156. package/src/wiki-links.ts +120 -0
  157. package/lib/types/intent/engine.d.ts +0 -122
  158. package/lib/types/intent/engine.d.ts.map +0 -1
  159. package/lib/types/intent/engine.js +0 -488
  160. package/lib/types/intent/engine.js.map +0 -1
  161. package/lib/types/intent/host.d.ts +0 -68
  162. package/lib/types/intent/host.d.ts.map +0 -1
  163. package/lib/types/intent/host.js +0 -249
  164. package/lib/types/intent/host.js.map +0 -1
  165. package/lib/types/intent/scope.d.ts +0 -25
  166. package/lib/types/intent/scope.d.ts.map +0 -1
  167. package/lib/types/intent/scope.js +0 -116
  168. package/lib/types/intent/scope.js.map +0 -1
  169. package/lib/types/intent/store.d.ts +0 -33
  170. package/lib/types/intent/store.d.ts.map +0 -1
  171. package/lib/types/intent/store.js +0 -239
  172. package/lib/types/intent/store.js.map +0 -1
  173. package/lib/types/intent/tools.d.ts +0 -62
  174. package/lib/types/intent/tools.d.ts.map +0 -1
  175. package/lib/types/intent/tools.js +0 -130
  176. package/lib/types/intent/tools.js.map +0 -1
  177. package/lib/types/intent/types.d.ts +0 -170
  178. package/lib/types/intent/types.d.ts.map +0 -1
  179. package/lib/types/intent/types.js +0 -56
  180. package/lib/types/intent/types.js.map +0 -1
  181. package/src/client/IntentLogic.tsx +0 -192
  182. package/src/client/IntentTab.tsx +0 -343
  183. package/src/intent/README.md +0 -42
  184. package/src/intent/engine.ts +0 -515
  185. package/src/intent/host.ts +0 -315
  186. package/src/intent/scope.ts +0 -125
  187. package/src/intent/store.ts +0 -218
  188. package/src/intent/tools.ts +0 -154
  189. package/src/intent/types.ts +0 -229
@@ -1,154 +0,0 @@
1
- /**
2
- * 两个 `intent_*` 工具的**注册器**:与「引擎住在哪个平面」解耦。
3
- *
4
- * ## 为什么要单独一个文件
5
- *
6
- * 工具由 Host 层注册,因此可以被标准模式调用。由于 Host 工具也可能出现在其他 preset
7
- * 中,执行端会检查会话,只接受 `standard`。
8
- *
9
- * @module
10
- */
11
-
12
- import { defineTool, type ToolRunContext } from '@deepseek-ai/dsh-tools'
13
- import { envelopeFailure } from '#contracts'
14
- import type { LineageContext } from '#contracts'
15
- import { isIntentAgentSession } from './scope.js'
16
-
17
- /**
18
- * 注册这两个工具需要引擎提供的能力。
19
- *
20
- * 刻意是**结构化的最小面**而不是 `IntentEngine` 本身:宿主平面通过
21
- * `INTENT_SERVICE` 提供它,注册器只按这个形状使用引擎,不依赖其具体实现位置。
22
- */
23
- export interface IntentToolHost {
24
- /** `intent_record` 的**工具描述就是路由提示词**(0023)。 */
25
- routingPrompt(): string
26
- record(args: Record<string, unknown>, exec?: ToolRunContext): unknown
27
- view(sessionKey: string, includePrompt?: boolean): unknown
28
- }
29
-
30
- /** `intent_record` 的参数表。描述是路由提示词(工具级),所以这里只声明字段。 */
31
- const INTENT_RECORD_PARAMS: Record<string, unknown> = {
32
- user_input: { type: 'string', required: true, description: '本轮用户原文' },
33
- act: { type: 'string', description: '本轮动作 id,取自工具描述里的 act 词表' },
34
- category: { type: 'string', description: '意图分类 id:先按预置分类匹配,命中就直接用它的 id;全不命中才自行新起一个 id 或落 unknown' },
35
- predicate: { type: 'string', description: '要执行的动作,例如 query_babel_data' },
36
- slots: { type: 'json', description: '从用户输入抽取的关键参数' },
37
- confidence: { type: 'number', description: '0-1,用于标注 lowConfidence' },
38
- refs: { type: 'array', description: '引用对象,例如 { id, kind, label }' },
39
- relation: { type: 'string', enum: ['new_task', 'subtask_of'], description: '本轮是新任务还是已有任务的子任务' },
40
- turn_id: { type: 'string', description: '当前对话轮次 id;不传则由 Host 生成' },
41
- task_id: { type: 'string', description: 'relation=subtask_of 时指向的已有业务任务 id;新任务不传' },
42
- subtask_id: { type: 'string', description: '已有子任务 id;新子任务不传,由 Host 生成' },
43
- parent_subtask_id: { type: 'string', description: '父任务节点 id;通常由 Host 生成' },
44
- run_id: { type: 'string', description: '已有执行尝试 id;重试时传新值' },
45
- trace_id: { type: 'string' },
46
- domain: { type: 'string' },
47
- }
48
-
49
- /** 工具的最小注册面。测试替身与真实 `ctx` 都满足它。 */
50
- export interface ToolRegistryLike {
51
- register(definition: unknown): unknown
52
- }
53
-
54
- export function jsonTool(name: string, description: string, parameters: Record<string, unknown>, execute: (args: any, exec?: ToolRunContext) => unknown) {
55
- return defineTool({
56
- name, description, parameters: parameters as any,
57
- output: { schema: { type: 'json' }, render: (_args: unknown, value: unknown) => [{ type: 'text' as const, text: JSON.stringify(value) }] },
58
- execute: async (args: any, exec: ToolRunContext) => execute(args, exec),
59
- } as any)
60
- }
61
-
62
- export function lineageOf(args: Record<string, unknown>, exec?: ToolRunContext): Partial<LineageContext> | undefined {
63
- const lineage: Partial<LineageContext> = {}
64
- // Session identity is execution context, never model-controlled input.
65
- const sessionId = exec?.agent?.session?.header?.id
66
- if (sessionId) lineage.sessionId = sessionId
67
- const fields: Array<[keyof LineageContext, string]> = [
68
- ['turnId', 'turn_id'], ['taskId', 'task_id'], ['subtaskId', 'subtask_id'],
69
- ['parentSubtaskId', 'parent_subtask_id'], ['runId', 'run_id'], ['traceId', 'trace_id'], ['domain', 'domain'],
70
- ]
71
- for (const [target, source] of fields) if (typeof args[source] === 'string' && args[source].trim()) lineage[target] = args[source].trim()
72
- return Object.keys(lineage).length > 0 ? lineage : undefined
73
- }
74
-
75
- export function sessionKeyOf(exec?: ToolRunContext): string | undefined {
76
- const sessionId = exec?.agent?.session?.header?.id
77
- return typeof sessionId === 'string' && sessionId.trim() ? sessionId.trim() : undefined
78
- }
79
-
80
- /**
81
- * 这个会话是不是**子代理**。
82
- *
83
- * 子代理会加入父会话的组合,所以它会继承到 `intent_*` 两个工具。而意图记录描述的是
84
- * 「用户在跟 Agent 要什么」:子代理做的是被拆出来的一个片段,它记一条只会污染任务树。
85
- *
86
- * 这条规矩原来写在 preset 的 delegation 行上(`toolFilter: { deny: [...] }`)。DSH 0.1.8
87
- * 起 `toolFilter`(与 `persona`)**不再被 `dsh-tool-subagent` 接受** —— 带上它的 preset
88
- * 直接挂载失败,整个组合都不会生效。平台给的替代是「在 Agent Preset 里配好工具,再用
89
- * `agentPreset` 选中它」,而那**只对 spawn provider 有效**:fork / codex / claude-code
90
- * 的子会话按定义继承父会话的组合,没有选择余地(`inheritsParentContext` 直接拒绝)。
91
- *
92
- * 所以判据搬进工具本身:看会话头,与「谁把子会话拉起来的」无关。四个 provider 一视同仁,
93
- * 也不会再出现「新增一个 delegation 行忘了 deny」这种漏法。
94
- *
95
- * 判据取两个字段:`origin === 'subagent'` 是产品分类,`delegationDepth > 0` 是递归深度
96
- * (持久化过,重启后仍然成立)。任一条成立就算子会话。
97
- */
98
- export function isSubagentSession(exec?: ToolRunContext): boolean {
99
- const header = exec?.agent?.session?.header
100
- if (!header) return false
101
- if (header.origin === 'subagent') return true
102
- return typeof header.delegationDepth === 'number' && header.delegationDepth > 0
103
- }
104
-
105
- /** 子代理调这两个工具时统一回这一条:说清为什么,并给出该走的路。 */
106
- function subagentRefusal(): unknown {
107
- return envelopeFailure({ sessionKey: null }, {
108
- code: 'SUBAGENT_NOT_RECORDED',
109
- message: '子代理不记录意图:意图描述的是用户与主 Agent 的交互。把要记的内容写进返回结果,由主 Agent 记录。',
110
- retryable: false,
111
- })
112
- }
113
-
114
- /**
115
- * 注册两个 `intent_*` 工具,返回一个把两者一起撤掉的 disposer。
116
- *
117
- * `intent_record` 的描述来自固定的会话审计契约,不依赖设置或注册表。
118
- *
119
- * 类型守卫(`typeof disposer === 'function'`)是因为测试替身的 `register` 不一定
120
- * 返回 disposer。
121
- */
122
- export function registerIntentTools(ctx: { tools: ToolRegistryLike }, host: IntentToolHost): () => void {
123
- const disposeRecord: unknown = ctx.tools.register(jsonTool('intent_record', host.routingPrompt(), INTENT_RECORD_PARAMS, (args, exec) => (
124
- isSubagentSession(exec) ? subagentRefusal() : host.record(args, exec)
125
- )))
126
- const disposeView: unknown = ctx.tools.register(jsonTool(
127
- 'intent_store_view', 'View recent intent records and active task ids for the current session. Only standard sessions can use this tool.',
128
- { include_prompt: { type: 'boolean' } },
129
- (args: { include_prompt?: boolean }, exec) => {
130
- if (isSubagentSession(exec)) return subagentRefusal()
131
- const session = exec?.agent?.session
132
- if (session && !isIntentAgentSession(session)) {
133
- return envelopeFailure({ sessionKey: null }, {
134
- code: 'INTENT_PRESET_UNSUPPORTED',
135
- message: '意图记录只支持标准模式。',
136
- retryable: false,
137
- })
138
- }
139
- const sessionKey = sessionKeyOf(exec)
140
- if (!sessionKey) {
141
- return envelopeFailure({ sessionKey: null }, {
142
- code: 'SESSION_CONTEXT_REQUIRED',
143
- message: '意图记录只能在有活动 DSH 会话的上下文中读取。',
144
- retryable: false,
145
- })
146
- }
147
- return host.view(sessionKey, args.include_prompt)
148
- },
149
- ))
150
- return () => {
151
- if (typeof disposeRecord === 'function') (disposeRecord as () => void)()
152
- if (typeof disposeView === 'function') (disposeView as () => void)()
153
- }
154
- }
@@ -1,229 +0,0 @@
1
- import type { ToolStatus } from '#contracts'
2
- import type { LineageContext } from '#contracts'
3
-
4
- export type { ToolStatus }
5
-
6
- /**
7
- * 一个动作类型(act)。
8
- *
9
- * act 回答"这一轮用户在**做什么**",与 category(做什么**业务**)正交:同一句
10
- * "帮我看下上个月的 GMV" 是 `query` × `data_analysis`。光有 id 时模型只能猜
11
- * `query` 和 `request` 的区别,所以每一类都带 label 与 description。
12
- */
13
- export interface IntentActDef {
14
- id: string
15
- label: string
16
- description: string
17
- enabled: boolean
18
- }
19
-
20
- /**
21
- * 内置 act 词表。它是会话审计的固定提示,不是知识召回配置,也不提供编辑入口。
22
- */
23
- export const DEFAULT_ACTS: IntentActDef[] = [
24
- { id: 'query', label: '查询', description: '向数据或知识提问,要一个答案或一批结果。', enabled: true },
25
- { id: 'request', label: '执行请求', description: '让 Agent 做一件事并产生副作用:写入、发送、导出、修改。', enabled: true },
26
- { id: 'inform', label: '补充信息', description: '用户提供事实、参数或上下文,本身不要求动作。', enabled: true },
27
- { id: 'confirm', label: '确认', description: '用户认可某个提议或方案,允许继续。', enabled: true },
28
- { id: 'select', label: '选择', description: '在多个候选中指定一个。', enabled: true },
29
- { id: 'correct', label: '纠正', description: '指出前面的理解或结果不对,要求改。', enabled: true },
30
- { id: 'cancel', label: '取消', description: '终止或撤回正在进行的任务。', enabled: true },
31
- { id: 'review', label: '审阅', description: '对已产出的内容做检查、评估与把关。', enabled: true },
32
- { id: 'explain', label: '解释', description: '要求讲清原理、口径或原因,而不是要新数据。', enabled: true },
33
- { id: 'compare', label: '对比', description: '把两个及以上对象放在一起比较差异。', enabled: true },
34
- { id: 'recommend', label: '推荐', description: '要建议与取舍意见。', enabled: true },
35
- { id: 'resume', label: '继续', description: '回到之前中断的任务继续做。', enabled: true },
36
- { id: 'reject', label: '拒绝', description: '不接受某个提议或结果。', enabled: true },
37
- { id: 'greet', label: '问候', description: '打招呼、开场。', enabled: true },
38
- { id: 'chat', label: '闲聊', description: '非任务性的对话。', enabled: true },
39
- { id: 'unknown', label: '未判定', description: '无法归入以上任何一类,或本轮信息不足以判断。', enabled: true },
40
- ]
41
-
42
- /** Free-form act id; validated against the fixed audit vocabulary when possible. */
43
- export type IntentAct = string
44
-
45
- /** How one turn relates to the session's existing tasks. */
46
- export type IntentRelation = 'new_task' | 'subtask_of' | 'unknown'
47
-
48
- /** `model` is a model-authored record; `fallback` is the Host's data-turn backfill. */
49
- export type IntentSource = 'model' | 'fallback'
50
-
51
- export interface IntentSlotMap {
52
- [name: string]: unknown
53
- }
54
-
55
- export interface IntentRef {
56
- id: string
57
- kind?: string
58
- label?: string
59
- }
60
-
61
- /**
62
- * One built-in intent category; `route` names the act it usually maps to.
63
- *
64
- * 固定分类的作用是**把模型的自由判断收窄成一次匹配**:
65
- * {@link description} 说明这一类"是什么",{@link examples} 给出用户可能怎么说。
66
- * 两者都会被拼进固定的 routing prompt,模型先按它们匹配,命中就直接用该 id。
67
- */
68
- export interface IntentCategory {
69
- id: string
70
- label: string
71
- route: string
72
- description: string
73
- /**
74
- * 预置说法(few-shot):用户可能怎么表达这一类意图,每行一条。
75
- *
76
- * 固定词表中的 few-shot 说法。
77
- */
78
- examples?: string[]
79
- enabled: boolean
80
- }
81
-
82
- /**
83
- * Recorder settings. 只有审计运行参数保留为内部默认值;分类词表属于固定契约,
84
- * 不再作为用户配置暴露。
85
- */
86
- export interface IntentSettings {
87
- /** Below this confidence a record is annotated lowConfidence; the model decides whether to clarify. */
88
- clarifyThreshold: number
89
- ttlSeconds: number
90
- /**
91
- * 0023:路由提示词**没有开关**。它随 `intent_record` 的工具描述一起下发,
92
- * 分类规则必须始终在场——否则模型退化成每轮从零判断。
93
- */
94
- /** Backfill one `unknown` record when an eligible data turn ends without a model record. */
95
- fallbackEnabled: boolean
96
- }
97
-
98
- function category(id: string, label: string, route: string, description: string, examples: string[]): IntentCategory & { examples: string[] } {
99
- return { id, label, route, description, examples, enabled: true }
100
- }
101
-
102
- /**
103
- * 出厂预置的意图分类。
104
- *
105
- * 每一项都**必须**带 `description` 与 `examples`:只给标签("数据分析")时模型
106
- * 只能靠猜,同一句话在不同轮次会被分到不同类。这些文案是模型的匹配依据,全部
107
- * 词表随代码发布,不通过知识库配置或 UI 修改。
108
- */
109
- export const DEFAULT_CATEGORIES: Array<IntentCategory & { examples: string[] }> = [
110
- category('data_analysis', '数据分析', 'query', '取数、算指标、拆口径的请求:给一个数或一段分析结论。', ['帮我算一下上个月的 GMV', '这个指标怎么拆', '跑个数看看环比']),
111
- category('metadata_exploration', '元数据探索', 'query', '问"有哪些表/字段/口径"本身,要的是结构而不是数字。', ['这张表有哪些字段', '库里有几张订单表', '这些指标的口径是怎么定义的']),
112
- category('data_validation', '数据校验', 'query', '核对数据是否可信:对不上、空值、重复、异常波动。', ['这两个数对不上,查一下', '帮我看下这列有没有重复', '空值率是不是偏高了']),
113
- category('knowledge_consultation', '知识咨询', 'query', '问组织既有的结论、规则、流程或负责人,答案在知识库里。', ['我们去年是怎么定这个口径的', '知识库里有没有相关文档', '这个流程找谁确认']),
114
- category('knowledge_building', '知识构建', 'request', '把材料沉淀进知识库:录入来源、写卡片、重建索引。', ['把这份文档存进知识库', '记一条:这个口径改成…', '帮我整理成一张知识卡片']),
115
- category('document_research', '文档研究', 'query', '对一份或多份长文档做通读、归纳、对比、找证据。', ['把这份 PRD 读一遍,总结需求点', '这几篇文档有没有冲突', '从报告里找出支持这个结论的证据']),
116
- category('message_collaboration', '消息协作', 'request', '替用户发消息、同步进度、在群里通知或拉人。', ['发条消息给张三', '在群里同步一下进度', '@一下负责人催确认']),
117
- category('artifact_delivery', '产物交付', 'request', '要一个可交付的文件:表格、报告、周报、导出件。', ['导出一份 Excel', '生成这周的周报', '把结果做成表格发我']),
118
- category('agent_engineering', 'Agent 工程', 'request', '改 Agent 自身:加工具、调提示词、改 skill、查它为什么这么答。', ['加一个工具', '这个 skill 怎么改', '它刚才为什么没调那个工具']),
119
- category('tooling_operations', '工具运维', 'request', '运维动作:重启、看队列、清缓存、处理环境报错。', ['重启一下服务', '看看任务队列', '这个报错怎么修']),
120
- category('personal_assistant', '个人助理', 'request', '个人日程与提醒类事务。', ['明天提醒我开会', '帮我约个会', '看下我今天的日程']),
121
- category('conversation', '普通对话', 'chat', '寒暄、闲聊、对 Agent 本身的提问,没有数据或交付目标。', ['你好', '你是谁', '谢谢,先这样']),
122
- ]
123
-
124
- export const DEFAULT_PREDICATES: string[] = [
125
- 'query_babel_data', 'query_knowledge', 'query_source_truth', 'query_metadata',
126
- 'query_graph', 'add_source', 'propose_wiki_cards', 'rebuild_knowledge',
127
- 'send_message', 'export_artifact', 'unknown',
128
- ]
129
-
130
- export const DEFAULT_INTENT_SETTINGS: IntentSettings = {
131
- clarifyThreshold: 0.65,
132
- ttlSeconds: 600,
133
- fallbackEnabled: true,
134
- }
135
-
136
- /** One recorded intent. The record is an audit fact; it never drives control flow. */
137
- export interface IntentRecord {
138
- id: string
139
- sessionKey: string
140
- /** `sessionKey#turn` — the upsert key that keeps one record per turn. */
141
- turnKey: string
142
- turnId: string
143
- userInput: string
144
- act: IntentAct
145
- category?: string
146
- predicate?: string
147
- slots: IntentSlotMap
148
- confidence?: number
149
- lowConfidence?: boolean
150
- refs: IntentRef[]
151
- relation: IntentRelation
152
- source: IntentSource
153
- createdAt: string
154
- updatedAt: string
155
- lineage: LineageContext
156
- meta: Record<string, unknown>
157
- }
158
-
159
- export interface IntentRecordInput {
160
- userInput: string
161
- act?: string
162
- category?: string
163
- predicate?: string
164
- slots?: IntentSlotMap
165
- confidence?: number
166
- refs?: IntentRef[]
167
- relation?: IntentRelation
168
- sessionKey: string
169
- turnId?: string
170
- lineage?: Partial<LineageContext>
171
- now?: number
172
- }
173
-
174
- /** Compact task context returned to the model so it can pick the next relation. */
175
- export interface IntentTaskSummary {
176
- taskId: string
177
- lastSubtaskId?: string
178
- category?: string
179
- ageSeconds: number
180
- }
181
-
182
- export interface IntentStoreView {
183
- sessionKey: string
184
- activeTaskId?: string
185
- activeIntentId?: string
186
- tasks: IntentTaskSummary[]
187
- recent: IntentRecord[]
188
- expiresAt?: string
189
- }
190
-
191
- export interface IntentResultData {
192
- intentId?: string
193
- taskId?: string
194
- subtaskId?: string
195
- parentSubtaskId?: string
196
- runId?: string
197
- turnId?: string
198
- act?: string
199
- category?: string
200
- relation?: IntentRelation
201
- source?: IntentSource
202
- lowConfidence?: boolean
203
- activeTasks?: IntentTaskSummary[]
204
- store?: IntentStoreView
205
- prompt?: string
206
- /** True when the scoped tool call was intentionally ignored as a non-data turn. */
207
- skipped?: boolean
208
- skipReason?: 'non_data_agent' | 'unsupported_preset' | 'non_data_turn'
209
- }
210
-
211
- export interface IntentResult {
212
- ok: boolean
213
- status: ToolStatus
214
- data: IntentResultData
215
- warnings: string[]
216
- }
217
-
218
- /** Live turn state: the provisional ids allocated before the model records. */
219
- export interface IntentTurnState {
220
- turn: number
221
- userInput: string
222
- subtaskId: string
223
- taskId?: string
224
- /** The turn entered the data intent scope through text, payload or a data tool. */
225
- eligible: boolean
226
- /** A data tool ran during this turn; a later chat classification cannot revoke it. */
227
- dataToolUsed: boolean
228
- committed: boolean
229
- }