dsh-wechat-studio 0.1.0 → 0.1.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/icon.svg ADDED
@@ -0,0 +1,28 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" role="img" aria-labelledby="title desc">
2
+ <title id="title">公众号成稿台</title>
3
+ <desc id="desc">暖橙色背景上的白色稿纸,最后一行文字化作向右上发布的箭头。</desc>
4
+ <defs>
5
+ <linearGradient id="background" x1="32" y1="20" x2="224" y2="240" gradientUnits="userSpaceOnUse">
6
+ <stop stop-color="#FFB982"/>
7
+ <stop offset="1" stop-color="#FF8757"/>
8
+ </linearGradient>
9
+ <filter id="paper-shadow" x="35" y="25" width="190" height="215" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
10
+ <feDropShadow dx="0" dy="8" stdDeviation="8" flood-color="#8A3D24" flood-opacity="0.18"/>
11
+ </filter>
12
+ </defs>
13
+
14
+ <rect width="256" height="256" rx="60" fill="url(#background)"/>
15
+ <circle cx="218" cy="38" r="64" fill="#FFFFFF" opacity="0.12"/>
16
+ <circle cx="34" cy="226" r="76" fill="#FFFFFF" opacity="0.08"/>
17
+
18
+ <g transform="rotate(-6 128 128)">
19
+ <path d="M61 46C61 39.4 66.4 34 73 34H159L197 72V202C197 208.6 191.6 214 185 214H73C66.4 214 61 208.6 61 202V46Z" fill="#FFFDF9" filter="url(#paper-shadow)"/>
20
+ <path d="M159 34V61C159 67.1 163.9 72 170 72H197L159 34Z" fill="#FFE0C8"/>
21
+ <path d="M159 34L197 72H170C163.9 72 159 67.1 159 61V34Z" fill="#F7C7A7"/>
22
+
23
+ <path d="M88 91H158" stroke="#262522" stroke-width="11" stroke-linecap="round"/>
24
+ <path d="M88 122H167" stroke="#262522" stroke-width="11" stroke-linecap="round"/>
25
+ <path d="M88 153H120" stroke="#262522" stroke-width="11" stroke-linecap="round"/>
26
+ <path d="M119 181L174 139M151 137L177 137L177 163" fill="none" stroke="#F27645" stroke-width="12" stroke-linecap="round" stroke-linejoin="round"/>
27
+ </g>
28
+ </svg>
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "dsh-wechat-studio",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "DeepSeek Harness 插件「公众号成稿台」:写稿、按段改稿、朱雀报告质检、公众号排版预览和一键复制。",
5
5
  "type": "module",
6
6
  "main": "src/host.js",
7
7
  "exports": {
8
8
  ".": "./src/host.js",
9
9
  "./client": "./dist/client.js",
10
+ "./icon": "./icon.svg",
10
11
  "./cordis.patch.yml": "./cordis.patch.yml",
11
12
  "./package.json": "./package.json"
12
13
  },
@@ -16,7 +17,13 @@
16
17
  },
17
18
  "engines": { "node": ">=20", "dsh": ">=0.2.1-rc.5 <0.3.0" },
18
19
  "keywords": ["dsh", "deepseek-harness", "dsh-plugin", "wechat"],
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/lqshow/dsh-wechat-studio.git"
23
+ },
24
+ "homepage": "https://github.com/lqshow/dsh-wechat-studio#readme",
19
25
  "license": "MIT",
26
+ "icon": "./icon.svg",
20
27
  "scripts": {
21
28
  "build": "node scripts/build.mjs",
22
29
  "watch": "node scripts/build.mjs --watch",
@@ -30,5 +37,5 @@
30
37
  "react-dom": "^18.3.1",
31
38
  "unpdf": "^1.4.0"
32
39
  },
33
- "files": ["src", "dist", "skills", "vendor", "cordis.patch.yml", "README.md", "LICENSE"]
40
+ "files": ["src", "dist", "skills", "vendor", "icon.svg", "cordis.patch.yml", "README.md", "LICENSE"]
34
41
  }
package/src/article.js CHANGED
@@ -128,6 +128,13 @@ export function undo(article) {
128
128
  article.hook = last.hook ?? null
129
129
  article.titles = last.titles
130
130
  article.blocks = last.blocks
131
+ if (last.reimportBefore) {
132
+ for (const key of ['summary', 'zhuque', 'imageImport']) {
133
+ const value = last.reimportBefore[key]
134
+ if (value === undefined) delete article[key]
135
+ else article[key] = structuredClone(value)
136
+ }
137
+ }
131
138
  touch(article)
132
139
  return last.label
133
140
  }
@@ -142,6 +149,8 @@ export function revisionChanges(article) {
142
149
  }
143
150
  const oldBlocks = new Map(before.blocks.map((block, i) => [block.id, { text: block.text, number: i + 1 }]))
144
151
  const newIds = new Set(after.blocks.map(block => block.id))
152
+ const oldRank = new Map(before.blocks.filter(block => newIds.has(block.id)).map((block, rank) => [block.id, rank]))
153
+ const newRank = new Map(after.blocks.filter(block => oldBlocks.has(block.id)).map((block, rank) => [block.id, rank]))
145
154
  let cursor = 0
146
155
  const deleted = block => rows.push({ kind: 'delete', before: oldBlocks.get(block.id), after: null })
147
156
  after.blocks.forEach((block, i) => {
@@ -155,6 +164,8 @@ export function revisionChanges(article) {
155
164
  }
156
165
  if (!old || old.text !== block.text) {
157
166
  rows.push({ kind: old ? 'rewrite' : 'insert', before: old ?? null, after: { text: block.text, number: i + 1 } })
167
+ } else if (oldRank.get(block.id) !== newRank.get(block.id)) {
168
+ rows.push({ kind: 'move', before: old, after: { text: block.text, number: i + 1 } })
158
169
  }
159
170
  })
160
171
  for (const block of before.blocks.slice(cursor)) {
package/src/host.js CHANGED
@@ -8,6 +8,7 @@ import { BANNER_CHOICES, BANNER_STYLES, DEFAULT_BANNER } from './banner.js'
8
8
  import { blockKind, clearSchedule, correctPublishedAt, createArticle, fixPlan, HOOK_IDS, isCheckable, listMeta, markPublished, newId, revisionChanges, setSchedule, snapshot, splitMarkdown, toMarkdown, touch, undo, unpublish } from './article.js'
9
9
  import { transferFeishuImages, uploadInlineImage } from './cloudinary.js'
10
10
  import { feishuImageUrls, replaceFeishuImages } from './markdown-images.js'
11
+ import { applyMarkdownReimport, planMarkdownReimport } from './markdown-reimport.js'
11
12
  import { generateInlineImage, readInlineAsset, readInlineImage, removeInlineImages, removeOrphanInlineImages, saveInlineImage } from './inline-assets.js'
12
13
  import { analyzeInlineDiagrams, DIAGRAM_KINDS, insertDiagramBlock, sourceHash } from './inline-diagrams.js'
13
14
  import { loadInlineStyle, readInlineStyleCatalog } from './inline-skill.js'
@@ -20,6 +21,7 @@ import { pdfToText } from './report.js'
20
21
  import { publicSettings, readSettings, updateSettings } from './settings.js'
21
22
  import { scheduleTime as parseScheduleTime } from './schedule-time.js'
22
23
  import { Store } from './store.js'
24
+ import { createVersionChecker } from './version.js'
23
25
  import { detect } from './zhuque.js'
24
26
  import { draftSvgCard, insertSvgCard, previewSvgCard } from './svg-cards.js'
25
27
 
@@ -326,7 +328,10 @@ function startImageImport(deps, article, urls) {
326
328
  const current = state.articles.find(item => item.id === article.id)
327
329
  if (!current) return
328
330
  // Apply URLs to the latest text so edits made during upload are preserved.
329
- for (const blocks of [current.blocks, ...current.history.map(entry => entry.blocks)]) {
331
+ const boundary = current.history.findLastIndex(entry => entry.reimportBefore)
332
+ const recent = current.history.slice(boundary + 1)
333
+ const blockSets = [current.blocks, ...recent.map(entry => entry.blocks)]
334
+ for (const blocks of blockSets) {
330
335
  for (const block of blocks) {
331
336
  block.text = replaceFeishuImages(block.text, replacements)
332
337
  if (block.prev) block.prev = replaceFeishuImages(block.prev, replacements)
@@ -356,6 +361,7 @@ function view(article, pipeline, store, inlineStyles = [], inlineStyleWarnings =
356
361
  }
357
362
  return {
358
363
  id: article.id, topic: article.topic, title: article.title, titles: article.titles, summary: article.summary,
364
+ publishedAt: article.publishedAt ?? null,
359
365
  blocks: article.blocks.map(block => ({
360
366
  id: block.id, text: block.text, kind: blockKind(block.text), checkable: isCheckable(block.text), check: block.check,
361
367
  hasPrev: Boolean(block.prev), previousText: previousText.get(block.id) ?? (block.prev !== block.text ? block.prev ?? null : null),
@@ -423,6 +429,19 @@ function mustActive(article, message) {
423
429
  if (article.archivedAt) throw Object.assign(new Error(message), { status: 409 })
424
430
  }
425
431
 
432
+ function importConflict(message) {
433
+ return Object.assign(new Error(message), { status: 409 })
434
+ }
435
+
436
+ function assertCanReimport(deps, article) {
437
+ mustActive(article, '归档稿件不能重新导入,请先恢复。')
438
+ if (article.publishedAt) throw importConflict('已发布稿件不能覆盖正文。')
439
+ notBusy(deps.pipeline, article.id)
440
+ if (coverJobMap(deps.store).has(article.id) || imageJobMap(deps.store).has(article.id) || diagramJobMap(deps.store).has(article.id)) {
441
+ throw importConflict('请等封面生成、图片转存或插图任务完成后再重新导入。')
442
+ }
443
+ }
444
+
426
445
  function mustPastPublication(at) {
427
446
  if (new Date(at).getTime() > Date.now()) {
428
447
  throw Object.assign(new Error('实际发表时间不能晚于现在。'), { status: 400 })
@@ -443,6 +462,7 @@ export async function route(deps, req, res) {
443
462
 
444
463
  if (get) {
445
464
  if (path === 'state') return ok()
465
+ if (path === 'version') return json(res, 200, await deps.versionChecker.check())
446
466
  if (path === 'settings') return json(res, 200, { ...publicSettings(await readSettings(store.root)), version: VERSION })
447
467
  if (path === 'models') return json(res, 200, { providers: await listModels(ctx), default: defaultSelection(ctx), current: modelOverride() })
448
468
  if (path === 'skills') {
@@ -663,6 +683,37 @@ export async function route(deps, req, res) {
663
683
  else throw Object.assign(new Error('没有这篇数据趋势文章'), { status: 404 })
664
684
  })
665
685
  return json(res, 200, await insightsView(deps, body.range))
686
+ case 'articles/reimport/preview': {
687
+ const article = mustFind(await store.read(), body.id)
688
+ assertCanReimport(deps, article)
689
+ const plan = planMarkdownReimport(article, body.markdown, { updateTitle: body.updateTitle === true })
690
+ return json(res, 200, {
691
+ token: plan.token, currentTitle: article.title, incomingTitle: plan.incomingTitle, finalTitle: plan.finalTitle,
692
+ changed: plan.changed, bodyChanged: plan.bodyChanged, kept: plan.kept, removed: plan.removed, added: plan.added,
693
+ removedMedia: plan.removedMedia, transfers: plan.bodyChanged ? feishuImageUrls(plan.entries).length : 0,
694
+ bannerReview: Boolean(article.banners?.[article.bannerStyle ?? DEFAULT_BANNER]),
695
+ })
696
+ }
697
+ case 'articles/reimport': {
698
+ const result = await store.update(state => {
699
+ const article = mustFind(state, body.id)
700
+ assertCanReimport(deps, article)
701
+ const plan = planMarkdownReimport(article, body.markdown, { updateTitle: body.updateTitle === true })
702
+ if (plan.token !== body.token) throw importConflict('稿件或导入选项已变化,请重新预检。')
703
+ if (plan.removedMedia.length && body.acknowledgeRemovedMedia !== true) {
704
+ throw importConflict('请先确认将移出的图片和动画卡。')
705
+ }
706
+ if (!plan.changed) throw importConflict('与当前稿件一致,无需覆盖。')
707
+ const applied = applyMarkdownReimport(article, plan)
708
+ if (applied.urls.length) {
709
+ article.imageImport = { error: '图片转存中断,可以重试。', remaining: applied.urls.length }
710
+ }
711
+ article.notice = { text: '已覆盖正文,可在改稿对比查看,或用顶部撤销恢复。', at: new Date().toISOString() }
712
+ return applied
713
+ })
714
+ startImageImport(deps, result.article, result.urls)
715
+ return ok()
716
+ }
666
717
  case 'articles/new': {
667
718
  const hasBody = typeof body.markdown === 'string' && body.markdown.trim()
668
719
  if (!hasBody && !String(body.topic ?? '').trim() && !String(body.material ?? '').trim()) throw Object.assign(new Error('写一句选题,或者贴入已有的文章。'), { status: 400 })
@@ -968,6 +1019,9 @@ export async function route(deps, req, res) {
968
1019
  await store.update(state => {
969
1020
  const article = mustFind(state, body.id)
970
1021
  notBusy(pipeline, article.id)
1022
+ if (article.history.at(-1)?.reimportBefore && imageJobMap(store).has(article.id)) {
1023
+ throw importConflict('图片转存完成后可恢复覆盖前版本。')
1024
+ }
971
1025
  const label = undo(article)
972
1026
  if (label) article.notice = { text: `已撤销:${label}`, at: new Date().toISOString() }
973
1027
  })
@@ -1048,7 +1102,8 @@ export function requestRejection(ctx, req) {
1048
1102
  export function createHandler(ctx, { store = new Store(), fetchImpl } = {}) {
1049
1103
  const pipeline = new Pipeline({ ctx, store, skillsDir: join(store.root, 'skills'), fetchImpl })
1050
1104
  const insightsStore = new Store(store.root, { file: 'insights.json', empty: INSIGHTS_EMPTY })
1051
- const deps = { ctx, store, pipeline, insightsStore, fetchImpl }
1105
+ const versionChecker = createVersionChecker({ currentVersion: VERSION, fetchImpl })
1106
+ const deps = { ctx, store, pipeline, insightsStore, versionChecker, fetchImpl }
1052
1107
  const inlineCleanup = (async () => {
1053
1108
  try {
1054
1109
  JSON.parse(await readFile(store.file, 'utf8'))
@@ -13,10 +13,17 @@ function isFeishuImage(value) {
13
13
 
14
14
  function imageMatches(markdown) {
15
15
  // Keep code examples untouched; only replace inline Markdown image destinations.
16
- const pattern = /^ {0,3}(`{3,}|~{3,})[^\n]*\n[\s\S]*?(?:^ {0,3}\1[\x60~]*[ \t]*\r?$|(?![\s\S]))|(`+)[^\n]*?\2|\\[^\n]|(!\[[^\]\n]*\]\(<?)([^\s>)]+)(>?(?:[ \t]+"[^"\n]*")?\))/gm
16
+ const pattern = /^ {0,3}(`{3,}|~{3,})[^\n]*\n[\s\S]*?(?:^ {0,3}\1[\x60~]*[ \t]*\r?$|(?![\s\S]))|(`+)[^\n]*?\2|\\[^\n]|(!\[(?:\\.|[^\]\\])*\]\(<?)([^\s>)]+)(>?(?:[ \t]+"[^"\n]*")?\))/gm
17
17
  return [...markdown.matchAll(pattern)].filter(match => match[4])
18
18
  }
19
19
 
20
+ export function markdownImageDestinations(text) {
21
+ return imageMatches(String(text ?? '')).map(match => ({
22
+ src: match[4],
23
+ caption: match[3].slice(2, match[3].lastIndexOf('](')).replace(/\\([\\\[\]])/g, '$1'),
24
+ }))
25
+ }
26
+
20
27
  export function feishuImageUrls(blocks) {
21
28
  return [...new Set(blocks.flatMap(block => imageMatches(block.text).map(match => match[4]).filter(isFeishuImage)))]
22
29
  }
@@ -0,0 +1,108 @@
1
+ import { createHash } from 'node:crypto'
2
+ import { newId, snapshot, splitMarkdown, touch } from './article.js'
3
+ import { feishuImageUrls, markdownImageDestinations } from './markdown-images.js'
4
+ import { parseSvgCardBlock } from './svg-cards.js'
5
+
6
+ const fail = message => Object.assign(new Error(message), { status: 400 })
7
+ const sha = value => createHash('sha256').update(JSON.stringify(value)).digest('hex')
8
+ const isSvg = text => /^```svg-[a-z]+(?:\s|$)/.test(text.trim())
9
+
10
+ function svgMedia(text, number, blockId) {
11
+ let card
12
+ try {
13
+ card = parseSvgCardBlock(text)
14
+ } catch (error) {
15
+ if (blockId === undefined) throw fail(`第 ${number} 块动画卡无效:${error.message}`)
16
+ const title = text.trim().match(/^```svg-[a-z]+(?:[ \t]+([^\n]+))?/)?.[1] ?? '动画卡'
17
+ return { key: `svg-raw:${text}`, item: { kind: 'svg', blockId, number, title } }
18
+ }
19
+ return {
20
+ key: `svg:${JSON.stringify(card)}`,
21
+ item: { kind: 'svg', blockId, number, title: card.title },
22
+ }
23
+ }
24
+
25
+ function mediaAt(text, number, blockId) {
26
+ if (isSvg(text)) return [svgMedia(text, number, blockId)]
27
+ return markdownImageDestinations(text).map((image, occurrence) => ({
28
+ key: `image:${image.src}`,
29
+ item: { kind: 'image', blockId, number, caption: image.caption, src: image.src, occurrence },
30
+ }))
31
+ }
32
+
33
+ export function planMarkdownReimport(article, markdown, { updateTitle = false } = {}) {
34
+ if (typeof markdown !== 'string') throw fail('Markdown 必须是文本。')
35
+ const parsed = splitMarkdown(markdown.replace(/^\uFEFF/, ''))
36
+ if (!parsed.blocks.length) throw fail('导入文件必须包含正文,只有标题或元信息不能覆盖。')
37
+ if (updateTitle && !parsed.title) throw fail('选择更新标题时,文件必须包含一级标题。')
38
+ if (updateTitle && parsed.title.length > 80) {
39
+ throw fail('一级标题不能超过 80 字;可取消同时更新标题后仅覆盖正文。')
40
+ }
41
+
42
+ const sameBody = parsed.blocks.length === article.blocks.length
43
+ && parsed.blocks.every((text, index) => text === article.blocks[index].text)
44
+ const oldFrequencies = new Map()
45
+ const newFrequencies = new Map()
46
+ const oldByText = new Map()
47
+ for (const block of article.blocks) {
48
+ oldFrequencies.set(block.text, (oldFrequencies.get(block.text) ?? 0) + 1)
49
+ oldByText.set(block.text, block)
50
+ }
51
+ for (const text of parsed.blocks) newFrequencies.set(text, (newFrequencies.get(text) ?? 0) + 1)
52
+ const entries = parsed.blocks.map((text, index) => {
53
+ const unique = oldFrequencies.get(text) === 1 && newFrequencies.get(text) === 1
54
+ return { text, existing: sameBody ? article.blocks[index] : unique ? oldByText.get(text) : null }
55
+ })
56
+
57
+ const incomingMedia = new Map()
58
+ parsed.blocks.forEach((text, index) => {
59
+ for (const media of mediaAt(text, index + 1)) {
60
+ incomingMedia.set(media.key, (incomingMedia.get(media.key) ?? 0) + 1)
61
+ }
62
+ })
63
+ const removedMedia = []
64
+ article.blocks.forEach((block, index) => {
65
+ for (const media of mediaAt(block.text, index + 1, block.id)) {
66
+ const remaining = incomingMedia.get(media.key) ?? 0
67
+ if (remaining > 0) incomingMedia.set(media.key, remaining - 1)
68
+ else removedMedia.push(media.item)
69
+ }
70
+ })
71
+
72
+ const finalTitle = updateTitle ? parsed.title : article.title
73
+ const changed = !sameBody || finalTitle !== article.title
74
+ const kept = entries.filter(entry => entry.existing).length
75
+ const token = sha([
76
+ article.id, article.title, article.summary, article.hook, article.titles,
77
+ article.blocks, article.zhuque, article.archivedAt, article.publishedAt,
78
+ parsed.blocks, parsed.title, updateTitle,
79
+ ])
80
+ return {
81
+ token, title: article.title, finalTitle, incomingTitle: parsed.title,
82
+ changed, bodyChanged: !sameBody, kept, removed: article.blocks.length - kept, added: entries.length - kept,
83
+ entries, removedMedia,
84
+ }
85
+ }
86
+
87
+ export function applyMarkdownReimport(article, plan) {
88
+ const bodyChanged = plan.bodyChanged
89
+ snapshot(article, '重新导入 Markdown')
90
+ article.history.at(-1).reimportBefore = {
91
+ summary: structuredClone(article.summary),
92
+ zhuque: structuredClone(article.zhuque),
93
+ imageImport: structuredClone(article.imageImport),
94
+ }
95
+ if (bodyChanged) {
96
+ article.blocks = plan.entries.map(entry => ({ id: entry.existing?.id ?? newId(), text: entry.text, check: null }))
97
+ article.summary = ''
98
+ article.titles = []
99
+ article.zhuque = { round: 0, lastAt: null }
100
+ article.imageImport = null
101
+ }
102
+ if (plan.finalTitle !== article.title) {
103
+ article.title = plan.finalTitle
104
+ article.hook = null
105
+ }
106
+ touch(article)
107
+ return { article, urls: bodyChanged ? feishuImageUrls(article.blocks) : [] }
108
+ }
package/src/version.js ADDED
@@ -0,0 +1,71 @@
1
+ const VERSION_URLS = [
2
+ 'https://registry.npmjs.org/dsh-wechat-studio/latest',
3
+ 'https://registry.npmmirror.com/dsh-wechat-studio/latest',
4
+ ]
5
+
6
+ const CACHE_TTL_MS = 60 * 60 * 1000
7
+ const FETCH_TIMEOUT_MS = 8_000
8
+
9
+ function parseVersion(version) {
10
+ const match = /^v?(\d+)\.(\d+)\.(\d+)(?:-(alpha|beta|rc)(?:\.(\d+))?)?(?:\+[0-9a-z.-]+)?$/i.exec(String(version).trim())
11
+ if (!match) return null
12
+ const channel = match[4]?.toLowerCase()
13
+ return {
14
+ major: Number(match[1]),
15
+ minor: Number(match[2]),
16
+ patch: Number(match[3]),
17
+ rank: channel === 'rc' ? 3 : channel === 'beta' ? 2 : channel === 'alpha' ? 1 : 4,
18
+ serial: match[5] ? Number(match[5]) : 0,
19
+ }
20
+ }
21
+
22
+ export function isNewerRelease(latest, current) {
23
+ const a = parseVersion(latest)
24
+ const b = parseVersion(current)
25
+ if (!a || !b) return false
26
+ for (const key of ['major', 'minor', 'patch', 'rank', 'serial']) {
27
+ if (a[key] !== b[key]) return a[key] > b[key]
28
+ }
29
+ return false
30
+ }
31
+
32
+ export function createVersionChecker({ currentVersion, fetchImpl = fetch, now = () => Date.now(), ttlMs = CACHE_TTL_MS }) {
33
+ let cached = null
34
+ let inflight = null
35
+
36
+ const read = async () => {
37
+ for (const url of VERSION_URLS) {
38
+ try {
39
+ const response = await fetchImpl(url, {
40
+ headers: { accept: 'application/json' },
41
+ signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
42
+ })
43
+ if (!response.ok) continue
44
+ const body = await response.json()
45
+ if (typeof body?.version !== 'string' || !body.version) continue
46
+ const latest = body.version
47
+ return {
48
+ ready: true,
49
+ failed: false,
50
+ checkedAt: now(),
51
+ current: currentVersion,
52
+ latest,
53
+ updateAvailable: isNewerRelease(latest, currentVersion),
54
+ }
55
+ } catch {
56
+ // Try the mirror when the registry is unavailable or returns invalid data.
57
+ }
58
+ }
59
+ return { ready: false, failed: true, checkedAt: now(), current: currentVersion, latest: null, updateAvailable: false }
60
+ }
61
+
62
+ return {
63
+ async check() {
64
+ if (cached && now() - cached.checkedAt < ttlMs) return cached
65
+ if (!inflight) {
66
+ inflight = read().then(result => { cached = result; return result }).finally(() => { inflight = null })
67
+ }
68
+ return inflight
69
+ },
70
+ }
71
+ }