dsh-onesheet 0.3.1 → 0.3.2
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 +4 -0
- package/client.js +15 -13
- package/index.js +22 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -38,6 +38,10 @@ dsh plugin add "link:/path/to/onesheet"
|
|
|
38
38
|
|
|
39
39
|
调用 `show_figure(scene)`。`say` 是这一页唯一那句话;`items` 里的元素画在 760 宽的坐标系里。
|
|
40
40
|
|
|
41
|
+
## 图卡模式是"每轮都在"的
|
|
42
|
+
|
|
43
|
+
开关打开后,宿主在**每次装配 system prompt 时**都会把那段要求放进去(动态 section + 装配末尾兜底,见 `index.js` 的 `ensureModeSection`)。之前的 0.3.x 只挂了一个静态 section,遇到把这个 preset 用 "complete 段" 整体替换时那段会消失——0.3.2 起不会了。
|
|
44
|
+
|
|
41
45
|
## 收起一张卡
|
|
42
46
|
|
|
43
47
|
每张卡标题行右侧有「收起 / 展开」。收起的卡只剩一行标题,长会话里可以把自己不用的卡折起来,翻页和内容都还在,点「展开」原样回来。
|
package/client.js
CHANGED
|
@@ -578,21 +578,23 @@ window.__ModuleLoader__.load({
|
|
|
578
578
|
pill.textContent = on ? '图卡 · 开' : '图卡 · 关'
|
|
579
579
|
|
|
580
580
|
pill.classList.toggle('fk-mode-on', on)
|
|
581
|
-
//
|
|
581
|
+
// 和宿主对一次状态(启动时 + 每 15 秒):别让本地缓存的标签和真实状态漂移
|
|
582
|
+
const syncStatus = async () => {
|
|
583
|
+
try {
|
|
584
|
+
const r = await fetch('/api/onesheet/cardmode', {
|
|
585
|
+
method: 'POST',
|
|
586
|
+
headers: { 'content-type': 'application/json' },
|
|
587
|
+
body: JSON.stringify({ action: 'status' }),
|
|
588
|
+
credentials: 'same-origin',
|
|
589
|
+
})
|
|
590
|
+
const payload = await r.json()
|
|
591
|
+
if (payload && payload.ok) setPillUi(payload.on ? '1' : '0')
|
|
592
|
+
} catch {}
|
|
593
|
+
}
|
|
582
594
|
if (!window.__fkModeSynced) {
|
|
583
595
|
window.__fkModeSynced = true
|
|
584
|
-
void (
|
|
585
|
-
|
|
586
|
-
const r = await fetch('/api/onesheet/cardmode', {
|
|
587
|
-
method: 'POST',
|
|
588
|
-
headers: { 'content-type': 'application/json' },
|
|
589
|
-
body: JSON.stringify({ action: 'status' }),
|
|
590
|
-
credentials: 'same-origin',
|
|
591
|
-
})
|
|
592
|
-
const payload = await r.json()
|
|
593
|
-
if (payload && payload.ok) setPillUi(payload.on ? '1' : '0')
|
|
594
|
-
} catch {}
|
|
595
|
-
})()
|
|
596
|
+
void syncStatus()
|
|
597
|
+
window.setInterval(() => { void syncStatus() }, 15000)
|
|
596
598
|
}
|
|
597
599
|
}
|
|
598
600
|
|
package/index.js
CHANGED
|
@@ -148,20 +148,30 @@ function figureId() {
|
|
|
148
148
|
return `f${Date.now().toString(36)}${Math.random().toString(36).slice(2, 6)}`
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
+
function ensureModeSection(ctx) {
|
|
152
|
+
try {
|
|
153
|
+
ctx.systemPrompt.section({
|
|
154
|
+
name: 'onesheet-card-mode',
|
|
155
|
+
order: 900,
|
|
156
|
+
text: () => (readMode() ? MODE_TEXT : ''),
|
|
157
|
+
})
|
|
158
|
+
} catch {}
|
|
159
|
+
try {
|
|
160
|
+
ctx.on('system-prompt/assemble', async (assembly, _context, next) => {
|
|
161
|
+
const out = await next()
|
|
162
|
+
try {
|
|
163
|
+
if (!readMode()) return out
|
|
164
|
+
const sections = Array.isArray(out.sections) ? out.sections : []
|
|
165
|
+
if (sections.some((entry) => entry && entry.name === 'onesheet-card-mode')) return out
|
|
166
|
+
return { ...out, sections: [...sections, { name: 'onesheet-card-mode', text: MODE_TEXT }] }
|
|
167
|
+
} catch { return out }
|
|
168
|
+
})
|
|
169
|
+
} catch {}
|
|
170
|
+
}
|
|
171
|
+
|
|
151
172
|
export function apply(ctx) {
|
|
173
|
+
ensureModeSection(ctx)
|
|
152
174
|
// 图卡模式:状态存在 ~/.dsh/onesheet/card-mode.json(旧版本写在插件目录,首次读取时迁移),开时往系统提示里加一段(不改用户的输入)
|
|
153
|
-
let sectionDispose = null
|
|
154
|
-
const syncSection = (on) => {
|
|
155
|
-
if (sectionDispose) { try { sectionDispose() } catch {} ; sectionDispose = null }
|
|
156
|
-
if (!on) return
|
|
157
|
-
try {
|
|
158
|
-
sectionDispose = ctx.systemPrompt.section({ name: 'onesheet-card-mode', text: MODE_TEXT, order: 900 })
|
|
159
|
-
} catch {
|
|
160
|
-
sectionDispose = null
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
syncSection(readMode())
|
|
164
|
-
|
|
165
175
|
ctx.effect(() =>
|
|
166
176
|
ctx.tools.register({
|
|
167
177
|
name: 'card_mode',
|
|
@@ -196,7 +206,6 @@ export function apply(ctx) {
|
|
|
196
206
|
}
|
|
197
207
|
const on = action === 'on'
|
|
198
208
|
const ok = writeMode(on)
|
|
199
|
-
syncSection(on)
|
|
200
209
|
return {
|
|
201
210
|
ok,
|
|
202
211
|
on,
|
|
@@ -224,7 +233,6 @@ export function apply(ctx) {
|
|
|
224
233
|
const off = ['off', '关', '0', 'false'].includes(arg)
|
|
225
234
|
if (!on && !off) return { kind: 'error', text: '用法:/cardmode on | off | status' }
|
|
226
235
|
const ok = writeMode(on)
|
|
227
|
-
syncSection(on)
|
|
228
236
|
return {
|
|
229
237
|
kind: 'success',
|
|
230
238
|
text: on
|
|
@@ -350,7 +358,6 @@ export function apply(ctx) {
|
|
|
350
358
|
else if (action === 'toggle') on = !on
|
|
351
359
|
if (mutating) {
|
|
352
360
|
writeMode(on)
|
|
353
|
-
syncSection(on)
|
|
354
361
|
}
|
|
355
362
|
return new Response(JSON.stringify({ ok: true, on, message: '图卡模式:' + (on ? '开' : '关') }), {
|
|
356
363
|
status: 200,
|