dsh-share-html 0.5.1 → 0.6.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.
package/README.md CHANGED
@@ -119,19 +119,21 @@ dsh plugin --profile web add github:unknown3310v0/dsh-share-html
119
119
  - 无 `<script>`、无 `<link>`、无 `<img>` 外链
120
120
  - 深浅主题跟随系统偏好
121
121
  - 文件附件只显示名称/类型/大小,不含字节内容
122
+ - 每轮末尾的「已编辑 N 个文件 +x −y」摘要可展开查看逐文件行数(受上面的限制影响)
122
123
 
123
124
  ## 已知限制
124
125
 
125
126
  - **仅 Web**:`dsh.client.platform` 为 `web`,暂不支持其他端。
126
127
  - **locale 未接线**:`locale/*.json` 已备好,但界面文案目前是中文硬编码,非中文用户看到的是中文。
127
128
  - **体积**:「完整」档产物中约 90% 是工具结果原文(这本就是该档的定义)。几十轮带大量工具调用的会话可到数百 KB;只要结论请选「对话」档。
129
+ - **文件改动摘要受限于 Host 内存**:DSH 的 `workspace/changes` 事件只记录轮次号,改动明细缓存在 Host 进程内存里。重启 DSH 后再导出旧会话,这一块拿不到(此时不显示,而不是显示成「没有改动」)。
128
130
 
129
131
  ## 开发
130
132
 
131
133
  ```bash
132
134
  npm install # 只有一个 devDependency:esbuild
133
135
  npm run build # 把 src/host 打包成 lib/kernel.js
134
- npm test # 197 条测试
136
+ npm test # 211 条测试
135
137
  ```
136
138
 
137
139
  测试只需 Node 内置 `node:test`,但 `build` 需要 esbuild。
package/lib/client.js CHANGED
@@ -26,6 +26,14 @@ window.__ModuleLoader__.load({
26
26
  var useRef = React.useRef
27
27
 
28
28
  var SLOT_ACTIONS = 'conversation.session.header.actions'
29
+ /**
30
+ * 每轮工具栏(复制 / 赞踩 / 分支那一行)的插槽。
31
+ *
32
+ * owner props 只有 `{ messageId }`,但插槽 scope 是 'session',
33
+ * 宿主会把 sessionId 一并注进来 —— 弹窗需要它。
34
+ * 位置在「复制」与「分支」之间(见 DSH 的 MessageIconActions.extraActions)。
35
+ */
36
+ var SLOT_TURN_ACTIONS = 'conversation.chat.assistant-actions'
29
37
 
30
38
  // ---- 令牌:与导出产物同源(DSH 宿主内它们本来就有效,可直接引用变量) ------
31
39
  var RADIUS_SM = 'var(--dsw-radius-sm, 8px)'
@@ -809,6 +817,69 @@ window.__ModuleLoader__.load({
809
817
  ])
810
818
  }
811
819
 
820
+ /**
821
+ * 每轮工具栏里的「分享」按钮。
822
+ *
823
+ * 与左上角那个共用同一个弹窗,只是入口更贴近内容 —— 读者看完某一轮想导出时,
824
+ * 视线就在这条工具栏上。
825
+ *
826
+ * 图标用内联 SVG(导出箭头),不依赖宿主图标库,避免不同 DSH 版本缺图标时白屏。
827
+ */
828
+ function ShareTurnAction(props) {
829
+ var sessionId = props.sessionId
830
+ || (props.session && (props.session.id || props.session.sessionId))
831
+ || props.session_id
832
+ var ctx = props.ctx
833
+ var openState = useState(false)
834
+ var open = openState[0]
835
+ var setOpen = openState[1]
836
+
837
+ var Portal = function (child) {
838
+ if (typeof document === 'undefined') return null
839
+ var host = document.getElementById('dsh-share-html-root')
840
+ if (!host) {
841
+ host = document.createElement('div')
842
+ host.id = 'dsh-share-html-root'
843
+ document.body.appendChild(host)
844
+ }
845
+ return require('react-dom').createPortal(child, host)
846
+ }
847
+
848
+ // 图标用 DSH 自己的 share-outline(SVG 路径逐字取自
849
+ // @deepseek-ai/dsh-client-ui-primitives 的 IconShareOutlineRegular),
850
+ // 这样与宿主里其它分享入口的图形一致 —— 先前手画的向下箭头看起来像「下载」。
851
+ var icon = h('svg', {
852
+ xmlns: 'http://www.w3.org/2000/svg',
853
+ viewBox: '0 0 16 16',
854
+ fill: 'none',
855
+ stroke: 'currentColor',
856
+ strokeWidth: 1,
857
+ 'aria-hidden': 'true',
858
+ }, h('path', {
859
+ d: 'M14.1256 7.58723C14.3483 7.81942 14.3482 8.18589 14.1254 8.41799L8.6646 14.1077C8.53985 14.2377 8.32031 14.1494 8.32031 13.9692L8.32035 10.2039C8.32035 10.1943 8.31534 10.1864 8.30592 10.1849C8.08306 10.148 5.30067 9.7729 1.50993 13.2904C1.49711 13.3023 1.47561 13.2943 1.4757 13.2768C1.49273 9.87168 3.42001 5.07166 8.29999 5.05835C8.31103 5.05832 8.32035 5.04937 8.32035 5.03832L8.32031 2.03109C8.32031 1.85088 8.53993 1.76259 8.66466 1.89266L14.1256 7.58723Z',
860
+ }))
861
+
862
+ return h(React.Fragment, null, [
863
+ h('button', {
864
+ key: 'btn',
865
+ type: 'button',
866
+ // 与 DSH 的 MessageIconActions 图标按钮同一套外观:无边框、悬停浮底色
867
+ className: 'dsh-share-html-turn-action',
868
+ title: sessionId ? '导出当前会话为离线 HTML' : '当前没有可导出的会话',
869
+ 'aria-label': '分享',
870
+ disabled: !sessionId,
871
+ onClick: function () { if (sessionId) setOpen(true) },
872
+ }, icon),
873
+ open && sessionId
874
+ ? Portal(h(Dialog, {
875
+ ctx: ctx,
876
+ sessionId: sessionId,
877
+ onClose: function () { setOpen(false) },
878
+ }))
879
+ : null,
880
+ ])
881
+ }
882
+
812
883
  // ---- 注册 ---------------------------------------------------------------
813
884
  //
814
885
  // 插槽 API(对照 dsh-client-ui-jobs 的真实用法):
@@ -819,7 +890,45 @@ window.__ModuleLoader__.load({
819
890
  exports.name = 'dsh-share-html/client'
820
891
  exports.inject = ['slots', 'connection']
821
892
 
893
+ /**
894
+ * 每轮工具栏按钮的样式:与 DSH 的 MessageIconActions 图标按钮同一套外观
895
+ * (28px 见方、无边框、tertiary 色、悬停浮底色)。
896
+ * 只注入一次 —— 插槽可能重挂载,重复插入会让 <style> 越积越多。
897
+ */
898
+ var TURN_ACTION_CSS = [
899
+ '.dsh-share-html-turn-action{',
900
+ 'display:inline-flex;align-items:center;justify-content:center;',
901
+ 'width:28px;height:28px;padding:6px;',
902
+ 'border:none;border-radius:var(--dsw-radius-sm,8px);',
903
+ 'background:transparent;color:var(--dsw-alias-label-tertiary,#81858c);',
904
+ 'cursor:pointer;transition:background 100ms ease,color 100ms ease;',
905
+ '}',
906
+ '.dsh-share-html-turn-action:hover:not(:disabled){',
907
+ 'background:var(--dsw-alias-interactive-bg-hover,rgba(0,0,0,.05));',
908
+ 'color:var(--dsw-alias-label-secondary,#61666b);',
909
+ '}',
910
+ // 与邻居图标同尺寸(DSH 的 .action svg 是 15px + 字号增量)
911
+ '.dsh-share-html-turn-action svg{',
912
+ 'width:calc(15px + var(--dsh-content-font-delta, 0px));',
913
+ 'height:calc(15px + var(--dsh-content-font-delta, 0px));',
914
+ '}',
915
+ '.dsh-share-html-turn-action:disabled{opacity:.4;cursor:default;}',
916
+ '.dsh-share-html-turn-action:focus-visible{',
917
+ 'outline:none;box-shadow:inset 0 0 0 2px var(--dsw-focus-ring-color,#4d6bfe);',
918
+ '}',
919
+ ].join('')
920
+
921
+ function injectTurnActionStyle() {
922
+ if (typeof document === 'undefined') return
923
+ if (document.getElementById('dsh-share-html-turn-style')) return
924
+ var el = document.createElement('style')
925
+ el.id = 'dsh-share-html-turn-style'
926
+ el.textContent = TURN_ACTION_CSS
927
+ document.head.appendChild(el)
928
+ }
929
+
822
930
  exports.apply = function apply(ctx) {
931
+ injectTurnActionStyle()
823
932
  ctx.slots.inject(SLOT_ACTIONS, function () {
824
933
  return ctx.slots.register({
825
934
  name: SLOT_ACTIONS,
@@ -837,6 +946,31 @@ window.__ModuleLoader__.load({
837
946
  }, ShareHeaderAction)
838
947
  })
839
948
  console.log('[dsh-share-html] registered share button on ' + SLOT_ACTIONS)
949
+
950
+ // 每轮工具栏里的入口。插槽是 'list' 类型,同一 session 下每个 messageId
951
+ // 都会渲染一次;id 用固定值,避免重复注册。
952
+ try {
953
+ ctx.slots.inject(SLOT_TURN_ACTIONS, function () {
954
+ return ctx.slots.register({
955
+ name: SLOT_TURN_ACTIONS,
956
+ id: 'share-html-turn',
957
+ order: 20,
958
+ locale: null,
959
+ inject: function () {
960
+ return {
961
+ ctx: ctx,
962
+ shareInvoke: function (method, args) {
963
+ return invoke(ctx, method, args)
964
+ },
965
+ }
966
+ },
967
+ }, ShareTurnAction)
968
+ })
969
+ console.log('[dsh-share-html] registered share button on ' + SLOT_TURN_ACTIONS)
970
+ } catch (error) {
971
+ // 老版本 DSH 可能没有这个插槽:左上角的按钮仍可用,不影响导出
972
+ console.warn('[dsh-share-html] turn action slot unavailable:', error && error.message)
973
+ }
840
974
  }
841
975
 
842
976
  return module.exports