dsh-as-aistudio 0.4.2 → 0.4.3

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,16 @@
4
4
 
5
5
  ## 中文
6
6
 
7
+ **0.4.3** —— 编辑入口不再"等半天才出现"(`/state` 从 25 MB 降到几百 KB)。
8
+
9
+ - **组件跟进**:`dsh-edit-turn` **0.5.9**(另三个不变:`dsh-rerun-turn` 0.2.6、`dsh-delete-turn` 0.1.15、`dsh-markdown-bubble` 0.1.5)。
10
+
11
+ - **症状**:编辑笔要等很久才出现;而且在这之前按复制,拿到的是改写前的原文。
12
+
13
+ - **根因(两件事同一个原因)**:`dsh-edit-turn` 的 `/state` 把每条回复的**整轮**推理与正文全文都发了出去。实测一个会话 291 条回复 = **27.9 MB**,一次 `/state` 要 **13 秒**。这段时间里浏览器半部没有任何编辑条目 —— 笔不出现,复制也就不会被插件接管。
14
+
15
+ - **修法**:`/state` 的 `replies` 只发身份(`seq` / `turn` / `messageId` / `attachments` / `textLength` / `blockCount`),全文与分块走新的 `/reply` 接口,只在按复制或打开编辑器时取一次。
16
+
7
17
  **0.4.2** —— 复制拿到改写后的文本(改到平台写入器这一层)。
8
18
 
9
19
  - **组件跟进**:`dsh-edit-turn` **0.5.8**(另三个不变:`dsh-rerun-turn` 0.2.6、`dsh-delete-turn` 0.1.15、`dsh-markdown-bubble` 0.1.5)。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-as-aistudio",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
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, and render sent prompts as Markdown. Self-contained: the plugin list shows this one row, and the four components 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
@@ -43,7 +43,7 @@ window.__ModuleLoader__.load({
43
43
  const RERUN_PREFIX = '/dsh-rerun-turn'
44
44
 
45
45
  /** Keep in sync with package.json and lib/index.js. */
46
- const PLUGIN_VERSION = '0.5.8'
46
+ const PLUGIN_VERSION = '0.5.9'
47
47
 
48
48
  // --- copy -----------------------------------------------------------------
49
49
 
@@ -139,6 +139,7 @@ window.__ModuleLoader__.load({
139
139
  'error.attachment-too-large': '这个文件太大,无法作为附件。',
140
140
  'error.too-large': '这次修改太大,服务器没有接收。',
141
141
  'error.replay-partial': '已保存并改写了这条回答,但后面的轮次没能全部重放回来,请重新打开会话确认。',
142
+ 'error.reply-not-found': '这条回答已经不可编辑了(可能已被改写或不在当前上下文里)。',
142
143
  }
143
144
 
144
145
  const en = {
@@ -228,6 +229,7 @@ window.__ModuleLoader__.load({
228
229
  'error.attachment-too-large': 'That file is too large to attach.',
229
230
  'error.too-large': 'That revision was too large for the host to accept.',
230
231
  'error.replay-partial': 'Saved and corrected, but the turns after it could not all be replayed; reopen the session to check.',
232
+ 'error.reply-not-found': 'That reply is no longer editable (it may have been rewritten, or left the current context).',
231
233
  }
232
234
 
233
235
  // Every error code the host can return travels through here. A code is
@@ -643,6 +645,9 @@ window.__ModuleLoader__.load({
643
645
  this.sessionId = sessionId
644
646
  this.listeners = new Set()
645
647
  this.inflight = null
648
+ // One reply's full wording, fetched on demand and kept: `/state` ships
649
+ // identities only (a reply carries its whole turn's text).
650
+ this.replyBodies = new Map()
646
651
  this.animateOnce = false
647
652
  this.rowCount = -1
648
653
  this.editor = null
@@ -747,6 +752,32 @@ window.__ModuleLoader__.load({
747
752
  return value
748
753
  }
749
754
 
755
+ /**
756
+ * One reply's full wording and blocks, on demand.
757
+ *
758
+ * `/state` publishes identities only: a reply carries its whole turn's
759
+ * reasoning and answer text, and a long session's list ran to 27.9 MB -
760
+ * 13 seconds for one refresh, which is why the edit entry appeared so late.
761
+ *
762
+ * @param {string} messageId - the reply's message id.
763
+ * @returns {Promise<object|null>} `{ text, blocks, attachments }`, or null.
764
+ */
765
+ replyBody(messageId) {
766
+ if (typeof messageId !== 'string' || messageId === '') return Promise.resolve(null)
767
+ const cached = this.replyBodies.get(messageId)
768
+ if (cached !== undefined) return cached
769
+ const url = `${ROUTE_PREFIX}/reply?sessionId=${encodeURIComponent(this.sessionId)}&messageId=${encodeURIComponent(messageId)}`
770
+ const pending = fetch(url, { headers: { accept: 'application/json' } })
771
+ .then(async (res) => {
772
+ const data = await res.json().catch(() => ({}))
773
+ if (!res.ok || !data.ok) throw new Error(data && data.error ? String(data.error) : `HTTP ${res.status}`)
774
+ return { text: data.text, blocks: Array.isArray(data.blocks) ? data.blocks : [], attachments: data.attachments }
775
+ })
776
+ .catch(() => null)
777
+ this.replyBodies.set(messageId, pending)
778
+ return pending
779
+ }
780
+
750
781
  load(force) {
751
782
  // A refresh asked for while one is already running has to land *after*
752
783
  // it: handing back the in-flight response would answer with a snapshot
@@ -4825,37 +4856,55 @@ window.__ModuleLoader__.load({
4825
4856
  const open = (event) => {
4826
4857
  event.preventDefault()
4827
4858
  event.stopPropagation()
4828
- controller.open({
4829
- anchor: event.currentTarget,
4830
- seq: entry.seq,
4831
- mode: 'reply',
4832
- turn: entry.turn,
4833
- messageId: entry.messageId,
4834
- text: typeof entry.text === 'string' ? entry.text : '',
4835
- attachments: typeof entry.attachments === 'number' ? entry.attachments : 0,
4836
- ...(Array.isArray(entry.blocks) ? { blocks: entry.blocks, patch: true } : { blocks: [] }),
4837
- })
4859
+ // `currentTarget` is null once this handler returns, so it is read before
4860
+ // the await that may fetch the reply's wording.
4861
+ const anchor = event.currentTarget
4862
+ void (async () => {
4863
+ let body = null
4864
+ if (!Array.isArray(entry.blocks) && typeof entry.blockCount === 'number' && entry.blockCount > 0) {
4865
+ body = await controller.replyBody(entry.messageId)
4866
+ }
4867
+ const blocks = body !== null && Array.isArray(body.blocks)
4868
+ ? body.blocks
4869
+ : Array.isArray(entry.blocks) ? entry.blocks : []
4870
+ controller.open({
4871
+ anchor,
4872
+ seq: entry.seq,
4873
+ mode: 'reply',
4874
+ turn: entry.turn,
4875
+ messageId: entry.messageId,
4876
+ text: body !== null && typeof body.text === 'string'
4877
+ ? body.text
4878
+ : typeof entry.text === 'string' ? entry.text : '',
4879
+ attachments: typeof entry.attachments === 'number' ? entry.attachments : 0,
4880
+ ...(blocks.length > 0 ? { blocks, patch: true } : { blocks: [] }),
4881
+ })
4882
+ })()
4838
4883
  }
4839
4884
  const copy = (event) => {
4840
4885
  event.preventDefault()
4841
4886
  event.stopPropagation()
4842
- const text = replyCopyText(entry)
4843
- if (text === '') return
4844
- const write = primitives !== null && primitives !== undefined && typeof primitives.writeClipboard === 'function'
4845
- ? primitives.writeClipboard
4846
- : typeof navigator !== 'undefined' && navigator.clipboard && typeof navigator.clipboard.writeText === 'function'
4847
- ? (value) => navigator.clipboard.writeText(value)
4848
- : null
4849
- if (write === null) return
4850
- Promise.resolve()
4851
- .then(() => write(text))
4852
- .then(
4853
- () => {
4854
- setCopied(true)
4855
- window.setTimeout(() => setCopied(false), 1200)
4856
- },
4857
- () => {},
4858
- )
4887
+ void (async () => {
4888
+ let text = replyCopyText(entry)
4889
+ if (text === '' && typeof entry.blockCount === 'number' && entry.blockCount > 0) {
4890
+ const body = await controller.replyBody(entry.messageId)
4891
+ if (body !== null) text = replyCopyText(body)
4892
+ }
4893
+ if (text === '') return
4894
+ const write = primitives !== null && primitives !== undefined && typeof primitives.writeClipboard === 'function'
4895
+ ? primitives.writeClipboard
4896
+ : typeof navigator !== 'undefined' && navigator.clipboard && typeof navigator.clipboard.writeText === 'function'
4897
+ ? (value) => navigator.clipboard.writeText(value)
4898
+ : null
4899
+ if (write === null) return
4900
+ try {
4901
+ await write(text)
4902
+ } catch {
4903
+ return
4904
+ }
4905
+ setCopied(true)
4906
+ window.setTimeout(() => setCopied(false), 1200)
4907
+ })()
4859
4908
  }
4860
4909
  return jsxs('div', {
4861
4910
  className: 'dshet-tail',
@@ -9147,7 +9196,7 @@ window.__ModuleLoader__.load({
9147
9196
  const NS = 'dsh-as-aistudio'
9148
9197
 
9149
9198
  /** Keep in sync with package.json and src/components.js. */
9150
- const PLUGIN_VERSION = '0.4.2'
9199
+ const PLUGIN_VERSION = '0.4.3'
9151
9200
 
9152
9201
  /** Presence marker the live verifier reads. */
9153
9202
  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.4.2'
29
+ export const STUDIO_VERSION = '0.4.3'
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.8, sha256 5c6fa30edaffed61)
3
+ // Source: ../dsh-edit-turn/lib/index.js (v0.5.9, sha256 a007714c89acfae5)
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.8'
88
+ export const PLUGIN_VERSION = '0.5.9'
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
@@ -1693,6 +1693,50 @@ export async function attachmentBytes(ctx, sessionId, seq, index) {
1693
1693
 
1694
1694
  // --- operations --------------------------------------------------------------
1695
1695
 
1696
+ /**
1697
+ * A reply's identity, without its words.
1698
+ *
1699
+ * One reply carries every reasoning and answer block of its **turn**, so a long
1700
+ * session's reply list is tens of megabytes: measured 291 replies = 27.9 MB, and
1701
+ * a single `/state` took 13 seconds - long enough that the browser showed no edit
1702
+ * entry, and slow enough to look like the plugin had not loaded at all. The words
1703
+ * are fetched when the user actually wants them (`/reply`).
1704
+ *
1705
+ * @param {object} entry - one entry from `editableReplies`.
1706
+ * @returns {object} the identity-only projection.
1707
+ */
1708
+ export function lightReply(entry) {
1709
+ return {
1710
+ seq: entry.seq,
1711
+ turn: entry.turn,
1712
+ messageId: entry.messageId,
1713
+ attachments: entry.attachments,
1714
+ textLength: typeof entry.text === 'string' ? entry.text.length : 0,
1715
+ blockCount: Array.isArray(entry.blocks) ? entry.blocks.length : 0,
1716
+ }
1717
+ }
1718
+
1719
+ /**
1720
+ * One reply's full wording and blocks, for a copy press or an opened editor.
1721
+ *
1722
+ * @param ctx - plugin context.
1723
+ * @param {string} sessionId - the session.
1724
+ * @param {object} config - resolved config.
1725
+ * @param {string} messageId - the reply's message id.
1726
+ * @returns {Promise<object|null>} `{ text, blocks, attachments }`, or null.
1727
+ */
1728
+ async function replyOf(ctx, sessionId, config, messageId) {
1729
+ const events = await readEvents(ctx, sessionId)
1730
+ if (!events) return null
1731
+ const folded = foldSurface(events)
1732
+ const entry = editableReplies(events, folded.nodes, {
1733
+ patches: patchesOf(events),
1734
+ patch: config.patch === true,
1735
+ }).find((candidate) => candidate.messageId === messageId)
1736
+ if (entry === undefined) return null
1737
+ return { text: entry.text, blocks: entry.blocks, attachments: entry.attachments }
1738
+ }
1739
+
1696
1740
  async function stateOf(ctx, sessionId, config) {
1697
1741
  const events = await readEvents(ctx, sessionId)
1698
1742
  if (!events) {
@@ -1741,7 +1785,7 @@ async function stateOf(ctx, sessionId, config) {
1741
1785
  // editor promising to keep blocks the host would have to drop.
1742
1786
  const store = resolveAttachmentStore(ctx)
1743
1787
  const turns = editableTurns(events, folded.nodes, { preview: canPreviewAttachments(store) })
1744
- const replies = editableReplies(events, folded.nodes, { patches, patch: config.patch === true })
1788
+ const replies = editableReplies(events, folded.nodes, { patches, patch: config.patch === true }).map(lightReply)
1745
1789
  noteRequest({
1746
1790
  kind: 'state',
1747
1791
  sessionId,
@@ -2594,6 +2638,33 @@ export function apply(ctx, config) {
2594
2638
  }),
2595
2639
  )
2596
2640
 
2641
+ // One reply's wording and blocks, on demand: `/state` publishes identities
2642
+ // only, because a reply can carry a whole turn's worth of text.
2643
+ fiber.effect(() =>
2644
+ webServer.register({
2645
+ kind: 'exact',
2646
+ path: `${ROUTE_PREFIX}/reply`,
2647
+ handler: async (req, res) => {
2648
+ if (!guard(req, res)) return
2649
+ if (req.method !== 'GET') {
2650
+ sendJson(res, 405, { ok: false, code: 'method', error: 'GET only' })
2651
+ return
2652
+ }
2653
+ try {
2654
+ const url = new URL(req.url ?? '/', 'http://127.0.0.1')
2655
+ const sessionId = requireSessionId(url.searchParams.get('sessionId') ?? '')
2656
+ const messageId = String(url.searchParams.get('messageId') ?? '').trim()
2657
+ if (messageId === '') throw new HttpError(400, 'invalid', 'messageId required')
2658
+ const body = await replyOf(ctx, sessionId, resolved, messageId)
2659
+ if (body === null) throw new HttpError(404, 'reply-not-found', 'this reply is not editable')
2660
+ sendJson(res, 200, { ok: true, messageId, ...body })
2661
+ } catch (error) {
2662
+ failure(res, error)
2663
+ }
2664
+ },
2665
+ }),
2666
+ )
2667
+
2597
2668
  // The bytes behind one block, for the editor's chips. Read-only, loopback
2598
2669
  // and same-origin like everything else here, and answered only for a block
2599
2670
  // the session's own log cites.
@@ -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.8, sha256 5e1e8cce1d168f6c)
3
+ // Source: ../dsh-edit-turn/lib/patch.js (v0.5.9, 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,5 +1,5 @@
1
1
  {
2
- "dsh-edit-turn": "0.5.8",
2
+ "dsh-edit-turn": "0.5.9",
3
3
  "dsh-rerun-turn": "0.2.6",
4
4
  "dsh-delete-turn": "0.1.15",
5
5
  "dsh-markdown-bubble": "0.1.5"