@cheemsup/dsh-plugin-console 0.1.1 → 0.2.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.
- package/LICENSE +2 -0
- package/README.md +95 -86
- package/icon.svg +203 -0
- package/lib/client.control.js +7 -2
- package/lib/client.disable-preview.js +904 -0
- package/lib/client.editor.js +3 -3
- package/lib/client.impact-tree.js +487 -0
- package/lib/client.js +38 -8
- package/lib/client.page.js +69 -7
- package/lib/client.plugins.js +5 -3
- package/lib/client.preview-messages.js +14 -3
- package/lib/client.preview.js +3 -2
- package/lib/client.relation-graph.js +364 -0
- package/lib/client.search.js +409 -408
- package/lib/client.shared.js +3 -0
- package/lib/client.styles.js +589 -524
- package/lib/host/attribution.js +34 -0
- package/lib/host/config-layers.js +589 -0
- package/lib/host/constants.js +3 -0
- package/lib/host/disable-preview.js +651 -0
- package/lib/host/entries.js +1 -1
- package/lib/host/impact.js +10 -4
- package/lib/host/injection-owners.js +60 -0
- package/lib/host/patch-config.js +554 -0
- package/lib/host/preview-contexts.js +198 -174
- package/lib/host/recipe-overlay.js +208 -209
- package/lib/host/routes/disable-preview.js +19 -0
- package/lib/host/session-influence.js +2 -10
- package/lib/index.js +4 -1
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +124 -113
|
@@ -1,209 +1,208 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 把一份提示词模板 recipe 叠加到**预演结果**上。
|
|
3
|
-
*
|
|
4
|
-
* 这一层只做纯投影:不注册 section/context、不写 session log、不创建 Agent。
|
|
5
|
-
* 真实会话的同一份语义由 `templates/materialize.js` + `templates/message-overlay.js`
|
|
6
|
-
* 落地;两边的条目过滤与目录帧共用 `catalog.js`,避免预演与实测漂移。
|
|
7
|
-
* @module dsh-plugin-console/host/recipe-overlay
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { applyCatalogOverrides, renderCatalogMessage } from './catalog.js'
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
/** 追加段落的名字与位置,与物化时保持一致(DSH 最高段 order 是 10200)。 */
|
|
14
|
-
const APPEND_SECTION = 'template:extra'
|
|
15
|
-
const APPEND_ORDER = 20000
|
|
16
|
-
|
|
17
|
-
/** 把 `template` 加进依据列表,不重复。 */
|
|
18
|
-
function withTemplateBasis(message) {
|
|
19
|
-
const basis = Array.isArray(message.basis) ? message.basis : []
|
|
20
|
-
return basis.includes('template') ? basis : [...basis, 'template']
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** 一条被模板改写的预览消息。 */
|
|
24
|
-
function overriddenMessage(message, text, extra = {}) {
|
|
25
|
-
return {
|
|
26
|
-
...message,
|
|
27
|
-
text,
|
|
28
|
-
length: text.length,
|
|
29
|
-
overridden: true,
|
|
30
|
-
basis: withTemplateBasis(message),
|
|
31
|
-
...extra,
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* 叠加 system 段、runtime context、工具可见集,并重算统计。
|
|
37
|
-
* @param {object} assembly - `previewAssembly()` 的结果。
|
|
38
|
-
* @param {object} recipe - 提示词模板配方。
|
|
39
|
-
* @returns {object} 叠加后的装配结果。
|
|
40
|
-
*/
|
|
41
|
-
export function applyRecipeToAssembly(assembly, recipe) {
|
|
42
|
-
const prompt = recipe?.prompt ?? {}
|
|
43
|
-
const sectionOverrides = prompt.sectionOverrides ?? {}
|
|
44
|
-
const applied = { sections: [], contexts: [], tools: [], appended: false }
|
|
45
|
-
|
|
46
|
-
const sections = (assembly.sections ?? []).map((section) => {
|
|
47
|
-
const text = sectionOverrides[section.name]
|
|
48
|
-
if (typeof text !== 'string') return section
|
|
49
|
-
applied.sections.push(section.name)
|
|
50
|
-
return {
|
|
51
|
-
...section,
|
|
52
|
-
text,
|
|
53
|
-
rendered: text,
|
|
54
|
-
length: text.length,
|
|
55
|
-
interpolate: false,
|
|
56
|
-
unresolved: [],
|
|
57
|
-
overridden: true,
|
|
58
|
-
}
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
// 独占提示词下追加段落无处安放;客户端算 recipe 时已经折进那一整段。
|
|
62
|
-
if (typeof prompt.appendText === 'string' && prompt.appendText.length > 0 && assembly.completeSection === null) {
|
|
63
|
-
const text = prompt.appendText
|
|
64
|
-
sections.push({
|
|
65
|
-
index: sections.length,
|
|
66
|
-
name: APPEND_SECTION,
|
|
67
|
-
order: APPEND_ORDER,
|
|
68
|
-
text,
|
|
69
|
-
rendered: text,
|
|
70
|
-
length: text.length,
|
|
71
|
-
interpolate: false,
|
|
72
|
-
unresolved: [],
|
|
73
|
-
overridden: true,
|
|
74
|
-
template: true,
|
|
75
|
-
})
|
|
76
|
-
applied.appended = true
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const contexts = (assembly.contexts ?? []).map((context) => {
|
|
80
|
-
const text = recipe?.contexts?.[context.name]
|
|
81
|
-
if (typeof text !== 'string') return context
|
|
82
|
-
applied.contexts.push(context.name)
|
|
83
|
-
return { ...context, text, length: text.length, interpolate: false, overridden: true }
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
const disabled = new Set(Array.isArray(recipe?.tools?.disabled) ? recipe.tools.disabled : [])
|
|
87
|
-
const tools = (assembly.tools ?? []).filter((tool) => {
|
|
88
|
-
if (typeof tool?.name !== 'string' || !disabled.has(tool.name)) return true
|
|
89
|
-
applied.tools.push(tool.name)
|
|
90
|
-
return false
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
const visible = new Set(tools.map((tool) => tool.name))
|
|
94
|
-
const toolSet = assembly.toolSet === undefined ? undefined : {
|
|
95
|
-
...assembly.toolSet,
|
|
96
|
-
layers: Object.fromEntries(
|
|
97
|
-
Object.entries(assembly.toolSet.layers ?? {}).map(([layer, names]) => [layer, (names ?? []).filter((name) => visible.has(name))]),
|
|
98
|
-
),
|
|
99
|
-
layerByName: Object.fromEntries(
|
|
100
|
-
Object.entries(assembly.toolSet.layerByName ?? {}).filter(([name]) => visible.has(name)),
|
|
101
|
-
),
|
|
102
|
-
counts: Object.fromEntries(
|
|
103
|
-
Object.entries(assembly.toolSet.layers ?? {}).map(([layer, names]) => [layer, (names ?? []).filter((name) => visible.has(name)).length]),
|
|
104
|
-
),
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const systemText = sections.map((section) => section.rendered ?? section.text ?? '').filter((text) => text.length > 0).join('\n\n')
|
|
108
|
-
const stats = {
|
|
109
|
-
...(assembly.stats ?? {}),
|
|
110
|
-
sections: sections.length,
|
|
111
|
-
sectionChars: sections.reduce((sum, section) => sum + (section.length ?? 0), 0),
|
|
112
|
-
contexts: contexts.length,
|
|
113
|
-
contextChars: contexts.reduce((sum, context) => sum + (context.length ?? 0), 0),
|
|
114
|
-
tools: tools.length,
|
|
115
|
-
toolSchemaChars: JSON.stringify(tools).length,
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return {
|
|
119
|
-
...assembly,
|
|
120
|
-
sections,
|
|
121
|
-
contexts,
|
|
122
|
-
tools,
|
|
123
|
-
...(toolSet === undefined ? {} : { toolSet }),
|
|
124
|
-
systemText,
|
|
125
|
-
stats,
|
|
126
|
-
applied,
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* 叠加预览消息列表。
|
|
132
|
-
*
|
|
133
|
-
* 预览消息是本插件自己的形状(`sourceKind / text / parts / length`),所以这里
|
|
134
|
-
* 不处理 DSH 的 `content` 数组;真实请求的对应逻辑在 `templates/message-overlay.js`。
|
|
135
|
-
* @param {Array<object>} messages - `previewMessages()` 的结果。
|
|
136
|
-
* @param {Array<object>} skipped - 已跳过的消息原因。
|
|
137
|
-
* @param {object} recipe - 提示词配方。
|
|
138
|
-
* @param {object} assembly - 叠加后的装配结果(用于判断 required context)。
|
|
139
|
-
* @returns {{messages: Array<object>, skipped: Array<object>, applied: object}} 叠加结果。
|
|
140
|
-
*/
|
|
141
|
-
export function overlayPreviewMessages(messages, skipped, recipe, assembly) {
|
|
142
|
-
const out = []
|
|
143
|
-
const skippedOut = Array.isArray(skipped) ? [...skipped] : []
|
|
144
|
-
const applied = { messages: [], catalogEntries: [], skipped: [] }
|
|
145
|
-
|
|
146
|
-
for (const message of Array.isArray(messages) ? messages : []) {
|
|
147
|
-
const kind = message.sourceKind
|
|
148
|
-
if (kind === 'runtime-context') {
|
|
149
|
-
const hidden = recipe?.messages?.['runtime-context']?.hidden === true
|
|
150
|
-
if (!hidden) {
|
|
151
|
-
out.push(message)
|
|
152
|
-
continue
|
|
153
|
-
}
|
|
154
|
-
// suppressRuntimeContext 只压可选上下文;required 的仍会进入请求。
|
|
155
|
-
const required = new Set((assembly?.contexts ?? []).filter((context) => context.required === true).map((context) => context.name))
|
|
156
|
-
const parts = (message.parts ?? []).filter((part) => required.has(part.name))
|
|
157
|
-
if (parts.length === 0) {
|
|
158
|
-
skippedOut.push({ sourceKind: 'runtime-context', reason: '模板隐藏' })
|
|
159
|
-
applied.skipped.push('runtime-context')
|
|
160
|
-
continue
|
|
161
|
-
}
|
|
162
|
-
const body = parts.map((part) => part.text).filter((text) => typeof text === 'string' && text.length > 0).join('\n\n')
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
applied.
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 把一份提示词模板 recipe 叠加到**预演结果**上。
|
|
3
|
+
*
|
|
4
|
+
* 这一层只做纯投影:不注册 section/context、不写 session log、不创建 Agent。
|
|
5
|
+
* 真实会话的同一份语义由 `templates/materialize.js` + `templates/message-overlay.js`
|
|
6
|
+
* 落地;两边的条目过滤与目录帧共用 `catalog.js`,避免预演与实测漂移。
|
|
7
|
+
* @module dsh-plugin-console/host/recipe-overlay
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { applyCatalogOverrides, renderCatalogMessage } from './catalog.js'
|
|
11
|
+
import { wrapRuntimeContext } from './preview-contexts.js'
|
|
12
|
+
|
|
13
|
+
/** 追加段落的名字与位置,与物化时保持一致(DSH 最高段 order 是 10200)。 */
|
|
14
|
+
const APPEND_SECTION = 'template:extra'
|
|
15
|
+
const APPEND_ORDER = 20000
|
|
16
|
+
|
|
17
|
+
/** 把 `template` 加进依据列表,不重复。 */
|
|
18
|
+
function withTemplateBasis(message) {
|
|
19
|
+
const basis = Array.isArray(message.basis) ? message.basis : []
|
|
20
|
+
return basis.includes('template') ? basis : [...basis, 'template']
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** 一条被模板改写的预览消息。 */
|
|
24
|
+
function overriddenMessage(message, text, extra = {}) {
|
|
25
|
+
return {
|
|
26
|
+
...message,
|
|
27
|
+
text,
|
|
28
|
+
length: text.length,
|
|
29
|
+
overridden: true,
|
|
30
|
+
basis: withTemplateBasis(message),
|
|
31
|
+
...extra,
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 叠加 system 段、runtime context、工具可见集,并重算统计。
|
|
37
|
+
* @param {object} assembly - `previewAssembly()` 的结果。
|
|
38
|
+
* @param {object} recipe - 提示词模板配方。
|
|
39
|
+
* @returns {object} 叠加后的装配结果。
|
|
40
|
+
*/
|
|
41
|
+
export function applyRecipeToAssembly(assembly, recipe) {
|
|
42
|
+
const prompt = recipe?.prompt ?? {}
|
|
43
|
+
const sectionOverrides = prompt.sectionOverrides ?? {}
|
|
44
|
+
const applied = { sections: [], contexts: [], tools: [], appended: false }
|
|
45
|
+
|
|
46
|
+
const sections = (assembly.sections ?? []).map((section) => {
|
|
47
|
+
const text = sectionOverrides[section.name]
|
|
48
|
+
if (typeof text !== 'string') return section
|
|
49
|
+
applied.sections.push(section.name)
|
|
50
|
+
return {
|
|
51
|
+
...section,
|
|
52
|
+
text,
|
|
53
|
+
rendered: text,
|
|
54
|
+
length: text.length,
|
|
55
|
+
interpolate: false,
|
|
56
|
+
unresolved: [],
|
|
57
|
+
overridden: true,
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
// 独占提示词下追加段落无处安放;客户端算 recipe 时已经折进那一整段。
|
|
62
|
+
if (typeof prompt.appendText === 'string' && prompt.appendText.length > 0 && assembly.completeSection === null) {
|
|
63
|
+
const text = prompt.appendText
|
|
64
|
+
sections.push({
|
|
65
|
+
index: sections.length,
|
|
66
|
+
name: APPEND_SECTION,
|
|
67
|
+
order: APPEND_ORDER,
|
|
68
|
+
text,
|
|
69
|
+
rendered: text,
|
|
70
|
+
length: text.length,
|
|
71
|
+
interpolate: false,
|
|
72
|
+
unresolved: [],
|
|
73
|
+
overridden: true,
|
|
74
|
+
template: true,
|
|
75
|
+
})
|
|
76
|
+
applied.appended = true
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const contexts = (assembly.contexts ?? []).map((context) => {
|
|
80
|
+
const text = recipe?.contexts?.[context.name]
|
|
81
|
+
if (typeof text !== 'string') return context
|
|
82
|
+
applied.contexts.push(context.name)
|
|
83
|
+
return { ...context, text, length: text.length, interpolate: false, overridden: true }
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
const disabled = new Set(Array.isArray(recipe?.tools?.disabled) ? recipe.tools.disabled : [])
|
|
87
|
+
const tools = (assembly.tools ?? []).filter((tool) => {
|
|
88
|
+
if (typeof tool?.name !== 'string' || !disabled.has(tool.name)) return true
|
|
89
|
+
applied.tools.push(tool.name)
|
|
90
|
+
return false
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
const visible = new Set(tools.map((tool) => tool.name))
|
|
94
|
+
const toolSet = assembly.toolSet === undefined ? undefined : {
|
|
95
|
+
...assembly.toolSet,
|
|
96
|
+
layers: Object.fromEntries(
|
|
97
|
+
Object.entries(assembly.toolSet.layers ?? {}).map(([layer, names]) => [layer, (names ?? []).filter((name) => visible.has(name))]),
|
|
98
|
+
),
|
|
99
|
+
layerByName: Object.fromEntries(
|
|
100
|
+
Object.entries(assembly.toolSet.layerByName ?? {}).filter(([name]) => visible.has(name)),
|
|
101
|
+
),
|
|
102
|
+
counts: Object.fromEntries(
|
|
103
|
+
Object.entries(assembly.toolSet.layers ?? {}).map(([layer, names]) => [layer, (names ?? []).filter((name) => visible.has(name)).length]),
|
|
104
|
+
),
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const systemText = sections.map((section) => section.rendered ?? section.text ?? '').filter((text) => text.length > 0).join('\n\n')
|
|
108
|
+
const stats = {
|
|
109
|
+
...(assembly.stats ?? {}),
|
|
110
|
+
sections: sections.length,
|
|
111
|
+
sectionChars: sections.reduce((sum, section) => sum + (section.length ?? 0), 0),
|
|
112
|
+
contexts: contexts.length,
|
|
113
|
+
contextChars: contexts.reduce((sum, context) => sum + (context.length ?? 0), 0),
|
|
114
|
+
tools: tools.length,
|
|
115
|
+
toolSchemaChars: JSON.stringify(tools).length,
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
...assembly,
|
|
120
|
+
sections,
|
|
121
|
+
contexts,
|
|
122
|
+
tools,
|
|
123
|
+
...(toolSet === undefined ? {} : { toolSet }),
|
|
124
|
+
systemText,
|
|
125
|
+
stats,
|
|
126
|
+
applied,
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* 叠加预览消息列表。
|
|
132
|
+
*
|
|
133
|
+
* 预览消息是本插件自己的形状(`sourceKind / text / parts / length`),所以这里
|
|
134
|
+
* 不处理 DSH 的 `content` 数组;真实请求的对应逻辑在 `templates/message-overlay.js`。
|
|
135
|
+
* @param {Array<object>} messages - `previewMessages()` 的结果。
|
|
136
|
+
* @param {Array<object>} skipped - 已跳过的消息原因。
|
|
137
|
+
* @param {object} recipe - 提示词配方。
|
|
138
|
+
* @param {object} assembly - 叠加后的装配结果(用于判断 required context)。
|
|
139
|
+
* @returns {{messages: Array<object>, skipped: Array<object>, applied: object}} 叠加结果。
|
|
140
|
+
*/
|
|
141
|
+
export function overlayPreviewMessages(messages, skipped, recipe, assembly) {
|
|
142
|
+
const out = []
|
|
143
|
+
const skippedOut = Array.isArray(skipped) ? [...skipped] : []
|
|
144
|
+
const applied = { messages: [], catalogEntries: [], skipped: [] }
|
|
145
|
+
|
|
146
|
+
for (const message of Array.isArray(messages) ? messages : []) {
|
|
147
|
+
const kind = message.sourceKind
|
|
148
|
+
if (kind === 'runtime-context') {
|
|
149
|
+
const hidden = recipe?.messages?.['runtime-context']?.hidden === true
|
|
150
|
+
if (!hidden) {
|
|
151
|
+
out.push(message)
|
|
152
|
+
continue
|
|
153
|
+
}
|
|
154
|
+
// suppressRuntimeContext 只压可选上下文;required 的仍会进入请求。
|
|
155
|
+
const required = new Set((assembly?.contexts ?? []).filter((context) => context.required === true).map((context) => context.name))
|
|
156
|
+
const parts = (message.parts ?? []).filter((part) => required.has(part.name))
|
|
157
|
+
if (parts.length === 0) {
|
|
158
|
+
skippedOut.push({ sourceKind: 'runtime-context', reason: '模板隐藏' })
|
|
159
|
+
applied.skipped.push('runtime-context')
|
|
160
|
+
continue
|
|
161
|
+
}
|
|
162
|
+
const body = parts.map((part) => part.text).filter((text) => typeof text === 'string' && text.length > 0).join('\n\n')
|
|
163
|
+
out.push(overriddenMessage(message, wrapRuntimeContext(body), { parts }))
|
|
164
|
+
applied.messages.push('runtime-context')
|
|
165
|
+
continue
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (kind === 'agent-instructions' || kind === 'time-context') {
|
|
169
|
+
const spec = recipe?.messages?.[kind]
|
|
170
|
+
if (spec?.hidden === true || spec?.text === '') {
|
|
171
|
+
skippedOut.push({ sourceKind: kind, reason: '模板隐藏' })
|
|
172
|
+
applied.skipped.push(kind)
|
|
173
|
+
continue
|
|
174
|
+
}
|
|
175
|
+
if (typeof spec?.text === 'string') {
|
|
176
|
+
out.push(overriddenMessage(message, spec.text))
|
|
177
|
+
applied.messages.push(kind)
|
|
178
|
+
continue
|
|
179
|
+
}
|
|
180
|
+
out.push(message)
|
|
181
|
+
continue
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (kind === 'skill-catalog') {
|
|
185
|
+
const spec = recipe?.messages?.['skill-catalog']
|
|
186
|
+
if (spec?.hidden === true) {
|
|
187
|
+
skippedOut.push({ sourceKind: kind, reason: '模板隐藏' })
|
|
188
|
+
applied.skipped.push(kind)
|
|
189
|
+
continue
|
|
190
|
+
}
|
|
191
|
+
const hasEntryOverrides = Array.isArray(spec?.hiddenEntries) || (spec?.descriptions !== null && typeof spec?.descriptions === 'object')
|
|
192
|
+
if (!hasEntryOverrides) {
|
|
193
|
+
out.push(message)
|
|
194
|
+
continue
|
|
195
|
+
}
|
|
196
|
+
const entries = applyCatalogOverrides(message.parts ?? [], spec)
|
|
197
|
+
const text = renderCatalogMessage(entries, message.incomplete === true)
|
|
198
|
+
out.push(overriddenMessage(message, text, { parts: entries }))
|
|
199
|
+
applied.messages.push(kind)
|
|
200
|
+
applied.catalogEntries = entries.map((entry) => entry.name)
|
|
201
|
+
continue
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
out.push(message)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return { messages: out, skipped: skippedOut, applied }
|
|
208
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 禁用效果预演:GET ?id=<rowId|entryId>。
|
|
3
|
+
* @module dsh-plugin-console/host/routes/disable-preview
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { readDisablePreview } from '../disable-preview.js'
|
|
7
|
+
import { jsonError, jsonOk, searchParam } from '../http.js'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {object} ctx - host 插件上下文。
|
|
11
|
+
* @returns {Function} fetch 处理函数。
|
|
12
|
+
*/
|
|
13
|
+
export function createDisablePreviewRoute(ctx) {
|
|
14
|
+
return async (request) => {
|
|
15
|
+
const id = searchParam(request, 'id')
|
|
16
|
+
if (id === undefined) return jsonError(400, 'missing id')
|
|
17
|
+
return jsonOk(await readDisablePreview(ctx, id))
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
import { previewAssembly } from './assembly-preview.js'
|
|
18
18
|
import { scopeKeyOf } from './fiber.js'
|
|
19
|
+
import { MESSAGE_INJECTION_OWNERS } from './injection-owners.js'
|
|
19
20
|
import { readSessionEvents } from './session-events.js'
|
|
20
21
|
import { classifyToolSchemas, toolSchemaOf } from './tool-set.js'
|
|
21
22
|
|
|
@@ -29,15 +30,6 @@ const TEXT_LIMIT = 8000
|
|
|
29
30
|
*/
|
|
30
31
|
const SYSTEM_TEXT_LIMIT = 200000
|
|
31
32
|
|
|
32
|
-
/** 消息 source.kind → 产出它的包。没有映射的 kind 留空,由名字归属兜底。 */
|
|
33
|
-
const SOURCE_OWNERS = {
|
|
34
|
-
'runtime-context': ['@deepseek-ai/dsh-agent-loop'],
|
|
35
|
-
'time-context': ['@deepseek-ai/dsh-time-context'],
|
|
36
|
-
'skill-catalog': ['@deepseek-ai/dsh-tool-skill'],
|
|
37
|
-
'agent-message': ['@deepseek-ai/dsh-subagent'],
|
|
38
|
-
'subagent-settled': ['@deepseek-ai/dsh-subagent'],
|
|
39
|
-
}
|
|
40
|
-
|
|
41
33
|
/** 截断一个字符串,保留可读前缀。 */
|
|
42
34
|
function clip(text, limit = TEXT_LIMIT) {
|
|
43
35
|
const value = typeof text === 'string' ? text : ''
|
|
@@ -83,7 +75,7 @@ function messageOf(event, header) {
|
|
|
83
75
|
form: typeof source.form === 'string' ? source.form : undefined,
|
|
84
76
|
senderSessionId: typeof source.senderSessionId === 'string' ? source.senderSessionId : undefined,
|
|
85
77
|
summary: typeof source.summary === 'string' ? source.summary : undefined,
|
|
86
|
-
owner:
|
|
78
|
+
owner: MESSAGE_INJECTION_OWNERS[kind] ?? [],
|
|
87
79
|
blocks,
|
|
88
80
|
...clip(text),
|
|
89
81
|
}
|
package/lib/index.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* - 模板及其每会话开关写在自己的 storage domain(`plugin_console_templates`),
|
|
16
16
|
* 由 storageDomain 落到 `$DSH_HOME/storages`,不碰 session log,也不写 sidecar 文件。
|
|
17
17
|
*
|
|
18
|
-
* 实现分层见 README.md 的「代码结构」:本文件只做「等待 connection →
|
|
18
|
+
* 实现分层见 README.md 的「代码结构」:本文件只做「等待 connection → 挂全部路由 → 收尾」。
|
|
19
19
|
* @module dsh-plugin-console
|
|
20
20
|
*/
|
|
21
21
|
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
APPLY_PATH,
|
|
26
26
|
CLEANUP_PATH,
|
|
27
27
|
CONTROL_PATH,
|
|
28
|
+
DISABLE_PREVIEW_PATH,
|
|
28
29
|
IMPACT_PATH,
|
|
29
30
|
OPERATIONS_PATH,
|
|
30
31
|
PREVIEW_PATH,
|
|
@@ -39,6 +40,7 @@ import { createActivityRoute } from './host/routes/activity.js'
|
|
|
39
40
|
import { createApplyRoute } from './host/routes/apply.js'
|
|
40
41
|
import { createCleanupRoute } from './host/routes/cleanup.js'
|
|
41
42
|
import { createControlRoute } from './host/routes/control.js'
|
|
43
|
+
import { createDisablePreviewRoute } from './host/routes/disable-preview.js'
|
|
42
44
|
import { createImpactRoute } from './host/routes/impact.js'
|
|
43
45
|
import { createOperationsRoute } from './host/routes/operations.js'
|
|
44
46
|
import { createPreviewRoute } from './host/routes/preview.js'
|
|
@@ -97,6 +99,7 @@ export function apply(ctx) {
|
|
|
97
99
|
mount(SESSION_INFLUENCE_PATH, ['GET'], 'buffered', createSessionInfluenceRoute(ctx), 'plugin-console: session influence route')
|
|
98
100
|
mount(ACTIVITY_PATH, ['GET'], 'buffered', createActivityRoute(ctx), 'plugin-console: activity route')
|
|
99
101
|
mount(IMPACT_PATH, ['GET'], 'buffered', createImpactRoute(ctx), 'plugin-console: impact route')
|
|
102
|
+
mount(DISABLE_PREVIEW_PATH, ['GET'], 'buffered', createDisablePreviewRoute(ctx), 'plugin-console: disable preview route')
|
|
100
103
|
mount(CONTROL_PATH, ['POST'], 'buffered', createControlRoute(ctx, templateState), 'plugin-console: control route')
|
|
101
104
|
mount(OPERATIONS_PATH, ['GET'], 'buffered', createOperationsRoute(ctx, templateState), 'plugin-console: operations route')
|
|
102
105
|
})
|
package/locale/en.json
ADDED