@capyclaw/wall-suite 0.0.0-stage → 0.1.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 +20 -2
- package/composition.lock.json +48 -0
- package/contract/wall-contract.json +8 -0
- package/cordis.patch.yml +6 -0
- package/dsh-suite.json +128 -0
- package/lib/index.mjs +6 -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/portal/README.md +70 -0
- package/node_modules/@capyclaw/portal/lib/index.mjs +387 -0
- package/node_modules/@capyclaw/portal/lib/ledger.mjs +194 -0
- package/node_modules/@capyclaw/portal/lib/portal-agent.ps1 +811 -0
- package/node_modules/@capyclaw/portal/lib/portal-darwin.mjs +183 -0
- package/node_modules/@capyclaw/portal/package.json +40 -0
- package/node_modules/@capyclaw/service-broker/README.md +104 -0
- package/node_modules/@capyclaw/service-broker/cordis.patch.yml +8 -0
- package/node_modules/@capyclaw/service-broker/dsh-suite.json +21 -0
- package/node_modules/@capyclaw/service-broker/lib/control.mjs +209 -0
- package/node_modules/@capyclaw/service-broker/lib/discovery.mjs +109 -0
- package/node_modules/@capyclaw/service-broker/lib/engine.mjs +1290 -0
- package/node_modules/@capyclaw/service-broker/lib/host.mjs +187 -0
- package/node_modules/@capyclaw/service-broker/lib/manifest.mjs +262 -0
- package/node_modules/@capyclaw/service-broker/lib/recovery.mjs +275 -0
- package/node_modules/@capyclaw/service-broker/lib/skills-client.mjs +48 -0
- package/node_modules/@capyclaw/service-broker/lib/spec.mjs +78 -0
- package/node_modules/@capyclaw/service-broker/package.json +65 -0
- package/node_modules/@capyclaw/service-broker/server.mjs +81 -0
- package/node_modules/@capyclaw/service-broker/service.schema.json +62 -0
- package/node_modules/@capyclaw/service-broker/services.json +3 -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/tool-host/README.md +56 -0
- package/node_modules/@capyclaw/tool-host/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/tool-host/dsh-suite.json +30 -0
- package/node_modules/@capyclaw/tool-host/lib/host.mjs +46 -0
- package/node_modules/@capyclaw/tool-host/package.json +59 -0
- package/node_modules/@capyclaw/tool-host/src/admit-images.mjs +80 -0
- package/node_modules/@capyclaw/tool-host/src/caller-session.mjs +25 -0
- package/node_modules/@capyclaw/tool-host/src/descriptors.mjs +166 -0
- package/node_modules/@capyclaw/tool-host/src/index.mjs +461 -0
- package/node_modules/@capyclaw/tool-host/src/mode-gate.mjs +272 -0
- package/node_modules/@capyclaw/wall-workbench/README.md +58 -0
- package/node_modules/@capyclaw/wall-workbench/contract/wall-contract.json +8 -0
- package/node_modules/@capyclaw/wall-workbench/lib/host.mjs +1 -0
- package/node_modules/@capyclaw/wall-workbench/package.json +63 -0
- package/node_modules/@capyclaw/wall-workbench/plugin.mjs +13 -0
- package/node_modules/@capyclaw/wall-workbench/server/activate-log.mjs +66 -0
- package/node_modules/@capyclaw/wall-workbench/server/constants.mjs +12 -0
- package/node_modules/@capyclaw/wall-workbench/server/contract.mjs +12 -0
- package/node_modules/@capyclaw/wall-workbench/server/embedded-host.mjs +162 -0
- package/node_modules/@capyclaw/wall-workbench/server/infra/http.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/infra/tuning.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/relay.mjs +68 -0
- package/node_modules/@capyclaw/wall-workbench/server/routes/claim.mjs +46 -0
- package/node_modules/@capyclaw/wall-workbench/server/routes/workbench.mjs +29 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/SHARED_MANIFEST.json +70 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/asset-service.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/editor-host.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/editor/lease.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/service/api.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/service/http.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/service/mcp-http.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/tools/validate.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/tuning.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/kit/util/fs-lock.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/service-host.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/tool-host.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/shared/tuning.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/tools/capabilities/index.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/tools/index.mjs +12 -0
- package/node_modules/@capyclaw/wall-workbench/server/tools.mjs +2 -0
- package/node_modules/@capyclaw/wall-workbench/server/workbench-framework.mjs +339 -0
- package/node_modules/@capyclaw/wall-workbench/ui/app.js +225 -0
- package/node_modules/@capyclaw/wall-workbench/ui/index.html +20 -0
- package/node_modules/@capyclaw/wall-workbench/ui/style.css +77 -0
- package/package.json +72 -4
- package/services.json +3 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @capyclaw/wall-workbench 宿主插件(cordis 入口,loader 经包名加载本模块)。
|
|
3
|
+
*
|
|
4
|
+
* 承载形态由**基建**决定,业务插件不选端口:
|
|
5
|
+
* - 有 ctx.webServer(生产):挂到宿主 HTTP 路由前缀下,不监听任何端口,
|
|
6
|
+
* 生命周期随 DSH 启停;前缀由基建给(默认 /capyclaw/wall)。
|
|
7
|
+
* - 没有 webServer(开发/测试):才退回独立 loopback 端口。
|
|
8
|
+
*
|
|
9
|
+
* 与 ppt/canvas 的公共 host 模板不同,本文件为手写精简版(照 browser 先例):
|
|
10
|
+
* 展示墙零工具、零引擎、零文档 store/journal/workspace 依赖,装配面只有
|
|
11
|
+
* serviceHost 契约 + workStore 懒解析器 + 静态页/认领路由。
|
|
12
|
+
*/
|
|
13
|
+
import os from 'node:os'
|
|
14
|
+
import path from 'node:path'
|
|
15
|
+
import fs from 'node:fs'
|
|
16
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
17
|
+
import { assertServiceApi } from './shared/kit/service/api.mjs'
|
|
18
|
+
import { appendBoundedLog } from './activate-log.mjs'
|
|
19
|
+
|
|
20
|
+
export const name = 'wall-workbench-host'
|
|
21
|
+
/* 依赖倒置:业务等的是「宿主给的 HTTP 路由」,不是端口。 */
|
|
22
|
+
export const inject = ['webServer']
|
|
23
|
+
|
|
24
|
+
function safeGet(ctx, serviceName) {
|
|
25
|
+
// 原生插件里 ctx.get(name) 只对已 inject 的服务放行;可选依赖用 reflect.get
|
|
26
|
+
// 才不会因为「没在 inject 列表里」被拒绝(core 也是这么取依赖的)。
|
|
27
|
+
try {
|
|
28
|
+
if (ctx && ctx.reflect && typeof ctx.reflect.get === 'function') return ctx.reflect.get(serviceName)
|
|
29
|
+
return ctx?.get ? ctx.get(serviceName) : null
|
|
30
|
+
} catch { return null }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function requireApi(service, name) {
|
|
34
|
+
if (service) assertServiceApi(service, { name, major: 1 })
|
|
35
|
+
return service
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** 基建依赖(@capyclaw/portal)不保证在工作台包的依赖树里,按约定位置兜底解析。 */
|
|
39
|
+
async function loadPortal() {
|
|
40
|
+
try {
|
|
41
|
+
return await import('@capyclaw/portal')
|
|
42
|
+
} catch { /* 落到 profile 扫描 */ }
|
|
43
|
+
const home = process.env.DSH_HOME || path.join(os.homedir(), '.dsh')
|
|
44
|
+
const roots = []
|
|
45
|
+
try {
|
|
46
|
+
for (const dir of fs.readdirSync(path.join(home, 'profiles'))) roots.push(path.join(home, 'profiles', dir, 'node_modules'))
|
|
47
|
+
} catch { /* 没有 profiles 目录 */ }
|
|
48
|
+
for (const root of roots) {
|
|
49
|
+
for (const scope of ['core', 'ppt-suite', 'canvas-suite', 'browser-suite', 'wall-suite']) {
|
|
50
|
+
const file = path.join(root, '@capyclaw', scope, 'node_modules', '@capyclaw', 'portal', 'lib', 'index.mjs')
|
|
51
|
+
if (!fs.existsSync(file)) continue
|
|
52
|
+
try {
|
|
53
|
+
return await import(pathToFileURL(file).href)
|
|
54
|
+
} catch { /* 试下一个 */ }
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return null
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 激活失败的完整栈只留在宿主日志里,插件管理器/Web UI 只显示第一行;
|
|
62
|
+
* 这里把栈落到 hostDir,下次「1 entry did not activate」时能直接看到根因。
|
|
63
|
+
*/
|
|
64
|
+
export async function apply(ctx, config) {
|
|
65
|
+
try {
|
|
66
|
+
return await activate(ctx, config)
|
|
67
|
+
} catch (error) {
|
|
68
|
+
try {
|
|
69
|
+
const fallbackDir = path.join(os.homedir(), '.dsh-wall-bridge')
|
|
70
|
+
const hostDir = (config && config.hostDir) || process.env.WALL_BRIDGE_HOME || fallbackDir
|
|
71
|
+
fs.mkdirSync(hostDir, { recursive: true })
|
|
72
|
+
/* 有界写入:防反复激活失败把 activate-error.log 撑到无界(保留最近若干条栈)。 */
|
|
73
|
+
appendBoundedLog(
|
|
74
|
+
path.join(hostDir, 'activate-error.log'),
|
|
75
|
+
`[${new Date().toISOString()}] ${(error && error.stack) || error}\n`,
|
|
76
|
+
)
|
|
77
|
+
} catch { /* 诊断写盘失败不能覆盖真正的激活错误 */ }
|
|
78
|
+
throw error
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function activate(ctx, config) {
|
|
83
|
+
const packageDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
|
|
84
|
+
const { startRelay } = await import('./relay.mjs')
|
|
85
|
+
const hostDir = (config && config.hostDir)
|
|
86
|
+
|| process.env.WALL_BRIDGE_HOME
|
|
87
|
+
|| path.join(os.homedir(), '.dsh-wall-bridge')
|
|
88
|
+
/* 公共插件 API 契约:存在则校验 major,避免静默不兼容。 */
|
|
89
|
+
const serviceHost = requireApi(safeGet(ctx, 'serviceHost'), 'serviceHost')
|
|
90
|
+
|
|
91
|
+
const webServer = safeGet(ctx, 'webServer')
|
|
92
|
+
const mountPath = (config && config.mountPath) || '/capyclaw/wall'
|
|
93
|
+
const relayOptions = {
|
|
94
|
+
packageDir,
|
|
95
|
+
hostDir,
|
|
96
|
+
serviceHost,
|
|
97
|
+
strictPort: config?.strictPort != null ? !!config.strictPort : false,
|
|
98
|
+
allowReuse: config?.allowReuse != null ? !!config.allowReuse : true,
|
|
99
|
+
/* 会话模式锁的底座懒解析器(works.db 单一真源);底座缺席时认领自动 skipped。 */
|
|
100
|
+
getWorkStore: () => safeGet(ctx, 'workStore'),
|
|
101
|
+
}
|
|
102
|
+
if (webServer) {
|
|
103
|
+
relayOptions.webServer = webServer
|
|
104
|
+
relayOptions.mountPrefix = mountPath
|
|
105
|
+
} else {
|
|
106
|
+
/* 仅开发/测试:没有宿主路由时才自己听一个 loopback 端口。
|
|
107
|
+
端口写 0 = 交给操作系统分配;真实地址由 relay listen 之后给出。 */
|
|
108
|
+
relayOptions.port = (config && Number(config.port)) || 0
|
|
109
|
+
}
|
|
110
|
+
const relay = await startRelay(relayOptions)
|
|
111
|
+
|
|
112
|
+
const disposers = []
|
|
113
|
+
|
|
114
|
+
/* 自检端点:GET <前缀>/__host__。url 给入口地址(与 mount 同址)→
|
|
115
|
+
* 舞台读出 bridgePath='' → 无桥 → 内容闸对墙默认放行(墙是空态占位,不是文档编辑器)。 */
|
|
116
|
+
if (webServer && typeof webServer.register === 'function') {
|
|
117
|
+
const dispose = webServer.register({
|
|
118
|
+
kind: 'exact',
|
|
119
|
+
path: `${mountPath}/__host__`,
|
|
120
|
+
handler: (req, res) => {
|
|
121
|
+
const body = JSON.stringify({
|
|
122
|
+
workbench: 'wall',
|
|
123
|
+
mode: relay.mode,
|
|
124
|
+
url: relay.editorUrl,
|
|
125
|
+
editorUrl: relay.editorUrl,
|
|
126
|
+
mountPath,
|
|
127
|
+
tools: null,
|
|
128
|
+
}, null, 2)
|
|
129
|
+
res.writeHead(200, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
|
|
130
|
+
res.end(body)
|
|
131
|
+
},
|
|
132
|
+
})
|
|
133
|
+
if (typeof dispose === 'function') disposers.push(dispose)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/* 活动台账:embedded 形态没有端口,记 url 即可。注册行没有 title 字段,
|
|
137
|
+
* 主区舞台 /state 的标题靠台账补——这里给墙一个人类可读的名字。 */
|
|
138
|
+
try {
|
|
139
|
+
const portal = await loadPortal()
|
|
140
|
+
if (portal && typeof portal.recordActivity === 'function') {
|
|
141
|
+
portal.recordActivity({
|
|
142
|
+
id: 'wall-workbench',
|
|
143
|
+
url: relay.editorUrl,
|
|
144
|
+
title: (config && config.title) || '展示墙',
|
|
145
|
+
kind: 'service',
|
|
146
|
+
})
|
|
147
|
+
}
|
|
148
|
+
} catch { /* 台账失败不影响服务 */ }
|
|
149
|
+
|
|
150
|
+
console.log(relay.reused
|
|
151
|
+
? `[wall-workbench] 复用已运行的墙: ${relay.url}`
|
|
152
|
+
: `[wall-workbench] 墙已就绪: ${relay.url}`)
|
|
153
|
+
console.log(`[wall-workbench] 展示墙: ${relay.editorUrl}(${relay.mode === 'embedded' ? '挂在宿主路由,无端口' : '独立端口'})`)
|
|
154
|
+
|
|
155
|
+
return async () => {
|
|
156
|
+
for (const dispose of disposers) {
|
|
157
|
+
try { dispose() } catch { /* 忽略 */ }
|
|
158
|
+
}
|
|
159
|
+
await relay.stop()
|
|
160
|
+
console.log('[wall-workbench] 墙已停止')
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 展示墙 relay:**业务装配**(HTTP/锁/发现/独立入口由 server/workbench-framework.mjs 提供)。
|
|
3
|
+
*
|
|
4
|
+
* 展示墙是主区的空态选择器:列出已注册的工作台类型,用户点选即显式认领
|
|
5
|
+
* 会话模式(POST /claim)。零工具、零引擎、零文档模型——最精简的工作台实例,
|
|
6
|
+
* 与 browser 同构但没有 Playwright 面。
|
|
7
|
+
*
|
|
8
|
+
* 也可脱离 dsh 独立运行:node server/relay.mjs [--port 39319] [--dir <hostDir>]
|
|
9
|
+
* (standalone 形态没有 portal-hud 注册信息,页面降级为提示。)
|
|
10
|
+
*/
|
|
11
|
+
import { declareBridge } from '@capyclaw/foundation/abi'
|
|
12
|
+
import { CONTRACT_VERSION, PACKAGE_VERSION } from './contract.mjs'
|
|
13
|
+
import { DEFAULT_PORT } from './constants.mjs'
|
|
14
|
+
import { createWorkbenchRoutes } from './routes/workbench.mjs'
|
|
15
|
+
import { createClaimRoute } from './routes/claim.mjs'
|
|
16
|
+
import { runIfMain, createWorkbench } from './workbench-framework.mjs'
|
|
17
|
+
|
|
18
|
+
export { DEFAULT_PORT }
|
|
19
|
+
|
|
20
|
+
export const startRelay = createWorkbench({
|
|
21
|
+
id: 'wall-workbench',
|
|
22
|
+
title: 'Wall Workbench',
|
|
23
|
+
packageVersion: PACKAGE_VERSION,
|
|
24
|
+
contractVersion: CONTRACT_VERSION,
|
|
25
|
+
/* 展示墙是桥,但不提供文档模型(它是选择器,不是编辑器)。 */
|
|
26
|
+
bridge: declareBridge({ id: 'wall-workbench', model: null }),
|
|
27
|
+
/* 端口不再由业务决定:embedded 形态挂宿主路由,standalone(仅开发)才用 options.port。 */
|
|
28
|
+
basePath: '',
|
|
29
|
+
homeEnv: 'WALL_BRIDGE_HOME',
|
|
30
|
+
defaultHome: '.dsh-wall-bridge',
|
|
31
|
+
|
|
32
|
+
createStore: () => ({}),
|
|
33
|
+
|
|
34
|
+
/* 静态选择器页 + 显式认领端点。没有 MCP 面(省略 tools 钩子 → relay.tools=null),
|
|
35
|
+
* 也不需要会话缝入:claim 显式带 sid,静态页无会话状态。 */
|
|
36
|
+
routes: (ctx) => [
|
|
37
|
+
...createWorkbenchRoutes({ packageDir: ctx.packageDir }),
|
|
38
|
+
createClaimRoute(ctx),
|
|
39
|
+
],
|
|
40
|
+
|
|
41
|
+
health: (ctx) => ({
|
|
42
|
+
bridge: 'wall-workbench',
|
|
43
|
+
workbench: ctx.editorUrl,
|
|
44
|
+
selector: true,
|
|
45
|
+
injected: {
|
|
46
|
+
serviceHost: !!ctx.serviceHost,
|
|
47
|
+
workStore: !!(typeof ctx.getWorkStore === 'function' && ctx.getWorkStore()),
|
|
48
|
+
},
|
|
49
|
+
}),
|
|
50
|
+
|
|
51
|
+
metrics: () => [
|
|
52
|
+
['wall_workbench_memory_rss_bytes', process.memoryUsage().rss],
|
|
53
|
+
],
|
|
54
|
+
|
|
55
|
+
resultExtras: (ctx) => ({
|
|
56
|
+
workbenchUrl: ctx.editorUrl,
|
|
57
|
+
mountPath: ctx.mountPath,
|
|
58
|
+
}),
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
/* ---- 独立运行入口(无 dsh 也可手动拉起,供调试/演示)---- */
|
|
62
|
+
runIfMain(import.meta.url, async ({ port, dir }) => {
|
|
63
|
+
const relay = await startRelay({
|
|
64
|
+
port: port || DEFAULT_PORT,
|
|
65
|
+
hostDir: dir || process.env.WALL_BRIDGE_HOME || undefined,
|
|
66
|
+
})
|
|
67
|
+
console.log('[wall-workbench] 展示墙:', relay.workbenchUrl, '(浏览器打开即用;standalone 无注册信息,页面降级为提示)')
|
|
68
|
+
})
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 展示墙的显式认领端点:POST /claim {sid?, kind}。
|
|
3
|
+
*
|
|
4
|
+
* 墙自己零工具、不走懒认领写闸;用户在页面上点选类型时由这里代为认领
|
|
5
|
+
* (explicit:true —— 宿主半据此豁免内容闸,全新会话也能立刻摆出真实工作台)。
|
|
6
|
+
*
|
|
7
|
+
* sid 优先取 body:retarget 之后 iframe 的 URL 可能还带着旧会话段,
|
|
8
|
+
* 页面总是把当前 sid 放进 body;URL 的 /s/<sid> 段(u.sessionId)作兜底。
|
|
9
|
+
*
|
|
10
|
+
* work-store 底座缺席时降级 skipped(不启用模式锁),与
|
|
11
|
+
* @capyclaw/document-workbench/session-mode 的 createSessionModeRegistry 同语义。
|
|
12
|
+
* 认领结果原样回给页面:ok:false 带 lockedTo(已固化)也由页面提示,HTTP 仍 200。
|
|
13
|
+
*/
|
|
14
|
+
import { readBody } from '../shared/kit/service/http.mjs'
|
|
15
|
+
|
|
16
|
+
const KIND_RE = /^[a-z0-9][a-z0-9-]{0,63}$/
|
|
17
|
+
|
|
18
|
+
function replyJson(res, code, body) {
|
|
19
|
+
res.writeHead(code, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
|
|
20
|
+
res.end(JSON.stringify(body))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function createClaimRoute(ctx) {
|
|
24
|
+
return async (req, res, u) => {
|
|
25
|
+
if (req.method !== 'POST' || u.pathname !== '/claim') return false
|
|
26
|
+
let body
|
|
27
|
+
try {
|
|
28
|
+
body = await readBody(req, 64 * 1024)
|
|
29
|
+
} catch (error) {
|
|
30
|
+
replyJson(res, error && error.code === 'BODY_TOO_LARGE' ? 413 : 400, { ok: false, error: '请求体不是合法 JSON' })
|
|
31
|
+
return true
|
|
32
|
+
}
|
|
33
|
+
const kind = String((body && body.kind) || '')
|
|
34
|
+
if (!KIND_RE.test(kind)) {
|
|
35
|
+
replyJson(res, 400, { ok: false, error: 'kind 必须是 kebab-case 的工作台种类' })
|
|
36
|
+
return true
|
|
37
|
+
}
|
|
38
|
+
const sid = String((body && body.sid) || u.sessionId || '')
|
|
39
|
+
const ws = typeof ctx.getWorkStore === 'function' ? ctx.getWorkStore() : null
|
|
40
|
+
const result = (!ws || typeof ws.claimSessionMode !== 'function')
|
|
41
|
+
? { ok: true, kind, skipped: true }
|
|
42
|
+
: ws.claimSessionMode(sid, kind, 'wall-workbench', { explicit: true })
|
|
43
|
+
replyJson(res, 200, result)
|
|
44
|
+
return true
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** 展示墙静态页(白名单路由,杜绝路径穿越)。 */
|
|
2
|
+
import { readFile } from 'node:fs/promises'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
|
|
5
|
+
import { WALL_FILES } from '../constants.mjs'
|
|
6
|
+
|
|
7
|
+
export function createWorkbenchRoutes({ packageDir }) {
|
|
8
|
+
const uiDir = path.join(packageDir, 'ui')
|
|
9
|
+
return [
|
|
10
|
+
async (req, res, u) => {
|
|
11
|
+
if (req.method !== 'GET' && req.method !== 'HEAD') return false
|
|
12
|
+
const entry = WALL_FILES[u.pathname]
|
|
13
|
+
if (!entry) return false
|
|
14
|
+
try {
|
|
15
|
+
const content = await readFile(path.join(uiDir, entry[0]))
|
|
16
|
+
res.writeHead(200, {
|
|
17
|
+
'content-type': entry[1],
|
|
18
|
+
'cache-control': 'no-store',
|
|
19
|
+
'x-content-type-options': 'nosniff',
|
|
20
|
+
})
|
|
21
|
+
res.end(req.method === 'HEAD' ? undefined : content)
|
|
22
|
+
} catch {
|
|
23
|
+
res.writeHead(404, { 'content-type': 'text/plain; charset=utf-8' })
|
|
24
|
+
res.end('Not found')
|
|
25
|
+
}
|
|
26
|
+
return true
|
|
27
|
+
},
|
|
28
|
+
]
|
|
29
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "0.2.0",
|
|
3
|
+
"mode": "re-export",
|
|
4
|
+
"packages": {
|
|
5
|
+
"service-host": {
|
|
6
|
+
"package": "@capyclaw/service-host",
|
|
7
|
+
"version": "0.1.7",
|
|
8
|
+
"apiVersion": "1.0.0",
|
|
9
|
+
"spec": "@capyclaw/service-host/src",
|
|
10
|
+
"sha256": "af0a57d779bfe6a66dc935320178d591ef799a7e037f7a5823cdfa1fe5878eeb"
|
|
11
|
+
},
|
|
12
|
+
"tool-host": {
|
|
13
|
+
"package": "@capyclaw/tool-host",
|
|
14
|
+
"version": "0.3.2",
|
|
15
|
+
"apiVersion": "1.1.0",
|
|
16
|
+
"spec": "@capyclaw/tool-host/src",
|
|
17
|
+
"sha256": "23256dbcd5cbee0b96b33c97e4eb4e74d0e169cbdde52f91d4526f2fc0f60d3e"
|
|
18
|
+
},
|
|
19
|
+
"asset-service": {
|
|
20
|
+
"package": "@capyclaw/asset-service",
|
|
21
|
+
"version": "0.1.6",
|
|
22
|
+
"apiVersion": "1.0.0",
|
|
23
|
+
"spec": "@capyclaw/asset-service/src",
|
|
24
|
+
"sha256": "311a83e95d56dbb69b739d61aced0889b64e85eddd95b883e322e0fa5be8bd6f"
|
|
25
|
+
},
|
|
26
|
+
"editor-host": {
|
|
27
|
+
"package": "@capyclaw/editor-host",
|
|
28
|
+
"version": "0.1.7",
|
|
29
|
+
"apiVersion": "1.0.0",
|
|
30
|
+
"spec": "@capyclaw/editor-host/src",
|
|
31
|
+
"sha256": "c8b80dbd4f1b2bee9ef9001423a013031a21ea9a3b8897b5536fe6e5687f01b3"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"kit": {
|
|
35
|
+
"tuning.mjs": {
|
|
36
|
+
"spec": "@capyclaw/plugin-kit/tuning",
|
|
37
|
+
"sha256": "6dc1d89c97056b03c27d744e6256e0e8d88a772c340acc6e04a3413e9ee5cc8b"
|
|
38
|
+
},
|
|
39
|
+
"service/api.mjs": {
|
|
40
|
+
"spec": "@capyclaw/plugin-kit/service/api",
|
|
41
|
+
"sha256": "336a92237d5575709d421cb8199bad7c56fbd95bfd2b30b5d9b913f719db8402"
|
|
42
|
+
},
|
|
43
|
+
"service/http.mjs": {
|
|
44
|
+
"spec": "@capyclaw/plugin-kit/service/http",
|
|
45
|
+
"sha256": "5839bf8872a208f14a219ba7528e2d19e9884f6e6a2645689d58369952d0476f"
|
|
46
|
+
},
|
|
47
|
+
"service/mcp-http.mjs": {
|
|
48
|
+
"spec": "@capyclaw/plugin-kit/service/mcp-http",
|
|
49
|
+
"sha256": "54bce272839c9477d460a483ee4bce62ca9f61b56174247ed718a7711eec7ee2"
|
|
50
|
+
},
|
|
51
|
+
"tools/validate.mjs": {
|
|
52
|
+
"spec": "@capyclaw/plugin-kit/tools/validate",
|
|
53
|
+
"sha256": "d88424caa66913acfc49a340c6e6eea6fe930a676ee8d32581d6366877f21389"
|
|
54
|
+
},
|
|
55
|
+
"editor/lease.mjs": {
|
|
56
|
+
"spec": "@capyclaw/plugin-kit/editor/lease",
|
|
57
|
+
"sha256": "4b1fe0ea3678d27f5283827a1d658784b915914cb6a0780f9534426ffd66b25f"
|
|
58
|
+
},
|
|
59
|
+
"util/fs-lock.mjs": {
|
|
60
|
+
"spec": "@capyclaw/plugin-kit/util/fs-lock",
|
|
61
|
+
"sha256": "c528e30271d83be2c857c160246598f96e636dacb2561a5e2109337e84d0865b"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"pkgRoot": {
|
|
65
|
+
"capyclaw-service-host/tuning.mjs": {
|
|
66
|
+
"spec": "@capyclaw/service-host/tuning",
|
|
67
|
+
"sha256": "1425851a3bff8c672a58536096faa321c74a4d4333cc0ae9268c1cfe83696492"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工具组装:展示墙零能力 → 空 registry 面。
|
|
3
|
+
* 保留与 browser/ppt/canvas 同形的导出,流水线与未来扩展都从这里拿工具面。
|
|
4
|
+
*/
|
|
5
|
+
import { CAPABILITIES } from './capabilities/index.mjs'
|
|
6
|
+
|
|
7
|
+
export { CAPABILITIES }
|
|
8
|
+
|
|
9
|
+
export const TOOLS = []
|
|
10
|
+
export const TOOL_IMPL = {}
|
|
11
|
+
export const TOOL_META = {}
|
|
12
|
+
export const FEATURES = []
|