dsh-kb-layers 0.1.0 → 0.1.2
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 +7 -0
- package/lib/word-convert.ps1 +56 -56
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,6 +28,13 @@ pip install pymupdf python-docx python-pptx openpyxl
|
|
|
28
28
|
|
|
29
29
|
兼容性:DSH `>=0.2.0-rc.1 <0.3.0-0`(区间含 rc 预发布),Node `>=22.5`(依赖内置 `node:sqlite` 的 FTS5)。
|
|
30
30
|
|
|
31
|
+
## 截图
|
|
32
|
+
|
|
33
|
+

|
|
34
|
+
|
|
35
|
+
左侧是知识库列表,右侧是当前库的文档表:每个文件带页数 / 行数 / 片段数 / 章节数,以及章节树、原文预览、重建摘要等入口。
|
|
36
|
+
截图里的库名与文件名是脱敏后的通用示例,不对应任何真实资料。
|
|
37
|
+
|
|
31
38
|
## 它解决什么
|
|
32
39
|
|
|
33
40
|
纯向量 RAG 在 Agent 场景有两个固定短板:切块过碎丢上下文,精确查条款/数字/表格容易漏。
|
package/lib/word-convert.ps1
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Convert a legacy Word binary to .docx with the Word that is already installed.
|
|
3
|
-
#
|
|
4
|
-
# Run by the host as an -EncodedCommand (UTF-16LE base64), so no script file ever
|
|
5
|
-
# needs to live outside the package. Inputs arrive through the environment:
|
|
6
|
-
#
|
|
7
|
-
# DSH_KB_DOC_IN absolute path of the .doc to read
|
|
8
|
-
# DSH_KB_DOC_OUT absolute path of the .docx to write
|
|
9
|
-
#
|
|
10
|
-
# Exit codes are the contract with lib/extract.js:
|
|
11
|
-
# 0 converted, DSH_KB_DOC_OUT exists
|
|
12
|
-
# 42 the user has Word or WPS open -> caller must NOT touch COM, just fall back
|
|
13
|
-
# 43 Word is not installed -> caller caches "no Word" for the process
|
|
14
|
-
# 1 conversion failed -> caller falls back to reading the bytes
|
|
15
|
-
#
|
|
16
|
-
$ErrorActionPreference = 'Stop'
|
|
17
|
-
$source = $env:DSH_KB_DOC_IN
|
|
18
|
-
$target = $env:DSH_KB_DOC_OUT
|
|
19
|
-
if (-not (Test-Path -LiteralPath $source)) { exit 2 }
|
|
20
|
-
|
|
21
|
-
# Word hands out one COM instance per desktop: New-Object here would attach to
|
|
22
|
-
# the document the user is editing, and Quit() at the end would close it. If
|
|
23
|
-
# Word — or WPS, which also answers to `Word.Application` — is already running
|
|
24
|
-
# we do not touch it at all. Checking only WINWORD missed the WPS case and let
|
|
25
|
-
# this script connect to the user's open document and Quit() it on the way out.
|
|
26
|
-
if (Get-Process -Name WINWORD, wps -ErrorAction SilentlyContinue) { exit 42 }
|
|
27
|
-
|
|
28
|
-
$word = $null
|
|
29
|
-
$document = $null
|
|
30
|
-
try {
|
|
31
|
-
try {
|
|
32
|
-
$word = New-Object -ComObject Word.Application
|
|
33
|
-
} catch {
|
|
34
|
-
exit 43
|
|
35
|
-
}
|
|
36
|
-
$word.Visible = $false
|
|
37
|
-
$word.DisplayAlerts = 0
|
|
38
|
-
# 3 = msoAutomationSecurityForceDisable: a .doc carrying a macro must never
|
|
39
|
-
# run just because it was uploaded.
|
|
40
|
-
$word.AutomationSecurity = 3
|
|
41
|
-
|
|
42
|
-
# Open read-only and do not ask about format conversion, so an odd file
|
|
43
|
-
# cannot park a modal dialog in front of an unmanned process.
|
|
44
|
-
$document = $word.Documents.Open($source, $false, $true)
|
|
45
|
-
# 12 = wdFormatXMLDocument (.docx)
|
|
46
|
-
$document.SaveAs([ref]$target, [ref]12)
|
|
47
|
-
$document.Close([ref]0)
|
|
48
|
-
} catch {
|
|
49
|
-
exit 1
|
|
50
|
-
} finally {
|
|
51
|
-
if ($null -ne $document) { try { [void]$document.Close([ref]0) } catch { } }
|
|
52
|
-
if ($null -ne $word) { try { $word.Quit() } catch { } }
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (Test-Path -LiteralPath $target) { exit 0 }
|
|
56
|
-
exit 1
|
|
1
|
+
#
|
|
2
|
+
# Convert a legacy Word binary to .docx with the Word that is already installed.
|
|
3
|
+
#
|
|
4
|
+
# Run by the host as an -EncodedCommand (UTF-16LE base64), so no script file ever
|
|
5
|
+
# needs to live outside the package. Inputs arrive through the environment:
|
|
6
|
+
#
|
|
7
|
+
# DSH_KB_DOC_IN absolute path of the .doc to read
|
|
8
|
+
# DSH_KB_DOC_OUT absolute path of the .docx to write
|
|
9
|
+
#
|
|
10
|
+
# Exit codes are the contract with lib/extract.js:
|
|
11
|
+
# 0 converted, DSH_KB_DOC_OUT exists
|
|
12
|
+
# 42 the user has Word or WPS open -> caller must NOT touch COM, just fall back
|
|
13
|
+
# 43 Word is not installed -> caller caches "no Word" for the process
|
|
14
|
+
# 1 conversion failed -> caller falls back to reading the bytes
|
|
15
|
+
#
|
|
16
|
+
$ErrorActionPreference = 'Stop'
|
|
17
|
+
$source = $env:DSH_KB_DOC_IN
|
|
18
|
+
$target = $env:DSH_KB_DOC_OUT
|
|
19
|
+
if (-not (Test-Path -LiteralPath $source)) { exit 2 }
|
|
20
|
+
|
|
21
|
+
# Word hands out one COM instance per desktop: New-Object here would attach to
|
|
22
|
+
# the document the user is editing, and Quit() at the end would close it. If
|
|
23
|
+
# Word — or WPS, which also answers to `Word.Application` — is already running
|
|
24
|
+
# we do not touch it at all. Checking only WINWORD missed the WPS case and let
|
|
25
|
+
# this script connect to the user's open document and Quit() it on the way out.
|
|
26
|
+
if (Get-Process -Name WINWORD, wps -ErrorAction SilentlyContinue) { exit 42 }
|
|
27
|
+
|
|
28
|
+
$word = $null
|
|
29
|
+
$document = $null
|
|
30
|
+
try {
|
|
31
|
+
try {
|
|
32
|
+
$word = New-Object -ComObject Word.Application
|
|
33
|
+
} catch {
|
|
34
|
+
exit 43
|
|
35
|
+
}
|
|
36
|
+
$word.Visible = $false
|
|
37
|
+
$word.DisplayAlerts = 0
|
|
38
|
+
# 3 = msoAutomationSecurityForceDisable: a .doc carrying a macro must never
|
|
39
|
+
# run just because it was uploaded.
|
|
40
|
+
$word.AutomationSecurity = 3
|
|
41
|
+
|
|
42
|
+
# Open read-only and do not ask about format conversion, so an odd file
|
|
43
|
+
# cannot park a modal dialog in front of an unmanned process.
|
|
44
|
+
$document = $word.Documents.Open($source, $false, $true)
|
|
45
|
+
# 12 = wdFormatXMLDocument (.docx)
|
|
46
|
+
$document.SaveAs([ref]$target, [ref]12)
|
|
47
|
+
$document.Close([ref]0)
|
|
48
|
+
} catch {
|
|
49
|
+
exit 1
|
|
50
|
+
} finally {
|
|
51
|
+
if ($null -ne $document) { try { [void]$document.Close([ref]0) } catch { } }
|
|
52
|
+
if ($null -ne $word) { try { $word.Quit() } catch { } }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (Test-Path -LiteralPath $target) { exit 0 }
|
|
56
|
+
exit 1
|