@capyclaw/rsp-suite 0.1.0 → 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/dsh-suite.json +13 -3
- 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 +72 -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/ledger.mjs +151 -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/{skill → node_modules/@capyclaw/rsp-skill-remote-screen}/contract/rsp-contract.json +102 -13
- package/{skill → node_modules/@capyclaw/rsp-skill-remote-screen}/skills/remote-screen/SKILL.md +13 -2
- package/{workbench → node_modules/@capyclaw/rsp-workbench}/contract/capabilities.json +32 -0
- package/{workbench → node_modules/@capyclaw/rsp-workbench}/lib/client.mjs +238 -11
- package/node_modules/@capyclaw/rsp-workbench/lib/host.mjs +51 -0
- package/{workbench → node_modules/@capyclaw/rsp-workbench}/lib/tools.mjs +116 -16
- package/{workbench → node_modules/@capyclaw/rsp-workbench}/lib/workbench.mjs +21 -2
- package/node_modules/@capyclaw/rsp-workbench/plugin.mjs +17 -0
- package/{workbench → node_modules/@capyclaw/rsp-workbench}/ui/index.html +113 -10
- 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 +597 -0
- package/node_modules/@capyclaw/service-host/src/tuning.mjs +63 -0
- package/node_modules/@capyclaw/suite-kit/README.md +289 -0
- package/node_modules/@capyclaw/suite-kit/bin/dsh-domain.mjs +98 -0
- package/node_modules/@capyclaw/suite-kit/bin/dsh-suite.mjs +174 -0
- package/node_modules/@capyclaw/suite-kit/client/embed.js +35 -0
- package/node_modules/@capyclaw/suite-kit/domain.schema.json +129 -0
- package/node_modules/@capyclaw/suite-kit/package.json +58 -0
- package/node_modules/@capyclaw/suite-kit/src/activation-registry.mjs +184 -0
- package/node_modules/@capyclaw/suite-kit/src/artifacts.mjs +131 -0
- package/node_modules/@capyclaw/suite-kit/src/capability.mjs +181 -0
- package/node_modules/@capyclaw/suite-kit/src/compose.mjs +201 -0
- package/node_modules/@capyclaw/suite-kit/src/domain.mjs +138 -0
- package/node_modules/@capyclaw/suite-kit/src/embed.mjs +81 -0
- package/node_modules/@capyclaw/suite-kit/src/host.mjs +251 -0
- package/node_modules/@capyclaw/suite-kit/src/index.mjs +24 -0
- package/node_modules/@capyclaw/suite-kit/src/manifest.mjs +263 -0
- package/node_modules/@capyclaw/suite-kit/src/orchestration.mjs +100 -0
- package/node_modules/@capyclaw/suite-kit/src/profile.mjs +584 -0
- package/node_modules/@capyclaw/suite-kit/src/surface.mjs +28 -0
- package/node_modules/@capyclaw/suite-kit/suite.schema.json +128 -0
- package/node_modules/@capyclaw/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/ws/LICENSE +20 -0
- package/node_modules/ws/README.md +539 -0
- package/node_modules/ws/browser.js +8 -0
- package/node_modules/ws/index.js +22 -0
- package/node_modules/ws/lib/buffer-util.js +142 -0
- package/node_modules/ws/lib/constants.js +19 -0
- package/node_modules/ws/lib/event-target.js +292 -0
- package/node_modules/ws/lib/extension.js +203 -0
- package/node_modules/ws/lib/limiter.js +55 -0
- package/node_modules/ws/lib/permessage-deflate.js +530 -0
- package/node_modules/ws/lib/receiver.js +751 -0
- package/node_modules/ws/lib/sender.js +610 -0
- package/node_modules/ws/lib/stream.js +161 -0
- package/node_modules/ws/lib/subprotocol.js +62 -0
- package/node_modules/ws/lib/validation.js +152 -0
- package/node_modules/ws/lib/websocket-server.js +562 -0
- package/node_modules/ws/lib/websocket.js +1440 -0
- package/node_modules/ws/package.json +74 -0
- package/node_modules/ws/wrapper.mjs +21 -0
- package/package.json +22 -9
- package/workbench/lib/host.mjs +0 -111
- package/workbench/plugin.mjs +0 -2
- package/workbench/scripts/build-contract.mjs +0 -41
- package/workbench/scripts/drive.mjs +0 -66
- package/workbench/test/client.test.mjs +0 -218
- package/workbench/test/frames-prune.test.mjs +0 -49
- package/workbench/test/h264.test.mjs +0 -101
- package/workbench/test/live-persistent-smoke.mjs +0 -29
- package/workbench/test/live-smoke.mjs +0 -109
- package/workbench/test/mock-server.mjs +0 -194
- package/workbench/test/persistence.test.mjs +0 -177
- package/workbench/test/persistent.test.mjs +0 -160
- package/workbench/test/session-mode.test.mjs +0 -118
- package/workbench/test/workbench.test.mjs +0 -385
- package/workbench/verify-e2e.mjs +0 -44
- /package/{skill → node_modules/@capyclaw/rsp-skill-remote-screen}/README.md +0 -0
- /package/{skill → node_modules/@capyclaw/rsp-skill-remote-screen}/cordis.patch.yml +0 -0
- /package/{skill → node_modules/@capyclaw/rsp-skill-remote-screen}/package.json +0 -0
- /package/{skill → node_modules/@capyclaw/rsp-skill-remote-screen}/plugin.mjs +0 -0
- /package/{workbench → node_modules/@capyclaw/rsp-workbench}/lib/descriptors.mjs +0 -0
- /package/{workbench → node_modules/@capyclaw/rsp-workbench}/lib/manager.mjs +0 -0
- /package/{workbench → node_modules/@capyclaw/rsp-workbench}/lib/session-mode.mjs +0 -0
- /package/{workbench → node_modules/@capyclaw/rsp-workbench}/package.json +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @capyclaw/rsp-workbench 宿主入口:foundation ABI raw@1 逃生舱。
|
|
3
|
+
*
|
|
4
|
+
* 宿主在一次 apply 里同时装配共享 webServer 路由面(含 WS 升级)、toolHost 工具面、
|
|
5
|
+
* 能力描述符/表面/portal/mode-gate,多面共享同一连接/工作台状态;own-server@1/http-router@1 单 mount、
|
|
6
|
+
* tool-provider@1 拆分装配表达不了这种单 apply 多面形态,故用 raw@1 声明 inject:['webServer']。
|
|
7
|
+
* 已在 meta/foundation.allowlist.json raw 段登记(until P5)。skill 包已硬依赖 os.skills,
|
|
8
|
+
* @capyclaw/core 本就是套件运行时前提,不引入新依赖。业务装配仍在 lib/host.mjs(可单测/standalone)。
|
|
9
|
+
*/
|
|
10
|
+
import { createPlugin, rawPlugin } from '@capyclaw/foundation/abi'
|
|
11
|
+
import { name as hostName, apply as applyHost } from './lib/host.mjs'
|
|
12
|
+
|
|
13
|
+
export const { name, inject, apply } = createPlugin({
|
|
14
|
+
name: hostName,
|
|
15
|
+
inject: ['webServer'],
|
|
16
|
+
implements: [rawPlugin(({ ctx, config }) => applyHost(ctx, config))],
|
|
17
|
+
}, import.meta.url)
|
|
@@ -151,6 +151,75 @@ window.addEventListener('message', (ev) => {
|
|
|
151
151
|
refresh()
|
|
152
152
|
})
|
|
153
153
|
|
|
154
|
+
/* ---------- 表面可见性(渲染面生命周期,标准 §2/§5) ----------
|
|
155
|
+
本 UI 无构建、原样拷贝部署(workbench.mjs 的 app.static(uiDir)),不能 import 共享包,
|
|
156
|
+
故内联一个最小 visibility 订阅器(纯订阅,无桥)。协议常量真源:
|
|
157
|
+
C/packages/capyclaw-foundation/abi/visibility.mjs —— 改那边必须同步这里
|
|
158
|
+
(test/ui-visibility.test.mjs 有静态 parity 守护)。
|
|
159
|
+
iframe 内 document.hidden 只反映顶层 tab,被宿主藏起来不触发 visibilitychange,
|
|
160
|
+
表面可见性只能由宿主 postMessage 告知;hidden 必须挂起渲染面。
|
|
161
|
+
边界(标准 P1):这里只停 UI 侧屏幕流(api/screen.mjpg、api/screen.h264 代理)与渲染循环;
|
|
162
|
+
服务端常驻 screen.ws/control.ws 是 AI 无头观察/操控通道,绝不因表面隐藏而关。 */
|
|
163
|
+
const VISIBILITY_MESSAGE = 'capyclaw:workbench:visibility'
|
|
164
|
+
const VISIBILITY_ACK_MESSAGE = 'capyclaw:workbench:visibility-ack'
|
|
165
|
+
const VISIBILITY_STATES = ['foreground', 'background', 'hidden', 'detached']
|
|
166
|
+
|
|
167
|
+
let renderSuspended = false
|
|
168
|
+
let refreshTimer = null
|
|
169
|
+
let ageTimer = null
|
|
170
|
+
|
|
171
|
+
/* 渲染面循环的唯一起点:句柄 null-guard,快速切换不会叠出重复定时器。
|
|
172
|
+
起 = 状态轮询(1.5s) + 帧龄刷新(250ms);屏幕流由 refresh→renderStatus 按需重开。 */
|
|
173
|
+
function startRenderLoops() {
|
|
174
|
+
if (refreshTimer === null) refreshTimer = setInterval(refresh, 1500)
|
|
175
|
+
if (ageTimer === null) ageTimer = setInterval(tickAge, 250)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/* 停 = 渲染循环全清 + UI 侧屏幕流 abort(MJPEG img 与 H.264 fetch)。
|
|
179
|
+
上游每个 UI MJPEG 请求各算一个被控端 viewer,abort 即取消该订阅;
|
|
180
|
+
服务端常驻 screen.ws 仍是 AI 的 viewer,被控端采集不停(标准 P1/§5)。 */
|
|
181
|
+
function stopRenderLoops() {
|
|
182
|
+
if (refreshTimer !== null) { clearInterval(refreshTimer); refreshTimer = null }
|
|
183
|
+
if (ageTimer !== null) { clearInterval(ageTimer); ageTimer = null }
|
|
184
|
+
stopStream()
|
|
185
|
+
stopH264()
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/* 幂等:同态重复消息不重启/重停。hidden/detached 挂起渲染面;
|
|
189
|
+
foreground/background 恢复(background 只是失焦、仍可见,渲染面保持运转)。 */
|
|
190
|
+
function setRenderVisibility(next) {
|
|
191
|
+
const suspend = next === 'hidden' || next === 'detached'
|
|
192
|
+
if (suspend === renderSuspended) return
|
|
193
|
+
renderSuspended = suspend
|
|
194
|
+
if (suspend) { stopRenderLoops(); return }
|
|
195
|
+
startRenderLoops()
|
|
196
|
+
/* 回前台立即补一次状态:重开屏幕流并刷新画面(隐藏期可能已换会话/断连)。 */
|
|
197
|
+
refresh()
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function onVisibilityMessage(event) {
|
|
201
|
+
/* 只认同源宿主(浮标/portal 与本页同 origin);跨源消息一律丢弃。
|
|
202
|
+
状态按 abi 白名单校验,非法状态丢弃不回 ack(宿主发送前已归一化)。 */
|
|
203
|
+
if (event.origin !== location.origin) return
|
|
204
|
+
const data = event.data
|
|
205
|
+
if (!data || data.type !== VISIBILITY_MESSAGE) return
|
|
206
|
+
if (VISIBILITY_STATES.indexOf(data.state) === -1) return
|
|
207
|
+
setRenderVisibility(data.state)
|
|
208
|
+
try {
|
|
209
|
+
if (event.source) event.source.postMessage({ type: VISIBILITY_ACK_MESSAGE, state: data.state, sid: data.sid }, event.origin)
|
|
210
|
+
} catch {}
|
|
211
|
+
}
|
|
212
|
+
window.addEventListener('message', onVisibilityMessage)
|
|
213
|
+
|
|
214
|
+
/* 真实卸载:清渲染面循环并摘 visibility 订阅监听;
|
|
215
|
+
bfcache 冻结(persisted)保持原样——定时器被冻结而非销毁,恢复时自会续跑。 */
|
|
216
|
+
window.addEventListener('pagehide', (event) => {
|
|
217
|
+
if (event && event.persisted) return
|
|
218
|
+
renderSuspended = true // 卸载期禁止 stopH264 的兜底回退再拉起新流
|
|
219
|
+
stopRenderLoops()
|
|
220
|
+
window.removeEventListener('message', onVisibilityMessage)
|
|
221
|
+
})
|
|
222
|
+
|
|
154
223
|
/* Single source of truth for which stage layer is visible. A layer is only made
|
|
155
224
|
visible when it actually holds content, so transitions never flash blank. */
|
|
156
225
|
function showLayer(name) {
|
|
@@ -171,6 +240,7 @@ function setPill(kind, text) { $('pill').className = 'pill ' + kind; $('pillText
|
|
|
171
240
|
|
|
172
241
|
/* 静态快照层:保证任何时刻都有图可看(含静止画面/刚打开时)。 */
|
|
173
242
|
async function refreshSnapshot() {
|
|
243
|
+
if (renderSuspended) return
|
|
174
244
|
try {
|
|
175
245
|
const r = await fetch('api/frame?t=' + Date.now() + sessQ())
|
|
176
246
|
if (!r.ok) return
|
|
@@ -189,6 +259,7 @@ async function refreshSnapshot() {
|
|
|
189
259
|
|
|
190
260
|
/* 实时流层:叠加在快照之上;有变化时由被控端推帧覆盖。 */
|
|
191
261
|
function startStream() {
|
|
262
|
+
if (renderSuspended) return
|
|
192
263
|
if (streaming) return
|
|
193
264
|
streaming = true
|
|
194
265
|
const my = ++streamToken
|
|
@@ -240,20 +311,36 @@ function buildAvcC(sps, pps) {
|
|
|
240
311
|
}
|
|
241
312
|
const hex2 = (n) => n.toString(16).padStart(2, '0')
|
|
242
313
|
async function startH264() {
|
|
314
|
+
if (renderSuspended) return false
|
|
243
315
|
if (h264) return
|
|
244
316
|
if (!('VideoDecoder' in window)) return false // 无 WebCodecs → 回退 JPEG
|
|
245
317
|
const abort = new AbortController()
|
|
246
318
|
const canvas = $('video')
|
|
247
|
-
|
|
248
|
-
|
|
319
|
+
// desynchronized = low-latency canvas: hints the browser to present this surface
|
|
320
|
+
// outside the normal compositor vsync queue (tearing allowed), cutting the
|
|
321
|
+
// present-phase wait (up to one refresh) toward native. Falls back silently where
|
|
322
|
+
// unsupported. This is the client-side half of "near-native" latency.
|
|
323
|
+
const ctx = canvas.getContext('2d', { desynchronized: true })
|
|
324
|
+
let sps = null, pps = null, configured = false, ts = 0, decoded = 0, fpsT = performance.now(), lastOut = 0
|
|
325
|
+
// S5: decode-queue backpressure. When the decoder falls behind (slow hardware /
|
|
326
|
+
// throttled tab), feeding more deltas only grows latency. Drop deltas until the
|
|
327
|
+
// next self-contained IDR, then resume — bounds latency instead of letting it
|
|
328
|
+
// climb. Normal path (queue≈0) is untouched, preserving the zero-drop render.
|
|
329
|
+
let waitingKey = false
|
|
330
|
+
const QUEUE_LIMIT = 8
|
|
331
|
+
const sameNal = (a, b) => a && b && a.length === b.length && a.every((v, i) => v === b[i])
|
|
249
332
|
const decoder = new VideoDecoder({
|
|
250
333
|
output: (frame) => {
|
|
251
334
|
if (canvas.width !== frame.displayWidth || canvas.height !== frame.displayHeight) {
|
|
252
335
|
canvas.width = frame.displayWidth; canvas.height = frame.displayHeight
|
|
253
336
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
337
|
+
// Zero-drop rendering: draw EVERY decoded frame immediately (no rAF gate that
|
|
338
|
+
// coalesces/drops frames when 2 arrive per refresh). drawImage is GPU-backed;
|
|
339
|
+
// the browser presents the latest at vsync. Closing the previous pending frame
|
|
340
|
+
// only releases an already-rendered surface, never an unshown one.
|
|
341
|
+
ctx.drawImage(frame, 0, 0)
|
|
342
|
+
frame.close()
|
|
343
|
+
if (!h264Live) { h264Live = true; showLayer('video') }
|
|
257
344
|
decoded++
|
|
258
345
|
const now = performance.now()
|
|
259
346
|
if (now - fpsT >= 1000) { h264Fps = Math.round(decoded * 1000 / (now - fpsT)); decoded = 0; fpsT = now }
|
|
@@ -271,20 +358,35 @@ async function startH264() {
|
|
|
271
358
|
const concat = (a, b) => { const m = new Uint8Array(a.length + b.length); m.set(a); m.set(b, a.length); return m }
|
|
272
359
|
const push = (nal) => {
|
|
273
360
|
const t = nalType(nal)
|
|
274
|
-
if (t === 7) {
|
|
361
|
+
if (t === 7) {
|
|
362
|
+
// S1: a resolution/quality switch emits a new SPS — reconfigure on the next
|
|
363
|
+
// IDR instead of decoding new geometry with the old avcC description.
|
|
364
|
+
if (configured && !sameNal(sps, nal)) { configured = false; waitingKey = true; try { decoder.reset() } catch {} }
|
|
365
|
+
sps = nal; return
|
|
366
|
+
}
|
|
275
367
|
if (t === 8) { pps = nal; return }
|
|
276
368
|
if (t !== 1 && t !== 5) return
|
|
369
|
+
if (decoder.decodeQueueSize > QUEUE_LIMIT) waitingKey = true
|
|
370
|
+
if (waitingKey) {
|
|
371
|
+
if (t !== 5) return // drop deltas until a keyframe resyncs the stream
|
|
372
|
+
waitingKey = false
|
|
373
|
+
}
|
|
277
374
|
if (!configured) {
|
|
278
375
|
if (!sps || !pps) return
|
|
279
376
|
const s = nalBody(sps)
|
|
280
|
-
decoder.configure({ codec: 'avc1.' + hex2(s[1]) + hex2(s[2]) + hex2(s[3]), description: buildAvcC(sps, pps), optimizeForLatency: true })
|
|
377
|
+
decoder.configure({ codec: 'avc1.' + hex2(s[1]) + hex2(s[2]) + hex2(s[3]), description: buildAvcC(sps, pps), optimizeForLatency: true, hardwareAcceleration: 'prefer-hardware' })
|
|
281
378
|
configured = true
|
|
282
379
|
}
|
|
283
380
|
const body = nalBody(nal)
|
|
284
381
|
const data = new Uint8Array(4 + body.length)
|
|
285
382
|
new DataView(data.buffer).setUint32(0, body.length)
|
|
286
383
|
data.set(body, 4)
|
|
287
|
-
|
|
384
|
+
// Dynamic presentation timestamps from the real inter-frame interval (works at
|
|
385
|
+
// 30/55/60fps; the old fixed 33333µs assumed 30fps and mis-timed 60fps streams).
|
|
386
|
+
// bf=0 + optimizeForLatency means no reorder buffer, so ts only orders output.
|
|
387
|
+
const nowUs = Math.round(performance.now() * 1000)
|
|
388
|
+
ts = lastOut ? ts + Math.max(1000, Math.min(100000, nowUs - lastOut)) : nowUs
|
|
389
|
+
lastOut = nowUs
|
|
288
390
|
decoder.decode(new EncodedVideoChunk({ type: t === 5 ? 'key' : 'delta', timestamp: ts, data }))
|
|
289
391
|
}
|
|
290
392
|
for (;;) {
|
|
@@ -467,9 +569,10 @@ $('fullscreen').onclick = () => {
|
|
|
467
569
|
else if (el.webkitRequestFullscreen) el.webkitRequestFullscreen()
|
|
468
570
|
}
|
|
469
571
|
|
|
572
|
+
/* 渲染面循环统一由 startRenderLoops 起(状态轮询 1.5s + 帧龄 250ms),
|
|
573
|
+
宿主 visibility 消息 hidden 时经 stopRenderLoops 全停、foreground 时重建。 */
|
|
470
574
|
refresh()
|
|
471
|
-
|
|
472
|
-
setInterval(tickAge, 250)
|
|
575
|
+
startRenderLoops()
|
|
473
576
|
</script>
|
|
474
577
|
</body>
|
|
475
578
|
</html>
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# @capyclaw/service-host
|
|
2
|
+
|
|
3
|
+
DSH 公共服务宿主插件。功能插件通过 `ctx.serviceHost` 获得统一的 HTTP 运行时,不必再为每个插件复制 relay/路由/健康/指标/锁/静态资源代码。
|
|
4
|
+
|
|
5
|
+
## 使用
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
export const inject = ['serviceHost']
|
|
9
|
+
|
|
10
|
+
export function apply(ctx, config) {
|
|
11
|
+
const app = ctx.serviceHost.createApp({
|
|
12
|
+
id: 'my-plugin',
|
|
13
|
+
title: 'My Plugin',
|
|
14
|
+
version: '1.0.0',
|
|
15
|
+
contractVersion: '1.0.0',
|
|
16
|
+
health: () => ({ ready: true }),
|
|
17
|
+
metrics: () => [['my_items', 3]],
|
|
18
|
+
})
|
|
19
|
+
app.use(myRoutes)
|
|
20
|
+
await app.listen({
|
|
21
|
+
port: config.port,
|
|
22
|
+
hostDir: config.hostDir,
|
|
23
|
+
strictPort: config.strictPort,
|
|
24
|
+
})
|
|
25
|
+
return () => app.close()
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
独立运行:
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
import { createServiceApp } from '@capyclaw/service-host/src'
|
|
33
|
+
const app = createServiceApp({ id: 'my-plugin' })
|
|
34
|
+
app.get('/ping', (req, res) => res.end('pong'))
|
|
35
|
+
const info = await app.listen({ port: 39500 })
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
嵌入 DSH Web:
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
await app.listen({ webServer: ctx.webServer, basePath: '/plugins/my-plugin' })
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 共享宿主(多插件一个端口)
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
const host = ctx.serviceHost.createSharedHost({ id: 'dsh-app' })
|
|
48
|
+
host.mount('/plugins/ppt', pptApp)
|
|
49
|
+
host.mount('/plugins/canvas', canvasApp)
|
|
50
|
+
await host.listen({ port: 3080 })
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
子 app 仍由 `createServiceApp()` 创建;共享宿主只做前缀分发和统一生命周期。
|
|
54
|
+
|
|
55
|
+
## 每个会话一个地址(会话段)
|
|
56
|
+
|
|
57
|
+
挂载前缀之后允许再挂一层可选的会话段,`dispatch()` 会把它剥掉再交给工作台自己的路由:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
/capyclaw/ppt/ # 全局入口(不带会话)
|
|
61
|
+
/capyclaw/ppt/s/<会话id>/ # 这个会话的入口:页面就是编辑器本身
|
|
62
|
+
/capyclaw/ppt/s/<会话id>/app.js # 相对资源照旧
|
|
63
|
+
/capyclaw/ppt/s/<会话id>/api/... # 相对 API 照旧
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
- 剥段之后 `u.pathname` 与不带会话时完全一致,所以**工作台一行代码都不用改**;
|
|
67
|
+
需要区分会话的路由读 `u.sessionId`(或 `req.sessionId`)。
|
|
68
|
+
- 形状与网关的 `/s/<会话id>/` 一致;sid 只放行 `[A-Za-z0-9._~-]`,不会引入路径分隔歧义。
|
|
69
|
+
- `<prefix>/s/<会话id>` 少了尾斜杠会 301 补上——否则相对地址会被解析成
|
|
70
|
+
`<prefix>/s/<文件名>`,页面里的 `./app.js` 直接 404。
|
|
71
|
+
- 拿不到会话 id 时就不带这一段,行为与以前完全相同。
|
|
72
|
+
|
|
73
|
+
## 提供什么
|
|
74
|
+
|
|
75
|
+
- `createServiceApp(options)`:路由、静态、健康、指标、生命周期
|
|
76
|
+
- `createServiceHost(config)`:插件侧工厂
|
|
77
|
+
- 标准 `/healthz`:`{ ok, service, name, version, contractVersion, pid, port, uptimeSec, ...业务字段 }`
|
|
78
|
+
- 标准 `/metrics`:`<slug>_up`、`<slug>_uptime_seconds`、`<slug>_port` + 业务指标
|
|
79
|
+
- standalone:端口扫描、`strictPort`、复用探测、单实例锁、discovery 文件、优雅关闭
|
|
80
|
+
- embedded:注册到 `ctx.webServer` 的 `<basePath>` 前缀;每个会话自动获得 `<basePath>/s/<会话id>/` 子树
|
|
81
|
+
|
|
82
|
+
## 边界
|
|
83
|
+
|
|
84
|
+
- 不拥有业务状态;状态持久化用 `@capyclaw/document-workbench`(store/file-backend)
|
|
85
|
+
- 不拥有资产;资产用 `@capyclaw/asset-service`
|
|
86
|
+
- 不拥有编辑器;编辑器用 `@capyclaw/editor-host`
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "../capyclaw-suite-kit/suite.schema.json",
|
|
3
|
+
"name": "dsh-service-host-suite",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"title": "Service Host",
|
|
6
|
+
"description": "通用服务宿主:HTTP 路由、健康、指标、锁、复用、静态资源。",
|
|
7
|
+
"packages": {
|
|
8
|
+
"@capyclaw/service-host": {
|
|
9
|
+
"role": "provider",
|
|
10
|
+
"version": "^0.1.9",
|
|
11
|
+
"path": ".",
|
|
12
|
+
"provides": {
|
|
13
|
+
"services": [
|
|
14
|
+
"serviceHost"
|
|
15
|
+
],
|
|
16
|
+
"capabilities": {
|
|
17
|
+
"host.http": "1.0.0"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"rows": [
|
|
23
|
+
{
|
|
24
|
+
"id": "service-host",
|
|
25
|
+
"name": "@capyclaw/service-host"
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"checks": []
|
|
29
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @capyclaw/service-host 宿主插件:向同进程插件提供 ctx.serviceHost。
|
|
3
|
+
*
|
|
4
|
+
* 功能插件:
|
|
5
|
+
* export const inject = ['serviceHost']
|
|
6
|
+
* const app = ctx.serviceHost.createApp({ id: 'my-plugin', ... })
|
|
7
|
+
* app.use(myRoutes)
|
|
8
|
+
* await app.listen({ port, hostDir })
|
|
9
|
+
*/
|
|
10
|
+
import { defineDriver } from '@capyclaw/foundation/abi'
|
|
11
|
+
import { createServiceHost } from '../src/index.mjs'
|
|
12
|
+
|
|
13
|
+
export const { name, inject, apply } = defineDriver({
|
|
14
|
+
name: 'service-host',
|
|
15
|
+
service: 'serviceHost',
|
|
16
|
+
apply(ctx, config = {}) {
|
|
17
|
+
const service = createServiceHost(config)
|
|
18
|
+
const dispose = ctx.provide('serviceHost', service)
|
|
19
|
+
console.log('[service-host] ready')
|
|
20
|
+
return () => { if (typeof dispose === 'function') dispose() }
|
|
21
|
+
},
|
|
22
|
+
})
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capyclaw/service-host",
|
|
3
|
+
"version": "0.1.9",
|
|
4
|
+
"description": "DSH 公共服务宿主插件:统一 HTTP 路由、健康检查、指标、单实例锁、端口复用与静态资源,向插件提供 ctx.serviceHost。",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./lib/host.mjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./lib/host.mjs",
|
|
9
|
+
"./src": "./src/index.mjs",
|
|
10
|
+
"./package.json": "./package.json",
|
|
11
|
+
"./tuning": "./src/tuning.mjs"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=18",
|
|
15
|
+
"dsh": "^0.2.0-rc.2"
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"dsh": {
|
|
21
|
+
"bundle": {
|
|
22
|
+
"patch": "./cordis.patch.yml"
|
|
23
|
+
},
|
|
24
|
+
"suite": "./dsh-suite.json",
|
|
25
|
+
"category": "service",
|
|
26
|
+
"platform": "both",
|
|
27
|
+
"apiVersion": "1.0.0",
|
|
28
|
+
"driver": {
|
|
29
|
+
"service": "serviceHost"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"meta": {
|
|
33
|
+
"title": "公共服务宿主",
|
|
34
|
+
"description": "统一 HTTP 路由、健康检查、指标、单实例锁与端口复用,向插件提供 ctx.serviceHost"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"lib/",
|
|
38
|
+
"src/",
|
|
39
|
+
"cordis.patch.yml",
|
|
40
|
+
"dsh-suite.json",
|
|
41
|
+
"README.md"
|
|
42
|
+
],
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"scripts": {
|
|
45
|
+
"test": "node --test test/*.test.mjs"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@capyclaw/plugin-kit": "^0.2.9",
|
|
49
|
+
"@capyclaw/foundation": "^0.1.1"
|
|
50
|
+
},
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "git+https://github.com/Maple496/capyclaw.git",
|
|
54
|
+
"directory": "C/packages/capyclaw-service-host"
|
|
55
|
+
},
|
|
56
|
+
"bugs": {
|
|
57
|
+
"url": "https://github.com/Maple496/capyclaw/issues"
|
|
58
|
+
},
|
|
59
|
+
"homepage": "https://github.com/Maple496/capyclaw/tree/main/C/packages/capyclaw-service-host#readme"
|
|
60
|
+
}
|