@capyclaw/offline-ddr0 0.0.0-stage → 1.9.1
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/LICENSE +21 -0
- package/README.md +441 -2
- package/client/client.js +603 -0
- package/cordis.patch.yml +13 -0
- package/docs/STORAGE-MIGRATION.md +136 -0
- package/lib/atomic.mjs +40 -0
- package/lib/http-cache.mjs +42 -0
- package/lib/inbox.mjs +64 -0
- package/lib/media.mjs +242 -0
- package/lib/migrate-json.mjs +101 -0
- package/lib/mirror-index.mjs +105 -0
- package/lib/mirror.mjs +123 -0
- package/lib/proxy.mjs +188 -0
- package/lib/remote.mjs +158 -0
- package/lib/render.mjs +93 -0
- package/lib/repository.mjs +71 -0
- package/lib/store.mjs +610 -0
- package/lib/surface.mjs +74 -0
- package/lib/sync-ui.mjs +108 -0
- package/lib/sync.mjs +433 -0
- package/lib/wire.mjs +211 -0
- package/lib/workstore-repository.mjs +316 -0
- package/lib/workstore.mjs +348 -0
- package/mirror/files/00001.html +2045 -0
- package/mirror/files/00002.json +1 -0
- package/mirror/files/00003.json +1 -0
- package/mirror/files/00004.json +1 -0
- package/mirror/files/00005.json +1 -0
- package/mirror/files/00006.json +1 -0
- package/mirror/files/00007.json +1 -0
- package/mirror/files/00008.json +1 -0
- package/mirror/files/00009.json +1 -0
- package/mirror/files/00010.json +1 -0
- package/mirror/files/00011.json +1 -0
- package/mirror/files/00012.json +1 -0
- package/mirror/files/00013.json +1 -0
- package/mirror/files/00014.json +1 -0
- package/mirror/files/00015.json +1 -0
- package/mirror/files/00016.json +1 -0
- package/mirror/files/00017.json +1 -0
- package/mirror/files/00018.json +1 -0
- package/mirror/files/00019.json +1 -0
- package/mirror/files/00020.json +1 -0
- package/mirror/files/00021.json +1 -0
- package/mirror/files/00022.json +1 -0
- package/mirror/files/00023.js +205 -0
- package/mirror/files/00024.json +1 -0
- package/mirror/files/00025.json +1 -0
- package/mirror/files/00026.json +1 -0
- package/mirror/files/00027.js +51 -0
- package/mirror/files/00028.json +1 -0
- package/mirror/files/00029.json +1 -0
- package/mirror/files/00030.json +1 -0
- package/mirror/files/00031.json +1 -0
- package/mirror/files/00032.json +1 -0
- package/mirror/files/00033.json +1 -0
- package/mirror/files/00034.json +1 -0
- package/mirror/files/00035.json +1 -0
- package/mirror/files/00036.json +1 -0
- package/mirror/files/00037.json +1 -0
- package/mirror/files/00038.json +1 -0
- package/mirror/files/00039.json +1 -0
- package/mirror/files/00040.js +2311 -0
- package/mirror/files/00041.json +1 -0
- package/mirror/files/00042.json +1 -0
- package/mirror/files/00043.json +1 -0
- package/mirror/files/00044.json +1 -0
- package/mirror/files/00045.js +575 -0
- package/mirror/files/00046.json +1 -0
- package/mirror/files/00047.js +575 -0
- package/mirror/files/00048.js +575 -0
- package/mirror/files/00049.json +1 -0
- package/mirror/files/00050.json +1 -0
- package/mirror/files/00051.json +1 -0
- package/mirror/files/00052.json +1 -0
- package/mirror/files/00053.js +575 -0
- package/mirror/files/00054.json +1 -0
- package/mirror/files/00055.json +1 -0
- package/mirror/files/00056.js +575 -0
- package/mirror/files/00057.json +1 -0
- package/mirror/files/00058.json +1 -0
- package/mirror/files/00059.js +360 -0
- package/mirror/files/00060.json +1 -0
- package/mirror/files/00061.json +1 -0
- package/mirror/files/00062.json +1 -0
- package/mirror/files/00063.json +1 -0
- package/mirror/files/00064.json +1 -0
- package/mirror/files/00065.js +144 -0
- package/mirror/files/00066.js +7 -0
- package/mirror/files/00067.json +1 -0
- package/mirror/files/00068.json +1 -0
- package/mirror/files/00069.json +1 -0
- package/mirror/files/00070.json +1 -0
- package/mirror/files/00071.json +1 -0
- package/mirror/files/00072.json +1 -0
- package/mirror/files/00073.js +1 -0
- package/mirror/files/00074.json +1 -0
- package/mirror/files/00075.json +1 -0
- package/mirror/files/00076.json +1 -0
- package/mirror/files/00077.js +45 -0
- package/mirror/files/00078.js +1348 -0
- package/mirror/files/00079.json +1 -0
- package/mirror/files/00080.json +1 -0
- package/mirror/files/00081.js +1 -0
- package/mirror/files/00082.json +1 -0
- package/mirror/files/00083.json +1 -0
- package/mirror/files/00084.js +7 -0
- package/mirror/files/00085.json +1 -0
- package/mirror/files/00086.json +1 -0
- package/mirror/files/00087.js +7 -0
- package/mirror/files/00088.json +1 -0
- package/mirror/files/00089.json +1 -0
- package/mirror/files/00090.js +7 -0
- package/mirror/files/00091.json +1 -0
- package/mirror/files/00092.json +1 -0
- package/mirror/files/00093.js +102 -0
- package/mirror/files/00094.json +1 -0
- package/mirror/files/00095.json +1 -0
- package/mirror/files/00096.json +1 -0
- package/mirror/files/00097.json +1 -0
- package/mirror/files/00098.json +1 -0
- package/mirror/files/00099.json +1 -0
- package/mirror/files/00100.json +1 -0
- package/mirror/files/00101.js +102 -0
- package/mirror/files/00102.json +1 -0
- package/mirror/files/00103.json +1 -0
- package/mirror/files/00104.json +1 -0
- package/mirror/files/00105.json +1 -0
- package/mirror/files/00106.json +1 -0
- package/mirror/files/00107.js +110 -0
- package/mirror/files/00108.json +1 -0
- package/mirror/files/00109.json +1 -0
- package/mirror/files/00110.json +1 -0
- package/mirror/files/00111.json +1 -0
- package/mirror/files/00112.json +1 -0
- package/mirror/files/00113.json +1 -0
- package/mirror/files/00114.json +1 -0
- package/mirror/files/00115.json +1 -0
- package/mirror/files/00116.json +1 -0
- package/mirror/files/00117.json +1 -0
- package/mirror/files/00118.json +1 -0
- package/mirror/files/00119.json +1 -0
- package/mirror/files/00120.json +1 -0
- package/mirror/files/00121.json +1 -0
- package/mirror/files/00122.json +1 -0
- package/mirror/files/00123.json +1 -0
- package/mirror/files/00124.json +1 -0
- package/mirror/files/00125.json +1 -0
- package/mirror/files/00126.json +1 -0
- package/mirror/files/00127.json +1 -0
- package/mirror/files/00128.json +1 -0
- package/mirror/files/00129.json +1 -0
- package/mirror/files/00130.json +1 -0
- package/mirror/files/00131.json +1 -0
- package/mirror/files/00132.js +110 -0
- package/mirror/files/00133.json +1 -0
- package/mirror/files/00134.json +1 -0
- package/mirror/files/00135.json +1 -0
- package/mirror/files/00136.json +1 -0
- package/mirror/files/00137.js +26 -0
- package/mirror/files/00138.json +1 -0
- package/mirror/files/00139.json +1 -0
- package/mirror/files/00140.json +1 -0
- package/mirror/files/00141.json +1 -0
- package/mirror/files/00142.json +1 -0
- package/mirror/files/00143.json +1 -0
- package/mirror/files/00144.js +26 -0
- package/mirror/files/00145.json +1 -0
- package/mirror/files/00146.json +1 -0
- package/mirror/files/00147.js +29 -0
- package/mirror/files/00148.json +1 -0
- package/mirror/files/00149.json +1 -0
- package/mirror/files/00150.js +23 -0
- package/mirror/files/00151.json +1 -0
- package/mirror/files/00152.json +1 -0
- package/mirror/files/00153.js +719 -0
- package/mirror/files/00154.js +9575 -0
- package/mirror/files/00155.js +108 -0
- package/mirror/files/00156.js +379 -0
- package/mirror/files/00157.js +48 -0
- package/mirror/files/00158.json +16 -0
- package/mirror/manifest.json +1582 -0
- package/node_modules/@capyclaw/asset-service/README.md +48 -0
- package/node_modules/@capyclaw/asset-service/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/asset-service/dsh-suite.json +29 -0
- package/node_modules/@capyclaw/asset-service/lib/host.mjs +14 -0
- package/node_modules/@capyclaw/asset-service/package.json +59 -0
- package/node_modules/@capyclaw/asset-service/src/index.mjs +310 -0
- package/node_modules/@capyclaw/foundation/README.md +51 -0
- package/node_modules/@capyclaw/foundation/abi/assets.mjs +26 -0
- package/node_modules/@capyclaw/foundation/abi/bridge.mjs +88 -0
- package/node_modules/@capyclaw/foundation/abi/errors.mjs +63 -0
- package/node_modules/@capyclaw/foundation/abi/index.mjs +50 -0
- package/node_modules/@capyclaw/foundation/abi/kinds.mjs +271 -0
- package/node_modules/@capyclaw/foundation/abi/loader.mjs +352 -0
- package/node_modules/@capyclaw/foundation/abi/schema.mjs +98 -0
- package/node_modules/@capyclaw/foundation/abi/spec.mjs +258 -0
- package/node_modules/@capyclaw/foundation/abi/validate.mjs +24 -0
- package/node_modules/@capyclaw/foundation/abi/version.mjs +140 -0
- package/node_modules/@capyclaw/foundation/abi/visibility.mjs +90 -0
- package/node_modules/@capyclaw/foundation/cordis.patch.yml +5 -0
- package/node_modules/@capyclaw/foundation/kit/index.mjs +6 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/client-panel.mjs +98 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/host-event.mjs +35 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/http-router.mjs +69 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/lifecycle-hook.mjs +72 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/own-server.mjs +113 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/raw.mjs +69 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/runtime-driver.mjs +120 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/service-provider.mjs +77 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/skill-provider.mjs +56 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/tool-provider.mjs +50 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/ui-panel.mjs +64 -0
- package/node_modules/@capyclaw/foundation/lib/ctx-service.mjs +42 -0
- package/node_modules/@capyclaw/foundation/lib/host/caps.mjs +38 -0
- package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +88 -0
- package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +54 -0
- package/node_modules/@capyclaw/foundation/lib/host/memory.mjs +187 -0
- package/node_modules/@capyclaw/foundation/lib/host.mjs +23 -0
- package/node_modules/@capyclaw/foundation/lib/kernel.mjs +195 -0
- package/node_modules/@capyclaw/foundation/lib/skill/scan.mjs +115 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/events.mjs +60 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/log.mjs +51 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/net.mjs +198 -0
- package/node_modules/@capyclaw/foundation/package.json +53 -0
- package/node_modules/@capyclaw/foundation/runtime/index.mjs +20 -0
- package/node_modules/@capyclaw/plugin-kit/INTEGRATION.md +100 -0
- package/node_modules/@capyclaw/plugin-kit/README.md +70 -0
- package/node_modules/@capyclaw/plugin-kit/bin/sync.mjs +103 -0
- package/node_modules/@capyclaw/plugin-kit/package.json +71 -0
- package/node_modules/@capyclaw/plugin-kit/src/cli.mjs +56 -0
- package/node_modules/@capyclaw/plugin-kit/src/config.mjs +142 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat-worker.js +132 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat.mjs +26 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/lease.mjs +60 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/shadow.mjs +219 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/transport.js +13 -0
- package/node_modules/@capyclaw/plugin-kit/src/index.mjs +13 -0
- package/node_modules/@capyclaw/plugin-kit/src/pack.mjs +230 -0
- package/node_modules/@capyclaw/plugin-kit/src/runtime/context.mjs +128 -0
- package/node_modules/@capyclaw/plugin-kit/src/self-contained.mjs +307 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/api.mjs +45 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/http.mjs +113 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/mcp-http.mjs +150 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/server.mjs +131 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/static.mjs +79 -0
- package/node_modules/@capyclaw/plugin-kit/src/skills/provider.mjs +82 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/blob-store.mjs +109 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/content-store.mjs +17 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/journal-store.mjs +89 -0
- package/node_modules/@capyclaw/plugin-kit/src/tools/result.mjs +57 -0
- package/node_modules/@capyclaw/plugin-kit/src/tools/validate.mjs +150 -0
- package/node_modules/@capyclaw/plugin-kit/src/tuning.mjs +82 -0
- package/node_modules/@capyclaw/plugin-kit/src/util/fs-lock.mjs +132 -0
- package/node_modules/@capyclaw/plugin-kit/src/util/http.mjs +130 -0
- package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +664 -0
- package/node_modules/@capyclaw/plugin-kit/src/zip.mjs +181 -0
- package/node_modules/@capyclaw/service-host/README.md +86 -0
- package/node_modules/@capyclaw/service-host/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/service-host/dsh-suite.json +29 -0
- package/node_modules/@capyclaw/service-host/lib/host.mjs +22 -0
- package/node_modules/@capyclaw/service-host/package.json +60 -0
- package/node_modules/@capyclaw/service-host/src/index.mjs +570 -0
- package/node_modules/@capyclaw/service-host/src/tuning.mjs +63 -0
- package/node_modules/@capyclaw/suite-kit/README.md +289 -0
- package/node_modules/@capyclaw/suite-kit/bin/dsh-domain.mjs +98 -0
- package/node_modules/@capyclaw/suite-kit/bin/dsh-suite.mjs +174 -0
- package/node_modules/@capyclaw/suite-kit/client/embed.js +35 -0
- package/node_modules/@capyclaw/suite-kit/domain.schema.json +129 -0
- package/node_modules/@capyclaw/suite-kit/package.json +58 -0
- package/node_modules/@capyclaw/suite-kit/src/activation-registry.mjs +184 -0
- package/node_modules/@capyclaw/suite-kit/src/artifacts.mjs +131 -0
- package/node_modules/@capyclaw/suite-kit/src/capability.mjs +181 -0
- package/node_modules/@capyclaw/suite-kit/src/compose.mjs +201 -0
- package/node_modules/@capyclaw/suite-kit/src/domain.mjs +138 -0
- package/node_modules/@capyclaw/suite-kit/src/embed.mjs +81 -0
- package/node_modules/@capyclaw/suite-kit/src/host.mjs +230 -0
- package/node_modules/@capyclaw/suite-kit/src/index.mjs +24 -0
- package/node_modules/@capyclaw/suite-kit/src/manifest.mjs +263 -0
- package/node_modules/@capyclaw/suite-kit/src/orchestration.mjs +100 -0
- package/node_modules/@capyclaw/suite-kit/src/profile.mjs +584 -0
- package/node_modules/@capyclaw/suite-kit/src/surface.mjs +28 -0
- package/node_modules/@capyclaw/suite-kit/suite.schema.json +128 -0
- package/node_modules/@capyclaw/work-store/README.md +83 -0
- package/node_modules/@capyclaw/work-store/STANDARD.md +263 -0
- package/node_modules/@capyclaw/work-store/cordis.patch.yml +3 -0
- package/node_modules/@capyclaw/work-store/dsh-suite.json +33 -0
- package/node_modules/@capyclaw/work-store/icon.svg +7 -0
- package/node_modules/@capyclaw/work-store/lib/host.mjs +21 -0
- package/node_modules/@capyclaw/work-store/package.json +68 -0
- package/node_modules/@capyclaw/work-store/src/backend.mjs +90 -0
- package/node_modules/@capyclaw/work-store/src/db.mjs +199 -0
- package/node_modules/@capyclaw/work-store/src/envelope.mjs +132 -0
- package/node_modules/@capyclaw/work-store/src/index.mjs +571 -0
- package/node_modules/@capyclaw/work-store/src/interop.mjs +70 -0
- package/node_modules/@capyclaw/work-store/src/refs.mjs +99 -0
- package/node_modules/@capyclaw/work-store/src/routes.mjs +135 -0
- package/package.json +82 -4
- package/plugin.mjs +644 -0
- package/static/index.html +2068 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 引用标准:结构化正文里只写 `@asset/<sha256>`,字节在内容寻址 blob 仓,
|
|
3
|
+
* 读时展开成可加载地址。`@media/<sha>` 是 PPT 历史别名,一视同仁地解析。
|
|
4
|
+
*
|
|
5
|
+
* 两个纯工具,套件无关:
|
|
6
|
+
* extractDataUris(value, putAsset) 写入闸:把内联 data: URI 抽进 blob 仓换引用
|
|
7
|
+
* resolveRefs(value, urlBase) 读取展开:@asset/@media → <urlBase>/assets/<sha>
|
|
8
|
+
* collectRefs(value) 收集正文里引用的全部 blob id(供 work_assets 索引)
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const ASSET_REF = /@asset\/([a-f0-9]{64})/gi
|
|
12
|
+
const MEDIA_REF = /@media\/([a-f0-9]{8,64})/gi
|
|
13
|
+
const DATA_URI = /^data:([^;,]+);base64,([A-Za-z0-9+/=\s]+)$/
|
|
14
|
+
|
|
15
|
+
/** 内联字节超过这个阈值才抽进 blob 仓(小图标留着无妨)。 */
|
|
16
|
+
export const EXTRACT_THRESHOLD = 2048
|
|
17
|
+
|
|
18
|
+
export function isAssetRef(text) {
|
|
19
|
+
return typeof text === 'string' && (ASSET_REF.test(text) || MEDIA_REF.test(text))
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** 收集一个 JSON 值里引用的全部 blob id(去重)。 */
|
|
23
|
+
export function collectRefs(value) {
|
|
24
|
+
const found = new Set()
|
|
25
|
+
const walk = (node) => {
|
|
26
|
+
if (typeof node === 'string') {
|
|
27
|
+
for (const re of [ASSET_REF, MEDIA_REF]) {
|
|
28
|
+
re.lastIndex = 0
|
|
29
|
+
let m
|
|
30
|
+
while ((m = re.exec(node))) found.add(m[1].toLowerCase())
|
|
31
|
+
}
|
|
32
|
+
} else if (Array.isArray(node)) {
|
|
33
|
+
node.forEach(walk)
|
|
34
|
+
} else if (node && typeof node === 'object') {
|
|
35
|
+
Object.values(node).forEach(walk)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
walk(value)
|
|
39
|
+
return [...found]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 读取展开:把 @asset/<sha> 与 @media/<sha> 换成 `<urlBase>/assets/<sha>`。
|
|
44
|
+
* 返回**新副本**,不改原值(与 PPT 的就地 expand 不同,底座要纯)。
|
|
45
|
+
*/
|
|
46
|
+
export function resolveRefs(value, urlBase) {
|
|
47
|
+
const base = String(urlBase || '').replace(/\/$/, '')
|
|
48
|
+
const sub = (text) => text
|
|
49
|
+
.replace(ASSET_REF, (_m, sha) => `${base}/assets/${sha.toLowerCase()}`)
|
|
50
|
+
.replace(MEDIA_REF, (_m, sha) => `${base}/assets/${sha.toLowerCase()}`)
|
|
51
|
+
const walk = (node) => {
|
|
52
|
+
if (typeof node === 'string') return sub(node)
|
|
53
|
+
if (Array.isArray(node)) return node.map(walk)
|
|
54
|
+
if (node && typeof node === 'object') {
|
|
55
|
+
const out = {}
|
|
56
|
+
for (const [k, v] of Object.entries(node)) out[k] = walk(v)
|
|
57
|
+
return out
|
|
58
|
+
}
|
|
59
|
+
return node
|
|
60
|
+
}
|
|
61
|
+
return walk(value)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 写入闸:递归扫描,把超阈值的内联 data: URI 抽进 blob 仓,换成 @asset/<sha>。
|
|
66
|
+
* putAsset(buffer, contentType) → { id }(通常接 ctx.assets 的 put)。
|
|
67
|
+
* 返回 { value, extracted:[{ id, mime, size }] }。value 是新副本。
|
|
68
|
+
*/
|
|
69
|
+
export async function extractDataUris(value, putAsset, options = {}) {
|
|
70
|
+
const threshold = Number(options.threshold ?? EXTRACT_THRESHOLD)
|
|
71
|
+
const extracted = []
|
|
72
|
+
const walk = async (node) => {
|
|
73
|
+
if (typeof node === 'string') {
|
|
74
|
+
const m = DATA_URI.exec(node)
|
|
75
|
+
if (!m) return node
|
|
76
|
+
const mime = m[1]
|
|
77
|
+
const buf = Buffer.from(m[2].replace(/\s/g, ''), 'base64')
|
|
78
|
+
if (!buf.length || buf.length < threshold) return node
|
|
79
|
+
const asset = await putAsset(buf, mime)
|
|
80
|
+
const id = String(asset?.id || '').toLowerCase()
|
|
81
|
+
if (!/^[a-f0-9]{64}$/.test(id)) return node
|
|
82
|
+
extracted.push({ id, mime, size: buf.length })
|
|
83
|
+
return `@asset/${id}`
|
|
84
|
+
}
|
|
85
|
+
if (Array.isArray(node)) {
|
|
86
|
+
const out = []
|
|
87
|
+
for (const item of node) out.push(await walk(item))
|
|
88
|
+
return out
|
|
89
|
+
}
|
|
90
|
+
if (node && typeof node === 'object') {
|
|
91
|
+
const out = {}
|
|
92
|
+
for (const [k, v] of Object.entries(node)) out[k] = await walk(v)
|
|
93
|
+
return out
|
|
94
|
+
}
|
|
95
|
+
return node
|
|
96
|
+
}
|
|
97
|
+
const next = await walk(value)
|
|
98
|
+
return { value: next, extracted }
|
|
99
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 前端查询面:把 work-store 的目录/版本/文档暴露成 HTTP,供后期的本地作品浏览界面调用。
|
|
3
|
+
* 只读为主(浏览),写操作走服务 API;额外给一个 rollback 便利口。
|
|
4
|
+
*
|
|
5
|
+
* GET <base>/works 列表(suite/kind/session/status/tag/q/sort/limit/offset)
|
|
6
|
+
* GET <base>/works/stats 分类统计(仪表盘)
|
|
7
|
+
* GET <base>/works/<id> 单个作品(目录元数据 + 当前状态摘要)
|
|
8
|
+
* GET <base>/works/<id>/document 当前领域文档(?key=deck)
|
|
9
|
+
* GET <base>/works/<id>/versions 版本列表
|
|
10
|
+
* GET <base>/works/<id>/version/<n> 某版本快照
|
|
11
|
+
* GET <base>/works/<id>/assets 引用的 blob 清单
|
|
12
|
+
* POST <base>/works/<id>/rollback { version } 回滚
|
|
13
|
+
*
|
|
14
|
+
* 与 asset-service 一样返回裸 handler(req,res,u),由宿主的 prefix 路由挂载。
|
|
15
|
+
*/
|
|
16
|
+
import { send, readBody } from '@capyclaw/plugin-kit/service/http'
|
|
17
|
+
|
|
18
|
+
export function createWorkRoutes({ store, basePath = '/works' }) {
|
|
19
|
+
if (!store) throw new Error('createWorkRoutes 需要 store')
|
|
20
|
+
const base = String(basePath).replace(/\/$/, '')
|
|
21
|
+
|
|
22
|
+
return async function workRoutes(req, res, u) {
|
|
23
|
+
const p = u.pathname
|
|
24
|
+
if (!p.startsWith(base)) return false
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
if (req.method === 'GET' && p === `${base}/works`) {
|
|
28
|
+
const q = u.searchParams
|
|
29
|
+
const result = store.listWorks({
|
|
30
|
+
suite: q.get('suite') || undefined,
|
|
31
|
+
kind: q.get('kind') || undefined,
|
|
32
|
+
sessionId: q.get('session') ?? undefined,
|
|
33
|
+
status: q.has('status') ? Number(q.get('status')) : undefined,
|
|
34
|
+
tag: q.get('tag') || undefined,
|
|
35
|
+
query: q.get('q') || undefined,
|
|
36
|
+
sort: q.get('sort') || undefined,
|
|
37
|
+
limit: q.get('limit') ? Number(q.get('limit')) : undefined,
|
|
38
|
+
offset: q.get('offset') ? Number(q.get('offset')) : undefined,
|
|
39
|
+
includeDeleted: q.get('deleted') === '1',
|
|
40
|
+
})
|
|
41
|
+
send(req, res, 200, result)
|
|
42
|
+
return true
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (req.method === 'GET' && p === `${base}/works/stats`) {
|
|
46
|
+
send(req, res, 200, store.stats())
|
|
47
|
+
return true
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/* ---- 产物信封查询面(workStore.artifacts,docs/suite-interop-standard.md §B) ---- */
|
|
51
|
+
if (req.method === 'GET' && p === `${base}/artifacts`) {
|
|
52
|
+
const q = u.searchParams
|
|
53
|
+
send(req, res, 200, store.listArtifacts({
|
|
54
|
+
workId: q.get('work') || undefined,
|
|
55
|
+
sessionId: q.get('session') ?? undefined,
|
|
56
|
+
type: q.get('type') || undefined,
|
|
57
|
+
producer: q.get('producer') || undefined,
|
|
58
|
+
producerSuite: q.get('suite') || undefined,
|
|
59
|
+
query: q.get('q') || undefined,
|
|
60
|
+
sort: q.get('sort') || undefined,
|
|
61
|
+
limit: q.get('limit') ? Number(q.get('limit')) : undefined,
|
|
62
|
+
offset: q.get('offset') ? Number(q.get('offset')) : undefined,
|
|
63
|
+
includeDeleted: q.get('deleted') === '1',
|
|
64
|
+
}))
|
|
65
|
+
return true
|
|
66
|
+
}
|
|
67
|
+
if (req.method === 'GET' && p.startsWith(`${base}/artifacts/`)) {
|
|
68
|
+
const restA = p.slice(`${base}/artifacts/`.length)
|
|
69
|
+
const [aid, ...atail] = restA.split('/')
|
|
70
|
+
const artifactId = decodeURIComponent(aid)
|
|
71
|
+
if (atail[0] === 'chain') {
|
|
72
|
+
send(req, res, 200, { artifactId, chain: store.artifactChain(artifactId) })
|
|
73
|
+
return true
|
|
74
|
+
}
|
|
75
|
+
const env = store.getArtifact(artifactId)
|
|
76
|
+
if (!env) { send(req, res, 404, { error: 'artifact not found' }); return true }
|
|
77
|
+
const urlBase = u.searchParams.get('base')
|
|
78
|
+
send(req, res, 200, urlBase ? store.resolveArtifact(artifactId, urlBase) : env)
|
|
79
|
+
return true
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const rest = p.slice(`${base}/works/`.length)
|
|
83
|
+
if (!p.startsWith(`${base}/works/`) || !rest) return false
|
|
84
|
+
const [id, ...tail] = rest.split('/')
|
|
85
|
+
const workId = decodeURIComponent(id)
|
|
86
|
+
|
|
87
|
+
if (req.method === 'GET' && tail.length === 0) {
|
|
88
|
+
const work = store.getWork(workId)
|
|
89
|
+
if (!work) { send(req, res, 404, { error: 'work not found' }); return true }
|
|
90
|
+
const state = store.readState(workId)
|
|
91
|
+
send(req, res, 200, { work, hasState: state != null, seq: state?.seq | 0, assets: store.listAssets(workId) })
|
|
92
|
+
return true
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (req.method === 'GET' && tail[0] === 'document') {
|
|
96
|
+
const key = u.searchParams.get('key') || undefined
|
|
97
|
+
const doc = store.getDocument(workId, key)
|
|
98
|
+
if (doc == null) { send(req, res, 404, { error: 'document not found' }); return true }
|
|
99
|
+
send(req, res, 200, { workId, key: key || null, document: doc })
|
|
100
|
+
return true
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (req.method === 'GET' && tail[0] === 'versions') {
|
|
104
|
+
send(req, res, 200, { workId, versions: store.listVersions(workId) })
|
|
105
|
+
return true
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (req.method === 'GET' && tail[0] === 'version' && tail[1]) {
|
|
109
|
+
const v = store.getVersion(workId, Number(tail[1]))
|
|
110
|
+
if (!v) { send(req, res, 404, { error: 'version not found' }); return true }
|
|
111
|
+
send(req, res, 200, v)
|
|
112
|
+
return true
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (req.method === 'GET' && tail[0] === 'assets') {
|
|
116
|
+
send(req, res, 200, { workId, assets: store.listAssets(workId) })
|
|
117
|
+
return true
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (req.method === 'POST' && tail[0] === 'rollback') {
|
|
121
|
+
const body = await readBody(req, 64 * 1024)
|
|
122
|
+
const version = Number(body?.version)
|
|
123
|
+
if (!Number.isInteger(version)) { send(req, res, 400, { error: '缺少 version' }); return true }
|
|
124
|
+
const work = store.rollback(workId, version)
|
|
125
|
+
send(req, res, 200, { work })
|
|
126
|
+
return true
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return false
|
|
130
|
+
} catch (error) {
|
|
131
|
+
send(req, res, 500, { error: String(error?.message || error) })
|
|
132
|
+
return true
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,84 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capyclaw/offline-ddr0",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.9.1",
|
|
4
|
+
"description": "真离线版 ddr0 + 作品/会话统一持久化地基:接口快照与作品代码打包在插件内,断网也能打开;本地库稳定存储作品与会话,可管理/查看/继续对话;本地 work-store(SQLite)生成物按 ddr0 作品契约进画廊,PPT 用 PPTist 装饰器只读放映;ETag/304 协商缓存+列表瘦身提速 by CapyClaw",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./plugin.mjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./plugin.mjs",
|
|
9
|
+
"./client": "./client/client.js",
|
|
10
|
+
"./package.json": "./package.json"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@capyclaw/plugin-kit": "^0.2.0",
|
|
14
|
+
"@capyclaw/foundation": "^0.1.9",
|
|
15
|
+
"@capyclaw/service-host": "^0.1.0",
|
|
16
|
+
"@capyclaw/work-store": "^0.3.0",
|
|
17
|
+
"@capyclaw/asset-service": "^0.1.4",
|
|
18
|
+
"@capyclaw/suite-kit": "^0.2.0"
|
|
19
|
+
},
|
|
20
|
+
"dsh": {
|
|
21
|
+
"bundle": {
|
|
22
|
+
"patch": "./cordis.patch.yml"
|
|
23
|
+
},
|
|
24
|
+
"client": {
|
|
25
|
+
"platform": "web",
|
|
26
|
+
"immediately": true,
|
|
27
|
+
"inject": []
|
|
28
|
+
},
|
|
29
|
+
"category": "service",
|
|
30
|
+
"platform": "both",
|
|
31
|
+
"requires": {
|
|
32
|
+
"capabilities": {
|
|
33
|
+
"os.net": "^1.0.0"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"dsh": "^0.2.0-rc.2",
|
|
39
|
+
"node": ">=22"
|
|
40
|
+
},
|
|
41
|
+
"meta": {
|
|
42
|
+
"title": "离线 ddr0",
|
|
43
|
+
"description": "断网也能打开的 ddr0:站点前端、社区列表、作品详情与作品代码全部由宿主半本地直出,命中即不出网 by CapyClaw"
|
|
44
|
+
},
|
|
45
|
+
"files": [
|
|
46
|
+
"plugin.mjs",
|
|
47
|
+
"lib/",
|
|
48
|
+
"client/",
|
|
49
|
+
"static/",
|
|
50
|
+
"mirror/",
|
|
51
|
+
"docs/",
|
|
52
|
+
"cordis.patch.yml",
|
|
53
|
+
"README.md"
|
|
54
|
+
],
|
|
55
|
+
"license": "MIT",
|
|
56
|
+
"author": {
|
|
57
|
+
"name": "CapyClaw",
|
|
58
|
+
"url": "https://github.com/capyclaw",
|
|
59
|
+
"email": "support@capyclaw.dev"
|
|
60
|
+
},
|
|
61
|
+
"repository": {
|
|
62
|
+
"type": "git",
|
|
63
|
+
"url": "git+https://github.com/Maple496/capyclaw.git",
|
|
64
|
+
"directory": "B/official/capyclaw-offline-ddr0"
|
|
65
|
+
},
|
|
66
|
+
"bugs": {
|
|
67
|
+
"url": "https://github.com/Maple496/capyclaw/issues"
|
|
68
|
+
},
|
|
69
|
+
"homepage": "https://github.com/capyclaw/dsh-plugins",
|
|
70
|
+
"scripts": {
|
|
71
|
+
"test": "node --test --test-isolation=none test/*.test.mjs"
|
|
72
|
+
},
|
|
73
|
+
"publishConfig": {
|
|
74
|
+
"access": "public"
|
|
75
|
+
},
|
|
76
|
+
"bundledDependencies": [
|
|
77
|
+
"@capyclaw/asset-service",
|
|
78
|
+
"@capyclaw/foundation",
|
|
79
|
+
"@capyclaw/plugin-kit",
|
|
80
|
+
"@capyclaw/service-host",
|
|
81
|
+
"@capyclaw/suite-kit",
|
|
82
|
+
"@capyclaw/work-store"
|
|
83
|
+
]
|
|
84
|
+
}
|