dsh-as-aistudio 0.5.11 → 0.5.13

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/CHANGELOG.md CHANGED
@@ -4,6 +4,13 @@
4
4
 
5
5
  ## 中文
6
6
 
7
+ **0.5.13** —— 跟进 dsh-rerun-turn 0.2.11(`/state` 走内存快照 + 派生缓存)。
8
+
9
+ **0.5.12** —— 跟进 dsh-rerun-turn 0.2.10(行增长节流 + 传输层重试)。
10
+
11
+ - 内嵌 rerun 半部:行数增长改成 20 秒节流的尾随刷新,`Failed to fetch` 静默重试 3 次;
12
+ 大会话里不再一次回答就排队几十次 `/state`。
13
+
7
14
  **0.5.11** —— 跟进 dsh-log-trim 0.7.0(worker 扫描 + 异步裁剪 + 用量账本)。
8
15
 
9
16
  - 内嵌 log-trim 升到 0.7.0:开机扫描在 worker 里跑(`src/vendor/host/dsh-log-trim.worker.mjs`),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-as-aistudio",
3
- "version": "0.5.11",
3
+ "version": "0.5.13",
4
4
  "description": "Google-AI-Studio-style turn controls for DeepSeek Harness, in one install: edit a prompt and re-run it, re-run a reply in place, delete a turn from the model context, render sent prompts as Markdown, and trim idle session logs on boot. Self-contained: the plugin list shows this one row, and the five components (four actions + one maintenance) are vendored inside it - installing the studio installs nothing else.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/client.js CHANGED
@@ -5530,7 +5530,7 @@ window.__ModuleLoader__.load({
5530
5530
  const ROUTE_PREFIX = '/dsh-rerun-turn'
5531
5531
 
5532
5532
  /** Keep in sync with package.json and lib/index.js. */
5533
- const PLUGIN_VERSION = '0.2.9'
5533
+ const PLUGIN_VERSION = '0.2.11'
5534
5534
 
5535
5535
  // --- copy -----------------------------------------------------------------
5536
5536
 
@@ -5835,6 +5835,17 @@ window.__ModuleLoader__.load({
5835
5835
  })
5836
5836
  }
5837
5837
 
5838
+ // 行增长触发的最短刷新间隔。20 秒足够跟上一次回答的节奏,又不会把
5839
+ // 大会话的 /state 请求排成一串(单次要 35 s 的那种会话尤其明显)。
5840
+ const ROW_REFRESH_MIN_MS = (typeof process !== 'undefined' && process.env && process.env.DSH_RERUN_ROW_REFRESH_MS)
5841
+ ? Math.max(1, Number(process.env.DSH_RERUN_ROW_REFRESH_MS))
5842
+ : 20000
5843
+ // 传输层失败最多试几次(1 s / 2 s / 4 s),之后才把错误显示出来。
5844
+ const LOAD_RETRIES = 3
5845
+ const RETRY_BASE_MS = (typeof process !== 'undefined' && process.env && process.env.DSH_RERUN_RETRY_MS)
5846
+ ? Math.max(1, Number(process.env.DSH_RERUN_RETRY_MS))
5847
+ : 1000
5848
+
5838
5849
  // --- controller -----------------------------------------------------------
5839
5850
 
5840
5851
  class RerunController {
@@ -5844,6 +5855,13 @@ window.__ModuleLoader__.load({
5844
5855
  this.inflight = null
5845
5856
  this.pollTimer = null
5846
5857
  this.rowCount = -1
5858
+ // 行数增长不再“每加一行就重拉一次”:大会话的 /state 要几十秒,
5859
+ // 一次回答里能看到几十次增长,旧逻辑等于把宿主按死。
5860
+ this.rowTimer = null
5861
+ this.lastRowRefreshAt = 0
5862
+ // 传输层失败(Failed to fetch):静默重试几次,别一断就把错误钉在界面上。
5863
+ this.loadAttempts = 0
5864
+ this.retryTimer = null
5847
5865
  this.confirmTarget = null
5848
5866
  // Set by dispose(): a listener that outlives the apply (an adopted
5849
5867
  // button still carries the previous instance's click handler) must not
@@ -5901,6 +5919,36 @@ window.__ModuleLoader__.load({
5901
5919
  window.clearInterval(this.pollTimer)
5902
5920
  this.pollTimer = null
5903
5921
  }
5922
+ if (this.rowTimer !== null) {
5923
+ window.clearTimeout(this.rowTimer)
5924
+ this.rowTimer = null
5925
+ }
5926
+ if (this.retryTimer !== null) {
5927
+ window.clearTimeout(this.retryTimer)
5928
+ this.retryTimer = null
5929
+ }
5930
+ }
5931
+
5932
+ /**
5933
+ * 行数增长后请求一次刷新,但两次之间至少隔 `ROW_REFRESH_MIN_MS`。
5934
+ * 增长本身不重要,重要的是“这轮回答结束后要有一条新数据”。
5935
+ */
5936
+ requestRowRefresh() {
5937
+ if (this.disposed === true) return
5938
+ if (this.rowTimer !== null) return
5939
+ const now = Date.now()
5940
+ const wait = ROW_REFRESH_MIN_MS - (now - this.lastRowRefreshAt)
5941
+ if (wait <= 0) {
5942
+ this.lastRowRefreshAt = now
5943
+ this.load(true)
5944
+ return
5945
+ }
5946
+ this.rowTimer = setTimeout(() => {
5947
+ this.rowTimer = null
5948
+ if (this.disposed === true) return
5949
+ this.lastRowRefreshAt = Date.now()
5950
+ this.load(true)
5951
+ }, wait)
5904
5952
  }
5905
5953
 
5906
5954
  load(force) {
@@ -5981,6 +6029,7 @@ window.__ModuleLoader__.load({
5981
6029
  }
5982
6030
  }
5983
6031
  hostConfirm = Boolean(data.config && data.config.confirm)
6032
+ this.loadAttempts = 0
5984
6033
  this.publish({
5985
6034
  hidden,
5986
6035
  replies,
@@ -6003,6 +6052,17 @@ window.__ModuleLoader__.load({
6003
6052
  else this.stopPolling()
6004
6053
  })
6005
6054
  .catch((error) => {
6055
+ // 传输层失败(断网、宿主重启、请求被掐)不该一断就钉死错误:
6056
+ // 先静默重试 1 s / 2 s / 4 s,仍失败才把原因显示出来。
6057
+ this.loadAttempts = (this.loadAttempts || 0) + 1
6058
+ if (this.loadAttempts <= LOAD_RETRIES) {
6059
+ const delay = RETRY_BASE_MS * 2 ** (this.loadAttempts - 1)
6060
+ this.retryTimer = setTimeout(() => {
6061
+ this.retryTimer = null
6062
+ if (this.disposed !== true) this.load(true)
6063
+ }, delay)
6064
+ return
6065
+ }
6006
6066
  // The host says WHY (`invalid session id`, `no session log for this
6007
6067
  // id`, a 500, a network failure). Swallowing it left the panel with
6008
6068
  // "状态加载失败,稍后重试。" for every cause alike - including the
@@ -6286,7 +6346,11 @@ window.__ModuleLoader__.load({
6286
6346
  controller.rowCount = rowCount
6287
6347
  // Only new rows can add edit targets / a fresh turn; shrink churn (the
6288
6348
  // host rebuilding its list) does not need a refresh.
6289
- if (grew) controller.load(true)
6349
+ if (grew) {
6350
+ // 真实控制器有节流;测试里的轻量替身只有 load(),退回旧行为。
6351
+ if (typeof controller.requestRowRefresh === 'function') controller.requestRowRefresh()
6352
+ else controller.load(true)
6353
+ }
6290
6354
  }
6291
6355
 
6292
6356
  function applyDom(snapshot, view, controller, t) {
@@ -10104,7 +10168,7 @@ window.__ModuleLoader__.load({
10104
10168
  const NS = 'dsh-as-aistudio'
10105
10169
 
10106
10170
  /** Keep in sync with package.json and src/components.js. */
10107
- const PLUGIN_VERSION = '0.5.11'
10171
+ const PLUGIN_VERSION = '0.5.13'
10108
10172
 
10109
10173
  /** Presence marker the live verifier reads. */
10110
10174
  const DEBUG_KEY = '__DSH_AS_AISTUDIO__'
package/src/components.js CHANGED
@@ -26,7 +26,7 @@
26
26
  export const STUDIO_ID = 'dsh-as-aistudio'
27
27
 
28
28
  /** Keep in sync with package.json and src/client.js. */
29
- export const STUDIO_VERSION = '0.5.11'
29
+ export const STUDIO_VERSION = '0.5.13'
30
30
 
31
31
  /**
32
32
  * The AI Studio action strip this studio composes, in the order the user meets
@@ -1,6 +1,6 @@
1
1
  // dsh-edit-turn host half (dsh-edit-turn.js), VENDORED by tools/vendor.mjs - DO NOT EDIT.
2
2
  //
3
- // Source: ../dsh-edit-turn/lib/index.js (v0.5.16, sha256 3b2f76b4ef352e73)
3
+ // Source: ../dsh-edit-turn/lib/index.js (v0.5.18, sha256 3a2e3a4008b8c061)
4
4
  // Regenerate with `npm run vendor`; test/sync.test.js fails when this is stale.
5
5
  //
6
6
  // src/shell.js imports the copy named after the component, which is why the
@@ -85,7 +85,7 @@ export const PLUGIN_ID = 'dsh-edit-turn'
85
85
  export const name = PLUGIN_ID
86
86
 
87
87
  /** Keep in sync with package.json and lib/client.js. */
88
- export const PLUGIN_VERSION = '0.5.16'
88
+ export const PLUGIN_VERSION = '0.5.18'
89
89
 
90
90
  // A ring of the last few requests, answering "did the browser half even ask, and
91
91
  // what did it get?" without needing its console. Read-only diagnostics: the
@@ -1,6 +1,6 @@
1
1
  // dsh-edit-turn host half (dsh-edit-turn.patch.js), VENDORED by tools/vendor.mjs - DO NOT EDIT.
2
2
  //
3
- // Source: ../dsh-edit-turn/lib/patch.js (v0.5.16, sha256 5e1e8cce1d168f6c)
3
+ // Source: ../dsh-edit-turn/lib/patch.js (v0.5.18, sha256 5e1e8cce1d168f6c)
4
4
  // Regenerate with `npm run vendor`; test/sync.test.js fails when this is stale.
5
5
  //
6
6
  // src/shell.js imports the copy named after the component, which is why the
@@ -1,6 +1,6 @@
1
1
  // dsh-rerun-turn host half (dsh-rerun-turn.js), VENDORED by tools/vendor.mjs - DO NOT EDIT.
2
2
  //
3
- // Source: ../dsh-rerun-turn/lib/index.js (v0.2.9, sha256 60fce2958ddc3d13)
3
+ // Source: ../dsh-rerun-turn/lib/index.js (v0.2.11, sha256 e795e5c3eb214e8f)
4
4
  // Regenerate with `npm run vendor`; test/sync.test.js fails when this is stale.
5
5
  //
6
6
  // src/shell.js imports the copy named after the component, which is why the
@@ -90,7 +90,7 @@ export const PLUGIN_ID = 'dsh-rerun-turn'
90
90
  export const name = PLUGIN_ID
91
91
 
92
92
  /** Keep in sync with package.json and lib/client.js. */
93
- export const PLUGIN_VERSION = '0.2.9'
93
+ export const PLUGIN_VERSION = '0.2.11'
94
94
 
95
95
  const ROUTE_PREFIX = '/dsh-rerun-turn'
96
96
  // A session id is an OPAQUE string to DSH: the host's own schema is
@@ -1862,6 +1862,12 @@ function eventsFromLive(session) {
1862
1862
  // Live-preferred read through the public query service; the live session's own
1863
1863
  // snapshot is the fallback when the service is absent.
1864
1864
  async function readEvents(ctx, sessionId) {
1865
+ // 打开着的会话先读它自己的内存快照:`snapshotEvents()` 是 O(1) 的引用,
1866
+ // 而 `readSession` 会把整份日志重新解码一遍(大会话实测几十秒)。
1867
+ // 面板可见时宿主一定持有这个 session,所以这是最常走的路径。
1868
+ const live = findLiveSession(ctx, sessionId)
1869
+ const fromLive = eventsFromLive(live)
1870
+ if (Array.isArray(fromLive) && fromLive.length > 0) return fromLive
1865
1871
  const query = ctx.get('sessionQuery')
1866
1872
  if (query && typeof query.readSession === 'function') {
1867
1873
  try {
@@ -1871,7 +1877,6 @@ async function readEvents(ctx, sessionId) {
1871
1877
  // fall through to the live snapshot
1872
1878
  }
1873
1879
  }
1874
- const live = findLiveSession(ctx, sessionId)
1875
1880
  return eventsFromLive(live) ?? null
1876
1881
  }
1877
1882
 
@@ -2337,6 +2342,33 @@ function emptyState(config) {
2337
2342
  }
2338
2343
  }
2339
2344
 
2345
+
2346
+ // /state 的派生结果缓存:同一份事件流被反复请求时(轮询、行增长、多个标签页),
2347
+ // 只算一次。键是「事件数 + 最后 seq」——日志只追加,这两个数变了才重算。
2348
+ const STATE_CACHE_LIMIT = 8
2349
+ const stateCache = new Map()
2350
+
2351
+ /**
2352
+ * 取出(或计算)一份事件流的派生结果。
2353
+ *
2354
+ * @param {string} sessionId - 会话 id。
2355
+ * @param {object[]} events - 事件数组。
2356
+ * @returns {{ folded: object, ledger: object, replies: object[] }} 派生结果。
2357
+ */
2358
+ function derivedOf(sessionId, events) {
2359
+ const lastSeq = events.length > 0 ? events[events.length - 1].seq : -1
2360
+ const signature = events.length + ':' + lastSeq
2361
+ const cached = stateCache.get(sessionId)
2362
+ if (cached !== undefined && cached.signature === signature) return cached.value
2363
+ const folded = foldSurface(events)
2364
+ const ledger = rerunLedger(events)
2365
+ const replies = rerunnableReplies(events, folded.nodes)
2366
+ const value = { folded, ledger, replies }
2367
+ stateCache.set(sessionId, { signature, value })
2368
+ if (stateCache.size > STATE_CACHE_LIMIT) stateCache.delete(stateCache.keys().next().value)
2369
+ return value
2370
+ }
2371
+
2340
2372
  async function stateOf(ctx, sessionId, config) {
2341
2373
  const events = await readEvents(ctx, sessionId)
2342
2374
  if (!events) {
@@ -2344,10 +2376,8 @@ async function stateOf(ctx, sessionId, config) {
2344
2376
  noteRequest({ kind: 'state', sessionId, ok: true, code: 'session-empty' })
2345
2377
  return emptyState(config)
2346
2378
  }
2347
- const folded = foldSurface(events)
2348
- const ledger = rerunLedger(events)
2379
+ const { folded, ledger, replies } = derivedOf(sessionId, events)
2349
2380
  const live = findLiveSession(ctx, sessionId)
2350
- const replies = rerunnableReplies(events, folded.nodes)
2351
2381
  const busy = isBusy(events)
2352
2382
  const rerunning = locked(sessionId)
2353
2383
  const current = progress.get(sessionId) || null
@@ -1,6 +1,6 @@
1
1
  {
2
- "dsh-edit-turn": "0.5.16",
3
- "dsh-rerun-turn": "0.2.9",
2
+ "dsh-edit-turn": "0.5.18",
3
+ "dsh-rerun-turn": "0.2.11",
4
4
  "dsh-delete-turn": "0.2.4",
5
5
  "dsh-markdown-bubble": "0.1.5",
6
6
  "dsh-log-trim": "0.7.0"