dsh-synapse 0.5.5 → 0.5.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/README.md +17 -0
- package/client.js +110 -2
- package/docs/en/README.md +16 -0
- package/docs/zh-CN/README.md +16 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -54,11 +54,28 @@ corepack pnpm dsh web
|
|
|
54
54
|
| 保留真实分支 | 按 DSH 原生 fork 关系连接卡片,不制造另一套会话历史。 |
|
|
55
55
|
| 追问更顺手 | 选中回答中的文字可直接带入新的追问;常用补充词可编辑。 |
|
|
56
56
|
| 双向同步 | 在地图或 DSH 原生对话中切换会话,当前上下文保持一致。 |
|
|
57
|
+
| 过程不挡路 | 工具调用与结果按 `callId` 折叠进对应回答,只显示「工具 N」。 |
|
|
58
|
+
| 可移动入口 | 顶部「对话 / 会话地图」开关可拖动、记忆位置、双击复位。 |
|
|
59
|
+
| 详情侧栏 | 点卡片在右侧展开整轮详情:完整回答、工具过程、追问 / 分支 / 打开 DSH。 |
|
|
60
|
+
| 归档一致 | 归档在地图与 DSH 侧栏之间共用同一份集合,不会各记一套。 |
|
|
61
|
+
|
|
62
|
+
## 最近更新
|
|
63
|
+
|
|
64
|
+
**0.5.6**
|
|
65
|
+
|
|
66
|
+
- 顶部开关可拖动、记忆位置(按浏览器)、双击复位、方向键微调,并保证不会被拖到屏幕外。
|
|
67
|
+
- 交互与渲染一致性修正:切会话会把该会话带入视野;折叠卡片不再移动画布;正文里有选区时侧栏与详情仍能更新;卡片右侧折叠 / 分支按钮不再被相邻卡片遮住。
|
|
68
|
+
- 工作区加载竞态修正:切换工作区不再被后台轮询顶掉;画布只在数据真变化时重建(此前每秒重建数次)。
|
|
69
|
+
- `workspaces.json` 读不出来时改为**明确报错并保持只读**,不再用旧备份覆盖原文件。
|
|
70
|
+
|
|
71
|
+
历史版本见[提交记录](https://github.com/liangmianya/dsh-synapse/commits/main)。
|
|
57
72
|
|
|
58
73
|
## 从原生对话进入
|
|
59
74
|
|
|
60
75
|
在 DSH 原生对话中,通过顶部的 **会话地图** 进入 Synapse;返回 **对话** 后,仍是同一个 DSH 会话。
|
|
61
76
|
|
|
77
|
+
这个开关挡着内容时可以挪走:**按住左侧六点手柄拖动**,位置按浏览器记住;**双击手柄**复位;手柄聚焦后可用方向键微调。
|
|
78
|
+
|
|
62
79
|

|
|
63
80
|
|
|
64
81
|
## 文档
|
package/client.js
CHANGED
|
@@ -39,6 +39,42 @@ window.__ModuleLoader__.load({
|
|
|
39
39
|
return Array.isArray(snapshot.archivedSessionIds) ? snapshot.archivedSessionIds.map(String) : []
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
// The pill can be dragged anywhere it stays reachable; the position survives
|
|
43
|
+
// reloads. Kept next to the module so the drag arithmetic is testable without
|
|
44
|
+
// a DOM (see test/switch-drag.test.js).
|
|
45
|
+
const SWITCH_POSITION_KEY = 'dsh-synapse:switch-position:v1'
|
|
46
|
+
const SWITCH_MARGIN = 8
|
|
47
|
+
const SWITCH_STEP = 8
|
|
48
|
+
|
|
49
|
+
/** Keep the pill fully inside the viewport, with a margin to grab it again. */
|
|
50
|
+
function clampSwitchPosition(position, viewport, size) {
|
|
51
|
+
const maxLeft = Math.max(SWITCH_MARGIN, viewport.width - size.width - SWITCH_MARGIN)
|
|
52
|
+
const maxTop = Math.max(SWITCH_MARGIN, viewport.height - size.height - SWITCH_MARGIN)
|
|
53
|
+
return {
|
|
54
|
+
left: Math.min(Math.max(SWITCH_MARGIN, Math.round(position.left)), maxLeft),
|
|
55
|
+
top: Math.min(Math.max(SWITCH_MARGIN, Math.round(position.top)), maxTop),
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function readSwitchPosition(storage) {
|
|
60
|
+
try {
|
|
61
|
+
const value = JSON.parse(storage.getItem(SWITCH_POSITION_KEY) ?? 'null')
|
|
62
|
+
if (value === null || typeof value !== 'object') return null
|
|
63
|
+
if (!Number.isFinite(value.left) || !Number.isFinite(value.top)) return null
|
|
64
|
+
return { left: Math.round(value.left), top: Math.round(value.top) }
|
|
65
|
+
} catch {
|
|
66
|
+
return null
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function writeSwitchPosition(storage, position) {
|
|
71
|
+
try { storage.setItem(SWITCH_POSITION_KEY, JSON.stringify(position)) } catch { /* private mode */ }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function clearSwitchPosition(storage) {
|
|
75
|
+
try { storage.removeItem(SWITCH_POSITION_KEY) } catch { /* private mode */ }
|
|
76
|
+
}
|
|
77
|
+
|
|
42
78
|
module.exports.inject = ['sessions', 'workspaces', 'uiWorkspace', 'uiConversation']
|
|
43
79
|
module.exports.apply = ctx => {
|
|
44
80
|
const prompt = async (sessionId, text) => {
|
|
@@ -77,11 +113,11 @@ window.__ModuleLoader__.load({
|
|
|
77
113
|
// rightward (title, lineage and agent-preset chips). Half the sidebar
|
|
78
114
|
// width puts the pill over the centre of the content area instead of
|
|
79
115
|
// the window; `min()` pulls it back in on narrow windows.
|
|
80
|
-
style.textContent = '.dsh-synapse-switch{position:fixed;z-index:200;top:calc(var(--dsh-frame-chrome-top,var(--dsh-frame-top-clearance,0px)) + 12px);left:min(calc(50% + 130px),calc(100% - 96px));display:flex;gap:2px;transform:translateX(-50%);border:1px solid #d1d5db;border-radius:999px;background:rgba(255,255,255,.96);padding:3px;backdrop-filter:blur(10px);-webkit-app-region:no-drag;box-shadow:0 2px 8px rgba(17,24,39,.1)}.dsh-synapse-switch button{height:28px;border:0;border-radius:999px;background:transparent;padding:0 11px;color:#6b7280;font:600 12px Inter,system-ui,sans-serif;cursor:pointer;white-space:nowrap;-webkit-app-region:no-drag}.dsh-synapse-switch button:hover{background:#f3f4f6;color:#111827}.dsh-synapse-switch button.active{background:#111827;color:#fff}.dsh-synapse-switch button:focus-visible{outline:2px solid #111827;outline-offset:2px}.dsh-synapse-overlay{position:fixed;z-index:100;inset:var(--dsh-frame-chrome-top,var(--dsh-frame-top-clearance,0px)) 0 0 0;background:#f5f7fa}.dsh-synapse-overlay.is-opening{visibility:hidden}.dsh-synapse-overlay[hidden]{display:none}.dsh-synapse-overlay iframe{display:block;width:100%;height:100%;border:0}html[data-fullscreen] .dsh-synapse-overlay{top:0}html[data-fullscreen] .dsh-synapse-switch{top:12px}'
|
|
116
|
+
style.textContent = '.dsh-synapse-switch{position:fixed;z-index:200;top:calc(var(--dsh-frame-chrome-top,var(--dsh-frame-top-clearance,0px)) + 12px);left:min(calc(50% + 130px),calc(100% - 96px));display:flex;gap:2px;transform:translateX(-50%);border:1px solid #d1d5db;border-radius:999px;background:rgba(255,255,255,.96);padding:3px;backdrop-filter:blur(10px);-webkit-app-region:no-drag;box-shadow:0 2px 8px rgba(17,24,39,.1)}.dsh-synapse-switch button{height:28px;border:0;border-radius:999px;background:transparent;padding:0 11px;color:#6b7280;font:600 12px Inter,system-ui,sans-serif;cursor:pointer;white-space:nowrap;-webkit-app-region:no-drag}.dsh-synapse-switch button:hover{background:#f3f4f6;color:#111827}.dsh-synapse-switch button.active{background:#111827;color:#fff}.dsh-synapse-switch button:focus-visible{outline:2px solid #111827;outline-offset:2px}.dsh-synapse-overlay{position:fixed;z-index:100;inset:var(--dsh-frame-chrome-top,var(--dsh-frame-top-clearance,0px)) 0 0 0;background:#f5f7fa}.dsh-synapse-overlay.is-opening{visibility:hidden}.dsh-synapse-overlay[hidden]{display:none}.dsh-synapse-overlay iframe{display:block;width:100%;height:100%;border:0}html[data-fullscreen] .dsh-synapse-overlay{top:0}html[data-fullscreen] .dsh-synapse-switch{top:12px}.dsh-synapse-grip{display:grid;width:16px;height:28px;place-items:center;border-radius:999px;color:#9ca3af;background:transparent;cursor:grab;touch-action:none;-webkit-app-region:no-drag}.dsh-synapse-grip:hover{background:#f3f4f6;color:#4b5563}.dsh-synapse-grip:focus-visible{outline:2px solid #111827;outline-offset:2px}.dsh-synapse-grip svg{width:8px;height:14px;fill:currentColor}.dsh-synapse-switch.is-dragging .dsh-synapse-grip{cursor:grabbing}'
|
|
81
117
|
document.head.append(style)
|
|
82
118
|
const host = document.createElement('div')
|
|
83
119
|
host.className = 'dsh-synapse-host'
|
|
84
|
-
host.innerHTML = '<div class="dsh-synapse-switch" role="group" aria-label="视图切换"><button type="button" data-view="dialog" class="active" aria-pressed="true">对话</button><button type="button" data-view="map" aria-pressed="false">会话地图</button></div><section class="dsh-synapse-overlay" hidden><iframe title="会话地图" src="/synapse/"></iframe></section>'
|
|
120
|
+
host.innerHTML = '<div class="dsh-synapse-switch" role="group" aria-label="视图切换"><span class="dsh-synapse-grip" role="button" tabindex="0" aria-label="拖动位置" title="拖动位置(双击复位,方向键微调)"><svg aria-hidden="true" viewBox="0 0 8 14"><circle cx="2" cy="2" r="1.3"/><circle cx="6" cy="2" r="1.3"/><circle cx="2" cy="7" r="1.3"/><circle cx="6" cy="7" r="1.3"/><circle cx="2" cy="12" r="1.3"/><circle cx="6" cy="12" r="1.3"/></svg></span><button type="button" data-view="dialog" class="active" aria-pressed="true">对话</button><button type="button" data-view="map" aria-pressed="false">会话地图</button></div><section class="dsh-synapse-overlay" hidden><iframe title="会话地图" src="/synapse/"></iframe></section>'
|
|
85
121
|
document.body.append(host)
|
|
86
122
|
const switchEl = host.querySelector('.dsh-synapse-switch')
|
|
87
123
|
// Two live instances (a bundle loaded twice, or a sibling that outlived a
|
|
@@ -107,6 +143,77 @@ window.__ModuleLoader__.load({
|
|
|
107
143
|
const mapButton = host.querySelector('[data-view="map"]')
|
|
108
144
|
const overlay = host.querySelector('.dsh-synapse-overlay')
|
|
109
145
|
const frame = host.querySelector('iframe')
|
|
146
|
+
const grip = host.querySelector('.dsh-synapse-grip')
|
|
147
|
+
|
|
148
|
+
// --- dragging the pill -------------------------------------------------
|
|
149
|
+
// A stored position switches the pill from its CSS seat (centred, under the
|
|
150
|
+
// window chrome) to explicit viewport coordinates; `transform` has to be
|
|
151
|
+
// dropped with it or the pill would stay half a width to the left.
|
|
152
|
+
const switchSize = () => ({ width: switchEl.offsetWidth, height: switchEl.offsetHeight })
|
|
153
|
+
const viewportSize = () => ({ width: window.innerWidth, height: window.innerHeight })
|
|
154
|
+
const applySwitchPosition = position => {
|
|
155
|
+
if (position === null) {
|
|
156
|
+
switchEl.style.removeProperty('left')
|
|
157
|
+
switchEl.style.removeProperty('top')
|
|
158
|
+
switchEl.style.removeProperty('transform')
|
|
159
|
+
return
|
|
160
|
+
}
|
|
161
|
+
switchEl.style.left = `${position.left}px`
|
|
162
|
+
switchEl.style.top = `${position.top}px`
|
|
163
|
+
switchEl.style.transform = 'none'
|
|
164
|
+
}
|
|
165
|
+
const storedSwitchPosition = readSwitchPosition(window.localStorage)
|
|
166
|
+
if (storedSwitchPosition !== null) {
|
|
167
|
+
applySwitchPosition(clampSwitchPosition(storedSwitchPosition, viewportSize(), switchSize()))
|
|
168
|
+
}
|
|
169
|
+
let switchDrag = null
|
|
170
|
+
const finishSwitchDrag = event => {
|
|
171
|
+
if (switchDrag === null) return
|
|
172
|
+
const drag = switchDrag
|
|
173
|
+
switchDrag = null
|
|
174
|
+
switchEl.classList.remove('is-dragging')
|
|
175
|
+
try { grip.releasePointerCapture(event.pointerId) } catch { /* already released */ }
|
|
176
|
+
if (drag.moved && drag.position !== null) writeSwitchPosition(window.localStorage, drag.position)
|
|
177
|
+
}
|
|
178
|
+
grip.addEventListener('pointerdown', event => {
|
|
179
|
+
if (event.button !== 0) return
|
|
180
|
+
event.preventDefault()
|
|
181
|
+
const rect = switchEl.getBoundingClientRect()
|
|
182
|
+
switchDrag = { x: event.clientX, y: event.clientY, left: rect.left, top: rect.top, moved: false, position: null }
|
|
183
|
+
switchEl.classList.add('is-dragging')
|
|
184
|
+
try { grip.setPointerCapture(event.pointerId) } catch { /* capture is best effort */ }
|
|
185
|
+
})
|
|
186
|
+
grip.addEventListener('pointermove', event => {
|
|
187
|
+
if (switchDrag === null) return
|
|
188
|
+
const dx = event.clientX - switchDrag.x
|
|
189
|
+
const dy = event.clientY - switchDrag.y
|
|
190
|
+
if (!switchDrag.moved && Math.hypot(dx, dy) < 3) return
|
|
191
|
+
switchDrag.moved = true
|
|
192
|
+
switchDrag.position = clampSwitchPosition({ left: switchDrag.left + dx, top: switchDrag.top + dy }, viewportSize(), switchSize())
|
|
193
|
+
applySwitchPosition(switchDrag.position)
|
|
194
|
+
})
|
|
195
|
+
grip.addEventListener('pointerup', finishSwitchDrag)
|
|
196
|
+
grip.addEventListener('pointercancel', finishSwitchDrag)
|
|
197
|
+
// Double-click resets the pill to its shipped seat.
|
|
198
|
+
grip.addEventListener('dblclick', () => {
|
|
199
|
+
clearSwitchPosition(window.localStorage)
|
|
200
|
+
applySwitchPosition(null)
|
|
201
|
+
})
|
|
202
|
+
// Keyboard path: arrows nudge, so the control is usable without a pointer.
|
|
203
|
+
grip.addEventListener('keydown', event => {
|
|
204
|
+
const step = { ArrowLeft: [-SWITCH_STEP, 0], ArrowRight: [SWITCH_STEP, 0], ArrowUp: [0, -SWITCH_STEP], ArrowDown: [0, SWITCH_STEP] }[event.key]
|
|
205
|
+
if (step === undefined) return
|
|
206
|
+
event.preventDefault()
|
|
207
|
+
const rect = switchEl.getBoundingClientRect()
|
|
208
|
+
const position = clampSwitchPosition({ left: rect.left + step[0], top: rect.top + step[1] }, viewportSize(), switchSize())
|
|
209
|
+
applySwitchPosition(position)
|
|
210
|
+
writeSwitchPosition(window.localStorage, position)
|
|
211
|
+
})
|
|
212
|
+
const keepSwitchInView = () => {
|
|
213
|
+
const stored = readSwitchPosition(window.localStorage)
|
|
214
|
+
if (stored !== null) applySwitchPosition(clampSwitchPosition(stored, viewportSize(), switchSize()))
|
|
215
|
+
}
|
|
216
|
+
window.addEventListener('resize', keepSwitchInView)
|
|
110
217
|
|
|
111
218
|
const setView = view => {
|
|
112
219
|
const showingMap = view === 'map'
|
|
@@ -385,6 +492,7 @@ window.__ModuleLoader__.load({
|
|
|
385
492
|
frame.removeEventListener('load', onFrameLoad)
|
|
386
493
|
window.removeEventListener('message', onMessage)
|
|
387
494
|
window.removeEventListener('keydown', onKeyDown)
|
|
495
|
+
window.removeEventListener('resize', keepSwitchInView)
|
|
388
496
|
themeObserver?.disconnect()
|
|
389
497
|
unsubscribeSessions()
|
|
390
498
|
unsubscribeWorkspaces()
|
package/docs/en/README.md
CHANGED
|
@@ -104,6 +104,22 @@ The canvas supports:
|
|
|
104
104
|
- Smooth card scrolling and Markdown table rendering.
|
|
105
105
|
- Folding tool calls and results into the related assistant answer by `callId`.
|
|
106
106
|
|
|
107
|
+
The **Dialogue / Session Map** switch can be moved too:
|
|
108
|
+
|
|
109
|
+
- Drag it by the six-dot grip on its left edge; the position is remembered per browser.
|
|
110
|
+
- Double-click the grip to return it to its shipped seat (centred under the window chrome).
|
|
111
|
+
- With the grip focused, the arrow keys nudge it by 8px.
|
|
112
|
+
- It always keeps an 8px grab margin from the viewport edges, so shrinking the window cannot strand it off screen.
|
|
113
|
+
|
|
114
|
+
## Recent changes
|
|
115
|
+
|
|
116
|
+
**0.5.6**
|
|
117
|
+
|
|
118
|
+
- The top switch is draggable, remembers where you left it, and resets on a double-click (new).
|
|
119
|
+
- Interaction and rendering consistency: switching a conversation now brings it into view; folding a card no longer moves the canvas; a text selection in an answer no longer freezes the sidebar and the details panel; the fold/branch buttons on a card's right edge are no longer covered by the neighbouring card.
|
|
120
|
+
- Workspace switching no longer races the background poll, and the canvas is rebuilt only when data actually changes instead of several times a second.
|
|
121
|
+
- An unreadable `workspaces.json` now fails loudly and read-only instead of restoring an old backup over it (the 0.5.5 fallback was reverted).
|
|
122
|
+
|
|
107
123
|
## Configuration
|
|
108
124
|
|
|
109
125
|
The plugin is inserted through the profile's `cordis.patch.yml`. Override it in your own patch by targeting the row id `synapse`.
|
package/docs/zh-CN/README.md
CHANGED
|
@@ -104,6 +104,22 @@ corepack pnpm dsh web --port 0
|
|
|
104
104
|
- 卡片内部平滑滚动和 Markdown 表格渲染。
|
|
105
105
|
- 将工具调用和结果按 `callId` 折叠到对应助手回答中。
|
|
106
106
|
|
|
107
|
+
顶部「对话 / 会话地图」开关也可以挪位置:
|
|
108
|
+
|
|
109
|
+
- 按住开关左侧的**六点手柄**拖动,鬆手即记忆(存在浏览器本地,按浏览器各自独立);
|
|
110
|
+
- **双击手柄**复位到默认位置(标题栏下方居中);
|
|
111
|
+
- 手柄获得焦点后可用**方向键**微调,每次 8px;
|
|
112
|
+
- 开关始终保留离屏幕边缘 8px 的余量,缩小窗口也不会被挤到看不见的地方。
|
|
113
|
+
|
|
114
|
+
## 最近更新
|
|
115
|
+
|
|
116
|
+
**0.5.6**
|
|
117
|
+
|
|
118
|
+
- 顶部开关可以拖动、记忆位置、双击复位(本次新增)。
|
|
119
|
+
- 修正交互与渲染一致性:切换会话会把该会话带到视野内;折叠卡片不再移动画布;选区落在正文时侧栏与详情仍能更新;卡片右侧的折叠/分支按钮不再被相邻卡片遮住而点不到。
|
|
120
|
+
- 修正工作区加载竞态:切换工作区不会再被后台轮询顶掉,画布重建次数从「每秒数次」降到「仅在数据变化时一次」。
|
|
121
|
+
- `workspaces.json` 读不出来时改为**明确报错并保持只读**,不再用旧备份覆盖原文件(0.5.5 引入的回退已撤销)。
|
|
122
|
+
|
|
107
123
|
## 配置
|
|
108
124
|
|
|
109
125
|
插件通过 profile 的 `cordis.patch.yml` 注入。可以在自己的 patch 中通过行 id `synapse` 覆盖配置。
|