@capyclaw/offline-ddr0 0.0.0-stage → 1.9.0

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.
Files changed (295) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +441 -2
  3. package/client/client.js +603 -0
  4. package/cordis.patch.yml +13 -0
  5. package/docs/STORAGE-MIGRATION.md +136 -0
  6. package/lib/atomic.mjs +40 -0
  7. package/lib/http-cache.mjs +42 -0
  8. package/lib/inbox.mjs +64 -0
  9. package/lib/media.mjs +242 -0
  10. package/lib/migrate-json.mjs +101 -0
  11. package/lib/mirror-index.mjs +105 -0
  12. package/lib/mirror.mjs +123 -0
  13. package/lib/proxy.mjs +188 -0
  14. package/lib/remote.mjs +158 -0
  15. package/lib/render.mjs +93 -0
  16. package/lib/repository.mjs +71 -0
  17. package/lib/store.mjs +610 -0
  18. package/lib/surface.mjs +74 -0
  19. package/lib/sync-ui.mjs +108 -0
  20. package/lib/sync.mjs +433 -0
  21. package/lib/wire.mjs +211 -0
  22. package/lib/workstore-repository.mjs +316 -0
  23. package/lib/workstore.mjs +338 -0
  24. package/mirror/files/00001.html +2045 -0
  25. package/mirror/files/00002.json +1 -0
  26. package/mirror/files/00003.json +1 -0
  27. package/mirror/files/00004.json +1 -0
  28. package/mirror/files/00005.json +1 -0
  29. package/mirror/files/00006.json +1 -0
  30. package/mirror/files/00007.json +1 -0
  31. package/mirror/files/00008.json +1 -0
  32. package/mirror/files/00009.json +1 -0
  33. package/mirror/files/00010.json +1 -0
  34. package/mirror/files/00011.json +1 -0
  35. package/mirror/files/00012.json +1 -0
  36. package/mirror/files/00013.json +1 -0
  37. package/mirror/files/00014.json +1 -0
  38. package/mirror/files/00015.json +1 -0
  39. package/mirror/files/00016.json +1 -0
  40. package/mirror/files/00017.json +1 -0
  41. package/mirror/files/00018.json +1 -0
  42. package/mirror/files/00019.json +1 -0
  43. package/mirror/files/00020.json +1 -0
  44. package/mirror/files/00021.json +1 -0
  45. package/mirror/files/00022.json +1 -0
  46. package/mirror/files/00023.js +205 -0
  47. package/mirror/files/00024.json +1 -0
  48. package/mirror/files/00025.json +1 -0
  49. package/mirror/files/00026.json +1 -0
  50. package/mirror/files/00027.js +51 -0
  51. package/mirror/files/00028.json +1 -0
  52. package/mirror/files/00029.json +1 -0
  53. package/mirror/files/00030.json +1 -0
  54. package/mirror/files/00031.json +1 -0
  55. package/mirror/files/00032.json +1 -0
  56. package/mirror/files/00033.json +1 -0
  57. package/mirror/files/00034.json +1 -0
  58. package/mirror/files/00035.json +1 -0
  59. package/mirror/files/00036.json +1 -0
  60. package/mirror/files/00037.json +1 -0
  61. package/mirror/files/00038.json +1 -0
  62. package/mirror/files/00039.json +1 -0
  63. package/mirror/files/00040.js +2311 -0
  64. package/mirror/files/00041.json +1 -0
  65. package/mirror/files/00042.json +1 -0
  66. package/mirror/files/00043.json +1 -0
  67. package/mirror/files/00044.json +1 -0
  68. package/mirror/files/00045.js +575 -0
  69. package/mirror/files/00046.json +1 -0
  70. package/mirror/files/00047.js +575 -0
  71. package/mirror/files/00048.js +575 -0
  72. package/mirror/files/00049.json +1 -0
  73. package/mirror/files/00050.json +1 -0
  74. package/mirror/files/00051.json +1 -0
  75. package/mirror/files/00052.json +1 -0
  76. package/mirror/files/00053.js +575 -0
  77. package/mirror/files/00054.json +1 -0
  78. package/mirror/files/00055.json +1 -0
  79. package/mirror/files/00056.js +575 -0
  80. package/mirror/files/00057.json +1 -0
  81. package/mirror/files/00058.json +1 -0
  82. package/mirror/files/00059.js +360 -0
  83. package/mirror/files/00060.json +1 -0
  84. package/mirror/files/00061.json +1 -0
  85. package/mirror/files/00062.json +1 -0
  86. package/mirror/files/00063.json +1 -0
  87. package/mirror/files/00064.json +1 -0
  88. package/mirror/files/00065.js +144 -0
  89. package/mirror/files/00066.js +7 -0
  90. package/mirror/files/00067.json +1 -0
  91. package/mirror/files/00068.json +1 -0
  92. package/mirror/files/00069.json +1 -0
  93. package/mirror/files/00070.json +1 -0
  94. package/mirror/files/00071.json +1 -0
  95. package/mirror/files/00072.json +1 -0
  96. package/mirror/files/00073.js +1 -0
  97. package/mirror/files/00074.json +1 -0
  98. package/mirror/files/00075.json +1 -0
  99. package/mirror/files/00076.json +1 -0
  100. package/mirror/files/00077.js +45 -0
  101. package/mirror/files/00078.js +1348 -0
  102. package/mirror/files/00079.json +1 -0
  103. package/mirror/files/00080.json +1 -0
  104. package/mirror/files/00081.js +1 -0
  105. package/mirror/files/00082.json +1 -0
  106. package/mirror/files/00083.json +1 -0
  107. package/mirror/files/00084.js +7 -0
  108. package/mirror/files/00085.json +1 -0
  109. package/mirror/files/00086.json +1 -0
  110. package/mirror/files/00087.js +7 -0
  111. package/mirror/files/00088.json +1 -0
  112. package/mirror/files/00089.json +1 -0
  113. package/mirror/files/00090.js +7 -0
  114. package/mirror/files/00091.json +1 -0
  115. package/mirror/files/00092.json +1 -0
  116. package/mirror/files/00093.js +102 -0
  117. package/mirror/files/00094.json +1 -0
  118. package/mirror/files/00095.json +1 -0
  119. package/mirror/files/00096.json +1 -0
  120. package/mirror/files/00097.json +1 -0
  121. package/mirror/files/00098.json +1 -0
  122. package/mirror/files/00099.json +1 -0
  123. package/mirror/files/00100.json +1 -0
  124. package/mirror/files/00101.js +102 -0
  125. package/mirror/files/00102.json +1 -0
  126. package/mirror/files/00103.json +1 -0
  127. package/mirror/files/00104.json +1 -0
  128. package/mirror/files/00105.json +1 -0
  129. package/mirror/files/00106.json +1 -0
  130. package/mirror/files/00107.js +110 -0
  131. package/mirror/files/00108.json +1 -0
  132. package/mirror/files/00109.json +1 -0
  133. package/mirror/files/00110.json +1 -0
  134. package/mirror/files/00111.json +1 -0
  135. package/mirror/files/00112.json +1 -0
  136. package/mirror/files/00113.json +1 -0
  137. package/mirror/files/00114.json +1 -0
  138. package/mirror/files/00115.json +1 -0
  139. package/mirror/files/00116.json +1 -0
  140. package/mirror/files/00117.json +1 -0
  141. package/mirror/files/00118.json +1 -0
  142. package/mirror/files/00119.json +1 -0
  143. package/mirror/files/00120.json +1 -0
  144. package/mirror/files/00121.json +1 -0
  145. package/mirror/files/00122.json +1 -0
  146. package/mirror/files/00123.json +1 -0
  147. package/mirror/files/00124.json +1 -0
  148. package/mirror/files/00125.json +1 -0
  149. package/mirror/files/00126.json +1 -0
  150. package/mirror/files/00127.json +1 -0
  151. package/mirror/files/00128.json +1 -0
  152. package/mirror/files/00129.json +1 -0
  153. package/mirror/files/00130.json +1 -0
  154. package/mirror/files/00131.json +1 -0
  155. package/mirror/files/00132.js +110 -0
  156. package/mirror/files/00133.json +1 -0
  157. package/mirror/files/00134.json +1 -0
  158. package/mirror/files/00135.json +1 -0
  159. package/mirror/files/00136.json +1 -0
  160. package/mirror/files/00137.js +26 -0
  161. package/mirror/files/00138.json +1 -0
  162. package/mirror/files/00139.json +1 -0
  163. package/mirror/files/00140.json +1 -0
  164. package/mirror/files/00141.json +1 -0
  165. package/mirror/files/00142.json +1 -0
  166. package/mirror/files/00143.json +1 -0
  167. package/mirror/files/00144.js +26 -0
  168. package/mirror/files/00145.json +1 -0
  169. package/mirror/files/00146.json +1 -0
  170. package/mirror/files/00147.js +29 -0
  171. package/mirror/files/00148.json +1 -0
  172. package/mirror/files/00149.json +1 -0
  173. package/mirror/files/00150.js +23 -0
  174. package/mirror/files/00151.json +1 -0
  175. package/mirror/files/00152.json +1 -0
  176. package/mirror/files/00153.js +719 -0
  177. package/mirror/files/00154.js +9575 -0
  178. package/mirror/files/00155.js +108 -0
  179. package/mirror/files/00156.js +379 -0
  180. package/mirror/files/00157.js +48 -0
  181. package/mirror/files/00158.json +16 -0
  182. package/mirror/manifest.json +1582 -0
  183. package/node_modules/@capyclaw/asset-service/README.md +48 -0
  184. package/node_modules/@capyclaw/asset-service/cordis.patch.yml +4 -0
  185. package/node_modules/@capyclaw/asset-service/dsh-suite.json +29 -0
  186. package/node_modules/@capyclaw/asset-service/lib/host.mjs +14 -0
  187. package/node_modules/@capyclaw/asset-service/package.json +59 -0
  188. package/node_modules/@capyclaw/asset-service/src/index.mjs +223 -0
  189. package/node_modules/@capyclaw/foundation/README.md +51 -0
  190. package/node_modules/@capyclaw/foundation/abi/bridge.mjs +86 -0
  191. package/node_modules/@capyclaw/foundation/abi/errors.mjs +63 -0
  192. package/node_modules/@capyclaw/foundation/abi/index.mjs +35 -0
  193. package/node_modules/@capyclaw/foundation/abi/kinds.mjs +271 -0
  194. package/node_modules/@capyclaw/foundation/abi/loader.mjs +345 -0
  195. package/node_modules/@capyclaw/foundation/abi/schema.mjs +98 -0
  196. package/node_modules/@capyclaw/foundation/abi/spec.mjs +255 -0
  197. package/node_modules/@capyclaw/foundation/abi/validate.mjs +24 -0
  198. package/node_modules/@capyclaw/foundation/abi/version.mjs +82 -0
  199. package/node_modules/@capyclaw/foundation/cordis.patch.yml +5 -0
  200. package/node_modules/@capyclaw/foundation/kit/index.mjs +6 -0
  201. package/node_modules/@capyclaw/foundation/lib/adapters/client-panel.mjs +98 -0
  202. package/node_modules/@capyclaw/foundation/lib/adapters/host-event.mjs +35 -0
  203. package/node_modules/@capyclaw/foundation/lib/adapters/http-router.mjs +69 -0
  204. package/node_modules/@capyclaw/foundation/lib/adapters/lifecycle-hook.mjs +55 -0
  205. package/node_modules/@capyclaw/foundation/lib/adapters/own-server.mjs +113 -0
  206. package/node_modules/@capyclaw/foundation/lib/adapters/raw.mjs +68 -0
  207. package/node_modules/@capyclaw/foundation/lib/adapters/runtime-driver.mjs +113 -0
  208. package/node_modules/@capyclaw/foundation/lib/adapters/service-provider.mjs +77 -0
  209. package/node_modules/@capyclaw/foundation/lib/adapters/skill-provider.mjs +56 -0
  210. package/node_modules/@capyclaw/foundation/lib/adapters/tool-provider.mjs +50 -0
  211. package/node_modules/@capyclaw/foundation/lib/adapters/ui-panel.mjs +64 -0
  212. package/node_modules/@capyclaw/foundation/lib/ctx-service.mjs +42 -0
  213. package/node_modules/@capyclaw/foundation/lib/host/caps.mjs +34 -0
  214. package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +85 -0
  215. package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +50 -0
  216. package/node_modules/@capyclaw/foundation/lib/host/memory.mjs +160 -0
  217. package/node_modules/@capyclaw/foundation/lib/host.mjs +23 -0
  218. package/node_modules/@capyclaw/foundation/lib/kernel.mjs +185 -0
  219. package/node_modules/@capyclaw/foundation/lib/skill/scan.mjs +87 -0
  220. package/node_modules/@capyclaw/foundation/lib/subsystems/events.mjs +60 -0
  221. package/node_modules/@capyclaw/foundation/lib/subsystems/log.mjs +51 -0
  222. package/node_modules/@capyclaw/foundation/lib/subsystems/net.mjs +188 -0
  223. package/node_modules/@capyclaw/foundation/package.json +53 -0
  224. package/node_modules/@capyclaw/foundation/runtime/index.mjs +20 -0
  225. package/node_modules/@capyclaw/plugin-kit/INTEGRATION.md +100 -0
  226. package/node_modules/@capyclaw/plugin-kit/README.md +70 -0
  227. package/node_modules/@capyclaw/plugin-kit/bin/sync.mjs +103 -0
  228. package/node_modules/@capyclaw/plugin-kit/package.json +69 -0
  229. package/node_modules/@capyclaw/plugin-kit/src/cli.mjs +56 -0
  230. package/node_modules/@capyclaw/plugin-kit/src/config.mjs +142 -0
  231. package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat-worker.js +129 -0
  232. package/node_modules/@capyclaw/plugin-kit/src/editor/lease.mjs +139 -0
  233. package/node_modules/@capyclaw/plugin-kit/src/editor/shadow.mjs +219 -0
  234. package/node_modules/@capyclaw/plugin-kit/src/editor/transport.js +13 -0
  235. package/node_modules/@capyclaw/plugin-kit/src/index.mjs +13 -0
  236. package/node_modules/@capyclaw/plugin-kit/src/pack.mjs +230 -0
  237. package/node_modules/@capyclaw/plugin-kit/src/runtime/context.mjs +128 -0
  238. package/node_modules/@capyclaw/plugin-kit/src/self-contained.mjs +307 -0
  239. package/node_modules/@capyclaw/plugin-kit/src/service/api.mjs +45 -0
  240. package/node_modules/@capyclaw/plugin-kit/src/service/http.mjs +113 -0
  241. package/node_modules/@capyclaw/plugin-kit/src/service/mcp-http.mjs +150 -0
  242. package/node_modules/@capyclaw/plugin-kit/src/service/server.mjs +131 -0
  243. package/node_modules/@capyclaw/plugin-kit/src/skills/provider.mjs +82 -0
  244. package/node_modules/@capyclaw/plugin-kit/src/store/blob-store.mjs +109 -0
  245. package/node_modules/@capyclaw/plugin-kit/src/store/content-store.mjs +17 -0
  246. package/node_modules/@capyclaw/plugin-kit/src/store/journal-store.mjs +89 -0
  247. package/node_modules/@capyclaw/plugin-kit/src/tools/result.mjs +57 -0
  248. package/node_modules/@capyclaw/plugin-kit/src/tools/validate.mjs +150 -0
  249. package/node_modules/@capyclaw/plugin-kit/src/tuning.mjs +82 -0
  250. package/node_modules/@capyclaw/plugin-kit/src/util/fs-lock.mjs +132 -0
  251. package/node_modules/@capyclaw/plugin-kit/src/util/http.mjs +130 -0
  252. package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +656 -0
  253. package/node_modules/@capyclaw/plugin-kit/src/zip.mjs +181 -0
  254. package/node_modules/@capyclaw/service-host/README.md +86 -0
  255. package/node_modules/@capyclaw/service-host/cordis.patch.yml +4 -0
  256. package/node_modules/@capyclaw/service-host/dsh-suite.json +29 -0
  257. package/node_modules/@capyclaw/service-host/lib/host.mjs +22 -0
  258. package/node_modules/@capyclaw/service-host/package.json +60 -0
  259. package/node_modules/@capyclaw/service-host/src/index.mjs +571 -0
  260. package/node_modules/@capyclaw/service-host/src/tuning.mjs +63 -0
  261. package/node_modules/@capyclaw/suite-kit/README.md +238 -0
  262. package/node_modules/@capyclaw/suite-kit/bin/dsh-domain.mjs +98 -0
  263. package/node_modules/@capyclaw/suite-kit/bin/dsh-suite.mjs +174 -0
  264. package/node_modules/@capyclaw/suite-kit/client/embed.js +35 -0
  265. package/node_modules/@capyclaw/suite-kit/domain.schema.json +129 -0
  266. package/node_modules/@capyclaw/suite-kit/package.json +54 -0
  267. package/node_modules/@capyclaw/suite-kit/src/activation-registry.mjs +184 -0
  268. package/node_modules/@capyclaw/suite-kit/src/artifacts.mjs +131 -0
  269. package/node_modules/@capyclaw/suite-kit/src/capability.mjs +181 -0
  270. package/node_modules/@capyclaw/suite-kit/src/compose.mjs +201 -0
  271. package/node_modules/@capyclaw/suite-kit/src/domain.mjs +138 -0
  272. package/node_modules/@capyclaw/suite-kit/src/embed.mjs +81 -0
  273. package/node_modules/@capyclaw/suite-kit/src/index.mjs +10 -0
  274. package/node_modules/@capyclaw/suite-kit/src/manifest.mjs +263 -0
  275. package/node_modules/@capyclaw/suite-kit/src/orchestration.mjs +100 -0
  276. package/node_modules/@capyclaw/suite-kit/src/profile.mjs +584 -0
  277. package/node_modules/@capyclaw/suite-kit/src/surface.mjs +28 -0
  278. package/node_modules/@capyclaw/suite-kit/suite.schema.json +112 -0
  279. package/node_modules/@capyclaw/work-store/README.md +83 -0
  280. package/node_modules/@capyclaw/work-store/STANDARD.md +257 -0
  281. package/node_modules/@capyclaw/work-store/cordis.patch.yml +3 -0
  282. package/node_modules/@capyclaw/work-store/dsh-suite.json +26 -0
  283. package/node_modules/@capyclaw/work-store/icon.svg +7 -0
  284. package/node_modules/@capyclaw/work-store/lib/host.mjs +21 -0
  285. package/node_modules/@capyclaw/work-store/package.json +68 -0
  286. package/node_modules/@capyclaw/work-store/src/backend.mjs +89 -0
  287. package/node_modules/@capyclaw/work-store/src/db.mjs +199 -0
  288. package/node_modules/@capyclaw/work-store/src/envelope.mjs +132 -0
  289. package/node_modules/@capyclaw/work-store/src/index.mjs +570 -0
  290. package/node_modules/@capyclaw/work-store/src/interop.mjs +70 -0
  291. package/node_modules/@capyclaw/work-store/src/refs.mjs +99 -0
  292. package/node_modules/@capyclaw/work-store/src/routes.mjs +135 -0
  293. package/package.json +82 -4
  294. package/plugin.mjs +636 -0
  295. package/static/index.html +2068 -0
@@ -0,0 +1,584 @@
1
+ /**
2
+ * 安装 / doctor:把 suite 装进 DSH profile,并验证组合是否真的工作。
3
+ */
4
+ import fs from 'node:fs'
5
+ import os from 'node:os'
6
+ import path from 'node:path'
7
+ import { spawnSync } from 'node:child_process'
8
+ import { composeSuites, renderCordisPatch } from './compose.mjs'
9
+ import { loadSuiteManifest, validateSuiteManifest } from './manifest.mjs'
10
+ import { resolvePackageSpec } from './artifacts.mjs'
11
+ import { writeActivationRegistry } from './activation-registry.mjs'
12
+
13
+ export function defaultDshHome() {
14
+ return process.env.DSH_HOME || path.join(os.homedir(), '.dsh')
15
+ }
16
+
17
+ export function profileDirOf(dshHome, profile) {
18
+ return path.join(path.resolve(dshHome), 'profiles', profile)
19
+ }
20
+
21
+ function readJson(file) {
22
+ return JSON.parse(fs.readFileSync(file, 'utf8'))
23
+ }
24
+
25
+ function writeJson(file, value) {
26
+ fs.writeFileSync(file, JSON.stringify(value, null, 2) + '\n')
27
+ }
28
+
29
+ function backup(file) {
30
+ if (!fs.existsSync(file)) return
31
+ const stamp = new Date().toISOString().replace(/[:.]/g, '-')
32
+ fs.copyFileSync(file, `${file}.bak-${stamp}`)
33
+ }
34
+
35
+ function readJsonSafe(file) {
36
+ try { return JSON.parse(fs.readFileSync(file, 'utf8')) } catch { return null }
37
+ }
38
+
39
+ function packageVersionOf(dir, entry) {
40
+ const target = entry?.path ? path.resolve(dir, entry.path) : null
41
+ const manifest = target ? readJsonSafe(path.join(target, 'package.json')) : null
42
+ return {
43
+ version: manifest?.version || entry?.version || '',
44
+ apiVersion: manifest?.dsh?.apiVersion || null,
45
+ dir: target,
46
+ }
47
+ }
48
+
49
+ function buildCompositionLock({ profile, dir, suites, composed }) {
50
+ const packages = {}
51
+ for (const pkg of composed.packages) {
52
+ const info = packageVersionOf(pkg.dir, pkg.entry)
53
+ packages[pkg.name] = {
54
+ version: info.version,
55
+ range: pkg.entry?.version || '',
56
+ role: pkg.entry?.role || '',
57
+ apiVersion: info.apiVersion,
58
+ suite: pkg.suite || '',
59
+ }
60
+ }
61
+ return {
62
+ version: 1,
63
+ profile,
64
+ suites: suites.map(({ manifest }) => ({ name: manifest.name, version: manifest.version })),
65
+ packages: Object.fromEntries(Object.entries(packages).sort(([a], [b]) => a.localeCompare(b))),
66
+ }
67
+ }
68
+
69
+ function majorOf(version) {
70
+ const match = /^(\d+)/.exec(String(version || ''))
71
+ return match ? match[1] : ''
72
+ }
73
+
74
+ function diffCompositionLocks(previous, next) {
75
+ if (!previous) return []
76
+ const changes = []
77
+ const names = new Set([...Object.keys(previous.packages || {}), ...Object.keys(next.packages || {})])
78
+ for (const name of [...names].sort()) {
79
+ const before = previous.packages?.[name]
80
+ const after = next.packages?.[name]
81
+ if (!before) changes.push({ type: 'added', name, version: after.version })
82
+ else if (!after) changes.push({ type: 'removed', name, version: before.version })
83
+ else if (before.version !== after.version || before.range !== after.range || before.role !== after.role) {
84
+ changes.push({ type: 'updated', name, from: before.version, to: after.version })
85
+ }
86
+ if (before && after && before.apiVersion && after.apiVersion && majorOf(before.apiVersion) !== majorOf(after.apiVersion)) {
87
+ changes.push({ type: 'api-major', name, from: before.apiVersion, to: after.apiVersion })
88
+ }
89
+ }
90
+ const suiteNames = new Set([
91
+ ...(previous.suites || []).map((suite) => suite.name),
92
+ ...(next.suites || []).map((suite) => suite.name),
93
+ ])
94
+ for (const name of [...suiteNames].sort()) {
95
+ const before = (previous.suites || []).find((suite) => suite.name === name)
96
+ const after = (next.suites || []).find((suite) => suite.name === name)
97
+ if (!before) changes.push({ type: 'suite-added', name, version: after.version })
98
+ else if (!after) changes.push({ type: 'suite-removed', name, version: before.version })
99
+ else if (before.version !== after.version) changes.push({ type: 'suite-updated', name, from: before.version, to: after.version })
100
+ }
101
+ return changes
102
+ }
103
+
104
+ function validateSuiteLock(suite, composed) {
105
+ const file = path.join(suite.dir, 'composition.lock.json')
106
+ const lock = readJsonSafe(file)
107
+ if (!lock) return { file, ok: true, warnings: [] }
108
+ const warnings = []
109
+ if (lock.suite !== suite.manifest.name) {
110
+ warnings.push(`${suite.manifest.name}: composition.lock 的 suite=${lock.suite} 与 manifest 不一致`)
111
+ }
112
+ if (String(lock.suiteVersion) !== String(suite.manifest.version)) {
113
+ warnings.push(`${suite.manifest.name}: composition.lock 版本 ${lock.suiteVersion} 与 manifest ${suite.manifest.version} 不一致`)
114
+ }
115
+ const byName = new Map((composed?.packages || []).map((pkg) => [pkg.name, pkg]))
116
+ for (const [name, locked] of Object.entries(lock.packages || {})) {
117
+ const pkg = byName.get(name)
118
+ if (!pkg) { warnings.push(`${suite.manifest.name}: composition.lock 引用了不存在的包 ${name}`); continue }
119
+ const actual = packageVersionOf(pkg.dir, pkg.entry)
120
+ if (locked.version && actual.version && locked.version !== actual.version) {
121
+ warnings.push(`${suite.manifest.name}: ${name} lock 版本 ${locked.version} ≠ 实际 ${actual.version}`)
122
+ }
123
+ if (locked.apiVersion && actual.apiVersion && majorOf(locked.apiVersion) !== majorOf(actual.apiVersion)) {
124
+ warnings.push(`${suite.manifest.name}: ${name} lock API major ${locked.apiVersion} ≠ 实际 ${actual.apiVersion}`)
125
+ }
126
+ }
127
+ return { file, ok: warnings.length === 0, lock, warnings }
128
+ }
129
+
130
+ function samePath(left, right) {
131
+ try { return fs.realpathSync(left).toLowerCase() === fs.realpathSync(right).toLowerCase() } catch { return false }
132
+ }
133
+
134
+ function linkDir(target, dest) {
135
+ fs.mkdirSync(path.dirname(dest), { recursive: true })
136
+ try {
137
+ const stat = fs.lstatSync(dest)
138
+ if (stat.isSymbolicLink()) {
139
+ if (samePath(dest, target)) return false
140
+ fs.rmSync(dest, { recursive: true, force: true })
141
+ } else if (stat.isDirectory()) {
142
+ let name = ''
143
+ try { name = readJson(path.join(dest, 'package.json')).name } catch { /* 非包目录 */ }
144
+ if (name !== path.basename(dest)) {
145
+ throw new Error(`${dest} 是真实目录且不是同名包,拒绝覆盖`)
146
+ }
147
+ fs.rmSync(dest, { recursive: true, force: true })
148
+ }
149
+ } catch (error) {
150
+ if (error.code !== 'ENOENT') throw error
151
+ }
152
+ fs.symlinkSync(target, dest, 'junction')
153
+ return true
154
+ }
155
+
156
+ /** 从 insert 块中按 entry 删除指定 row,保留同块内其它 row。 */
157
+ function filterInsertBlock(block, wanted) {
158
+ const header = block[0]
159
+ const entries = []
160
+ let current = []
161
+ for (const line of block.slice(1)) {
162
+ if (/^\s+- id:\s*/.test(line)) {
163
+ if (current.length) entries.push(current)
164
+ current = [line]
165
+ } else {
166
+ current.push(line)
167
+ }
168
+ }
169
+ if (current.length) entries.push(current)
170
+ if (!entries.length) return block
171
+ const kept = entries.filter((entry) => {
172
+ const hit = /^\s+- id:\s*([^\s#]+)\s*$/.exec(entry[0])
173
+ return !hit || !wanted.has(hit[1])
174
+ })
175
+ if (!kept.length) return []
176
+ return [header, ...kept.flat()]
177
+ }
178
+
179
+ /** 从 profile patch 里移除指定 row 的顶层块(用于旧版单装迁移)。 */
180
+ export function stripPatchRows(text, ids) {
181
+ const wanted = new Set(ids || [])
182
+ if (!wanted.size) return text
183
+ const lines = text.split(/\r?\n/)
184
+ const out = []
185
+ for (let i = 0; i < lines.length; i++) {
186
+ const line = lines[i]
187
+ if (/^- insert:\s*$/.test(line)) {
188
+ let j = i + 1
189
+ const block = [line]
190
+ while (j < lines.length) {
191
+ const next = lines[j]
192
+ if (next.trim() !== '' && !/^\s/.test(next)) break
193
+ block.push(next)
194
+ j++
195
+ }
196
+ out.push(...filterInsertBlock(block, wanted))
197
+ i = j - 1
198
+ continue
199
+ }
200
+ const hit = /^- id:\s*([^\s#]+)\s*$/.exec(line)
201
+ if (hit && wanted.has(hit[1])) {
202
+ let j = i + 1
203
+ while (j < lines.length && (lines[j].trim() === '' || /^\s/.test(lines[j]))) j++
204
+ i = j - 1
205
+ continue
206
+ }
207
+ out.push(line)
208
+ }
209
+ return out.join('\n').replace(/\n{3,}/g, '\n\n')
210
+ }
211
+
212
+ function runPnpm(profileDir) {
213
+ const result = process.platform === 'win32'
214
+ ? spawnSync(process.env.ComSpec || 'cmd.exe',
215
+ ['/d', '/s', '/c', 'pnpm install --ignore-scripts --reporter=silent'],
216
+ { cwd: profileDir, stdio: 'inherit' })
217
+ : spawnSync('pnpm', ['install', '--ignore-scripts', '--reporter=silent'],
218
+ { cwd: profileDir, stdio: 'inherit' })
219
+ return result.status === 0
220
+ }
221
+
222
+ /**
223
+ * @param {{
224
+ * suiteInputs: string[],
225
+ * profile?: string,
226
+ * dshHome?: string,
227
+ * dryRun?: boolean,
228
+ * runPnpm?: boolean,
229
+ * removeDependencies?: string[],
230
+ * packageSpecs?: string[],
231
+ * rollbackTo?: string,
232
+ * artifactRoot?: string
233
+ * }} options
234
+ */
235
+ export function installSuites(options) {
236
+ const profile = options.profile || process.env.DSH_PROFILE || 'web'
237
+ const dshHome = options.dshHome || defaultDshHome()
238
+ const dir = profileDirOf(dshHome, profile)
239
+ const manifestPath = path.join(dir, 'package.json')
240
+ const patchPath = path.join(dir, 'cordis.patch.yml')
241
+ if (!fs.existsSync(manifestPath)) throw new Error(`找不到 profile: ${dir}`)
242
+
243
+ const suites = options.suiteInputs.map((input) => loadSuiteManifest(input))
244
+ const composed = composeSuites(suites)
245
+ if (!composed.ok) throw new Error('suite 组合冲突:\n- ' + composed.errors.join('\n- '))
246
+
247
+ const overrides = []
248
+ const applyOverride = (spec) => {
249
+ const meta = resolvePackageSpec(spec, { root: options.artifactRoot })
250
+ const pkg = composed.packages.find((item) => item.name === meta.name)
251
+ if (!pkg) throw new Error(`artifact 覆盖失败: suite 组合里没有包 ${meta.name}`)
252
+ pkg.entry = { ...pkg.entry, path: meta.dir, version: meta.version }
253
+ pkg.artifact = meta
254
+ overrides.push({ name: meta.name, version: meta.version, dir: meta.dir })
255
+ return meta
256
+ }
257
+ if (options.rollbackTo) {
258
+ const target = path.resolve(options.rollbackTo)
259
+ const targetLock = readJsonSafe(target)
260
+ if (!targetLock?.packages) throw new Error(`rollback 锁文件不可读或缺少 packages: ${target}`)
261
+ for (const [name, meta] of Object.entries(targetLock.packages)) {
262
+ if (!meta?.version) continue
263
+ try { applyOverride(`${name}@${meta.version}`) }
264
+ catch (error) { throw new Error(`rollback ${name}@${meta.version} 失败: ${error.message}`) }
265
+ }
266
+ }
267
+ for (const spec of options.packageSpecs || []) applyOverride(spec)
268
+
269
+ const compositionLockPath = path.join(dir, 'dsh-composition.lock.json')
270
+ const previousLock = readJsonSafe(compositionLockPath)
271
+ const compositionLock = buildCompositionLock({ profile, dir, suites, composed })
272
+ const lockChanges = diffCompositionLocks(previousLock, compositionLock)
273
+ const suiteLockResults = suites.map((suite) => validateSuiteLock(suite, composed))
274
+ const lockWarnings = []
275
+ for (const change of lockChanges) {
276
+ if (change.type === 'api-major') {
277
+ lockWarnings.push(`公共插件 ${change.name} API major ${change.from} → ${change.to};请确认消费者已升级`)
278
+ }
279
+ }
280
+ for (const result of suiteLockResults) lockWarnings.push(...result.warnings)
281
+
282
+ const legacy = new Set(options.removeDependencies || [])
283
+ const manifest = readJson(manifestPath)
284
+ manifest.dependencies ||= {}
285
+ manifest.dsh ||= {}
286
+ manifest.dsh.profile ||= {}
287
+ const previous = manifest.dshSuiteKit?.managedPackages || []
288
+ for (const name of previous) delete manifest.dependencies[name]
289
+ for (const name of manifest.dshSuiteKit?.suites || []) {
290
+ delete manifest.dependencies[name]
291
+ }
292
+ for (const name of legacy) delete manifest.dependencies[name]
293
+
294
+ for (const suite of suites) {
295
+ manifest.dependencies[suite.manifest.name] = `link:${suite.dir.replace(/\\/g, '/')}`
296
+ }
297
+
298
+ const managedPackages = composed.packages
299
+ .filter(({ entry }) => entry.path)
300
+ .map(({ name }) => name)
301
+ const suiteNames = suites.map(({ manifest: m }) => m.name)
302
+ const bundles = (manifest.dsh.profile.bundles || [])
303
+ .filter((name) => !previous.includes(name))
304
+ .filter((name) => !(manifest.dshSuiteKit?.suites || []).includes(name))
305
+ .filter((name) => !legacy.has(name))
306
+ for (const name of suiteNames) if (!bundles.includes(name)) bundles.push(name)
307
+ manifest.dsh.profile.bundles = bundles
308
+ manifest.dshSuiteKit = {
309
+ version: 1,
310
+ suites: suiteNames,
311
+ managedPackages,
312
+ updatedAt: new Date().toISOString(),
313
+ }
314
+
315
+ const plan = {
316
+ profile,
317
+ dir,
318
+ suites: suiteNames,
319
+ bundles,
320
+ dependencies: Object.keys(manifest.dependencies),
321
+ managedPackages,
322
+ warnings: [...composed.warnings, ...lockWarnings],
323
+ dryRun: !!options.dryRun,
324
+ lock: compositionLock,
325
+ lockPath: compositionLockPath,
326
+ lockChanges,
327
+ suiteLocks: suiteLockResults.map((result) => ({ file: result.file, ok: result.ok })),
328
+ overrides,
329
+ rollbackTo: options.rollbackTo ? path.resolve(options.rollbackTo) : null,
330
+ }
331
+ if (options.dryRun) return plan
332
+
333
+ backup(manifestPath)
334
+ backup(patchPath)
335
+ backup(compositionLockPath)
336
+ writeJson(manifestPath, manifest)
337
+ writeJson(compositionLockPath, compositionLock)
338
+ const writtenLock = readJsonSafe(compositionLockPath)
339
+ if (!writtenLock || JSON.stringify(writtenLock) !== JSON.stringify(compositionLock)) {
340
+ throw new Error(`组合锁写入校验失败: ${compositionLockPath}`)
341
+ }
342
+
343
+ /* 运行期激活面:suite 组合结果编译成 launch-engine 注册表,随 profile 落盘。 */
344
+ const activationRegistry = writeActivationRegistry(dir, { suites, composed })
345
+ plan.activationRegistry = { file: activationRegistry.file, capabilities: activationRegistry.capabilities }
346
+ for (const warning of activationRegistry.warnings) plan.warnings.push(`activation-registry: ${warning}`)
347
+ if (options.removeRows?.length && fs.existsSync(patchPath)) {
348
+ const before = fs.readFileSync(patchPath, 'utf8')
349
+ const after = stripPatchRows(before, options.removeRows)
350
+ if (after !== before) fs.writeFileSync(patchPath, after)
351
+ }
352
+
353
+ if (options.runPnpm !== false) {
354
+ if (!runPnpm(dir)) plan.warnings.push('pnpm install 未成功;junction 仍会建立,但 lockfile 可能不是最新')
355
+ }
356
+
357
+ const linked = []
358
+ for (const suite of suites) {
359
+ linkDir(suite.dir, path.join(dir, 'node_modules', suite.manifest.name))
360
+ linked.push(suite.manifest.name)
361
+ }
362
+ for (const packageInfo of composed.packages) {
363
+ const target = packageInfo.entry.path
364
+ ? path.resolve(packageInfo.dir, packageInfo.entry.path)
365
+ : null
366
+ if (!target) continue
367
+ linkDir(target, path.join(dir, 'node_modules', packageInfo.name))
368
+ linked.push(packageInfo.name)
369
+ }
370
+ plan.linked = linked
371
+ return plan
372
+ }
373
+
374
+ async function fetchJson(url, init, timeoutMs) {
375
+ const controller = new AbortController()
376
+ const timer = setTimeout(() => controller.abort(), timeoutMs)
377
+ try {
378
+ const response = await fetch(url, { ...init, signal: controller.signal })
379
+ const text = await response.text()
380
+ let body = null
381
+ try { body = JSON.parse(text) } catch { /* 非 JSON */ }
382
+ return { status: response.status, body, text }
383
+ } finally {
384
+ clearTimeout(timer)
385
+ }
386
+ }
387
+
388
+ function pidAlive(pid) {
389
+ if (!Number.isInteger(pid) || pid <= 0) return false
390
+ try { process.kill(pid, 0); return true } catch { return false }
391
+ }
392
+
393
+ /** 把静态 check.url 的 origin 换成注册表里的真实 origin(端口是动态分配的)。 */
394
+ function rebaseUrl(original, base) {
395
+ try {
396
+ const url = new URL(original)
397
+ const real = new URL(base)
398
+ url.protocol = real.protocol
399
+ url.host = real.host
400
+ return url.toString()
401
+ } catch { return base }
402
+ }
403
+
404
+ /**
405
+ * 检查项指向的是"服务"而不是"固定端口"。
406
+ *
407
+ * 端口是动态分配的,写死任何固定端口只会制造两种假象:服务明明活着却报 connection
408
+ * refused;或者端口刚好被别的进程占用,报个假"健康"。这里按服务 id 查注册表,
409
+ * 并顺带核对进程是否真的还在 —— 这才是"插件启用了就必须能用"的判据。
410
+ */
411
+ function resolveServiceUrl(check, dshHome) {
412
+ const id = check.service
413
+ if (!id) return { url: check.url }
414
+ let rows = null
415
+ try {
416
+ rows = JSON.parse(fs.readFileSync(path.join(dshHome, 'services.json'), 'utf8'))?.services || {}
417
+ } catch {
418
+ return { error: `读不到 ${path.join(dshHome, 'services.json')},无法确认 ${id} 是否在运行` }
419
+ }
420
+ const row = rows[id]
421
+ if (!row) return { error: `注册表里没有 ${id}:服务没有被拉起(先启动 DSH 或让它自愈)` }
422
+ if (row.state !== 'running') return { error: `${id} 状态是 ${row.state},不是 running` }
423
+ if (!pidAlive(row.pid)) return { error: `${id} 登记为 running(pid ${row.pid})但进程已不存在:注册表是活的、服务是死的` }
424
+ if (!row.url) return { error: `${id} 的注册表行缺少 url` }
425
+ return { url: rebaseUrl(check.url, row.url) }
426
+ }
427
+
428
+ async function runCheck(check, dshHome, timeoutMs) {
429
+ const target = resolveServiceUrl(check, dshHome)
430
+ if (target.error) return { id: check.id, ok: false, detail: target.error }
431
+ const resolved = { ...check, url: target.url }
432
+ return check.type === 'contract' ? checkContract(resolved, timeoutMs) : checkHttp(resolved, timeoutMs)
433
+ }
434
+
435
+ async function checkHttp(check, timeoutMs) {
436
+ try {
437
+ const response = await fetchJson(check.url, { method: check.method || 'GET' }, check.timeoutMs || timeoutMs)
438
+ const wantStatus = check.expectStatus ?? 200
439
+ if (response.status !== wantStatus) {
440
+ return { id: check.id, ok: false, detail: `HTTP ${response.status},期望 ${wantStatus}` }
441
+ }
442
+ if (check.expectBody) {
443
+ for (const [key, value] of Object.entries(check.expectBody)) {
444
+ if (JSON.stringify(response.body?.[key]) !== JSON.stringify(value)) {
445
+ return { id: check.id, ok: false, detail: `body.${key}=${JSON.stringify(response.body?.[key])},期望 ${JSON.stringify(value)}` }
446
+ }
447
+ }
448
+ }
449
+ return { id: check.id, ok: true, detail: `HTTP ${response.status}` }
450
+ } catch (error) {
451
+ return { id: check.id, ok: false, detail: String(error.message || error) }
452
+ }
453
+ }
454
+
455
+ async function checkContract(check, timeoutMs) {
456
+ const timeout = check.timeoutMs || timeoutMs
457
+ try {
458
+ const init = await fetchJson(check.url, {
459
+ method: 'POST',
460
+ headers: { 'content-type': 'application/json' },
461
+ body: JSON.stringify({
462
+ jsonrpc: '2.0', id: 1, method: 'initialize',
463
+ params: { protocolVersion: '2025-03-26', capabilities: {} },
464
+ }),
465
+ }, timeout)
466
+ if (init.status !== 200) return { id: check.id, ok: false, detail: `initialize HTTP ${init.status}` }
467
+ const call = await fetchJson(check.url, {
468
+ method: 'POST',
469
+ headers: { 'content-type': 'application/json' },
470
+ body: JSON.stringify({
471
+ jsonrpc: '2.0', id: 2, method: 'tools/call',
472
+ params: { name: check.tool, arguments: {} },
473
+ }),
474
+ }, timeout)
475
+ if (call.status !== 200) return { id: check.id, ok: false, detail: `C/tools/call HTTP ${call.status}` }
476
+ const text = call.body?.result?.content?.[0]?.text
477
+ if (call.body?.result?.isError) return { id: check.id, ok: false, detail: String(text || '工具返回 isError') }
478
+ const payload = JSON.parse(text)
479
+ const major = Number(String(payload.contractVersion || '').split('.')[0])
480
+ if (major !== check.major) {
481
+ return { id: check.id, ok: false, detail: `contractVersion=${payload.contractVersion},期望 major ${check.major}` }
482
+ }
483
+ return { id: check.id, ok: true, detail: `contractVersion=${payload.contractVersion}` }
484
+ } catch (error) {
485
+ return { id: check.id, ok: false, detail: String(error.message || error) }
486
+ }
487
+ }
488
+
489
+ /**
490
+ * @param {{profile?: string, dshHome?: string, dshBin?: string, timeoutMs?: number}} [options]
491
+ */
492
+ export async function doctor(options = {}) {
493
+ const profile = options.profile || process.env.DSH_PROFILE || 'web'
494
+ const dshHome = options.dshHome || defaultDshHome()
495
+ const dir = profileDirOf(dshHome, profile)
496
+ const manifestPath = path.join(dir, 'package.json')
497
+ const errors = []
498
+ const warnings = []
499
+ const checks = []
500
+
501
+ if (!fs.existsSync(manifestPath)) {
502
+ return { ok: false, errors: [`找不到 profile: ${dir}`], warnings, checks }
503
+ }
504
+ const manifest = readJson(manifestPath)
505
+ /* 只对"源码组合"形态(dsh-* 的 suite bundle)做 compose 校验。
506
+ * 已安装的 drop-store 套件各自内嵌一份基建包,跨套件 compose 必然报路径/版本冲突,
507
+ * 那不是说套件坏了。已安装环境的体检走 `npm run check:install`(对比 drop 实载版本与构建产物)。 */
508
+ const suiteNames = manifest.dshSuiteKit?.suites
509
+ || (manifest.dsh?.profile?.bundles || []).filter((name) => name.startsWith('dsh-') && name.includes('suite'))
510
+ if (!suiteNames.length) warnings.push('profile 没有 dshSuiteKit.suites,按 bundle 名称猜测 suite')
511
+
512
+ const suites = []
513
+ for (const name of suiteNames) {
514
+ const packageDir = path.join(dir, 'node_modules', name)
515
+ if (!fs.existsSync(packageDir)) {
516
+ errors.push(`suite ${name} 未安装(缺少 node_modules/${name})`)
517
+ continue
518
+ }
519
+ try {
520
+ const loaded = loadSuiteManifest(packageDir)
521
+ const validation = validateSuiteManifest(loaded.manifest, { baseDir: loaded.dir })
522
+ if (!validation.ok) errors.push(...validation.errors.map((e) => `${name}: ${e}`))
523
+ const generated = composeSuites([loaded])
524
+ if (generated.ok) {
525
+ const expected = renderCordisPatch(generated.rows)
526
+ const patchFile = path.join(packageDir, 'cordis.patch.yml')
527
+ if (!fs.existsSync(patchFile) || fs.readFileSync(patchFile, 'utf8') !== expected) {
528
+ errors.push(`${name}: cordis.patch.yml 与 dsh-suite.json 生成结果不一致,请重跑 compose`)
529
+ }
530
+ }
531
+ suites.push(loaded)
532
+ } catch (error) {
533
+ errors.push(`${name}: ${error.message}`)
534
+ }
535
+ }
536
+
537
+ if (suites.length) {
538
+ const composed = composeSuites(suites)
539
+ errors.push(...composed.errors)
540
+ warnings.push(...composed.warnings)
541
+ for (const pkg of composed.packages) {
542
+ if (!pkg.entry.path) continue
543
+ const target = path.resolve(pkg.dir, pkg.entry.path)
544
+ if (!fs.existsSync(path.join(target, 'package.json'))) {
545
+ errors.push(`包 ${pkg.name} 不存在或不是包: ${target}`)
546
+ }
547
+ }
548
+ for (const check of composed.checks) {
549
+ checks.push(await runCheck(check, dshHome, options.timeoutMs || 3000))
550
+ }
551
+ }
552
+
553
+ if (options.dshBin) {
554
+ const bin = path.resolve(options.dshBin)
555
+ const result = spawnSync(bin, ['--profile', profile, '--dump-config'], {
556
+ cwd: dshHome,
557
+ env: { ...process.env, DSH_HOME: dshHome },
558
+ encoding: 'utf8',
559
+ timeout: 30000,
560
+ shell: process.platform === 'win32',
561
+ })
562
+ if (result.status !== 0) {
563
+ warnings.push(`dsh --dump-config 失败: ${(result.stderr || result.stdout || '').slice(0, 300)}`)
564
+ } else {
565
+ const ids = [...result.stdout.matchAll(/^- id: (.+)$/gm)].map((m) => m[1].trim())
566
+ const counts = new Map()
567
+ for (const id of ids) counts.set(id, (counts.get(id) || 0) + 1)
568
+ for (const [id, count] of counts) {
569
+ if (count > 1) errors.push(`组合后 row.id 重复: ${id} × ${count}`)
570
+ }
571
+ }
572
+ }
573
+
574
+ return { ok: errors.length === 0 && checks.every((c) => c.ok), errors, warnings, checks }
575
+ }
576
+
577
+ export function formatReport(report) {
578
+ const lines = []
579
+ for (const check of report.checks || []) lines.push(`${check.ok ? '✓' : '✗'} ${check.id}: ${check.detail}`)
580
+ for (const warning of report.warnings || []) lines.push(`! ${warning}`)
581
+ for (const error of report.errors || []) lines.push(`✗ ${error}`)
582
+ lines.push(report.ok ? '✓ suite doctor 通过' : '✗ suite doctor 未通过')
583
+ return lines.join('\n')
584
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * 呈现面接线助手(标准 §A.5 / §C.7 双模态):给任意 service-host app 挂上
3
+ * GET /embed.js —— 嵌入握手客户端(suite-kit/client/embed.js 的唯一真源副本)
4
+ * GET /api/surface —— 呈现面自描述(standalone/embeddable/embedPath/协议版本)
5
+ * 套件只需 attachSurface(app, { suite, embedPath }),不必各自复制握手代码。
6
+ * 控制面不分模式:工具/HTTP 接口在两种模式下完全相同。
7
+ */
8
+ import fs from 'node:fs'
9
+ import path from 'node:path'
10
+ import { fileURLToPath } from 'node:url'
11
+ import { EMBED_PROTOCOL_VERSION } from './embed.mjs'
12
+
13
+ const CLIENT_PATH = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'client', 'embed.js')
14
+
15
+ export function attachSurface(app, { suite, embedPath, standalone = true } = {}) {
16
+ if (!app || typeof app.get !== 'function') throw new Error('attachSurface: 需要 service-host app(含 .get)')
17
+ if (typeof suite !== 'string' || !suite) throw new Error('attachSurface: suite 必填')
18
+ if (typeof embedPath !== 'string' || !embedPath.startsWith('/')) throw new Error('attachSurface: embedPath 必须以 / 开头(同源本地地址)')
19
+ app.get('/embed.js', (req, res) => {
20
+ res.writeHead(200, { 'content-type': 'application/javascript; charset=utf-8', 'cache-control': 'no-cache' })
21
+ res.end(fs.readFileSync(CLIENT_PATH, 'utf8'))
22
+ })
23
+ app.get('/api/surface', (req, res) => {
24
+ res.writeHead(200, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-cache' })
25
+ res.end(JSON.stringify({ ok: true, suite, standalone, embeddable: true, embedPath, protocolVersion: EMBED_PROTOCOL_VERSION }))
26
+ })
27
+ return { suite, embedPath, protocolVersion: EMBED_PROTOCOL_VERSION }
28
+ }