dsh-remote-plugin 0.7.4 → 0.7.6

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/public/index.html CHANGED
@@ -14,6 +14,8 @@
14
14
  <link rel="stylesheet" href="styles.css">
15
15
  <link rel="stylesheet" href="genui.css">
16
16
  <link rel="stylesheet" href="plugin-center.css">
17
+ <link rel="stylesheet" href="skills.css">
18
+ <link rel="stylesheet" href="extensions.css">
17
19
  <link rel="stylesheet" href="insights.css">
18
20
  </head>
19
21
  <body>
@@ -749,7 +751,7 @@
749
751
  <div class="session-dialog-head"><strong id="session-actions-title" data-i18n="session.more">更多操作</strong><button type="button" data-session-dialog-close aria-label="关闭">×</button></div>
750
752
  <button id="btn-rename-session" class="icon-btn hidden" data-i18n-title="session.rename" data-i18n-aria="session.rename" data-i18n="session.rename">重命名会话</button>
751
753
  <button id="btn-stats" class="icon-btn" data-i18n-title="stats.title" data-i18n-aria="stats.title" data-i18n="stats.title">本轮统计</button>
752
- <button id="btn-insights" class="icon-btn" data-i18n-title="insights.title" data-i18n-aria="insights.title" data-i18n="insights.title">上下文与费用</button>
754
+ <button id="btn-insights" class="icon-btn hidden" data-i18n-title="insights.title" data-i18n-aria="insights.title" data-i18n="insights.title">上下文与费用</button>
753
755
 
754
756
  <button id="btn-session-info" type="button" data-i18n="session.details">会话详情</button>
755
757
  <button id="btn-archive-session" class="mini-btn hidden" data-i18n="session.archive">归档</button>
@@ -983,7 +985,7 @@
983
985
  'session.stop': '停止本轮', 'session.history': '对话', 'session.errorMsg': '会话出错:{msg}', 'session.recovering': '恢复会话中…', 'session.recoveryReady': '会话已恢复', 'session.recoveryFailed': '会话恢复失败', 'session.recoveryCached': '正在查看缓存历史',
984
986
  'session.confirmStop': '停止当前回合?排队中的消息不会被删除。', 'session.stopFailed': '停止失败', 'session.stopRequested': '已请求停止本轮', 'session.archive': '归档', 'session.archiveConfirm': '归档这个会话?归档后可在“显示已归档会话”中打开。', 'session.archiveFailed': '归档失败:{msg}', 'session.archived': '会话已归档', 'session.archiveTitle': '确认归档会话', 'session.archiveDesc': '归档后会话将从普通列表隐藏,但不会删除对话记录。', 'session.archiveConversation': '对话', 'session.archiveWorkspace': '工作区', 'session.archiveCancel': '取消', 'session.archiveConfirmAction': '确认归档', 'session.rename': '重命名会话', 'session.renameTitle': '重命名会话', 'session.renamePlaceholder': '输入新的会话名称', 'session.renameCancel': '取消', 'session.renameConfirm': '保存', 'session.renameEmpty': '会话名称不能为空', 'session.renameFailed': '重命名失败', 'session.renamed': '会话名称已更新',
985
987
  'notify.approvalTitle': '工具审批', 'notify.approvalBody': '{tool} 需要批准', 'notify.questionTitle': 'DSH 提问', 'notify.questionBody': '需要你回答',
986
- 'notify.permissionFailed': '通知权限申请失败:{msg}',
988
+ 'notify.permissionFailed': '通知权限申请失败:{msg}', 'notify.hostUnavailable': '此通知所属服务器已移除或令牌已变更,请重新连接后查看待处理事项',
987
989
  'history.cached': '本地缓存', 'history.syncing': '本地缓存 · 正在同步', 'history.synced': '最新记录已同步', 'history.saved': '最新记录 · 已缓存', 'history.offline': '本地记录 · 网络不可用', 'history.earlier': '加载更早的记录', 'history.loadingEarlier': '正在加载更早的记录…', 'history.latest': '回到最新', 'history.cacheFailed': '已同步 · 本地缓存未保存', 'history.loading': '加载历史…', 'history.cacheFallback': '网络不可用:显示本地缓存的历史', 'history.loadFailed': '加载历史失败:{msg}', 'history.retry': '重试',
988
990
  'history.offlineCache': '离线缓存 {n} 条', 'history.count': '{n} 条', 'history.empty': '还没有消息',
989
991
  'history.queueAndCount': '队列 {q} · 历史 {n}', 'history.countOnly': '历史 {n}',
@@ -994,6 +996,8 @@
994
996
  'block.image': '图片', 'block.thinking': '🧠 思考过程', 'block.thinkingLive': '🧠 思考中…', 'block.toolCall': '工具调用', 'block.toolResult': '工具结果', 'block.unknown': '块 · {type}',
995
997
  'truncated': '…(截断)',
996
998
  'insights.title': '上下文与费用',
999
+ 'insights.contextTitle': '上下文分析',
1000
+ 'insights.costTitle': '费用与额度',
997
1001
  'stats.title': '本轮统计', 'stats.roundTitle': '本轮统计', 'stats.turnsSteps': '轮次 / 步骤',
998
1002
  'stats.llmTime': '模型耗时', 'stats.minutes': ' 分钟', 'stats.outputCache': '输出 / 缓存读',
999
1003
  'stats.ctxPressure': '上下文压力', 'stats.permission': '权限', 'stats.empty': '暂无统计数据',
@@ -1222,7 +1226,7 @@
1222
1226
  'session.stop': 'Stop turn', 'session.history': 'Conversation', 'session.errorMsg': 'Session error: {msg}', 'session.recovering': 'Restoring session…', 'session.recoveryReady': 'Session ready', 'session.recoveryFailed': 'Session restore failed', 'session.recoveryCached': 'Viewing cached history',
1223
1227
  'session.confirmStop': 'Stop the current turn? Queued messages will be kept.', 'session.stopFailed': 'Stop failed', 'session.stopRequested': 'Stop requested', 'session.archive': 'Archive', 'session.archiveConfirm': 'Archive this session? You can open it from “Show archived”.', 'session.archiveFailed': 'Archive failed: {msg}', 'session.archived': 'Session archived', 'session.archiveTitle': 'Confirm archive', 'session.archiveDesc': 'The session will be hidden from the normal list, but its conversation will not be deleted.', 'session.archiveConversation': 'Conversation', 'session.archiveWorkspace': 'Workspace', 'session.archiveCancel': 'Cancel', 'session.archiveConfirmAction': 'Archive session', 'session.rename': 'Rename session', 'session.renameTitle': 'Rename session', 'session.renamePlaceholder': 'Enter a new session name', 'session.renameCancel': 'Cancel', 'session.renameConfirm': 'Save', 'session.renameEmpty': 'Session name cannot be empty', 'session.renameFailed': 'Rename failed', 'session.renamed': 'Session name updated',
1224
1228
  'notify.approvalTitle': 'Tool approval', 'notify.approvalBody': '{tool} needs approval', 'notify.questionTitle': 'DSH question', 'notify.questionBody': 'Needs your answer',
1225
- 'notify.permissionFailed': 'Notification permission failed: {msg}',
1229
+ 'notify.permissionFailed': 'Notification permission failed: {msg}', 'notify.hostUnavailable': 'This notification belongs to a removed server or changed credential. Reconnect to view pending requests.',
1226
1230
  'history.cached': 'Local cache', 'history.syncing': 'Local cache · Syncing', 'history.synced': 'Latest history synced', 'history.saved': 'Latest history · Cached', 'history.offline': 'Local history · Offline', 'history.earlier': 'Load earlier history', 'history.loadingEarlier': 'Loading earlier history…', 'history.latest': 'Jump to latest', 'history.cacheFailed': 'Synced · Cache could not be saved', 'history.loading': 'Loading history…', 'history.cacheFallback': 'Network unavailable: showing cached history', 'history.loadFailed': 'Failed to load history: {msg}', 'history.retry': 'Retry',
1227
1231
  'history.offlineCache': 'Offline cache {n} items', 'history.count': '{n} items', 'history.empty': 'No messages yet',
1228
1232
  'history.queueAndCount': 'Queue {q} · History {n}', 'history.countOnly': 'History {n}',
@@ -1233,6 +1237,8 @@
1233
1237
  'block.image': 'Image', 'block.thinking': '🧠 Thinking', 'block.thinkingLive': '🧠 Thinking…', 'block.toolCall': 'Tool call', 'block.toolResult': 'Tool result', 'block.unknown': 'Block · {type}',
1234
1238
  'truncated': '…(truncated)',
1235
1239
  'insights.title': 'Context & costs',
1240
+ 'insights.contextTitle': 'Context analysis',
1241
+ 'insights.costTitle': 'Cost & quotas',
1236
1242
  'stats.title': 'This round', 'stats.roundTitle': 'This round', 'stats.turnsSteps': 'Turns / steps',
1237
1243
  'stats.llmTime': 'LLM time', 'stats.minutes': ' min', 'stats.outputCache': 'Output / cache read',
1238
1244
  'stats.ctxPressure': 'Context pressure', 'stats.permission': 'Permission', 'stats.empty': 'No stats yet',
@@ -1397,12 +1403,15 @@
1397
1403
  <script src="i18n.js"></script>
1398
1404
  <script src="theme.js"></script>
1399
1405
  <script src="genui.js"></script>
1406
+ <script src="chat-files.js"></script>
1400
1407
  <script src="md.js"></script>
1401
1408
  <script src="vendor/gsap/gsap.min.js"></script>
1402
1409
  <script src="motion.js"></script>
1403
1410
  <script type="module" src="morphicons-init.js"></script>
1404
1411
  <script src="plugin-center.js"></script>
1412
+ <script src="skills.js"></script>
1405
1413
  <script src="insights.js"></script>
1414
+ <script src="extensions.js"></script>
1406
1415
  <script src="history.js"></script>
1407
1416
  <script src="link-check.js"></script>
1408
1417
  <script src="network.js"></script>
@@ -12,3 +12,5 @@
12
12
  @media(max-width:560px){.ins-dialog{width:100%;max-width:100%;height:88dvh;max-height:88dvh;margin:auto 0 0;border-radius:20px 20px 0 0;border-bottom:0}.ins-header{padding:20px 18px 14px}.ins-tabs{padding:0 18px 14px;gap:6px}.ins-tabs button{padding:8px 12px;font-size:13px}.ins-content{padding:16px 14px max(20px,env(safe-area-inset-bottom))}.ins-section{padding:16px}.ins-metric strong{font-size:20px}.ins-category{grid-template-columns:76px minmax(0,1fr) 58px;gap:8px}.ins-events li>div{flex-wrap:wrap;gap:4px}.ins-badge{font-size:9px}}
13
13
  @media(prefers-reduced-motion:reduce){.ins-dialog::backdrop{backdrop-filter:none}}
14
14
  .ins-tabs [aria-selected=true]{color:var(--dsr-on-accent,#fff)}
15
+ .ins-page{width:100%;max-height:none;border:0;box-shadow:none;background:transparent;display:flex;flex-direction:column}.ins-page .ins-header{padding:0 0 18px}.ins-page .ins-tabs{padding:0 0 16px;flex-wrap:wrap}.ins-page .ins-content{max-height:calc(100dvh - 300px);min-height:260px;padding:18px 0}.ins-page .ins-tabs select{max-width:100%;padding:10px;border:1px solid var(--dsr-line);border-radius:10px;background:var(--dsr-panel);color:var(--dsr-text)}.ins-page .ins-header h2{font-size:24px}.ins-page .ins-metrics{grid-template-columns:repeat(auto-fit,minmax(160px,1fr))}@media(max-width:620px){.ins-page .ins-content{max-height:calc(100dvh - 330px)}}
16
+ .ins-full-page{width:min(1060px,calc(100vw - 24px));max-height:94dvh;height:94dvh}.ins-full-page .ins-content{flex:1;min-height:0}.ins-full-page [data-ins-close]{font-size:14px;padding:10px 16px}.ins-full-page .ins-tabs select{color:var(--dsr-text);background:var(--dsr-panel);border:1px solid var(--dsr-line);border-radius:10px;min-height:44px;padding:8px 12px}.ins-dialog [hidden]{display:none!important}
@@ -7,9 +7,9 @@
7
7
  const categories = ['system', 'tools', 'user', 'inject', 'skill', 'assistant', 'tool']
8
8
  const labels = {
9
9
  zh: { title: '会话洞察', context: '上下文', cost: '费用与额度', close: '关闭', refresh: '刷新', loading: '正在读取…',
10
- none: '选择一个会话后查看洞察。', missing: '此主机尚未提供 dsh-context 数据。请安装并启用插件后刷新。',
10
+ none: '选择一个会话后查看洞察。', missing: '当前连接暂未提供此会话的上下文数据。',
11
11
  unavailable: '读取失败,请重试。已有概览仍可查看。', unsupported: '当前插件或 DSH 版本暂不支持此数据格式。',
12
- costMissing: '此主机尚未提供费用数据。需要启用 dsh-cost-meter,并更新主机端 Remote 插件。',
12
+ costMissing: '当前连接暂未提供费用数据,可返回插件列表查看运行状态。',
13
13
  occupancy: '上下文占用', modelName: '当前模型', estimated: '组成 Token 为插件估算;占用优先使用 DSH 官方投影。',
14
14
  system: '系统提示', tools: '工具定义', user: '用户消息', inject: '注入内容', skill: '技能', assistant: '助手消息', tool: '工具结果',
15
15
  composition: '当前组成', events: '最近上下文变化', noEvents: '尚无压缩、裁剪或注入记录。',
@@ -22,9 +22,9 @@
22
22
  error: '供应商查询失败', stale: '缓存数据', unknown: '暂无有效数据', unlimited: '不限量', reset: '重置',
23
23
  rolling: '滚动窗口', weekly: '每周', monthly: '每月', date: '主机记账日', details: '明细' },
24
24
  en: { title: 'Session insights', context: 'Context', cost: 'Cost & quotas', close: 'Close', refresh: 'Refresh', loading: 'Loading…',
25
- none: 'Select a session to view insights.', missing: 'This host has no dsh-context data. Enable the plugin, then refresh.',
25
+ none: 'Select a session to view insights.', missing: 'Context data for this session is not available on this connection.',
26
26
  unavailable: 'Could not read data. Retry; the current overview is still available.', unsupported: 'This plugin or DSH version uses an unsupported data format.',
27
- costMissing: 'Enable dsh-cost-meter and update the host Remote plugin to read costs.', occupancy: 'Context occupancy', modelName: 'Current model',
27
+ costMissing: 'Cost data is unavailable on this connection. Check its status in the installed plugins.', occupancy: 'Context occupancy', modelName: 'Current model',
28
28
  estimated: 'Composition tokens are plugin estimates; occupancy uses the DSH projection when available.',
29
29
  system: 'System prompt', tools: 'Tool definitions', user: 'User messages', inject: 'Injections', skill: 'Skills', assistant: 'Assistant', tool: 'Tool results',
30
30
  composition: 'Current composition', events: 'Recent context changes', noEvents: 'No compaction, pruning or injection records yet.',
@@ -60,7 +60,7 @@
60
60
  const value = num(percent)
61
61
  return value === null ? '' : `<div class="ins-progress" role="progressbar" aria-label="${esc(label)}" aria-valuemin="0" aria-valuemax="100" aria-valuenow="${Math.min(value, 100)}"><span style="width:${Math.min(value, 100)}%"></span></div>`
62
62
  }
63
- function contextHtml(session, detail, detailStatus) {
63
+ function contextHtml(session, detail, detailStatus, settings = {}) {
64
64
  const values = obj(session?.projections?.values) || {}, head = contextOf(values.contextTimeline)
65
65
  // Only combine a detail with the projection revision that requested it.
66
66
  const compatible = detail && (!head || head.detailRev === detail.rev)
@@ -84,15 +84,19 @@
84
84
  html += `<section class="ins-section"><h3>${esc(t('events'))}</h3>`
85
85
  if (head?.detailRev !== undefined && !compatible) html += `<p class="ins-note">${esc(t(detailStatus === 'loading' ? 'detailsLoading' : 'detailsFailed'))}</p>`
86
86
  else if (!Array.isArray(events) || !events.length) html += `<p class="ins-note">${esc(t('noEvents'))}</p>`
87
- else html += '<ol class="ins-events">' + events.filter(row => obj(row) && ['compaction', 'prune', 'inject', 'model', 'mode'].includes(row.kind)).slice(-8).reverse().map(row => `<li><div><strong>${esc(t(row.kind))}</strong><time>${esc(time(row.time))}</time></div><span>${esc(row.name || row.sub || '')}${num(row.tokens) !== null ? ' · ' + tokens(row.tokens) + ' tokens' : ''}</span></li>`).join('') + '</ol>'
87
+ else {
88
+ const rows = events.filter(row => obj(row) && ['compaction', 'prune', 'inject', 'model', 'mode'].includes(row.kind) && (!settings.kind || row.kind === settings.kind))
89
+ if (settings.full) html += `<p class="ins-note">${lang === 'en' ? 'Host change records' : '主机提供的变化记录'} · ${rows.length}${rows.length > 500 ? (lang === 'en' ? ' · Showing latest 500' : ' · 显示最近 500 条') : ''}</p>`
90
+ html += '<ol class="ins-events">' + rows.slice(settings.full ? -500 : -8).reverse().map(row => `<li><div><strong>${esc(t(row.kind))}</strong><time>${esc(time(row.time))}</time></div><span>${esc(row.name || row.sub || '')}${num(row.tokens) !== null ? ' · ' + tokens(row.tokens) + ' tokens' : ''}</span></li>`).join('') + '</ol>'
91
+ }
88
92
  return html + `</section><p class="ins-source">${esc(t('source'))} · dsh-context / DSH</p>`
89
93
  }
90
- function costHtml(raw, phase) {
94
+ function costHtml(raw, phase, overview = false) {
91
95
  const data = costOf(raw)
92
96
  if (!data) return `<p class="ins-empty">${esc(t(phase === 'loading' ? 'loading' : phase === 'error' ? 'unavailable' : raw?.available === false ? 'costMissing' : 'unsupported'))}</p>`
93
97
  const own = data.session?.found === true ? data.session.own : null
94
98
  let html = (phase === 'error' ? `<p role="status" class="ins-note">${esc(t('unavailable'))}</p>` : '') + `<section class="ins-section"><div class="ins-section-head"><h3>${esc(t('cost'))}</h3><span class="ins-badge">dsh-cost-meter</span></div><div class="ins-metrics">
95
- ${metric(t('session'), money(own?.apiCost), own ? '' : t('sessionMissing'))}${metric(t('today'), money(data.today?.apiCost), data.day ? t('date') + ' · ' + data.day : '')}
99
+ ${overview ? '' : metric(t('session'), money(own?.apiCost), own ? '' : t('sessionMissing'))}${metric(t('today'), money(data.today?.apiCost), data.day ? t('date') + ' · ' + data.day : '')}
96
100
  ${own && num(own.cost) !== null && own.cost !== own.apiCost ? metric(t('equivalent'), money(own.cost)) : ''}
97
101
  ${num(data.session?.subagentCount) > 0 ? metric(t('subagents'), money(data.session?.subagents?.apiCost)) : ''}</div><p class="ins-note">${esc(t('estimateNote'))}</p></section>`
98
102
  if (obj(data.balance)) {
@@ -122,16 +126,19 @@
122
126
  return html + `</section><p class="ins-source">${esc(t('source'))} · dsh-cost-meter<br>${esc(t('assembled'))} · ${esc(time(data.generatedAt))}</p>`
123
127
  }
124
128
 
125
- let dialog, options, tab = 'context', generation = 0, controller, poll, debounce
129
+ let dialog, options, tab = 'context', generation = 0, controller, poll, debounce, page = false, inline = false, eventKind = '', allowedTabs = ['context','cost']
126
130
  let detail = null, detailStatus = '', cost = null, costStatus = '', detailTask = false, detailRevision
127
131
  function current() { return options?.getSession?.() }
128
- function valid(g) { return g === generation && dialog?.open && options.connection.valid() && current()?.sessionId === options.sessionId }
132
+ function valid(g) { return g === generation && dialog?.open && options.connection.valid() && (options.hostOverview || current()?.sessionId === options.sessionId) }
129
133
  function render() {
130
134
  if (!dialog?.open) return
131
135
  if (!valid(generation)) { close(); return }
132
- dialog.querySelector('.ins-content').innerHTML = tab === 'context' ? contextHtml(current(), detail, detailStatus) : costHtml(cost, costStatus)
136
+ const content = dialog.querySelector('.ins-content'), scroll = content.scrollTop
137
+ const html = tab === 'context' ? contextHtml(current(), detail, detailStatus, { full: page, kind: eventKind }) : costHtml(cost, costStatus, options.hostOverview)
138
+ if (content.innerHTML !== html) { content.innerHTML = html; content.scrollTop = scroll }
133
139
  for (const button of dialog.querySelectorAll('[data-ins-tab]')) {
134
140
  const active = button.dataset.insTab === tab
141
+ button.hidden = page || !allowedTabs.includes(button.dataset.insTab)
135
142
  button.setAttribute('aria-selected', String(active)); button.tabIndex = active ? 0 : -1
136
143
  }
137
144
  dialog.querySelector('.ins-content').setAttribute('aria-labelledby', 'ins-tab-' + tab)
@@ -182,7 +189,7 @@
182
189
  if (!valid(g) || tab !== 'cost' || costStatus === 'loading') return
183
190
  costStatus = 'loading'; render()
184
191
  try {
185
- const data = await request('/remote/api/insights/cost?sessionId=' + encodeURIComponent(options.sessionId), null, g)
192
+ const data = await request('/remote/api/insights/cost' + (options.sessionId ? '?sessionId=' + encodeURIComponent(options.sessionId) : ''), null, g)
186
193
  if (!valid(g)) return
187
194
  if (data.available === false || costOf(data)) { cost = data; costStatus = '' }
188
195
  else costStatus = 'error'
@@ -192,37 +199,57 @@
192
199
  function scheduleContext() { clearTimeout(debounce); debounce = setTimeout(() => loadContext(), 400) }
193
200
  function close() {
194
201
  generation++; controller?.abort(); clearInterval(poll); clearTimeout(debounce)
195
- if (dialog?.open) dialog.close()
202
+ const onClose = options?.onClose
203
+ if (inline) { if (dialog) { dialog.open = false; dialog.remove(); dialog = null } }
204
+ else if (dialog?.open) dialog.close()
196
205
  options = null; detail = null; cost = null; detailTask = false; detailStatus = ''; costStatus = ''
206
+ onClose?.()
197
207
  }
198
- function open(opts) {
199
- close(); options = opts; tab = opts.tab === 'cost' ? 'cost' : 'context'; lang = root.I18N?.lang === 'en' ? 'en' : 'zh'
200
- options.sessionId = current()?.sessionId
201
- if (!options.sessionId) return
208
+ function open(opts, target) {
209
+ close(); options = opts; allowedTabs = ['context','cost'].filter(value => !opts.allowedTabs || opts.allowedTabs.includes(value))
210
+ if (!allowedTabs.length) { options = null; return }
211
+ tab = allowedTabs.includes(opts.tab) ? opts.tab : allowedTabs[0]; lang = root.I18N?.lang === 'en' ? 'en' : 'zh'
212
+ inline = !!target; page = inline || opts.fullPage === true; eventKind = ''
213
+ options.sessionId = opts.hostOverview ? '' : current()?.sessionId
214
+ if (!opts.hostOverview && !options.sessionId) return
202
215
  controller = new AbortController(); detailRevision = undefined
216
+ if (target) { dialog?.remove(); dialog = document.createElement('section'); dialog.className = 'ins-dialog ins-page'; dialog.open = true; target.replaceChildren(dialog) }
203
217
  if (!dialog) {
204
218
  dialog = document.createElement('dialog'); dialog.className = 'ins-dialog'; document.body.append(dialog)
205
219
  dialog.addEventListener('cancel', event => { event.preventDefault(); close() })
206
220
  dialog.addEventListener('close', () => { if (options && !dialog.open) close() })
207
221
  }
208
- dialog.innerHTML = `<header class="ins-header"><div><h2 id="ins-title">${esc(t('title'))}</h2><p>${esc(opts.getTitle?.() || options.sessionId)}</p></div><button type="button" data-ins-close aria-label="${esc(t('close'))}">×</button></header>
222
+ if (!inline) dialog.className = 'ins-dialog' + (page ? ' ins-full-page' : '')
223
+ const title = opts.hostOverview || page && tab === 'cost' ? t('cost') : page ? (lang === 'en' ? 'Context analysis' : '上下文分析') : allowedTabs.length === 1 ? t(allowedTabs[0]) : t('title')
224
+ dialog.innerHTML = `<header class="ins-header"><div><h2 id="ins-title">${esc(title)}</h2><p>${esc(opts.hostOverview ? (lang === 'en' ? 'Current host · today, balance and plan quotas' : '当前主机 · 今日费用、账户余额与套餐额度') : opts.getTitle?.() || options.sessionId)}</p></div>${inline ? '' : `<button type="button" data-ins-close aria-label="${esc(t('close'))}">${page ? (lang === 'en' ? 'Back' : '返回') : '×'}</button>`}</header>
209
225
  <nav class="ins-tabs" role="tablist" aria-label="${esc(t('title'))}"><button type="button" role="tab" id="ins-tab-context" data-ins-tab="context" aria-controls="ins-content">${esc(t('context'))}</button><button type="button" role="tab" id="ins-tab-cost" data-ins-tab="cost" aria-controls="ins-content">${esc(t('cost'))}</button><button type="button" data-ins-refresh>${esc(t('refresh'))}</button></nav><div id="ins-content" class="ins-content" role="tabpanel" tabindex="0"></div>`
210
226
  dialog.setAttribute('aria-labelledby', 'ins-title')
211
- dialog.querySelector('[data-ins-close]').addEventListener('click', close)
212
- function select(value) { tab = value; render(); tab === 'cost' ? loadCost() : loadContext() }
227
+ if (!inline) dialog.querySelector('[data-ins-close]').addEventListener('click', close)
228
+ if (page) {
229
+ dialog.querySelectorAll('[data-ins-tab]').forEach(button => { button.hidden = true })
230
+ if (tab === 'context') {
231
+ const filter = document.createElement('select'); filter.setAttribute('aria-label', lang === 'en' ? 'Change type' : '变化类型')
232
+ filter.innerHTML = [['', lang === 'en' ? 'All changes' : '全部变化'], ...['compaction', 'prune', 'inject', 'model', 'mode'].map(kind => [kind, t(kind)])].map(([value,label]) => `<option value="${value}">${esc(label)}</option>`).join('')
233
+ filter.addEventListener('change', () => { eventKind = filter.value; render() }); dialog.querySelector('.ins-tabs').prepend(filter)
234
+ }
235
+ } else if (opts.onFullPage) {
236
+ const expand = document.createElement('button'); expand.type = 'button'; expand.textContent = lang === 'en' ? 'Open page' : '打开完整页面'
237
+ expand.addEventListener('click', () => { const selected = tab; close(); opts.onFullPage(selected) }); dialog.querySelector('.ins-tabs').append(expand)
238
+ }
239
+ function select(value) { if(!allowedTabs.includes(value))return;tab = value; render(); tab === 'cost' ? loadCost() : loadContext() }
213
240
  dialog.querySelectorAll('[data-ins-tab]').forEach(button => {
214
241
  button.addEventListener('click', () => select(button.dataset.insTab))
215
242
  button.addEventListener('keydown', event => {
216
243
  if (!['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key)) return
217
- event.preventDefault(); select(event.key === 'Home' ? 'context' : event.key === 'End' ? 'cost' : tab === 'context' ? 'cost' : 'context')
244
+ event.preventDefault(); select(event.key === 'Home' ? allowedTabs[0] : event.key === 'End' ? allowedTabs.at(-1) : allowedTabs[(allowedTabs.indexOf(tab)+1)%allowedTabs.length])
218
245
  dialog.querySelector('[data-ins-tab="' + tab + '"]').focus()
219
246
  })
220
247
  })
221
248
  dialog.querySelector('[data-ins-refresh]').addEventListener('click', () => tab === 'cost' ? loadCost() : loadContext(true))
222
- dialog.showModal(); render(); tab === 'cost' ? loadCost() : loadContext()
249
+ if (!inline) dialog.showModal(); render(); tab === 'cost' ? loadCost() : loadContext()
223
250
  poll = setInterval(() => { if (!valid(generation)) close(); else if (tab === 'cost') loadCost(); else { render(); loadContext() } }, 60000)
224
251
  }
225
- const api = { open, close, update() { if (dialog?.open) { render(); if (dialog.open && tab === 'context') scheduleContext() } }, contextOf, costOf, contextHtml, costHtml }
252
+ const api = { open, mount: (opts, target) => open(opts, target), close, update() { if (dialog?.open) { render(); if (dialog?.open && tab === 'context') scheduleContext() } }, contextOf, costOf, contextHtml, costHtml }
226
253
  root.DshInsights = api
227
254
  if (typeof module !== 'undefined') module.exports = api
228
255
  })(typeof window !== 'undefined' ? window : globalThis)
package/public/md.js CHANGED
@@ -6,9 +6,9 @@
6
6
  * 同时支持浏览器全局 window.mdToHtml 与 Node CommonJS module.exports。
7
7
  */
8
8
  (function (root, factory) {
9
- if (typeof module === 'object' && module.exports) module.exports = factory(require('./genui.js'))
10
- else root.mdToHtml = factory(root.DshGenUi)
11
- })(typeof self !== 'undefined' ? self : this, function (genui) {
9
+ if (typeof module === 'object' && module.exports) module.exports = factory(require('./genui.js'), require('./chat-files.js'))
10
+ else root.mdToHtml = factory(root.DshGenUi, root.DshChatFiles)
11
+ })(typeof self !== 'undefined' ? self : this, function (genui, files) {
12
12
  'use strict'
13
13
 
14
14
  function escapeHtml(s) {
@@ -23,13 +23,21 @@
23
23
  })
24
24
  }
25
25
 
26
- function inline(s) {
26
+ function inline(s, fileLinks) {
27
27
  s = s.replace(/`([^`]+)`/g, '<code>$1</code>')
28
28
  s = s.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>')
29
29
  s = s.replace(/(^|[^*])\*([^*\n]+)\*/g, '$1<em>$2</em>')
30
- s = s.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, function (m, text, url) {
30
+ s = s.replace(/\[([^\]]+)\]\(([^)\n]+)\)/g, function (m, text, url) {
31
31
  url = url.trim()
32
- if (!/^https?:\/\//i.test(url)) return m
32
+ if (url.startsWith('&lt;') && url.endsWith('&gt;')) url = url.slice(4, -4)
33
+ let path
34
+ const entities = { '&amp;': '&', '&quot;': '"', '&#39;': "'", '&lt;': '<', '&gt;': '>' }
35
+ try {
36
+ const raw = url.replace(/&(?:amp|quot|lt|gt);|&#39;/g, entity => entities[entity])
37
+ path = /^file:/i.test(raw) ? files?.pathOf(raw) : decodeURIComponent(raw)
38
+ } catch { return m }
39
+ if (fileLinks && (files?.pathOf(path) || files?.relativePath(path))) return '<a href="#" data-dsh-file-path="' + escapeHtml(path) + '">' + text + '</a>'
40
+ if (!/^https?:\/\//i.test(url) || /\s/.test(url)) return m
33
41
  return '<a href="' + url + '" target="_blank" rel="noopener noreferrer">' + text + '</a>'
34
42
  })
35
43
  return s
@@ -81,10 +89,10 @@
81
89
  return { headers: headers, alignments: alignments, rows: rows, next: i }
82
90
  }
83
91
 
84
- function tableHtml(table) {
92
+ function tableHtml(table, fileLinks) {
85
93
  function cellTag(tag, value, align) {
86
94
  var style = align ? ' style="text-align:' + align + '"' : ''
87
- return '<' + tag + style + '>' + inline(value) + '</' + tag + '>'
95
+ return '<' + tag + style + '>' + inline(value, fileLinks) + '</' + tag + '>'
88
96
  }
89
97
  var head = '<thead><tr>' + table.headers.map(function (value, i) {
90
98
  return cellTag('th', value, table.alignments[i])
@@ -99,7 +107,7 @@
99
107
  return '<div class="md-table-wrap"><table>' + head + body + '</table></div>'
100
108
  }
101
109
 
102
- function renderLines(lines) {
110
+ function renderLines(lines, fileLinks) {
103
111
  var html = ''
104
112
  var i = 0
105
113
  while (i < lines.length) {
@@ -109,19 +117,19 @@
109
117
  var h = line.match(/^(#{1,3})\s+(.*)$/)
110
118
  if (h) {
111
119
  var level = h[1].length
112
- html += '<h' + level + '>' + inline(h[2]) + '</h' + level + '>'
120
+ html += '<h' + level + '>' + inline(h[2], fileLinks) + '</h' + level + '>'
113
121
  i++
114
122
  continue
115
123
  }
116
124
  var table = tableAt(lines, i)
117
125
  if (table) {
118
- html += tableHtml(table)
126
+ html += tableHtml(table, fileLinks)
119
127
  i = table.next
120
128
  continue
121
129
  }
122
130
  var q = line.match(/^&gt;\s?(.*)$/)
123
131
  if (q) {
124
- html += '<blockquote>' + inline(q[1]) + '</blockquote>'
132
+ html += '<blockquote>' + inline(q[1], fileLinks) + '</blockquote>'
125
133
  i++
126
134
  continue
127
135
  }
@@ -131,7 +139,7 @@
131
139
  while (i < lines.length) {
132
140
  var um = lines[i].match(/^[-*]\s+(.*)$/)
133
141
  if (!um) break
134
- items.push(inline(um[1]))
142
+ items.push(inline(um[1], fileLinks))
135
143
  i++
136
144
  }
137
145
  html += '<ul>' + items.map(function (x) { return '<li>' + x + '</li>' }).join('') + '</ul>'
@@ -143,7 +151,7 @@
143
151
  while (i < lines.length) {
144
152
  var om = lines[i].match(/^\d+[.)]\s+(.*)$/)
145
153
  if (!om) break
146
- oitems.push(inline(om[1]))
154
+ oitems.push(inline(om[1], fileLinks))
147
155
  i++
148
156
  }
149
157
  html += '<ol>' + oitems.map(function (x) { return '<li>' + x + '</li>' }).join('') + '</ol>'
@@ -155,7 +163,7 @@
155
163
  var ct = cur.trim()
156
164
  if (!ct) break
157
165
  if (/^(#{1,3})\s+/.test(cur) || /^&gt;\s?/.test(cur) || /^[-*]\s+/.test(cur) || /^\d+[.)]\s+/.test(cur)) break
158
- para.push(inline(cur))
166
+ para.push(inline(cur, fileLinks))
159
167
  i++
160
168
  }
161
169
  if (para.length) html += '<p>' + para.join('<br>') + '</p>'
@@ -163,7 +171,7 @@
163
171
  return html
164
172
  }
165
173
 
166
- function mdToHtml(text) {
174
+ function mdToHtml(text, options) {
167
175
  var raw = String(text == null ? '' : text)
168
176
  var parts = raw.split(/```/)
169
177
  var out = ''
@@ -174,7 +182,7 @@
174
182
  if (code.slice(-1) === '\n') code = code.slice(0, -1)
175
183
  var fence = code.match(/^([^\n]*)\n([\s\S]*)$/)
176
184
  // Wait for the closing fence: streaming partial JSON stays readable as source.
177
- if (genui && fence && i < parts.length - 1 && fence[2].length <= 200000) {
185
+ if (options?.richContent !== false && genui && fence && i < parts.length - 1 && fence[2].length <= 200000) {
178
186
  var language = fence[1].trim().toLowerCase()
179
187
  try {
180
188
  if (/^(?:dsh-ui|json dsh-ui|dsh-ui json)$/.test(language)) {
@@ -188,7 +196,7 @@
188
196
  out += '<pre><code>' + escapeHtml(code) + '</code></pre>'
189
197
  } else {
190
198
  var escaped = escapeHtml(parts[i])
191
- out += renderLines(escaped.split('\n'))
199
+ out += renderLines(escaped.split('\n'), options?.fileLinks === true)
192
200
  }
193
201
  }
194
202
  return out
@@ -52,8 +52,9 @@
52
52
  .pc-toggle::after{content:'';position:absolute;top:4px;left:4px;width:16px;height:16px;border-radius:50%;background:var(--dsr-muted,#a7b0bc);transition:transform .15s}
53
53
  .pc-dialog .pc-toggle[aria-checked=true]{background:var(--dsr-accent,#58a6ff);border-color:var(--dsr-accent,#58a6ff)}
54
54
  .pc-toggle[aria-checked=true]::after{transform:translateX(16px);background:var(--dsr-on-accent,#07111f)}
55
- .pc-card-actions{display:flex;align-items:center;gap:6px;border-top:1px solid var(--dsr-line,#30363d);padding-top:12px;margin-top:auto}
56
- .pc-card-actions button{border-color:transparent;background:transparent;font-size:12px;padding:8px 10px}
55
+ .pc-card-actions{display:flex;flex-wrap:wrap;align-items:center;gap:6px;border-top:1px solid var(--dsr-line,#30363d);padding-top:12px;margin-top:auto}
56
+ .pc-card-actions button{flex-shrink:0;white-space:nowrap;border-color:transparent;background:transparent;font-size:12px;padding:8px 10px}
57
+ .pc-card-actions .pc-open-feature{flex:1 0 100%;border-color:var(--dsr-accent-line,#58a6ff66);background:var(--dsr-accent-soft,#58a6ff1f);color:var(--dsr-accent-strong,#79c0ff);margin-bottom:4px}
57
58
  .pc-card-actions .pc-detail-button{background:var(--dsr-accent-soft,#58a6ff1f);color:var(--dsr-accent-strong,#79c0ff);margin-right:auto}
58
59
  .pc-card-actions .pc-danger-button{color:var(--dsr-muted,#a7b0bc)}
59
60
  .pc-card-actions .pc-danger-button:hover{background:var(--dsr-error-soft,#ff8f6b24);color:var(--dsr-error,#ff8f6b);border-color:transparent}
@@ -80,7 +81,7 @@
80
81
  .pc-dialog{padding:18px}.pc-page{padding:6px 0 24px}.pc-dialog h2{font-size:24px}
81
82
  .pc-context{align-items:flex-start;flex-direction:column;gap:10px;margin:18px 0}.pc-summary{gap:24px}
82
83
  .pc-controls{padding:10px;margin-bottom:16px}.pc-toolbar{gap:4px}.pc-tabs{flex:1}
83
- .pc-tabs button{flex:1;padding:9px 8px;font-size:12px}
84
+ .pc-tabs button{flex:1;padding:9px 6px;font-size:12px}.pc-tabs{overflow-x:auto}
84
85
  .pc-filters:not([hidden]),.pc-market-tools:not([hidden]){gap:7px}
85
86
  .pc-dialog input,.pc-dialog select{font-size:12px;padding:11px 9px}
86
87
  .pc-card{padding:16px}.pc-card-actions button{min-height:40px;padding:9px 10px}
@@ -98,3 +99,6 @@
98
99
 
99
100
  .pc-list { align-items:start; }
100
101
  .pc-inline-detail button,.pc-card-actions button { min-height:44px; }
102
+ .pc-progress:not([hidden]) { border:1px solid var(--dsr-accent-line,#58a6ff66); border-radius:12px; padding:12px 14px; margin-bottom:16px; background:var(--dsr-accent-soft,#58a6ff1f); overflow-wrap:anywhere; }
103
+ .pc-progress p { margin:8px 0 0; font-size:13px; }
104
+ .pc-job-progress { color:var(--dsr-muted,#a7b0bc); }