@omdp/dsh-connector 0.3.0 → 0.3.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/index.js +27 -22
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -41,7 +41,7 @@ const TRANSPORTS = new Set(['stdio', 'streamable-http'])
|
|
|
41
41
|
// patch file itself (NUL, control chars). Tab/newline are already rejected by
|
|
42
42
|
// the single-token rules; this catches the rest defensively.
|
|
43
43
|
const CONTROL_CHARS = /[\x00-\x1f\x7f]/
|
|
44
|
-
export const inject = ['webServer']
|
|
44
|
+
export const inject = ['webServer', 'settings']
|
|
45
45
|
|
|
46
46
|
// ── MCP 工具过滤(tool-filter, 0.3.0 新增)────────────────────────────
|
|
47
47
|
// dsh-mcp-client 的 Config schema 是封闭的:未知键会拒收并导致下次启动失败,
|
|
@@ -924,31 +924,36 @@ async function readBody(req) {
|
|
|
924
924
|
|
|
925
925
|
export function apply(ctx) {
|
|
926
926
|
// ── 工具过滤三件套之 (0):settings namespace 注册 + 快照缓存 ──
|
|
927
|
-
// settings
|
|
927
|
+
// settings 经声明式 inject 依赖保证就绪(见上方 export const inject),
|
|
928
|
+
// 这里同步拿服务;万一缺失不炸,过滤保持全放行(零回归)。
|
|
929
|
+
// 注:cordis 的 ctx.inject(deps, cb) 回调按 (ctx, config) 调用,不是服务展开,
|
|
930
|
+
// 不能拿回调参数当 service 用 —— 0.3.0 曾因此 register 从未落地。
|
|
931
|
+
const settings = ctx.get('settings')
|
|
928
932
|
let toolFilters = {}
|
|
929
933
|
const refreshFilters = () => { toolFilters = readToolFilters(ctx) }
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
934
|
+
if (settings) {
|
|
935
|
+
try {
|
|
936
|
+
const scope = settings.register(CONNECTOR_SETTINGS_NS, ToolFilterSchema, { base: { toolFilters: {} } })
|
|
937
|
+
refreshFilters()
|
|
938
|
+
ctx.effect(() => scope.watch(() => refreshFilters()), 'connector: watch tool filters')
|
|
939
|
+
} catch (error) {
|
|
940
|
+
console.error('[dsh-connector] register tool filter settings failed:', error?.message ?? error)
|
|
941
|
+
}
|
|
942
|
+
}
|
|
935
943
|
|
|
936
|
-
// ── 三件套之 (1):prompt 层过滤 ——
|
|
937
|
-
// tools
|
|
938
|
-
//
|
|
944
|
+
// ── 三件套之 (1):prompt 层过滤 —— assemble waterfall 真替换 ──
|
|
945
|
+
// 注意:systemPrompt.tools(provider) 是追加合并语义(各 provider 输出拼在一起),
|
|
946
|
+
// 只能加不能减,做减法必须监听 system-prompt/assemble,await next() 后替换 tools 数组。
|
|
947
|
+
// 成熟参照:hyqhyq3/dsh-mcp-manager 就是 ctx.on('system-prompt/assemble', …, { global: true })。
|
|
948
|
+
// { global: true } 让 scope filter 放行(见 dsh-scope scopeTarget 的 hook.global 短路)。
|
|
939
949
|
try {
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
} catch { return { schemas: [] } }
|
|
948
|
-
const kept = schemas.filter((s) => isToolAllowed(toolFilters, s && s.name))
|
|
949
|
-
return { schemas: kept, knownNames: schemas.map((s) => s && s.name).filter(Boolean) }
|
|
950
|
-
}), 'connector: mcp tool filter provider')
|
|
951
|
-
}
|
|
950
|
+
ctx.on('system-prompt/assemble', async (_assembly, _context, next) => {
|
|
951
|
+
const assembled = await next()
|
|
952
|
+
if (!assembled || !Array.isArray(assembled.tools)) return assembled
|
|
953
|
+
const kept = assembled.tools.filter((t) => isToolAllowed(toolFilters, t && t.name))
|
|
954
|
+
if (kept.length === assembled.tools.length) return assembled
|
|
955
|
+
return { ...assembled, tools: kept }
|
|
956
|
+
}, { global: true })
|
|
952
957
|
} catch {}
|
|
953
958
|
// ── 三件套之 (2):执行期硬拦截 —— 补 provider 漏网(如 guard 注册时序)──
|
|
954
959
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omdp/dsh-connector",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Unified DeepSeek Harness connector: edit MCP servers (cordis.patch.yml), user skills (~/.dsh/skills) and browse the ModelScope MCP/Skills marketplaces from one Web UI settings page.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|