dsh-data-domain-knowledge 0.1.0-alpha.1

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 (231) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +360 -0
  3. package/cordis.patch.yml +410 -0
  4. package/eval/README.md +76 -0
  5. package/eval/evaluate-retrieval.mjs +121 -0
  6. package/eval/queries.example.jsonl +2 -0
  7. package/lib/client.js +111415 -0
  8. package/lib/types/config-schema.d.ts +35 -0
  9. package/lib/types/config-schema.d.ts.map +1 -0
  10. package/lib/types/config-schema.js +34 -0
  11. package/lib/types/config-schema.js.map +1 -0
  12. package/lib/types/convert/core-loader.d.ts +32 -0
  13. package/lib/types/convert/core-loader.d.ts.map +1 -0
  14. package/lib/types/convert/core-loader.js +60 -0
  15. package/lib/types/convert/core-loader.js.map +1 -0
  16. package/lib/types/convert/host.d.ts +88 -0
  17. package/lib/types/convert/host.d.ts.map +1 -0
  18. package/lib/types/convert/host.js +479 -0
  19. package/lib/types/convert/host.js.map +1 -0
  20. package/lib/types/convert/ingest.d.ts +125 -0
  21. package/lib/types/convert/ingest.d.ts.map +1 -0
  22. package/lib/types/convert/ingest.js +228 -0
  23. package/lib/types/convert/ingest.js.map +1 -0
  24. package/lib/types/convert/settings-schema.d.ts +18 -0
  25. package/lib/types/convert/settings-schema.d.ts.map +1 -0
  26. package/lib/types/convert/settings-schema.js +26 -0
  27. package/lib/types/convert/settings-schema.js.map +1 -0
  28. package/lib/types/convert/types.d.ts +46 -0
  29. package/lib/types/convert/types.d.ts.map +1 -0
  30. package/lib/types/convert/types.js +41 -0
  31. package/lib/types/convert/types.js.map +1 -0
  32. package/lib/types/diagnosis/cards.d.ts +71 -0
  33. package/lib/types/diagnosis/cards.d.ts.map +1 -0
  34. package/lib/types/diagnosis/cards.js +482 -0
  35. package/lib/types/diagnosis/cards.js.map +1 -0
  36. package/lib/types/diagnosis/problem-classes.d.ts +51 -0
  37. package/lib/types/diagnosis/problem-classes.d.ts.map +1 -0
  38. package/lib/types/diagnosis/problem-classes.js +66 -0
  39. package/lib/types/diagnosis/problem-classes.js.map +1 -0
  40. package/lib/types/diagnosis/schema.d.ts +65 -0
  41. package/lib/types/diagnosis/schema.d.ts.map +1 -0
  42. package/lib/types/diagnosis/schema.js +208 -0
  43. package/lib/types/diagnosis/schema.js.map +1 -0
  44. package/lib/types/diagnosis/seed-source.d.ts +20 -0
  45. package/lib/types/diagnosis/seed-source.d.ts.map +1 -0
  46. package/lib/types/diagnosis/seed-source.js +96 -0
  47. package/lib/types/diagnosis/seed-source.js.map +1 -0
  48. package/lib/types/diagnosis/seed.d.ts +50 -0
  49. package/lib/types/diagnosis/seed.d.ts.map +1 -0
  50. package/lib/types/diagnosis/seed.js +242 -0
  51. package/lib/types/diagnosis/seed.js.map +1 -0
  52. package/lib/types/diagnosis/store.d.ts +81 -0
  53. package/lib/types/diagnosis/store.d.ts.map +1 -0
  54. package/lib/types/diagnosis/store.js +409 -0
  55. package/lib/types/diagnosis/store.js.map +1 -0
  56. package/lib/types/diagnosis/types.d.ts +124 -0
  57. package/lib/types/diagnosis/types.d.ts.map +1 -0
  58. package/lib/types/diagnosis/types.js +13 -0
  59. package/lib/types/diagnosis/types.js.map +1 -0
  60. package/lib/types/directory-picker.d.ts +94 -0
  61. package/lib/types/directory-picker.d.ts.map +1 -0
  62. package/lib/types/directory-picker.js +110 -0
  63. package/lib/types/directory-picker.js.map +1 -0
  64. package/lib/types/extract-model.d.ts +76 -0
  65. package/lib/types/extract-model.d.ts.map +1 -0
  66. package/lib/types/extract-model.js +193 -0
  67. package/lib/types/extract-model.js.map +1 -0
  68. package/lib/types/extract.d.ts +121 -0
  69. package/lib/types/extract.d.ts.map +1 -0
  70. package/lib/types/extract.js +549 -0
  71. package/lib/types/extract.js.map +1 -0
  72. package/lib/types/fts.d.ts +96 -0
  73. package/lib/types/fts.d.ts.map +1 -0
  74. package/lib/types/fts.js +184 -0
  75. package/lib/types/fts.js.map +1 -0
  76. package/lib/types/index.d.ts +39 -0
  77. package/lib/types/index.d.ts.map +1 -0
  78. package/lib/types/index.js +1112 -0
  79. package/lib/types/index.js.map +1 -0
  80. package/lib/types/intent/engine.d.ts +108 -0
  81. package/lib/types/intent/engine.d.ts.map +1 -0
  82. package/lib/types/intent/engine.js +501 -0
  83. package/lib/types/intent/engine.js.map +1 -0
  84. package/lib/types/intent/host.d.ts +88 -0
  85. package/lib/types/intent/host.d.ts.map +1 -0
  86. package/lib/types/intent/host.js +389 -0
  87. package/lib/types/intent/host.js.map +1 -0
  88. package/lib/types/intent/preset-tools.d.ts +37 -0
  89. package/lib/types/intent/preset-tools.d.ts.map +1 -0
  90. package/lib/types/intent/preset-tools.js +45 -0
  91. package/lib/types/intent/preset-tools.js.map +1 -0
  92. package/lib/types/intent/settings-schema.d.ts +59 -0
  93. package/lib/types/intent/settings-schema.d.ts.map +1 -0
  94. package/lib/types/intent/settings-schema.js +57 -0
  95. package/lib/types/intent/settings-schema.js.map +1 -0
  96. package/lib/types/intent/store.d.ts +75 -0
  97. package/lib/types/intent/store.d.ts.map +1 -0
  98. package/lib/types/intent/store.js +139 -0
  99. package/lib/types/intent/store.js.map +1 -0
  100. package/lib/types/intent/tools.d.ts +63 -0
  101. package/lib/types/intent/tools.d.ts.map +1 -0
  102. package/lib/types/intent/tools.js +108 -0
  103. package/lib/types/intent/tools.js.map +1 -0
  104. package/lib/types/intent/types.d.ts +189 -0
  105. package/lib/types/intent/types.d.ts.map +1 -0
  106. package/lib/types/intent/types.js +62 -0
  107. package/lib/types/intent/types.js.map +1 -0
  108. package/lib/types/knowledge-bases.d.ts +266 -0
  109. package/lib/types/knowledge-bases.d.ts.map +1 -0
  110. package/lib/types/knowledge-bases.js +1107 -0
  111. package/lib/types/knowledge-bases.js.map +1 -0
  112. package/lib/types/layout.d.ts +262 -0
  113. package/lib/types/layout.d.ts.map +1 -0
  114. package/lib/types/layout.js +312 -0
  115. package/lib/types/layout.js.map +1 -0
  116. package/lib/types/migrate.d.ts +110 -0
  117. package/lib/types/migrate.d.ts.map +1 -0
  118. package/lib/types/migrate.js +280 -0
  119. package/lib/types/migrate.js.map +1 -0
  120. package/lib/types/recall-rank.d.ts +158 -0
  121. package/lib/types/recall-rank.d.ts.map +1 -0
  122. package/lib/types/recall-rank.js +261 -0
  123. package/lib/types/recall-rank.js.map +1 -0
  124. package/lib/types/runtime.d.ts +568 -0
  125. package/lib/types/runtime.d.ts.map +1 -0
  126. package/lib/types/runtime.js +3045 -0
  127. package/lib/types/runtime.js.map +1 -0
  128. package/lib/types/settings-schema.d.ts +117 -0
  129. package/lib/types/settings-schema.d.ts.map +1 -0
  130. package/lib/types/settings-schema.js +92 -0
  131. package/lib/types/settings-schema.js.map +1 -0
  132. package/lib/types/settings-volatile.d.ts +102 -0
  133. package/lib/types/settings-volatile.d.ts.map +1 -0
  134. package/lib/types/settings-volatile.js +114 -0
  135. package/lib/types/settings-volatile.js.map +1 -0
  136. package/lib/types/types.d.ts +799 -0
  137. package/lib/types/types.d.ts.map +1 -0
  138. package/lib/types/types.js +387 -0
  139. package/lib/types/types.js.map +1 -0
  140. package/lib/types/wiki-types.d.ts +68 -0
  141. package/lib/types/wiki-types.d.ts.map +1 -0
  142. package/lib/types/wiki-types.js +322 -0
  143. package/lib/types/wiki-types.js.map +1 -0
  144. package/package.json +101 -0
  145. package/preset/tita-data-agent/agent.cordis.yml +376 -0
  146. package/preset/tita-data-agent/preset.yml +3 -0
  147. package/python/requirements.txt +8 -0
  148. package/scripts/doctor.mjs +70 -0
  149. package/scripts/e2e-pipeline.mjs +355 -0
  150. package/scripts/install-agent-preset.mjs +92 -0
  151. package/scripts/setup-embedding.sh +34 -0
  152. package/scripts/sync-agent-preset.mjs +188 -0
  153. package/src/client/AgentPresetCard.tsx +247 -0
  154. package/src/client/DirectoryPicker.tsx +357 -0
  155. package/src/client/InfoHint.tsx +65 -0
  156. package/src/client/IntentLogicTab.tsx +185 -0
  157. package/src/client/IntentTab.tsx +715 -0
  158. package/src/client/KnowledgeBaseTab.tsx +1454 -0
  159. package/src/client/KnowledgeGraphView.tsx +306 -0
  160. package/src/client/KnowledgePanel.tsx +381 -0
  161. package/src/client/KnowledgeStepRail.tsx +60 -0
  162. package/src/client/NodeSettings.tsx +392 -0
  163. package/src/client/PreviewSections.tsx +116 -0
  164. package/src/client/RecallPanel.tsx +399 -0
  165. package/src/client/TypeDefinitionDrawer.tsx +215 -0
  166. package/src/client/WikiFlowCard.tsx +226 -0
  167. package/src/client/WikiTypeEditor.tsx +332 -0
  168. package/src/client/agent-preset.ts +121 -0
  169. package/src/client/arch/AgentArchitectureGraph.tsx +219 -0
  170. package/src/client/arch/NodeLogicPanel.tsx +133 -0
  171. package/src/client/arch/ProblemDetailPanel.tsx +88 -0
  172. package/src/client/arch/model.ts +691 -0
  173. package/src/client/architecture.css +191 -0
  174. package/src/client/architecture.tsx +530 -0
  175. package/src/client/attribution/AttributionGraph.tsx +104 -0
  176. package/src/client/attribution/AttributionTab.tsx +332 -0
  177. package/src/client/attribution/CaseView.tsx +102 -0
  178. package/src/client/attribution/GraphStage.tsx +87 -0
  179. package/src/client/attribution/RunView.tsx +184 -0
  180. package/src/client/attribution/StageChrome.tsx +403 -0
  181. package/src/client/attribution/ViewSwitch.tsx +107 -0
  182. package/src/client/attribution/graph-options.ts +381 -0
  183. package/src/client/attribution/model.ts +462 -0
  184. package/src/client/config-scope.ts +119 -0
  185. package/src/client/convert/ConvertPanel.tsx +594 -0
  186. package/src/client/convert/styles.css +138 -0
  187. package/src/client/convert/styles.ts +49 -0
  188. package/src/client/format.ts +39 -0
  189. package/src/client/graph/layout.ts +181 -0
  190. package/src/client/graph.css +113 -0
  191. package/src/client/index.ts +98 -0
  192. package/src/client/problem-domains.ts +114 -0
  193. package/src/client/styles.css +940 -0
  194. package/src/client/styles.ts +11 -0
  195. package/src/client/useFitScale.ts +68 -0
  196. package/src/config-schema.ts +45 -0
  197. package/src/convert/core-loader.ts +68 -0
  198. package/src/convert/host.ts +579 -0
  199. package/src/convert/ingest.ts +367 -0
  200. package/src/convert/settings-schema.ts +27 -0
  201. package/src/convert/types.ts +65 -0
  202. package/src/diagnosis/cards.ts +498 -0
  203. package/src/diagnosis/problem-classes.ts +117 -0
  204. package/src/diagnosis/schema.ts +260 -0
  205. package/src/diagnosis/seed-source.ts +107 -0
  206. package/src/diagnosis/seed.ts +291 -0
  207. package/src/diagnosis/store.ts +432 -0
  208. package/src/diagnosis/types.ts +152 -0
  209. package/src/directory-picker.ts +164 -0
  210. package/src/extract-model.ts +227 -0
  211. package/src/extract.ts +632 -0
  212. package/src/fts.ts +203 -0
  213. package/src/index.ts +1091 -0
  214. package/src/intent/README.md +63 -0
  215. package/src/intent/engine.ts +527 -0
  216. package/src/intent/host.ts +462 -0
  217. package/src/intent/preset-tools.ts +48 -0
  218. package/src/intent/settings-schema.ts +63 -0
  219. package/src/intent/store.ts +143 -0
  220. package/src/intent/tools.ts +139 -0
  221. package/src/intent/types.ts +245 -0
  222. package/src/knowledge-bases.ts +1160 -0
  223. package/src/layout.ts +350 -0
  224. package/src/migrate.ts +262 -0
  225. package/src/python/embedding_worker.py +471 -0
  226. package/src/recall-rank.ts +299 -0
  227. package/src/runtime.ts +3069 -0
  228. package/src/settings-schema.ts +94 -0
  229. package/src/settings-volatile.ts +122 -0
  230. package/src/types.ts +1140 -0
  231. package/src/wiki-types.ts +357 -0
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The plugins ship plain CSS (no CSS modules), so a style key is simply its
3
+ * `tita-` class. The proxy keeps `styles.foo` / `styles[`foo${Tone}`]` readable
4
+ * at the call site without a hand-maintained lookup table.
5
+ */
6
+ export const styles: Record<string, string> = new Proxy({}, { get: (_target, key) => `tita-${String(key)}` })
7
+
8
+ /** `blue` → `Blue`, used to build tone-suffixed class names. */
9
+ export function toneSuffix(tone: string): string {
10
+ return `${tone[0]!.toUpperCase()}${tone.slice(1)}`
11
+ }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * 画布的「适应宽度 / 1:1」两档缩放。
3
+ *
4
+ * **为什么不用 G6 的 `fitView` / `zoomTo`**:这版 G6(5.1.1)对 HTML 节点算不出内容
5
+ * 包围盒,两个 API 都实测无效 —— 画布按 0.45 定了尺寸,内容仍按 1:1 画出去被裁掉。
6
+ * 所以做法是:**画布永远按设计尺寸渲染,再缩整块板**。比例是我们算出来的,
7
+ * 不依赖 G6 对内容边界的判断;命中判定不受影响(g 用元素的 bounding rect 反算坐标,
8
+ * 均匀缩放对它透明,点选已在浏览器里验证过)。
9
+ *
10
+ * 两个画布(Agent 概览的架构图、知识库的知识图谱)都用它 —— 两处各写一份,
11
+ * 迟早会出现「一张图能适应、另一张不能」。
12
+ */
13
+
14
+ import { useEffect, useState, type RefObject } from 'react'
15
+
16
+ /** 窄栏下的两档。`fit` = 整图缩到容器,`actual` = 1:1(滚动查看)。 */
17
+ export type ZoomMode = 'fit' | 'actual'
18
+
19
+ export interface FitScale {
20
+ scale: number
21
+ /** 缩放后的板高;容器高度就用它(`fit` 档下正好没有可滚的余量)。 */
22
+ boardH: number
23
+ }
24
+
25
+ /**
26
+ * `scroller` 由调用方持有并挂到滚动容器上 —— 组件自己拥有它的 DOM,
27
+ * 这里只负责量。
28
+ *
29
+ * @param contentW 设计宽度
30
+ * @param contentH 设计高度
31
+ * @param enabled 容器不可见时不要量(隐藏容器尺寸为 0,算出来的比例是 0)
32
+ * @param fullscreen 全屏时两个方向都按容器算;窄栏只有宽度可用
33
+ * @param mode 缩放档
34
+ */
35
+ export function useFitScale(
36
+ scroller: RefObject<HTMLDivElement | null>,
37
+ contentW: number,
38
+ contentH: number,
39
+ enabled: boolean,
40
+ fullscreen: boolean,
41
+ mode: ZoomMode,
42
+ ): FitScale {
43
+ /**
44
+ * 可视尺寸。用 `offsetWidth/Height` 而不是 `clientWidth/clientHeight`:后者会随
45
+ * 滚动条的有无变化,而板高又由缩放比算出来 —— 那是一条会自己来回抖的回路。
46
+ */
47
+ const [viewport, setViewport] = useState({ w: 0, h: 0 })
48
+
49
+ useEffect(() => {
50
+ const el = scroller.current
51
+ if (!el || !enabled) return undefined
52
+ const update = (): void => setViewport(prev => {
53
+ const next = { w: el.offsetWidth, h: el.offsetHeight }
54
+ return prev.w === next.w && prev.h === next.h ? prev : next
55
+ })
56
+ update()
57
+ const ro = new ResizeObserver(update)
58
+ ro.observe(el)
59
+ return () => ro.disconnect()
60
+ }, [enabled, fullscreen])
61
+
62
+ // 窄栏只有宽度是可用的:高度由板高自己决定,拿它去算比例就成了一条回路,
63
+ // 所以那里高度按设计高度算(即「只按宽度适应」)。
64
+ const availW = viewport.w || contentW
65
+ const availH = fullscreen ? (viewport.h || contentH) : contentH
66
+ const scale = mode === 'actual' ? 1 : Math.min(1, availW / contentW, availH / contentH)
67
+ return { scale, boardH: contentH * scale }
68
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * 插件 entry 的配置 schema(0.1.7)。
3
+ *
4
+ * ## 为什么单独一个模块
5
+ *
6
+ * 0.1.7 删掉了「设置命名空间 + `settings.installSection`」这一整套 API,改成
7
+ * **设置就是插件自己 entry 的 config**:schema 在这里声明,初值由 profile patch 的
8
+ * `config:` 提供,设置页里的改动由 `configEditor` 写回同一处,客户端按**路径**寻址
9
+ * (`{op:'set', path:['intent','categories']}`)。
10
+ *
11
+ * 三组沿用原来的三个命名空间边界,因为它们在语义上确实是三块(知识库 / 意图引擎 /
12
+ * 转换内核),缓存键与默认值各不相同 —— 变的只是「它们住在同一个 entry 下」。
13
+ *
14
+ * 「单独一个模块」的理由和 `settings-schema.ts`、`intent/settings-schema.ts` 一样,
15
+ * 是**可测**:`tests/settings-schema.test.mjs` 要能 import 这个 schema 并把它解析
16
+ * 一遍,而 `index.ts` 会拉进工具层(`dsh-tools` 的 `dsh-sandbox` peer 没有安装,
17
+ * `node --test` 里拉不起来)。所以组合必须发生在没有工具依赖的地方。
18
+ *
19
+ * @module
20
+ */
21
+
22
+ import z from '@deepseek-ai/schemastery'
23
+ import { KNOWLEDGE_SETTINGS_SCHEMA } from './settings-schema.js'
24
+ import { INTENT_SETTINGS_SCHEMA } from './intent/settings-schema.js'
25
+ import { CONVERT_SETTINGS_SCHEMA } from './convert/settings-schema.js'
26
+ import type { KnowledgeConfig } from './types.js'
27
+ import type { IntentSettings } from './intent/types.js'
28
+ import type { ConvertPluginConfig } from './convert/types.js'
29
+
30
+ /**
31
+ * 标注 `Schemastery` 是 TS2742 的要求(见 `intent/settings-schema.ts`):导出物必须
32
+ * 有一个能被命名的类型,否则 `.d.ts` 里会写进 cosmokit 的 `.pnpm` 路径。
33
+ */
34
+ export const Config: Schemastery = z.object({
35
+ knowledge: KNOWLEDGE_SETTINGS_SCHEMA,
36
+ intent: INTENT_SETTINGS_SCHEMA,
37
+ convert: CONVERT_SETTINGS_SCHEMA,
38
+ })
39
+
40
+ /** `Config` 的取值形态。三组都可选:缺的字段由 schema 默认值补齐。 */
41
+ export interface KnowledgePluginConfig {
42
+ knowledge?: Partial<KnowledgeConfig>
43
+ intent?: Partial<IntentSettings>
44
+ convert?: Partial<ConvertPluginConfig>
45
+ }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Lazy, optional access to the conversion kernel.
3
+ *
4
+ * `dsh-convert-core` is declared as an **optionalDependency**: it
5
+ * pulls in `@firecrawl/anydoc`, which ships a platform-specific prebuilt native
6
+ * binding. A user who only wants to ingest Markdown must still be able to
7
+ * install and run the knowledge plugin, so the kernel is imported on first use
8
+ * and a missing kernel degrades to one actionable error instead of taking the
9
+ * whole plugin (SourceRaw, compile, recall) down with it.
10
+ *
11
+ * Guardrail this file exists to enforce: nothing else in the plugin may import
12
+ * the kernel eagerly.
13
+ */
14
+
15
+ export type ConvertCoreModule = typeof import('dsh-convert-core')
16
+
17
+ export type ConvertCoreLoader = () => Promise<ConvertCoreModule>
18
+
19
+ const INSTALL_HINT = '转换内核是可选依赖:装上 dsh-convert-core 后重试(pnpm --filter dsh-data-domain-knowledge install)。knowledge 的录入、编译与召回不依赖它。'
20
+
21
+ /** Raised when the optional kernel cannot be loaded. */
22
+ export class ConvertCoreMissingError extends Error {
23
+ readonly code = 'DEPENDENCY_MISSING'
24
+ readonly retryable = true
25
+ readonly suggestion = INSTALL_HINT
26
+ constructor(cause?: unknown) {
27
+ const detail = cause instanceof Error ? cause.message : cause === undefined ? '' : String(cause)
28
+ super(`转换内核 dsh-convert-core 不可用${detail ? `:${detail}` : ''}`)
29
+ this.name = 'ConvertCoreMissingError'
30
+ }
31
+ }
32
+
33
+ async function importKernel(): Promise<ConvertCoreModule> {
34
+ return await import('dsh-convert-core')
35
+ }
36
+
37
+ let loader: ConvertCoreLoader = importKernel
38
+ let cached: ConvertCoreModule | undefined
39
+ let inflight: Promise<ConvertCoreModule> | undefined
40
+
41
+ /** Load (and memoise) the kernel, or throw `ConvertCoreMissingError`. */
42
+ export async function loadConvertCore(): Promise<ConvertCoreModule> {
43
+ if (cached) return cached
44
+ inflight ??= loader()
45
+ try {
46
+ const module = await inflight
47
+ cached = module
48
+ return module
49
+ } catch (cause) {
50
+ inflight = undefined
51
+ throw cause instanceof ConvertCoreMissingError ? cause : new ConvertCoreMissingError(cause)
52
+ }
53
+ }
54
+
55
+ /** Whether the kernel is already loaded; used by capabilities reporting. */
56
+ export function convertCoreLoaded(): boolean {
57
+ return cached !== undefined
58
+ }
59
+
60
+ /**
61
+ * Test seam. Pass a loader to simulate a missing/broken kernel, or `undefined`
62
+ * to restore the real dynamic import. Never used by production code.
63
+ */
64
+ export function setConvertCoreLoader(next?: ConvertCoreLoader): void {
65
+ loader = next ?? importKernel
66
+ cached = undefined
67
+ inflight = undefined
68
+ }