@cheemsup/dsh-plugin-console 0.0.0-stage → 0.2.0

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 (101) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +95 -3
  3. package/cordis.patch.yml +5 -0
  4. package/icon.svg +203 -0
  5. package/lib/client.activity.js +222 -0
  6. package/lib/client.apply.js +171 -0
  7. package/lib/client.changes.js +206 -0
  8. package/lib/client.cleanup.js +270 -0
  9. package/lib/client.control.js +247 -0
  10. package/lib/client.dialog.js +77 -0
  11. package/lib/client.disable-preview.js +904 -0
  12. package/lib/client.draft.js +280 -0
  13. package/lib/client.editor-messages.js +421 -0
  14. package/lib/client.editor-store.js +266 -0
  15. package/lib/client.editor.js +433 -0
  16. package/lib/client.effects.js +115 -0
  17. package/lib/client.impact-tree.js +487 -0
  18. package/lib/client.influence.js +361 -0
  19. package/lib/client.js +246 -0
  20. package/lib/client.page.js +646 -0
  21. package/lib/client.plugin-filters.js +62 -0
  22. package/lib/client.plugins.js +506 -0
  23. package/lib/client.preview-messages.js +506 -0
  24. package/lib/client.preview-raw.js +132 -0
  25. package/lib/client.preview-store.js +128 -0
  26. package/lib/client.preview-tools.js +194 -0
  27. package/lib/client.preview.js +448 -0
  28. package/lib/client.relation-graph.js +364 -0
  29. package/lib/client.schema.js +327 -0
  30. package/lib/client.search.js +409 -0
  31. package/lib/client.session-detail.js +503 -0
  32. package/lib/client.sessions.js +495 -0
  33. package/lib/client.shared.js +562 -0
  34. package/lib/client.store.js +452 -0
  35. package/lib/client.styles.js +589 -0
  36. package/lib/client.template-card.js +240 -0
  37. package/lib/client.tools.js +366 -0
  38. package/lib/client.workspace-picker.js +204 -0
  39. package/lib/host/activity.js +252 -0
  40. package/lib/host/assembly-preview.js +244 -0
  41. package/lib/host/attribution.js +341 -0
  42. package/lib/host/catalog.js +133 -0
  43. package/lib/host/categorize.js +40 -0
  44. package/lib/host/config-layers.js +589 -0
  45. package/lib/host/constants.js +69 -0
  46. package/lib/host/control.js +159 -0
  47. package/lib/host/disable-preview.js +651 -0
  48. package/lib/host/entries.js +289 -0
  49. package/lib/host/fiber.js +86 -0
  50. package/lib/host/fs.js +99 -0
  51. package/lib/host/health.js +178 -0
  52. package/lib/host/http.js +65 -0
  53. package/lib/host/impact.js +138 -0
  54. package/lib/host/injection-owners.js +60 -0
  55. package/lib/host/layers.js +132 -0
  56. package/lib/host/masks.js +145 -0
  57. package/lib/host/modes.js +96 -0
  58. package/lib/host/names.js +44 -0
  59. package/lib/host/patch-config.js +554 -0
  60. package/lib/host/patch-scan.js +103 -0
  61. package/lib/host/preview-conditions.js +281 -0
  62. package/lib/host/preview-contexts.js +174 -0
  63. package/lib/host/preview-envelope.js +31 -0
  64. package/lib/host/preview-instructions.js +450 -0
  65. package/lib/host/preview-messages.js +284 -0
  66. package/lib/host/preview-modules.js +233 -0
  67. package/lib/host/preview-skills.js +200 -0
  68. package/lib/host/prompt.js +213 -0
  69. package/lib/host/recipe-overlay.js +209 -0
  70. package/lib/host/request-preview.js +114 -0
  71. package/lib/host/routes/activation.js +96 -0
  72. package/lib/host/routes/activity.js +22 -0
  73. package/lib/host/routes/apply.js +93 -0
  74. package/lib/host/routes/cleanup.js +62 -0
  75. package/lib/host/routes/control.js +22 -0
  76. package/lib/host/routes/disable-preview.js +19 -0
  77. package/lib/host/routes/impact.js +19 -0
  78. package/lib/host/routes/operations.js +22 -0
  79. package/lib/host/routes/preview.js +58 -0
  80. package/lib/host/routes/session-influence.js +23 -0
  81. package/lib/host/routes/snapshot.js +21 -0
  82. package/lib/host/routes/template.js +54 -0
  83. package/lib/host/routes/templates.js +28 -0
  84. package/lib/host/scope-impact.js +125 -0
  85. package/lib/host/session-events.js +39 -0
  86. package/lib/host/session-influence.js +467 -0
  87. package/lib/host/sessions.js +293 -0
  88. package/lib/host/snapshot.js +218 -0
  89. package/lib/host/source-scan.js +225 -0
  90. package/lib/host/templates/cleanup.js +219 -0
  91. package/lib/host/templates/inheritance.js +144 -0
  92. package/lib/host/templates/materialize.js +317 -0
  93. package/lib/host/templates/message-overlay.js +184 -0
  94. package/lib/host/templates/repository.js +323 -0
  95. package/lib/host/templates/store.js +131 -0
  96. package/lib/host/tool-set.js +150 -0
  97. package/lib/host/tools.js +129 -0
  98. package/lib/index.js +106 -0
  99. package/locale/en.json +6 -0
  100. package/locale/zh.json +6 -0
  101. package/package.json +124 -6
@@ -0,0 +1,506 @@
1
+ /**
2
+ * 预演页的「消息与注入」标签:首请求里 user-role 消息的完整清单与溯源。
3
+ *
4
+ * 它回答的是系统提示词标签回答不了的问题:请求里除了 system 与 tools,还有几条
5
+ * 由 pre-step 监听器注入的 user 消息。每行给出 `#序号 · source.kind · 大小 · 归属 ·
6
+ * 置信度`,展开是分段与完整原文;机制/依据只在还能解释模型可见内容时留在正文,
7
+ * skill 目录与 `/name` 资源基座这类「内容从哪来」的信息收进容器标题的悬停提示。
8
+ *
9
+ * 置信度是这一页的立身之本:`实测` 是从活注册表/装配直接读到的,`推导` 是用同一份
10
+ * 配置与文件算出来的,`未知` 是取决于尚未提供的输入(例如首条消息)。把推导说成
11
+ * 实测,比不给答案更糟。
12
+ *
13
+ * 本文件是一个包内 chunk:入口用 `require.async('./client.preview-messages.js')` 取它。
14
+ */
15
+
16
+ window.__ModuleLoader__.load({
17
+ id: '@cheemsup/dsh-plugin-console',
18
+ chunk: 'client.preview-messages.js',
19
+ factory: (require) => {
20
+ const React = require('react')
21
+ const { createElement: h } = React
22
+
23
+ /** 置信度的界面说法;host 那边用的是英文枚举。 */
24
+ const CONFIDENCE = {
25
+ measured: { label: '实测', hint: '从活注册表或装配结果直接读取' },
26
+ derived: { label: '推导', hint: '使用配置、文件或者服务进行的确定性推导' },
27
+ unknown: { label: '未知', hint: '取决于尚未提供的输入,例如首条消息或未选工作区' },
28
+ unavailable: { label: '不可用', hint: '前置条件缺失,无法采集' },
29
+ }
30
+
31
+ /**
32
+ * 正文里还保留「机制 · 依据」一行的消息。
33
+ *
34
+ * 其余消息的这行元信息要么没有信息量(user、runtime-context、time-context),
35
+ * 要么更适合回答「内容从哪来」——skill 目录与 `/name` 资源基座收进容器标题的悬停提示。
36
+ */
37
+ const MECHANISM_IN_BODY = new Set(['agent-instructions'])
38
+
39
+ /** skill 目录的获取渠道:只回答目录从哪来,不展开 pre-step 机制。 */
40
+ const CATALOG_SOURCE_HINT = 'skill 目录来自工作区、预设与 skills-service'
41
+
42
+ /** 段内容推不出来时的占位:不要留白,也不要假装预测到了空内容。 */
43
+ const UNPREDICTABLE = '此项运行时内容无法预测'
44
+
45
+ /** 「影响条件」标签里的条件代号 → 界面说法;悬停提示要靠它把 workspace 这类英文讲清楚。 */
46
+ const BASIS_HINTS = {
47
+ workspace: '工作区路径',
48
+ preset: '预设模式',
49
+ permission: '权限预设(sandbox / approval)',
50
+ 'skills-service': 'skill 服务注册的目录',
51
+ draft: '首条消息草稿',
52
+ 'client-time-zone': '客户端时区',
53
+ }
54
+
55
+ return function create(deps) {
56
+ const { formatBytes, shortModule, textButton, rowEnd, foldNodes, setDetailsOpen, search } = deps
57
+
58
+ /** 一条消息(含它的分段 / skill 条目 / 文件清单)是否命中页头搜索。 */
59
+ function messageMatches(message, query) {
60
+ if (search.matchesQuery(query, [message.sourceKind, message.role, message.text])) return true
61
+ return (message.parts ?? []).some((part) => partMatches(part, query))
62
+ }
63
+
64
+ /** 分段、skill 条目与文件条目:名字、说明、正文都算用户会去搜的可见文字。 */
65
+ function partMatches(part, query) {
66
+ return search.matchesQuery(query, [part?.name, part?.displayPath, part?.description, part?.text, part?.source])
67
+ }
68
+
69
+ /** 置信度标签:文字只有「实测 / 推导」,种类靠悬停标题交代。 */
70
+ function confidenceTag(value) {
71
+ const meta = CONFIDENCE[value]
72
+ if (meta === undefined) return null
73
+ return h(
74
+ 'span',
75
+ {
76
+ className: 'ptTag',
77
+ 'data-tone': value === 'unknown' || value === 'unavailable' ? 'warn' : undefined,
78
+ title: '置信度:' + meta.hint,
79
+ },
80
+ meta.label,
81
+ )
82
+ }
83
+
84
+ /**
85
+ * 消息来源的行标签。
86
+ *
87
+ * 这里给出的是包名,而插件页的跳转要的是 Loader 行 id,所以先按 moduleName
88
+ * 回查一次;查不到就只显示名字,不做一个跳不到任何地方的按钮。
89
+ * @param {string[]} owners - 包名列表。
90
+ * @param {object} vc - 视图上下文。
91
+ * @returns {Array<object>} 标签节点。
92
+ */
93
+ function ownerTags(owners, vc) {
94
+ if (!Array.isArray(owners) || owners.length === 0) return []
95
+ // 注册表里的 owners 可能因为多个注册点指向同一插件而重复;标签只留一份。
96
+ return [...new Set(owners)].map((owner) => {
97
+ const row = (vc.snapshot?.entries ?? []).find((entry) => entry.moduleName === owner)
98
+ if (row === undefined) return h('span', { key: owner, className: 'ptTag', title: `注册插件:${owner};快照里没有这一行` }, shortModule(owner))
99
+ return h(
100
+ 'button',
101
+ {
102
+ key: owner,
103
+ type: 'button',
104
+ className: 'ptTag ptLink',
105
+ title: `注册插件:${owner};点击查看这个插件`,
106
+ onClick: (event) => {
107
+ event.preventDefault()
108
+ event.stopPropagation()
109
+ vc.gotoPlugin(row.rowId ?? row.entryId)
110
+ },
111
+ },
112
+ shortModule(owner),
113
+ )
114
+ })
115
+ }
116
+
117
+ /** agent-instructions 的文件清单:哪些进了预算、哪些被略过。 */
118
+ function fileList(files, query) {
119
+ if (!Array.isArray(files) || files.length === 0) return null
120
+ return h(
121
+ 'ul',
122
+ { className: 'ptList', style: { margin: '8px 12px 0' } },
123
+ files.map((file) => h(
124
+ 'li',
125
+ { key: file.displayPath, className: 'ptSub', style: { margin: 0 } },
126
+ h('span', { className: 'ptDepKey' }, search.markQuery(file.displayPath, query)),
127
+ h('span', { className: 'ptCount', style: { marginLeft: '6px' } }, formatBytes(file.bytes ?? 0)),
128
+ file.included
129
+ ? h('span', { className: 'ptTag', style: { marginLeft: '6px' } }, '已包含')
130
+ : h('span', { className: 'ptTag', 'data-tone': 'warn', style: { marginLeft: '6px' } }, '被预算略过'),
131
+ file.truncated ? h('span', { className: 'ptTag', 'data-tone': 'warn', style: { marginLeft: '4px' } }, '已截断') : null,
132
+ )),
133
+ )
134
+ }
135
+
136
+ /** 上下文分段在「本模式」里的关系:同名替换 / 只在本模式出现。 */
137
+ function contextRelation(overrides, name) {
138
+ if ((overrides?.overridden ?? []).some((row) => row.name === name)) return '本模式替换'
139
+ if ((overrides?.added ?? []).some((row) => row.name === name)) return '本模式追加'
140
+ return null
141
+ }
142
+
143
+ /**
144
+ * runtime-context 的分段:每段一个可展开的子容器。
145
+ *
146
+ * 摘要给来源(order、大小、置信度、注册插件、影响条件),展开给这一段真正注入的文本;
147
+ * 没有文本时写清「无法预测」,而不是留一个空容器让人以为模型收到的是空内容。
148
+ */
149
+ function segmentList(segments, vc, query) {
150
+ if (!Array.isArray(segments) || segments.length === 0) return null
151
+ const overrides = vc.preview?.scopeOverrides?.contexts
152
+ // 实测段的归属来自上下文注册表;host 只内建了三条推导段的 owner。
153
+ const registry = new Map((vc.snapshot?.prompt?.contexts ?? []).map((row) => [row.name, row]))
154
+ const visible = segments.filter((segment) => partMatches(segment, query))
155
+ if (visible.length === 0) return null
156
+ return h(
157
+ 'ul',
158
+ { className: 'ptList', style: { margin: '8px 12px 0' } },
159
+ visible.map((segment, index) => {
160
+ const relation = contextRelation(overrides, segment.name)
161
+ const owners = (segment.owners ?? []).length > 0
162
+ ? segment.owners
163
+ : registry.get(segment.name)?.owners ?? []
164
+ const text = typeof segment.text === 'string' ? segment.text : ''
165
+ // 命中的分段自动展开,否则用户只看到一个段名,还得自己点开确认。
166
+ // 从禁用预演跳过来的分段同样要展开,并挂上滚动锚点。
167
+ const hit = search.matchesQuery(query, [segment.name, text])
168
+ const focused = vc.focusSection === segment.name
169
+ return h(
170
+ 'li',
171
+ { key: segment.name },
172
+ h(
173
+ 'details',
174
+ {
175
+ className: 'ptToolBlock ptFold ptFoldable',
176
+ ...(focused ? { open: true, id: 'pt-section-focus' } : (hit ? { open: true } : {})),
177
+ },
178
+ h(
179
+ 'summary',
180
+ null,
181
+ h('span', { className: 'ptDepKey', title: '名称:这一段在 DSH 上下文注册表里的名字' }, search.markQuery('#' + (index + 1) + ' ' + segment.name, query)),
182
+ confidenceTag(segment.confidence),
183
+ ...ownerTags(owners, vc),
184
+ relation === null
185
+ ? null
186
+ : h('span', { className: 'ptTag', title: '与全局的关系:全局有同名上下文、本模式重新注册了一份;或全局没有、只在本模式出现' }, relation),
187
+ (segment.basis ?? []).length > 0
188
+ ? h(
189
+ 'span',
190
+ {
191
+ className: 'ptTag',
192
+ // 「依据」听起来像在重复「推导」。这里改答另一个问题:改哪些条件会改这段文字。
193
+ title: '影响条件:'
194
+ + segment.basis.map((token) => BASIS_HINTS[token] ?? token).join('、'),
195
+ },
196
+ segment.basis.join(' / '),
197
+ )
198
+ : null,
199
+ segment.reason === undefined
200
+ ? null
201
+ : h('span', { className: 'ptTag', 'data-tone': 'warn', title: '预测结果:' + segment.reason }, '未预测'),
202
+ // 顺序与大小是读数,统一靠右,正文左侧只留「这是什么」。
203
+ rowEnd(
204
+ typeof segment.order === 'number'
205
+ ? h('span', { className: 'ptCount', title: '顺序:DSH order,决定这一段在 runtime-context 快照里的先后' }, 'order ' + segment.order)
206
+ : null,
207
+ h('span', { className: 'ptCount', title: '长度:这一段注入文本的字符数(按 B / KB 显示)' }, formatBytes(segment.length ?? text.length)),
208
+ ),
209
+ ),
210
+ h(
211
+ 'div',
212
+ { className: 'ptFoldBody' },
213
+ text.length === 0
214
+ ? h('p', { className: 'ptSub', style: { margin: 0 } }, UNPREDICTABLE)
215
+ : h('pre', { className: 'ptPromptText', style: { margin: 0 } }, search.markQuery(text, query)),
216
+ ),
217
+ ),
218
+ )
219
+ }),
220
+ )
221
+ }
222
+
223
+ /**
224
+ * 注册了、但没有进入这条 runtime-context 的上下文。
225
+ *
226
+ * 装配结果里文本为空的段会被 loop 过滤掉——模型收不到,所以不能说成「收到空内容」。
227
+ * 这里把它们单独列出来并写明原因,取代旧「运行时上下文」标签里的空行;每项也是
228
+ * 一个子容器,展开给统一的占位文案,免得「点开什么都没有」被当成渲染坏了。
229
+ * @param {object} vc - 视图上下文。
230
+ * @param {string} query - 页头搜索词。
231
+ * @returns {object | null} 说明块。
232
+ */
233
+ function skippedContextList(vc, query) {
234
+ const contexts = vc.preview?.contexts ?? []
235
+ const parts = vc.preview?.messages?.find((row) => row.sourceKind === 'runtime-context')?.parts ?? []
236
+ const inMessage = new Set(parts.map((row) => row.name))
237
+ const assembled = contexts.filter((row) => !inMessage.has(row.name))
238
+ const assembledNames = new Set(contexts.map((row) => row.name))
239
+ const registry = new Map((vc.snapshot?.prompt?.contexts ?? []).map((row) => [row.name, row]))
240
+ const unassembled = (vc.snapshot?.prompt?.contexts ?? []).filter((row) => !assembledNames.has(row.name))
241
+ if (assembled.length === 0 && unassembled.length === 0) return null
242
+ const rows = [
243
+ ...assembled.map((row) => ({
244
+ name: row.name,
245
+ length: row.length,
246
+ // 标签只回答「为什么没有文本」;「模型收不到」是这份列表本身的意思,不再重复。
247
+ reason: '内容为空',
248
+ owners: registry.get(row.name)?.owners ?? [],
249
+ })),
250
+ ...unassembled.map((row) => ({
251
+ name: row.name,
252
+ length: undefined,
253
+ reason: '没有进入本次装配(注册条件未满足,或被 complete 独占段挡住)',
254
+ owners: row.owners ?? [],
255
+ })),
256
+ ]
257
+ const visible = rows.filter((row) => search.matchesQuery(query, [row.name, row.reason]))
258
+ if (visible.length === 0) return null
259
+ return h(
260
+ 'div',
261
+ { style: { margin: '10px 12px 0' } },
262
+ h(
263
+ 'ul',
264
+ { className: 'ptList', style: { margin: '4px 0 0' } },
265
+ visible.map((row) => h(
266
+ 'li',
267
+ { key: row.name },
268
+ h(
269
+ 'details',
270
+ {
271
+ className: 'ptToolBlock ptFold ptFoldable',
272
+ ...(vc.focusSection === row.name ? { open: true, id: 'pt-section-focus' } : {}),
273
+ },
274
+ h(
275
+ 'summary',
276
+ null,
277
+ h('span', { className: 'ptDepKey' }, search.markQuery(row.name, query)),
278
+ ...ownerTags(row.owners, vc),
279
+ h('span', { className: 'ptTag', 'data-tone': 'warn', title: '原因:' + row.reason }, row.reason),
280
+ row.length === undefined
281
+ ? null
282
+ : rowEnd(h('span', { className: 'ptCount', title: '长度:这一项已知部分的字符数(按 B / KB 显示)' }, formatBytes(row.length))),
283
+ ),
284
+ h(
285
+ 'div',
286
+ { className: 'ptFoldBody' },
287
+ h('p', { className: 'ptSub', style: { margin: 0 } }, UNPREDICTABLE),
288
+ ),
289
+ ),
290
+ )),
291
+ ),
292
+ )
293
+ }
294
+
295
+ /** skill 目录条目:与其它页面一致的 `#N 名称` 折叠行。 */
296
+ function skillList(entries, query) {
297
+ if (!Array.isArray(entries) || entries.length === 0) return null
298
+ const visible = entries.filter((entry) => partMatches(entry, query))
299
+ if (visible.length === 0) return null
300
+ return h(
301
+ 'ul',
302
+ { className: 'ptList', style: { margin: '8px 12px 0' } },
303
+ visible.map((entry, index) => h(
304
+ 'li',
305
+ { key: entry.name },
306
+ h(
307
+ 'details',
308
+ {
309
+ className: 'ptToolBlock ptFold ptFoldable',
310
+ ...(search.matchesQuery(query, [entry.name, entry.description]) ? { open: true } : {}),
311
+ },
312
+ h(
313
+ 'summary',
314
+ null,
315
+ h('span', { className: 'ptDepKey' }, search.markQuery('#' + (index + 1) + ' ' + entry.name, query)),
316
+ entry.provider === undefined ? null : h('span', { className: 'ptTag', title: '托管这个 skill 的服务的provider' }, entry.provider),
317
+ // 来源也是目录条目的一行事实,和 provider 并排放在摘要上,展开只留描述。
318
+ entry.source === undefined ? null : h('span', { className: 'ptTag', title: '来源,这个目录条目从哪里来' }, String(entry.source)),
319
+ ),
320
+ h(
321
+ 'div',
322
+ { className: 'ptFoldBody' },
323
+ h('p', { className: 'ptToolDesc', style: { margin: 0 } }, search.markQuery(entry.description ?? '', query)),
324
+ ),
325
+ ),
326
+ )),
327
+ )
328
+ }
329
+
330
+ /** 一条消息。 */
331
+ function messageRow(message, index, vc, query, searching) {
332
+ const parts = message.sourceKind === 'agent-instructions'
333
+ ? fileList(message.parts, query)
334
+ : message.sourceKind === 'runtime-context'
335
+ // 注册表视图并进这一条消息:它是 messages 里的一条,不是 messages 的兄弟。
336
+ ? h(React.Fragment, null, segmentList(message.parts, vc, query), skippedContextList(vc, query))
337
+ : message.sourceKind === 'skill-catalog'
338
+ ? skillList(message.parts, query)
339
+ : null
340
+ const hint = summaryHint(message)
341
+ // 目标分段在折叠的消息里时,外层消息必须一起展开,否则锚点不可见。
342
+ const focusedPart = vc.focusSection !== null && vc.focusSection !== undefined
343
+ && (message.parts ?? []).some((part) => part.name === vc.focusSection)
344
+ // user 与 time-context 只保留原文:它们的机制/依据不解释任何模型可见内容。
345
+ const mechanism = MECHANISM_IN_BODY.has(message.sourceKind)
346
+ ? h(
347
+ 'p',
348
+ { className: 'ptSub', style: { margin: 0 } },
349
+ '机制 ' + message.mechanism,
350
+ (message.basis ?? []).length > 0 ? ' · 依据 ' + message.basis.join(' / ') : '',
351
+ message.unavailable === undefined ? '' : ' · ' + message.unavailable.reason,
352
+ )
353
+ : null
354
+ // 原文前面还有别的行时留一点间距;单独一条原文就贴着内边距。
355
+ const text = message.length > 0
356
+ ? h(
357
+ 'pre',
358
+ { className: 'ptPromptText', style: { marginTop: mechanism !== null || parts !== null ? '8px' : 0 } },
359
+ search.markQuery(message.text, query),
360
+ )
361
+ : null
362
+ // 什么都没有时不留一个空的内边距块(首条消息未填写就是一个空的 user 容器)。
363
+ const body = [mechanism, parts, text].filter((node) => node !== null && node !== undefined)
364
+ return h(
365
+ 'li',
366
+ { key: message.sourceKind + '-' + message.index },
367
+ h(
368
+ 'details',
369
+ {
370
+ className: 'ptPromptBlock ptFold ptFoldable',
371
+ // 筛选激活时列出来的每一条都命中过,展开才能看到命中处;平时只展开第一条。
372
+ ...(index === 0 || searching || focusedPart ? { open: true } : {}),
373
+ },
374
+ h(
375
+ 'summary',
376
+ hint === null ? null : { title: hint },
377
+ h('span', { className: 'ptCount', style: { minWidth: '28px', display: 'inline-block' } }, '#' + message.index),
378
+ h('span', { className: 'ptPromptName' }, search.markQuery(message.sourceKind, query)),
379
+ h('span', { className: 'ptTag', title: '角色,这条消息在请求里的角色' }, message.role),
380
+ ...ownerTags(message.owners, vc),
381
+ message.incomplete === true
382
+ ? h('span', { className: 'ptTag', 'data-tone': 'warn', title: '状态:有些 skill 没能确认;模型会看到同样的不完整提示' }, '不完整')
383
+ : null,
384
+ confidenceTag(message.confidence),
385
+ // 长度是读数,统一靠右。
386
+ rowEnd(h('span', { className: 'ptCount', title: '长度,这条消息的字符数' }, formatBytes(message.length))),
387
+ ),
388
+ body.length > 0 ? h('div', { className: 'ptFoldBody' }, ...body) : null,
389
+ ),
390
+ )
391
+ }
392
+
393
+ /** 没有注入的消息类型:页面必须能回答「为什么没有这一条」。 */
394
+ function renderSkippedLine(skipped) {
395
+ if (!Array.isArray(skipped) || skipped.length === 0) return null
396
+ return h(
397
+ 'p',
398
+ { className: 'ptHint', style: { marginTop: '10px' } },
399
+ '未注入的消息类型:',
400
+ ...skipped.map((row) => h(
401
+ 'span',
402
+ { key: row.sourceKind, className: 'ptTag', style: { marginLeft: '4px' }, title: row.reason },
403
+ row.sourceKind + ' · ' + row.reason,
404
+ )),
405
+ )
406
+ }
407
+
408
+ /** `/name` 带出来的 skill 把资源放在哪:目录 / URL / provider 托管。 */
409
+ function resourceBaseText(parts) {
410
+ const base = (parts ?? [])[0]?.resourceBase
411
+ if (base === undefined) return '资源由 provider 托管'
412
+ if (base.kind === 'directory') return '资源目录 ' + base.path
413
+ if (base.kind === 'url') return '资源 URL ' + base.url
414
+ return '资源:' + (base.description ?? '')
415
+ }
416
+
417
+ /** 容器标题上的悬停提示:正文里不再单独占行的来源信息。 */
418
+ function summaryHint(message) {
419
+ if (message.sourceKind === 'skill-catalog') return CATALOG_SOURCE_HINT
420
+ if (message.sourceKind === 'skill-invocation') return resourceBaseText(message.parts)
421
+ return null
422
+ }
423
+
424
+ /** 首条消息草稿:决定 user 消息正文与 `/name` 展开。 */
425
+ function draftEditor(vc) {
426
+ return h(
427
+ 'div',
428
+ { style: { margin: '0 0 10px' } },
429
+ h('label', { className: 'ptEditorLabel', style: { display: 'block', marginBottom: '4px' } }, '首条消息草稿(可选)'),
430
+ h('textarea', {
431
+ className: 'ptEditor',
432
+ style: { minHeight: '56px' },
433
+ value: vc.previewDraft ?? '',
434
+ placeholder: '在此的输入可能影响运行时注入',
435
+ onChange: (event) => vc.setPreviewDraft(event.target.value),
436
+ }),
437
+ h(
438
+ 'div',
439
+ { className: 'ptActions', style: { marginTop: '6px' } },
440
+ h(
441
+ 'button',
442
+ {
443
+ type: 'button',
444
+ className: 'ptBtn',
445
+ disabled: vc.previewStatus === 'loading',
446
+ onClick: () => vc.applyDraft(),
447
+ },
448
+ vc.previewStatus === 'loading' ? '求值中…' : '按草稿重算',
449
+ ),
450
+ ),
451
+ )
452
+ }
453
+
454
+ /**
455
+ * @param {object} vc - 视图上下文。
456
+ * @returns {object} 消息标签的 React 节点。
457
+ */
458
+ function renderMessagesView(vc) {
459
+ const all = vc.preview?.messages ?? []
460
+ const query = vc.query ?? ''
461
+ // 这份标签以前完全不读 query:页头写着能搜消息,输入任何词都没有变化。
462
+ const searching = search.normalizeQuery(query) !== ''
463
+ const messages = searching ? all.filter((message) => messageMatches(message, query)) : all
464
+ // 定制页的「预览定制结果」复用这份视图,但那里没有预演页的草稿输入。
465
+ const interactive = typeof vc.setPreviewDraft === 'function'
466
+ return h(
467
+ 'div',
468
+ null,
469
+ interactive ? draftEditor(vc) : null,
470
+ vc.preview?.conditions?.workspace === null || vc.preview?.conditions?.workspace === undefined
471
+ ? h(
472
+ 'p',
473
+ { className: 'ptHint' },
474
+ h('span', { className: 'ptTag', 'data-tone': 'warn' }, '未指定工作区'),
475
+ ' skill 目录、workspace 指令与 cwd / sandbox / approval 文本都由工作区决定,现在无法推导。',
476
+ )
477
+ : null,
478
+ messages.length > 0
479
+ ? h(
480
+ 'div',
481
+ null,
482
+ // 「展开全部」连消息里的分段 / skill 条目一起打开:那是这一页真正的正文,
483
+ // 只开外层等于让人再点一遍。折叠是显示状态,不写回任何数据。
484
+ h(
485
+ 'div',
486
+ { className: 'ptSectionHead' },
487
+ h('span', { className: 'ptMeta' }, '按发送顺序排列,逐条可折叠'),
488
+ h(
489
+ 'div',
490
+ { className: 'ptActions' },
491
+ textButton('折叠全部', () => setDetailsOpen(foldNodes(), false), { title: '收起本标签里的全部消息与分段' }),
492
+ textButton('展开全部', () => setDetailsOpen(foldNodes(), true), { title: '展开本标签里的全部消息与分段' }),
493
+ ),
494
+ ),
495
+ h('ul', { className: 'ptList' }, messages.map((message, index) => messageRow(message, index, vc, query, searching))),
496
+ )
497
+ : searching
498
+ ? search.renderQueryEmpty({ noun: '消息', onClear: () => vc.setQuery('') })
499
+ : h('p', { className: 'ptEmpty' }, '没有可预测的消息。'),
500
+ )
501
+ }
502
+
503
+ return { renderMessagesView, renderSkippedLine }
504
+ }
505
+ },
506
+ })
@@ -0,0 +1,132 @@
1
+ /**
2
+ * 预演页的「请求结构」标签:按一次真实请求的三块结构展示 system、messages 与 tools。
3
+ *
4
+ * 内容会很长,所以每段独立折叠;顶部的全收 / 全开按钮直接操作 `.ptRawBlock`。
5
+ * 页内多词搜索也从这里接入:工具行在正文构建完成后才生成,才能拿到完整命中数。
6
+ *
7
+ * 本文件是一个包内 chunk:入口用 `require.async('./client.preview-raw.js')` 取它。
8
+ */
9
+
10
+ window.__ModuleLoader__.load({
11
+ id: '@cheemsup/dsh-plugin-console',
12
+ chunk: 'client.preview-raw.js',
13
+ factory: (require) => {
14
+ const React = require('react')
15
+ const { createElement: h } = React
16
+
17
+ return function create(deps) {
18
+ const { formatBytes, textButton, rowEnd, foldNodes, setDetailsOpen, search } = deps
19
+
20
+ /**
21
+ * 请求结构里的一段内容:独立折叠,默认展开。
22
+ *
23
+ * 默认展开是为了保留原来的可读性——这一段是「真实请求长这样」的证据,不是导航;
24
+ * 折叠用来在很长的 system / messages 之间跳读,所以每段都带箭头与右侧长度。
25
+ * @param {string} key - React key。
26
+ * @param {string} name - 主名,如 `messages[2]`。
27
+ * @param {string[]} tags - 次要标签(sourceKind / role / 项数)。
28
+ * @param {string} size - 右侧的长度读数。
29
+ * @param {object} body - 展开后的内容。
30
+ * @returns {object} React 节点。
31
+ */
32
+ function rawBlock(key, name, tags, size, body) {
33
+ return h(
34
+ 'details',
35
+ { key, className: 'ptPromptBlock ptFold ptFoldable ptRawBlock', open: true },
36
+ h(
37
+ 'summary',
38
+ null,
39
+ h('span', { className: 'ptFoldChevron', 'aria-hidden': 'true' }, '▶'),
40
+ h('span', { className: 'ptPromptName' }, name),
41
+ ...tags.map((tag) => h('span', { key: tag, className: 'ptTag' }, tag)),
42
+ rowEnd(h('span', { className: 'ptCount', title: '长度,这段内容的字符数' }, size)),
43
+ ),
44
+ body,
45
+ )
46
+ }
47
+
48
+ /**
49
+ * 渲染请求结构:system → 每条消息 → tools → envelope。
50
+ *
51
+ * 搜索只标正文:标题、标签与 envelope 不参与,避免把结构读数当成提示词内容。
52
+ * @param {object} preview - 预演结果。
53
+ * @param {object} vc - 视图上下文(页内搜索状态在这里)。
54
+ * @returns {object} React 节点。
55
+ */
56
+ function renderRawStructure(preview, vc) {
57
+ const state = vc?.previewSearch
58
+ const hl = search.createHighlighter(Array.isArray(state?.items) ? state.items : [])
59
+ const blocks = [
60
+ rawBlock(
61
+ 'system',
62
+ 'messages[0]',
63
+ ['role=system'],
64
+ formatBytes(preview.systemText.length),
65
+ h('pre', { className: 'ptPromptText' }, hl.text(preview.systemText)),
66
+ ),
67
+ // 这里按**真实顺序**列出消息。早先版本把 messages[1..] 统一标成 runtime context,
68
+ // 而实际上它们依次是 user / agent-instructions / runtime-context / skill-catalog / time-context。
69
+ ...(preview.messages ?? []).map((message) => rawBlock(
70
+ 'message-' + message.index,
71
+ 'messages[' + message.index + ']',
72
+ [message.sourceKind, 'role=' + message.role],
73
+ formatBytes(message.length),
74
+ message.length > 0
75
+ ? h('pre', { className: 'ptPromptText' }, hl.text(message.text))
76
+ : h('p', { className: 'ptSub', style: { margin: 0, padding: '10px 12px' } }, '(未输入首条消息)'),
77
+ )),
78
+ rawBlock(
79
+ 'tools',
80
+ 'tools',
81
+ [preview.tools.length + ' 项'],
82
+ formatBytes(preview.stats.toolSchemaChars),
83
+ h(
84
+ 'pre',
85
+ { className: 'ptPromptText' },
86
+ hl.text(JSON.stringify(
87
+ preview.tools.map((tool) => ({
88
+ name: tool.name,
89
+ description: tool.description,
90
+ parameters: tool.parameters,
91
+ })),
92
+ null,
93
+ 2,
94
+ )),
95
+ ),
96
+ ),
97
+ ]
98
+ return h(
99
+ 'div',
100
+ null,
101
+ // 请求结构会很长:每一段都可折叠,顶部再给一次全收 / 全开。
102
+ h(
103
+ 'div',
104
+ { className: 'ptSectionHead' },
105
+ h('span', { className: 'ptMeta' }, '按真实发送顺序,逐段可折叠'),
106
+ h(
107
+ 'div',
108
+ { className: 'ptActions' },
109
+ textButton('折叠全部', () => setDetailsOpen(foldNodes('.ptBody details.ptRawBlock'), false), { title: '收起请求结构里的所有内容段' }),
110
+ textButton('展开全部', () => setDetailsOpen(foldNodes('.ptBody details.ptRawBlock'), true), { title: '展开请求结构里的所有内容段' }),
111
+ ),
112
+ ),
113
+ // 工具行放在正文之后构建:这时 hl.counts 才统计完所有块。
114
+ state ? search.renderSearchBar(state, hl.counts, hl.capped) : null,
115
+ ...blocks,
116
+ preview.messages === undefined
117
+ ? h('p', { className: 'ptSub' }, '消息未采集:这份响应来自旧版本')
118
+ : null,
119
+ h(
120
+ 'p',
121
+ { className: 'ptSectionTitle', style: { marginTop: '14px' } },
122
+ `request envelope · provider=${preview.envelope?.provider ?? '未知'} · model=${preview.envelope?.model ?? '未知'}`
123
+ + ` · contextWindow=${preview.envelope?.contextWindow === null || preview.envelope?.contextWindow === undefined ? '未知' : preview.envelope.contextWindow.toLocaleString()}`
124
+ + ' —— 不进 messages,是请求本身的字段',
125
+ ),
126
+ )
127
+ }
128
+
129
+ return { renderRawStructure }
130
+ }
131
+ },
132
+ })