@capyclaw/gateway 0.0.0-stage → 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/README.md +89 -2
- package/cordis.patch.yml +4 -0
- package/lib/http.mjs +101 -0
- package/lib/index.mjs +714 -0
- package/lib/paths.mjs +171 -0
- package/lib/store.mjs +193 -0
- package/lib/upstream.mjs +111 -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/package.json +61 -4
- package/plugin.mjs +329 -0
package/lib/paths.mjs
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 网关的路径与名字规则:所有「从 URL 里读出来的东西」都必须先过这里。
|
|
3
|
+
*
|
|
4
|
+
* 设计前提:网关挂在 DSH 自带 Web 服务的同源前缀下,一个写坏的路径解析立刻
|
|
5
|
+
* 变成「读宿主上任意文件」或「代理到任意地址」。所以本文件只做两件事——
|
|
6
|
+
* **把外部输入收敛成有限形状**,以及**把绝对路径钉死在允许的根里**。
|
|
7
|
+
*/
|
|
8
|
+
import fs from 'node:fs'
|
|
9
|
+
import path from 'node:path'
|
|
10
|
+
|
|
11
|
+
/** 会话 id 的安全形状:DSH 的 sid 是 uuid 或 `session-<uuid>`,留一点余量但不放行分隔符。 */
|
|
12
|
+
export const SID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/
|
|
13
|
+
|
|
14
|
+
/** 条目名:相对路径,逐段 `[A-Za-z0-9._-]`,不允许空段、`..`、前导点。 */
|
|
15
|
+
const SEGMENT_RE = /^[A-Za-z0-9_-][A-Za-z0-9._-]*$/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 校验并归一化会话 id。
|
|
19
|
+
* @returns {string|null} 合法时返回原值,否则 null(调用方回 400,不要静默兜底)
|
|
20
|
+
*/
|
|
21
|
+
export function normalizeSid(raw) {
|
|
22
|
+
const value = String(raw ?? '').trim()
|
|
23
|
+
if (!value || !SID_RE.test(value)) return null
|
|
24
|
+
/* `.` / `..` 这类在正则下已经不可能通过(首字符必须字母数字),这里只挡纯点形状。 */
|
|
25
|
+
if (/^\.+$/.test(value)) return null
|
|
26
|
+
return value
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 校验条目名(`f/report.html` 里的 `report.html`,或 `app/preview` 里的 `preview`)。
|
|
31
|
+
* @returns {string|null} 归一化后的 posix 相对路径;非法返回 null
|
|
32
|
+
*/
|
|
33
|
+
export function normalizeName(raw) {
|
|
34
|
+
const value = String(raw ?? '').replace(/\\/g, '/').replace(/^\/+/, '').replace(/\/+$/, '')
|
|
35
|
+
if (!value) return null
|
|
36
|
+
const segments = value.split('/')
|
|
37
|
+
if (segments.length > 8) return null
|
|
38
|
+
for (const segment of segments) {
|
|
39
|
+
if (!segment || !SEGMENT_RE.test(segment)) return null
|
|
40
|
+
if (segment === '.' || segment === '..') return null
|
|
41
|
+
}
|
|
42
|
+
return segments.join('/')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 拆分 `/s/<sid>/<kind>/<name...>`。
|
|
47
|
+
* @param {string} rest 已经去掉 `/s` 前缀的路径(以 `/` 开头)
|
|
48
|
+
* @returns {{sid:string, kind:'f'|'app', name:string}|null}
|
|
49
|
+
*/
|
|
50
|
+
export function splitTarget(rest) {
|
|
51
|
+
const value = String(rest ?? '')
|
|
52
|
+
const parts = value.split('/').filter(Boolean)
|
|
53
|
+
if (parts.length < 2) return null
|
|
54
|
+
let sid
|
|
55
|
+
try {
|
|
56
|
+
sid = normalizeSid(decodeURIComponent(parts[0]))
|
|
57
|
+
} catch {
|
|
58
|
+
/* 坏转义(`%zz`)在 decodeURIComponent 处就抛,按非法处理,不要冒泡成 500。 */
|
|
59
|
+
return null
|
|
60
|
+
}
|
|
61
|
+
if (!sid) return null
|
|
62
|
+
const kind = parts[1]
|
|
63
|
+
if (kind !== 'f' && kind !== 'app') return null
|
|
64
|
+
const rest2 = parts.slice(2).join('/')
|
|
65
|
+
if (!rest2) return { sid, kind, name: '' }
|
|
66
|
+
let name
|
|
67
|
+
try {
|
|
68
|
+
name = normalizeName(decodeURIComponent(rest2))
|
|
69
|
+
} catch {
|
|
70
|
+
/* 坏转义(`%zz`)在 decodeURIComponent 处就抛,按非法处理。 */
|
|
71
|
+
return null
|
|
72
|
+
}
|
|
73
|
+
if (!name) return null
|
|
74
|
+
return { sid, kind, name }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/* MIME 表不在这里维护:全仓只有 @capyclaw/plugin-kit/util/http 一份。 */
|
|
78
|
+
export { mimeFor, isHtmlMime } from '@capyclaw/plugin-kit/util/http'
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 把「注册表里记的绝对路径」变成可以安全读的文件句柄。
|
|
82
|
+
*
|
|
83
|
+
* 两道校验:realpath 之后必须仍是文件(挡符号链接跳到别处、挡目录),
|
|
84
|
+
* 并且必须落在 `allow` 里的某个根之内(网关只发自己发布过的东西,
|
|
85
|
+
* 不做任意目录透传)。
|
|
86
|
+
*
|
|
87
|
+
* @param {string} absPath
|
|
88
|
+
* @param {string[]} allowRoots
|
|
89
|
+
* @returns {{ok:true, real:string, size:number, mtimeMs:number}|{ok:false, error:string, status:number}}
|
|
90
|
+
*/
|
|
91
|
+
export function resolveStaticFile(absPath, allowRoots) {
|
|
92
|
+
const target = String(absPath ?? '')
|
|
93
|
+
if (!target || !path.isAbsolute(target)) return { ok: false, error: '条目路径不是绝对路径', status: 500 }
|
|
94
|
+
let real
|
|
95
|
+
try {
|
|
96
|
+
real = fs.realpathSync(target)
|
|
97
|
+
} catch {
|
|
98
|
+
return { ok: false, error: '产物文件已不存在(可能被清理或改名)', status: 404 }
|
|
99
|
+
}
|
|
100
|
+
const roots = (allowRoots || []).filter(Boolean).map((root) => {
|
|
101
|
+
try { return fs.realpathSync(root) } catch { return null }
|
|
102
|
+
}).filter(Boolean)
|
|
103
|
+
if (roots.length) {
|
|
104
|
+
const lower = process.platform === 'win32'
|
|
105
|
+
const hit = roots.some((root) => {
|
|
106
|
+
const a = lower ? root.toLowerCase() : root
|
|
107
|
+
const b = lower ? real.toLowerCase() : real
|
|
108
|
+
return b === a || b.startsWith(a + path.sep)
|
|
109
|
+
})
|
|
110
|
+
if (!hit) return { ok: false, error: '产物路径不在允许的根目录内', status: 403 }
|
|
111
|
+
}
|
|
112
|
+
let stat
|
|
113
|
+
try {
|
|
114
|
+
stat = fs.statSync(real)
|
|
115
|
+
} catch {
|
|
116
|
+
return { ok: false, error: '产物文件不可读', status: 404 }
|
|
117
|
+
}
|
|
118
|
+
if (!stat.isFile()) return { ok: false, error: '条目指向的不是文件', status: 404 }
|
|
119
|
+
return { ok: true, real, size: stat.size, mtimeMs: stat.mtimeMs }
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 目录型产物(导出的 ppt / 带 assets 的 html 目录)用的安全子路径解析。
|
|
124
|
+
*
|
|
125
|
+
* 与 `resolveStaticFile` 的区别:这里允许「一个条目 = 一个目录」,只要子路径
|
|
126
|
+
* 逃不出这个目录。产物目录整体发布是真实需求——导出的 html 很少是单文件,
|
|
127
|
+
* 逼用户把每个 css/js 都注册一遍只会让人绕过网关。
|
|
128
|
+
*
|
|
129
|
+
* @param {string} dir 条目的绝对目录
|
|
130
|
+
* @param {string} rel 形如 `assets/app.css` 的相对子路径
|
|
131
|
+
*/
|
|
132
|
+
export function safeChild(dir, rel) {
|
|
133
|
+
const cleaned = String(rel ?? '').replace(/\\/g, '/').replace(/^\/+/, '')
|
|
134
|
+
if (cleaned.split('/').some((segment) => segment.startsWith('.'))) {
|
|
135
|
+
return { ok: false, error: '路径里不允许隐藏段', status: 400 }
|
|
136
|
+
}
|
|
137
|
+
let base
|
|
138
|
+
try {
|
|
139
|
+
base = fs.realpathSync(dir)
|
|
140
|
+
} catch {
|
|
141
|
+
return { ok: false, error: '产物目录已不存在', status: 404 }
|
|
142
|
+
}
|
|
143
|
+
const joined = path.resolve(base, cleaned || '.')
|
|
144
|
+
const guard = (value) => (process.platform === 'win32' ? value.toLowerCase() : value)
|
|
145
|
+
if (guard(joined) !== guard(base) && !guard(joined).startsWith(guard(base) + path.sep)) {
|
|
146
|
+
return { ok: false, error: '路径越出了产物目录', status: 403 }
|
|
147
|
+
}
|
|
148
|
+
let real
|
|
149
|
+
try {
|
|
150
|
+
real = fs.realpathSync(joined)
|
|
151
|
+
} catch {
|
|
152
|
+
return { ok: false, error: '文件不存在', status: 404 }
|
|
153
|
+
}
|
|
154
|
+
if (guard(real) !== guard(base) && !guard(real).startsWith(guard(base) + path.sep)) {
|
|
155
|
+
return { ok: false, error: '路径越出了产物目录(符号链接)', status: 403 }
|
|
156
|
+
}
|
|
157
|
+
let stat
|
|
158
|
+
try {
|
|
159
|
+
stat = fs.statSync(real)
|
|
160
|
+
} catch {
|
|
161
|
+
return { ok: false, error: '文件不可读', status: 404 }
|
|
162
|
+
}
|
|
163
|
+
return { ok: true, real, size: stat.size, isDirectory: stat.isDirectory() }
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** 把绝对路径压成给人看的形式(错误信息/索引页用,不泄露太多)。 */
|
|
167
|
+
export function displayPath(absPath) {
|
|
168
|
+
const value = String(absPath ?? '')
|
|
169
|
+
if (!value) return ''
|
|
170
|
+
return path.basename(value)
|
|
171
|
+
}
|
package/lib/store.mjs
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 注册表:`$DSH_HOME/gateway.json` 是网关唯一的真源。
|
|
3
|
+
*
|
|
4
|
+
* 为什么不用「内存里存一份 + 事件订阅」:进程会重启、插件会重载、用户会手动
|
|
5
|
+
* 删产物,任何订阅都一定会漏。落盘 + 每次请求现读是唯一不会漂的做法;
|
|
6
|
+
* 文件小(几百条以内),读一次几十微秒,不值得缓存。
|
|
7
|
+
*/
|
|
8
|
+
import fs from 'node:fs'
|
|
9
|
+
import path from 'node:path'
|
|
10
|
+
import os from 'node:os'
|
|
11
|
+
|
|
12
|
+
export const STORE_VERSION = 1
|
|
13
|
+
|
|
14
|
+
export function gatewayHome() {
|
|
15
|
+
return process.env.DSH_HOME || path.join(os.homedir(), '.dsh')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function storePath() {
|
|
19
|
+
return process.env.DSH_GATEWAY_STORE || path.join(gatewayHome(), 'gateway.json')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function emptyStore() {
|
|
23
|
+
return { version: STORE_VERSION, updatedAt: new Date().toISOString(), entries: {} }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 读注册表。文件不存在 → 空表;文件坏了 → 空表 + 把坏文件改名留证
|
|
28
|
+
* (不能直接删:里面是用户产物的索引,删掉就再也找不回来了)。
|
|
29
|
+
*/
|
|
30
|
+
export function readStore() {
|
|
31
|
+
const file = storePath()
|
|
32
|
+
let text
|
|
33
|
+
try {
|
|
34
|
+
text = fs.readFileSync(file, 'utf8')
|
|
35
|
+
} catch {
|
|
36
|
+
return emptyStore()
|
|
37
|
+
}
|
|
38
|
+
let parsed
|
|
39
|
+
try {
|
|
40
|
+
parsed = JSON.parse(text)
|
|
41
|
+
} catch {
|
|
42
|
+
try { fs.renameSync(file, `${file}.corrupt-${Date.now()}`) } catch { /* 留证失败不影响主流程 */ }
|
|
43
|
+
return emptyStore()
|
|
44
|
+
}
|
|
45
|
+
if (!parsed || typeof parsed !== 'object' || !parsed.entries || typeof parsed.entries !== 'object') {
|
|
46
|
+
return emptyStore()
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
version: STORE_VERSION,
|
|
50
|
+
updatedAt: String(parsed.updatedAt || ''),
|
|
51
|
+
entries: parsed.entries,
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** 原子写:先写同目录临时文件再 rename,避免读到半截 JSON。 */
|
|
56
|
+
export function writeStore(store) {
|
|
57
|
+
const file = storePath()
|
|
58
|
+
fs.mkdirSync(path.dirname(file), { recursive: true })
|
|
59
|
+
const next = {
|
|
60
|
+
version: STORE_VERSION,
|
|
61
|
+
updatedAt: new Date().toISOString(),
|
|
62
|
+
entries: store?.entries && typeof store.entries === 'object' ? store.entries : {},
|
|
63
|
+
}
|
|
64
|
+
const tmp = `${file}.tmp-${process.pid}-${Date.now()}`
|
|
65
|
+
fs.writeFileSync(tmp, `${JSON.stringify(next, null, 2)}\n`, { encoding: 'utf8', mode: 0o600 })
|
|
66
|
+
fs.renameSync(tmp, file)
|
|
67
|
+
return next
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** 该会话的条目表(不存在时返回空对象,不建条目——读操作不该有副作用)。 */
|
|
71
|
+
export function sessionEntry(store, sid) {
|
|
72
|
+
const entry = store?.entries?.[sid]
|
|
73
|
+
if (!entry || typeof entry !== 'object') return null
|
|
74
|
+
return {
|
|
75
|
+
sessionId: String(entry.sessionId || sid),
|
|
76
|
+
label: typeof entry.label === 'string' ? entry.label : '',
|
|
77
|
+
workspace: typeof entry.workspace === 'string' ? entry.workspace : '',
|
|
78
|
+
updatedAt: String(entry.updatedAt || ''),
|
|
79
|
+
// 会话自己的状态(关窗重开后据此复原)。空对象表示「还没有状态」。
|
|
80
|
+
state: entry.state && typeof entry.state === 'object' ? entry.state : {},
|
|
81
|
+
items: entry.items && typeof entry.items === 'object' ? entry.items : {},
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 记一点会话状态。这是「关掉再打开还能找到之前改到哪」的唯一落点:
|
|
87
|
+
* 条目(items)是给别人看的产物,状态(state)是给下一次打开的自己看的。
|
|
88
|
+
* `state` 浅合并,值为 null 表示擦掉该键;`items` 不在这里动。
|
|
89
|
+
*/
|
|
90
|
+
export function patchSession(store, sid, patch = {}) {
|
|
91
|
+
const now = new Date().toISOString()
|
|
92
|
+
const entries = store.entries || (store.entries = {})
|
|
93
|
+
const current = entries[sid] && typeof entries[sid] === 'object'
|
|
94
|
+
? entries[sid]
|
|
95
|
+
: { sessionId: sid, label: '', workspace: '', updatedAt: now, items: {} }
|
|
96
|
+
if (!current.items || typeof current.items !== 'object') current.items = {}
|
|
97
|
+
if (typeof patch.label === 'string' && patch.label) current.label = patch.label
|
|
98
|
+
if (typeof patch.workspace === 'string' && patch.workspace) current.workspace = patch.workspace
|
|
99
|
+
if (patch.state && typeof patch.state === 'object' && !Array.isArray(patch.state)) {
|
|
100
|
+
const next = current.state && typeof current.state === 'object' ? { ...current.state } : {}
|
|
101
|
+
for (const [key, value] of Object.entries(patch.state)) {
|
|
102
|
+
if (value === null || value === undefined) delete next[key]
|
|
103
|
+
else next[key] = value
|
|
104
|
+
}
|
|
105
|
+
current.state = next
|
|
106
|
+
}
|
|
107
|
+
current.sessionId = String(current.sessionId || sid)
|
|
108
|
+
current.updatedAt = now
|
|
109
|
+
entries[sid] = current
|
|
110
|
+
return current
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 写入/更新一个条目(幂等 upsert)。
|
|
115
|
+
* @returns {{created:boolean, item:object}}
|
|
116
|
+
*/
|
|
117
|
+
export function upsertItem(store, sid, key, item, meta = {}) {
|
|
118
|
+
const now = new Date().toISOString()
|
|
119
|
+
const entries = store.entries || (store.entries = {})
|
|
120
|
+
const current = entries[sid] && typeof entries[sid] === 'object'
|
|
121
|
+
? entries[sid]
|
|
122
|
+
: { sessionId: sid, label: '', workspace: '', updatedAt: now, items: {} }
|
|
123
|
+
if (!current.items || typeof current.items !== 'object') current.items = {}
|
|
124
|
+
if (typeof meta.label === 'string' && meta.label) current.label = meta.label
|
|
125
|
+
if (typeof meta.workspace === 'string' && meta.workspace) current.workspace = meta.workspace
|
|
126
|
+
current.sessionId = String(current.sessionId || sid)
|
|
127
|
+
current.updatedAt = now
|
|
128
|
+
const exists = Boolean(current.items[key])
|
|
129
|
+
current.items[key] = { ...item, addedAt: exists ? (current.items[key].addedAt || now) : now }
|
|
130
|
+
entries[sid] = current
|
|
131
|
+
return { created: !exists, item: current.items[key] }
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** 删一个条目;返回是否真的删掉了(给 404/200 区分用)。 */
|
|
135
|
+
export function removeItem(store, sid, key) {
|
|
136
|
+
const current = sessionEntry(store, sid)
|
|
137
|
+
if (!current) return false
|
|
138
|
+
if (!Object.prototype.hasOwnProperty.call(current.items, key)) return false
|
|
139
|
+
delete store.entries[sid].items[key]
|
|
140
|
+
store.entries[sid].updatedAt = new Date().toISOString()
|
|
141
|
+
// 没有条目了也要看有没有状态:状态还在,这个会话就还没结束。
|
|
142
|
+
const left = store.entries[sid]
|
|
143
|
+
if (!Object.keys(left.items || {}).length && !Object.keys(left.state || {}).length) delete store.entries[sid]
|
|
144
|
+
return true
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** 清掉整个会话(会话结束/用户关窗时用)。 */
|
|
148
|
+
export function removeSession(store, sid) {
|
|
149
|
+
if (!store?.entries || !store.entries[sid]) return false
|
|
150
|
+
delete store.entries[sid]
|
|
151
|
+
return true
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* 惰性 GC:只清「过期」和「静态文件已被删掉」的条目。
|
|
156
|
+
* 用户自己删了产物不该让网关一直 500,但也不能在他还能用时提前清掉。
|
|
157
|
+
*/
|
|
158
|
+
export function pruneStore(store, now = Date.now()) {
|
|
159
|
+
let removed = 0
|
|
160
|
+
for (const [sid, entry] of Object.entries(store.entries || {})) {
|
|
161
|
+
if (!entry || typeof entry !== 'object' || (!entry.items && !entry.state)) { delete store.entries[sid]; removed++; continue }
|
|
162
|
+
if (!entry.items || typeof entry.items !== 'object') entry.items = {}
|
|
163
|
+
for (const [key, item] of Object.entries(entry.items)) {
|
|
164
|
+
const expiresAt = Number(item?.expiresAt || 0)
|
|
165
|
+
if (expiresAt && expiresAt <= now) { delete entry.items[key]; removed++; continue }
|
|
166
|
+
if (item?.kind === 'static' && item?.absPath && !fs.existsSync(item.absPath)) {
|
|
167
|
+
delete entry.items[key]
|
|
168
|
+
removed++
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// 条目被清光但还留着状态的会话不算空:他下次打开还要看这些状态。
|
|
172
|
+
if (!Object.keys(entry.items).length && !Object.keys(entry.state || {}).length) {
|
|
173
|
+
delete store.entries[sid]
|
|
174
|
+
removed++
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return removed
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** 会话条目的可对外形态(不带绝对路径以外的东西;绝对路径留着给宿主半做定位)。 */
|
|
181
|
+
export function publicItems(entry) {
|
|
182
|
+
if (!entry) return []
|
|
183
|
+
return Object.entries(entry.items).map(([key, item]) => ({
|
|
184
|
+
key,
|
|
185
|
+
kind: item?.kind || 'static',
|
|
186
|
+
label: typeof item?.label === 'string' ? item.label : '',
|
|
187
|
+
absPath: item?.absPath || '',
|
|
188
|
+
serviceId: item?.serviceId || '',
|
|
189
|
+
mime: item?.mime || '',
|
|
190
|
+
addedAt: item?.addedAt || '',
|
|
191
|
+
expiresAt: Number(item?.expiresAt || 0) || 0,
|
|
192
|
+
}))
|
|
193
|
+
}
|
package/lib/upstream.mjs
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 上游解析:把「服务 id」换成「此刻真的在服务的 origin」。
|
|
3
|
+
*
|
|
4
|
+
* 关键取舍:URL 里永远不出现端口,注册表里也**不存端口**,只存服务 id。
|
|
5
|
+
* 端口是服务进程的私事(broker 每次启动都可能换号),存下来必然过期;
|
|
6
|
+
* 每次请求现查 `$DSH_HOME/services.json` 才是唯一不会漂的做法。
|
|
7
|
+
* 唯一需要的缓存是为了避免同一页面几十个资源请求打几十次盘——5 秒 TTL
|
|
8
|
+
* 足够吞掉一轮页面加载,又短到「重启服务后刷新一次就生效」。
|
|
9
|
+
*/
|
|
10
|
+
import fs from 'node:fs'
|
|
11
|
+
import path from 'node:path'
|
|
12
|
+
|
|
13
|
+
import { gatewayHome } from './store.mjs'
|
|
14
|
+
import { isLoopbackAddress } from '@capyclaw/plugin-kit/util/http'
|
|
15
|
+
|
|
16
|
+
const TTL_MS = 5000
|
|
17
|
+
let cache = { at: 0, services: null, file: '' }
|
|
18
|
+
|
|
19
|
+
export function servicesPath() {
|
|
20
|
+
return process.env.DSH_SERVICES_STORE || path.join(gatewayHome(), 'services.json')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** 读 broker 的发现表,容错两种形状(`{services:{}}` 与裸对象)。 */
|
|
24
|
+
function readServices(file) {
|
|
25
|
+
let parsed
|
|
26
|
+
try {
|
|
27
|
+
parsed = JSON.parse(fs.readFileSync(file, 'utf8'))
|
|
28
|
+
} catch {
|
|
29
|
+
return null
|
|
30
|
+
}
|
|
31
|
+
if (!parsed || typeof parsed !== 'object') return null
|
|
32
|
+
const bag = parsed.services && typeof parsed.services === 'object' ? parsed.services : parsed
|
|
33
|
+
const out = {}
|
|
34
|
+
for (const [id, value] of Object.entries(bag)) {
|
|
35
|
+
if (!value || typeof value !== 'object') continue
|
|
36
|
+
const url = typeof value.url === 'string' ? value.url : ''
|
|
37
|
+
if (!url) continue
|
|
38
|
+
out[id] = {
|
|
39
|
+
state: String(value.state || ''),
|
|
40
|
+
url,
|
|
41
|
+
healthPath: typeof value.healthPath === 'string' ? value.healthPath : '/healthz',
|
|
42
|
+
pid: Number(value.pid || 0) || 0,
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return out
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function listServices({ fresh = false } = {}) {
|
|
49
|
+
const file = servicesPath()
|
|
50
|
+
const now = Date.now()
|
|
51
|
+
if (!fresh && cache.services && cache.file === file && now - cache.at < TTL_MS) return cache.services
|
|
52
|
+
const services = readServices(file) || {}
|
|
53
|
+
cache = { at: now, services, file }
|
|
54
|
+
return services
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** 测试/诊断用:清掉缓存。 */
|
|
58
|
+
export function clearServiceCache() {
|
|
59
|
+
cache = { at: 0, services: null, file: '' }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 服务 id → origin(形如 `http://127.0.0.1:39321`,**不带尾斜杠**)。
|
|
64
|
+
*
|
|
65
|
+
* 只接受 loopback 地址:网关自己就是本机入口,转发到外网等于把本机变成
|
|
66
|
+
* 开放代理,一旦有人能写注册表就是 SSRF。
|
|
67
|
+
*
|
|
68
|
+
* @returns {{ok:true, origin:string, service:object}|{ok:false, status:number, error:string}}
|
|
69
|
+
*/
|
|
70
|
+
export function resolveService(serviceId) {
|
|
71
|
+
const id = String(serviceId || '').trim()
|
|
72
|
+
if (!id) return { ok: false, status: 500, error: '条目没有绑定服务 id' }
|
|
73
|
+
const services = listServices()
|
|
74
|
+
const service = services[id]
|
|
75
|
+
if (!service) {
|
|
76
|
+
return { ok: false, status: 503, error: `服务 ${id} 不在发现表里(可能还没启动,或已被卸载)` }
|
|
77
|
+
}
|
|
78
|
+
if (service.state && service.state !== 'running') {
|
|
79
|
+
return { ok: false, status: 503, error: `服务 ${id} 当前状态是 ${service.state},不是 running` }
|
|
80
|
+
}
|
|
81
|
+
let url
|
|
82
|
+
try {
|
|
83
|
+
url = new URL(service.url)
|
|
84
|
+
} catch {
|
|
85
|
+
return { ok: false, status: 503, error: `服务 ${id} 的地址不可解析:${service.url}` }
|
|
86
|
+
}
|
|
87
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
|
88
|
+
return { ok: false, status: 502, error: `服务 ${id} 的协议不受支持:${url.protocol}` }
|
|
89
|
+
}
|
|
90
|
+
if (!isLoopbackHost(url.hostname)) {
|
|
91
|
+
return { ok: false, status: 502, error: `服务 ${id} 指向非本机地址(${url.hostname}),网关不转发到外部` }
|
|
92
|
+
}
|
|
93
|
+
return { ok: true, origin: url.origin, service }
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/* 回环判定在基建里只有一份(顺带认 `::ffff:127.x.x.x` 这种 IPv4 映射地址)。 */
|
|
97
|
+
export const isLoopbackHost = isLoopbackAddress
|
|
98
|
+
|
|
99
|
+
/** 探活(转发失败时给一句能看懂的话,而不是干瘪的 ECONNREFUSED)。 */
|
|
100
|
+
export async function probeOrigin(origin, timeoutMs = 1500) {
|
|
101
|
+
const controller = new AbortController()
|
|
102
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs)
|
|
103
|
+
try {
|
|
104
|
+
const res = await fetch(`${origin}/healthz`, { signal: controller.signal, redirect: 'manual' })
|
|
105
|
+
return { ok: true, status: res.status }
|
|
106
|
+
} catch (error) {
|
|
107
|
+
return { ok: false, error: String(error?.message || error) }
|
|
108
|
+
} finally {
|
|
109
|
+
clearTimeout(timer)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# @capyclaw/foundation
|
|
2
|
+
|
|
3
|
+
dsh 插件基石层:接口 ABI、插件加载器与内核服务 `ctx.os`。
|
|
4
|
+
|
|
5
|
+
应用插件不再写 `inject` / `apply` / provider 装配,只声明「我实现了哪个接口」:
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import { createPlugin, skillProvider } from '@capyclaw/foundation/abi'
|
|
9
|
+
|
|
10
|
+
export const { name, inject, apply } = createPlugin({
|
|
11
|
+
name: 'canvas',
|
|
12
|
+
requires: ['canvas.runtime@^1'],
|
|
13
|
+
implements: [skillProvider({ skill: './skills/canvas' })],
|
|
14
|
+
}, import.meta.url)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 四个入口
|
|
18
|
+
|
|
19
|
+
| 入口 | 内容 | 谁用 |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| `.` | Cordis 插件,产出 `ctx.os` | dsh profile |
|
|
22
|
+
| `./abi` | 描述符构建器、加载器、错误码、版本工具 | 应用插件 |
|
|
23
|
+
| `./kit` | plugin-kit 兼容导出,包含 Node/dsh 耦合,非纯函数库 | 兼容调用方 |
|
|
24
|
+
| `./runtime` | `createKernel` 等宿主 API | dsh 之外的宿主(独立技能服务、测试夹具) |
|
|
25
|
+
|
|
26
|
+
## 状态
|
|
27
|
+
|
|
28
|
+
- 包清单当前为 `0.1.6`;0.1.6 修的是「关掉插件再启用撞 E_DUP_PLUGIN」(disposer 未登记 + 失败
|
|
29
|
+
记录占名),详见下面的「生命周期」。
|
|
30
|
+
- 分层:应用插件 → ABI → 内核 → Host 适配器 → 本地 Node.js agent 运行时。
|
|
31
|
+
dsh 服务访问位于 Host 适配层;memory 只是参考实现,不证明第二个真实 agent 兼容。
|
|
32
|
+
HTTP/资源/进程仍有本地 Node 协议约束,详见 `docs/HOST-ADAPTER.md`。
|
|
33
|
+
- ABI v1,六个标准接口 + `host-event@1` + `client-panel@1` + `service-provider@1` +
|
|
34
|
+
`own-server@1` + 可执行 `raw@1`;基建插件使用 `defineDriver` 驱动入口。
|
|
35
|
+
- 能力表按 `ctx` 实际服务探测(见 `lib/kernel.mjs` 的 `detectCapabilities`),不做空头承诺。
|
|
36
|
+
- 当前仓库:27 个插件走标准接口,`raw@1` 当前为空,6 个基建插件走
|
|
37
|
+
`defineDriver` 驱动层;`meta/foundation.allowlist.json` 的模糊豁免为 0。
|
|
38
|
+
详见 `docs/POLICY.md` 与 `docs/spec/plugin-abi.md`。
|
|
39
|
+
|
|
40
|
+
设计规范见 `docs/spec/plugin-abi.md`,强制规则见 `docs/POLICY.md`。
|
|
41
|
+
|
|
42
|
+
## 生命周期(0.1.6 起)
|
|
43
|
+
|
|
44
|
+
`createPlugin().apply` 会把 `os.mount()` 的 disposer 通过 `ctx.effect(() => () => dispose())`
|
|
45
|
+
登记到本次激活的 ctx 上——**不能只靠 apply 的返回值**:Cordis 只认 `ctx.effect` 回调返回的
|
|
46
|
+
disposer,返回值不可靠。漏登记时,关掉插件后内核里的记录不会摘除,再次启用就会撞
|
|
47
|
+
`E_DUP_PLUGIN: 插件 xxx 已挂载`。
|
|
48
|
+
|
|
49
|
+
加载器侧另有两条兜底:`mount()` 遇到 `disposed` / `failed` 的旧记录会先摘掉并尽力回收;
|
|
50
|
+
`start` 失败清理完成后立即让出插件名。两者共同保证「关掉 → 再启用」可重复无数次。
|
|
51
|
+
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 资产引用契约的单一真源(公共 ABI 常量)。
|
|
3
|
+
*
|
|
4
|
+
* 互操作标准里资产有两副面孔,前缀在这里定义一次,内核门面与资产服务都引用它,
|
|
5
|
+
* 避免「路由实现」与「URL 门面」各写一份 '/assets/' 而漂移:
|
|
6
|
+
* - 字节仓 HTTP 路由前缀 ASSET_URL_PREFIX = '/assets/' (asset-service 挂 GET/HEAD)
|
|
7
|
+
* - 结构化正文里的引用前缀 ASSET_REF_PREFIX = '@asset/' (work-store 信封/正文只存引用)
|
|
8
|
+
*
|
|
9
|
+
* 这是契约常量,不是宿主服务名——放 ABI 层,应用与驱动都可 import。
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** 资产字节仓的 HTTP 路由前缀(asset-service 实现,内核 os.assets.url 复用)。 */
|
|
13
|
+
export const ASSET_URL_PREFIX = '/assets/'
|
|
14
|
+
|
|
15
|
+
/** 结构化正文/产物信封里的内容寻址引用前缀(@asset/<sha256>)。 */
|
|
16
|
+
export const ASSET_REF_PREFIX = '@asset/'
|
|
17
|
+
|
|
18
|
+
/** 由资产 id 生成可加载 URL:/assets/<id>(id 做 URI 编码)。 */
|
|
19
|
+
export function assetUrl(id) {
|
|
20
|
+
return `${ASSET_URL_PREFIX}${encodeURIComponent(String(id))}`
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** 由资产 id 生成规范引用:@asset/<id>。 */
|
|
24
|
+
export function assetRef(id) {
|
|
25
|
+
return `${ASSET_REF_PREFIX}${String(id)}`
|
|
26
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 桥(editor bridge)与文档模型的标准声明。
|
|
3
|
+
*
|
|
4
|
+
* 这一层只放「协议常量 + 声明校验」,不放运行时:
|
|
5
|
+
* - 常量:协议版本、模型版本、能力名(suite 清单与 healthz 都用它)
|
|
6
|
+
* - declareBridge():把工作台的声明冻结成标准形状
|
|
7
|
+
* - assertBridgeRuntime():启动/巡检时把「声明」与「运行时实际上报」对齐
|
|
8
|
+
*
|
|
9
|
+
* 运行时(relay / 队列 / 租约)仍在 @capyclaw/document-workbench + service-host,
|
|
10
|
+
* 不进 ABI 层:foundation 是所有插件的地基,不该背 HTTP/store 依赖。
|
|
11
|
+
*
|
|
12
|
+
* 能力名(与 suite 清单的 requires/provides.capabilities 对应):
|
|
13
|
+
* editor.bridge —— 插件提供一个编辑器权威桥(/healthz + /status + /watch + /ack)
|
|
14
|
+
* doc.model —— 插件提供文档模型(稳定 ID / 清单 / 定位 / 编辑计划 / 校验)
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { AbiError, ERROR_CODES } from './errors.mjs'
|
|
18
|
+
|
|
19
|
+
/** 桥协议版本:端点集合与状态机语义的主版本。不兼容变更才升 major。 */
|
|
20
|
+
export const BRIDGE_PROTOCOL_VERSION = '1.0.0'
|
|
21
|
+
|
|
22
|
+
/** 文档模型版本:清单字段、定位器语义、编辑 op 的主版本。 */
|
|
23
|
+
export const DOC_MODEL_VERSION = '1.0.0'
|
|
24
|
+
|
|
25
|
+
export const BRIDGE_CAPABILITY = 'editor.bridge'
|
|
26
|
+
export const DOC_MODEL_CAPABILITY = 'doc.model'
|
|
27
|
+
|
|
28
|
+
/** healthz 里桥声明的字段名(避免与既有的 bridge: '<name>' 字符串冲突)。 */
|
|
29
|
+
export const BRIDGE_INFO_FIELD = 'bridgeInfo'
|
|
30
|
+
|
|
31
|
+
const ID_RE = /^[a-z0-9][a-z0-9-]*$/
|
|
32
|
+
const VERSION_RE = /^\d+\.\d+\.\d+$/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 校验并冻结一份桥声明。
|
|
36
|
+
* @param {{ id: string, protocol?: string, model?: string|null, editor?: 'required'|'optional' }} input
|
|
37
|
+
*/
|
|
38
|
+
export function declareBridge(input = {}) {
|
|
39
|
+
const { id, protocol = BRIDGE_PROTOCOL_VERSION, model = null, editor = 'required' } = input
|
|
40
|
+
const errors = []
|
|
41
|
+
if (typeof id !== 'string' || !ID_RE.test(id)) errors.push(`id 必须是 kebab-case:${id}`)
|
|
42
|
+
if (!VERSION_RE.test(protocol)) errors.push(`protocol 版本非法:${protocol}`)
|
|
43
|
+
if (model !== null && !VERSION_RE.test(model)) errors.push(`model 版本非法:${model}`)
|
|
44
|
+
if (editor !== 'required' && editor !== 'optional') errors.push(`editor 只能是 required/optional:${editor}`)
|
|
45
|
+
if (errors.length) throw new AbiError(ERROR_CODES.E_SCHEMA, `桥声明非法:${errors.join(';')}`, { errors })
|
|
46
|
+
return Object.freeze({ id, protocol, model, editor })
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 桥声明 → suite 清单里的 provides.capabilities。 */
|
|
50
|
+
export function bridgeCapabilities(declaration) {
|
|
51
|
+
const decl = declaration && declaration.protocol ? declaration : declareBridge(declaration)
|
|
52
|
+
return Object.freeze({
|
|
53
|
+
[BRIDGE_CAPABILITY]: decl.protocol,
|
|
54
|
+
...(decl.model ? { [DOC_MODEL_CAPABILITY]: decl.model } : {}),
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** 桥声明 → suite 清单里工具面对运行时的 requires.capabilities(skill 包用)。 */
|
|
59
|
+
export function bridgeConsumerRequirements(ns, { needsModel = false } = {}) {
|
|
60
|
+
const out = { [`${ns}.runtime`]: `^${BRIDGE_PROTOCOL_VERSION}` }
|
|
61
|
+
if (needsModel) out[DOC_MODEL_CAPABILITY] = `^${DOC_MODEL_VERSION}`
|
|
62
|
+
return Object.freeze(out)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 声明与运行时对账:启动或巡检时调用。
|
|
67
|
+
*
|
|
68
|
+
* @param {object} declaration declareBridge 的结果(来自插件代码/清单)
|
|
69
|
+
* @param {object} runtime healthz 里的 bridgeInfo(实际运行值)
|
|
70
|
+
* @returns {{ ok: boolean, issues: string[] }}
|
|
71
|
+
*/
|
|
72
|
+
export function assertBridgeRuntime(declaration, runtime) {
|
|
73
|
+
const issues = []
|
|
74
|
+
const decl = declaration && declaration.id ? declaration : declareBridge(declaration || {})
|
|
75
|
+
if (!runtime || typeof runtime !== 'object') {
|
|
76
|
+
return { ok: false, issues: [`运行时没有上报 ${BRIDGE_INFO_FIELD}`] }
|
|
77
|
+
}
|
|
78
|
+
if (runtime.id !== decl.id) issues.push(`id 不一致:声明 ${decl.id} / 运行 ${runtime.id}`)
|
|
79
|
+
if (runtime.protocol !== decl.protocol) {
|
|
80
|
+
issues.push(`协议版本不一致:声明 ${decl.protocol} / 运行 ${runtime.protocol}`)
|
|
81
|
+
}
|
|
82
|
+
const declaredModel = decl.model || null
|
|
83
|
+
const runtimeModel = runtime.model || null
|
|
84
|
+
if (declaredModel !== runtimeModel) {
|
|
85
|
+
issues.push(`模型版本不一致:声明 ${declaredModel || '无'} / 运行 ${runtimeModel || '无'}`)
|
|
86
|
+
}
|
|
87
|
+
return { ok: issues.length === 0, issues }
|
|
88
|
+
}
|