@capyclaw/rsp-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/README.md +84 -2
- package/cordis.patch.yml +8 -0
- package/dsh-suite.json +91 -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 +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/node_modules/@capyclaw/rsp-skill-remote-screen/README.md +7 -0
- package/node_modules/@capyclaw/rsp-skill-remote-screen/contract/rsp-contract.json +478 -0
- package/node_modules/@capyclaw/rsp-skill-remote-screen/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/rsp-skill-remote-screen/package.json +33 -0
- package/node_modules/@capyclaw/rsp-skill-remote-screen/plugin.mjs +15 -0
- package/node_modules/@capyclaw/rsp-skill-remote-screen/skills/remote-screen/SKILL.md +131 -0
- package/node_modules/@capyclaw/rsp-workbench/contract/capabilities.json +203 -0
- package/node_modules/@capyclaw/rsp-workbench/lib/client.mjs +681 -0
- package/node_modules/@capyclaw/rsp-workbench/lib/descriptors.mjs +28 -0
- package/node_modules/@capyclaw/rsp-workbench/lib/host.mjs +51 -0
- package/node_modules/@capyclaw/rsp-workbench/lib/manager.mjs +333 -0
- package/node_modules/@capyclaw/rsp-workbench/lib/session-mode.mjs +68 -0
- package/node_modules/@capyclaw/rsp-workbench/lib/tools.mjs +485 -0
- package/node_modules/@capyclaw/rsp-workbench/lib/workbench.mjs +184 -0
- package/node_modules/@capyclaw/rsp-workbench/package.json +47 -0
- package/node_modules/@capyclaw/rsp-workbench/plugin.mjs +17 -0
- package/node_modules/@capyclaw/rsp-workbench/ui/index.html +578 -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 +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 +53 -4
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RSP 控制端工具面(rsp_*)。经 toolHost.defineTool/defineCapability 定义,
|
|
3
|
+
* 由 workbench.createRegistry 装配、registerWithDsh 注册进 DSH。
|
|
4
|
+
*
|
|
5
|
+
* 坐标人体工学:鼠标/拖拽默认接受「最近一帧的像素坐标」(space:"frame"),
|
|
6
|
+
* 控制端用最近帧尺寸 + hello 逻辑尺寸换算成逻辑点上线(协议合规);space:"logical" 直传。
|
|
7
|
+
*/
|
|
8
|
+
import { mkdirSync, writeFileSync, readdirSync, unlinkSync } from 'node:fs'
|
|
9
|
+
import path from 'node:path'
|
|
10
|
+
import { tmpdir } from 'node:os'
|
|
11
|
+
import { splitText, MAX_TEXT_UNITS } from './client.mjs'
|
|
12
|
+
import { sessionFromExec } from './session-mode.mjs'
|
|
13
|
+
|
|
14
|
+
const MAX_INLINE_IMAGE_BYTES = 4 * 1024 * 1024
|
|
15
|
+
// 抓帧落盘只保留最近 N 张:AI 每步动作后都会抓帧验证,无上限会无界累积磁盘。
|
|
16
|
+
const MAX_SAVED_FRAMES = 40
|
|
17
|
+
const MODIFIERS = new Set(['cmd', 'ctrl', 'alt', 'shift'])
|
|
18
|
+
const MOUSE_ACTIONS = new Set(['move', 'down', 'up', 'click', 'scroll'])
|
|
19
|
+
const BUTTONS = new Set(['left', 'right', 'middle'])
|
|
20
|
+
|
|
21
|
+
// S1: 画质档位(与 client.mjs QUALITY_LADDER 对齐)。preset 选档,显式参数覆盖。
|
|
22
|
+
const QUALITY_PRESETS = {
|
|
23
|
+
low: { bitrateKbps: 500, h264Fps: 15, h264MaxWidth: 960 },
|
|
24
|
+
smooth: { bitrateKbps: 1000, h264Fps: 30, h264MaxWidth: 1280 },
|
|
25
|
+
balanced: { bitrateKbps: 2000, h264Fps: 30, h264MaxWidth: 1920 },
|
|
26
|
+
hd: { bitrateKbps: 4000, h264Fps: 60, h264MaxWidth: 1920 },
|
|
27
|
+
uhd: { bitrateKbps: 8000, h264Fps: 60, h264MaxWidth: 3840 },
|
|
28
|
+
}
|
|
29
|
+
const QUALITY_KNOBS = ['bitrateKbps', 'h264Fps', 'h264MaxWidth', 'jpegFps', 'jpegQuality', 'maxWidth']
|
|
30
|
+
|
|
31
|
+
// ---- 输出辅助 ----
|
|
32
|
+
function ok(text, extra) { return { content: [{ type: 'text', text }], isError: false, ...(extra || {}) } }
|
|
33
|
+
function okBlocks(blocks) { return { content: blocks, isError: false } }
|
|
34
|
+
function fail(code, message, hint) {
|
|
35
|
+
const text = `[${code}] ${message}` + (hint ? `\n提示:${hint}` : '')
|
|
36
|
+
return { content: [{ type: 'text', text }], isError: true }
|
|
37
|
+
}
|
|
38
|
+
function errToResult(e) { return fail(e.code || 'error', e.message || String(e), hintFor(e.code)) }
|
|
39
|
+
function hintFor(code) {
|
|
40
|
+
return ({
|
|
41
|
+
not_connected: '先调用 rsp_connect(可无参重连本会话记住的目标,或 name 选已记住别名)。',
|
|
42
|
+
no_target: '调用 rsp_connect 并传入被控端 url(或 host+port)与 token;或用 name 选已记住目标(rsp_status 的 remembered.targets)。',
|
|
43
|
+
unauthorized: '令牌无效:向被控端重新获取令牌后 rsp_connect 刷新。',
|
|
44
|
+
forbidden: '被控端禁用了操控通道(只读共享);画面仍可看。',
|
|
45
|
+
engine_unavailable: '被控端引擎未就绪/离线;稍后重试或检查被控端。',
|
|
46
|
+
no_frame: '先调用 rsp_screen 获取画面,再用帧像素坐标操控。',
|
|
47
|
+
no_dimensions: '尚未收到 hello/info 尺寸;先 rsp_screen 或 rsp_status。',
|
|
48
|
+
bad_event: '检查事件字段是否符合 RSP/1 §5。',
|
|
49
|
+
unsupported: '被控端为旧版 agent,不支持运行时调参/自动降档;升级 rsp-agent-win 并重启宿主后重试。',
|
|
50
|
+
})[code] || ''
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function clamp(v, lo, hi) { return Math.min(hi, Math.max(lo, v)) }
|
|
54
|
+
|
|
55
|
+
function logicalDims(client) {
|
|
56
|
+
if (client.hello) return { width: client.hello.width, height: client.hello.height }
|
|
57
|
+
if (client.info?.screen) return { width: client.info.screen.width, height: client.info.screen.height }
|
|
58
|
+
return null
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** 把工具坐标换算为逻辑点。space:frame 用最近帧尺寸映射;logical 直传。 */
|
|
62
|
+
function toLogical(client, x, y, space) {
|
|
63
|
+
const logical = logicalDims(client)
|
|
64
|
+
if (!logical || !logical.width || !logical.height) { const e = new Error('缺少屏幕逻辑尺寸'); e.code = 'no_dimensions'; throw e }
|
|
65
|
+
if (space === 'logical') return { x: clamp(Number(x), 0, logical.width), y: clamp(Number(y), 0, logical.height), logical }
|
|
66
|
+
const f = client.lastFrame
|
|
67
|
+
if (!f || !f.width || !f.height) { const e = new Error('尚无画面帧,无法按帧像素定位'); e.code = 'no_frame'; throw e }
|
|
68
|
+
const lx = Number(x) / f.width * logical.width
|
|
69
|
+
const ly = Number(y) / f.height * logical.height
|
|
70
|
+
return { x: clamp(lx, 0, logical.width), y: clamp(ly, 0, logical.height), logical, frame: { width: f.width, height: f.height } }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** 由工具参数构造 mouse 线上事件(逻辑点)。 */
|
|
74
|
+
function buildMouse(args, client) {
|
|
75
|
+
const action = args.action
|
|
76
|
+
if (!MOUSE_ACTIONS.has(action)) { const e = new Error(`action 必须是 move/down/up/click/scroll,收到 ${action}`); e.code = 'bad_event'; throw e }
|
|
77
|
+
const ev = { cmd: 'mouse', action }
|
|
78
|
+
if (action === 'scroll') {
|
|
79
|
+
ev.dx = Math.trunc(Number(args.dx ?? 0)); ev.dy = Math.trunc(Number(args.dy ?? 0))
|
|
80
|
+
return ev
|
|
81
|
+
}
|
|
82
|
+
if (args.x === undefined || args.y === undefined) { const e = new Error(`${action} 需要 x/y`); e.code = 'bad_event'; throw e }
|
|
83
|
+
const space = args.space === 'logical' ? 'logical' : 'frame'
|
|
84
|
+
const { x, y } = toLogical(client, args.x, args.y, space)
|
|
85
|
+
ev.x = x; ev.y = y
|
|
86
|
+
if (args.button !== undefined) {
|
|
87
|
+
if (!BUTTONS.has(args.button)) { const e = new Error(`button 必须是 left/right/middle`); e.code = 'bad_event'; throw e }
|
|
88
|
+
ev.button = args.button
|
|
89
|
+
}
|
|
90
|
+
if (args.clicks !== undefined) {
|
|
91
|
+
const c = Math.trunc(Number(args.clicks))
|
|
92
|
+
if (!(c >= 1 && c <= 3)) { const e = new Error('clicks 必须是 1…3'); e.code = 'bad_event'; throw e }
|
|
93
|
+
ev.clicks = c
|
|
94
|
+
}
|
|
95
|
+
return ev
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function buildKey(args) {
|
|
99
|
+
if (args.action !== 'down' && args.action !== 'up') { const e = new Error('key action 必须是 down/up'); e.code = 'bad_event'; throw e }
|
|
100
|
+
if (!args.code || typeof args.code !== 'string') { const e = new Error('key 需要 code(DOM KeyboardEvent.code)'); e.code = 'bad_event'; throw e }
|
|
101
|
+
const ev = { cmd: 'key', action: args.action, code: args.code }
|
|
102
|
+
if (args.modifiers !== undefined) {
|
|
103
|
+
if (!Array.isArray(args.modifiers)) { const e = new Error('modifiers 必须是数组'); e.code = 'bad_event'; throw e }
|
|
104
|
+
for (const m of args.modifiers) if (!MODIFIERS.has(m)) { const e = new Error(`modifier 必须是 cmd/ctrl/alt/shift,收到 ${m}`); e.code = 'bad_event'; throw e }
|
|
105
|
+
if (args.modifiers.length) ev.modifiers = args.modifiers
|
|
106
|
+
}
|
|
107
|
+
return ev
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** 归一化 batch 里的单个事件(可省略 cmd,按字段推断)。 */
|
|
111
|
+
function normalizeBatchEvent(ev, client) {
|
|
112
|
+
if (!ev || typeof ev !== 'object') { const e = new Error('batch 事件必须是对象'); e.code = 'bad_event'; throw e }
|
|
113
|
+
const cmd = ev.cmd || (ev.code ? 'key' : (ev.text !== undefined ? 'text' : 'mouse'))
|
|
114
|
+
if (cmd === 'mouse') return buildMouse(ev, client)
|
|
115
|
+
if (cmd === 'key') return buildKey(ev)
|
|
116
|
+
if (cmd === 'text') {
|
|
117
|
+
if (typeof ev.text !== 'string') { const e = new Error('text 事件需要字符串 text'); e.code = 'bad_event'; throw e }
|
|
118
|
+
return { cmd: 'text', text: ev.text }
|
|
119
|
+
}
|
|
120
|
+
const e = new Error(`未知 cmd ${cmd}`); e.code = 'bad_event'; throw e
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function framesDir(manager) { return path.join(manager.hostDir || tmpdir(), 'frames') }
|
|
124
|
+
|
|
125
|
+
/** 只保留最近 MAX_SAVED_FRAMES 张抓帧,其余删除(防磁盘无界累积)。失败静默:抓帧主路径不受影响。 */
|
|
126
|
+
export function pruneFrames(dir) {
|
|
127
|
+
try {
|
|
128
|
+
const names = readdirSync(dir).filter((n) => /^frame-\d+\.jpg$/.test(n)).sort()
|
|
129
|
+
for (const n of names.slice(0, Math.max(0, names.length - MAX_SAVED_FRAMES))) {
|
|
130
|
+
try { unlinkSync(path.join(dir, n)) } catch {}
|
|
131
|
+
}
|
|
132
|
+
} catch {}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** 抓帧并组装 rsp_screen 结果(内联 JPEG + 落盘 + 坐标映射说明)。 */
|
|
136
|
+
async function screenResult(client, manager, { save = true } = {}) {
|
|
137
|
+
const f = client.lastFrame
|
|
138
|
+
if (!f || !f.bytes) return fail('engine_unavailable', '尚无画面帧', '确认被控端引擎就绪(rsp_status 看 engine.ready);稍后重试。')
|
|
139
|
+
const logical = logicalDims(client)
|
|
140
|
+
let filePath = null
|
|
141
|
+
if (save !== false) {
|
|
142
|
+
try {
|
|
143
|
+
const dir = framesDir(manager); mkdirSync(dir, { recursive: true })
|
|
144
|
+
filePath = path.join(dir, `frame-${Date.now()}.jpg`)
|
|
145
|
+
writeFileSync(filePath, f.bytes)
|
|
146
|
+
pruneFrames(dir)
|
|
147
|
+
} catch { filePath = null }
|
|
148
|
+
}
|
|
149
|
+
const blocks = []
|
|
150
|
+
if (f.bytes.length <= MAX_INLINE_IMAGE_BYTES) blocks.push({ type: 'image', data: f.bytes.toString('base64'), mimeType: 'image/jpeg' })
|
|
151
|
+
const scale = logical && f.width ? { x: logical.width / f.width, y: logical.height / f.height } : null
|
|
152
|
+
const meta = {
|
|
153
|
+
frame: { width: f.width, height: f.height, bytes: f.bytes.length, ageMs: Date.now() - f.at },
|
|
154
|
+
logical,
|
|
155
|
+
frameToLogicalScale: scale,
|
|
156
|
+
path: filePath,
|
|
157
|
+
inline: f.bytes.length <= MAX_INLINE_IMAGE_BYTES,
|
|
158
|
+
coordinateNote: '默认 space="frame":x/y 用本图像素坐标(左上原点),控制端自动换算为逻辑点。也可 space="logical" 直传逻辑点。',
|
|
159
|
+
}
|
|
160
|
+
blocks.push({ type: 'text', text: JSON.stringify(meta, null, 2) })
|
|
161
|
+
return okBlocks(blocks)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function createRspCapabilities({ toolHost, manager, config = {} }) {
|
|
165
|
+
const { defineTool, defineCapability } = toolHost
|
|
166
|
+
const mountPath = config.mountPath || '/capyclaw/rsp'
|
|
167
|
+
const since = '0.1.0'
|
|
168
|
+
|
|
169
|
+
const capabilitiesTool = defineTool({
|
|
170
|
+
name: 'rsp_capabilities', kind: 'read', since,
|
|
171
|
+
description: '返回 RSP 控制端契约(协议 rsp/1、工具清单、能力)与当前连接状态。动作前先调用它确认工具可用、被控端已连接。',
|
|
172
|
+
inputSchema: { type: 'object', properties: {}, additionalProperties: false },
|
|
173
|
+
handler: async (args, ctx) => {
|
|
174
|
+
const report = ctx.contract.report(mountPath)
|
|
175
|
+
return ok(JSON.stringify({ protocol: 'rsp/1', contract: report, status: manager.status(sessionFromExec(ctx)) }, null, 2))
|
|
176
|
+
},
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
const connectTool = defineTool({
|
|
180
|
+
name: 'rsp_connect', kind: 'control', since,
|
|
181
|
+
description: '连接被控端:传 url(http://host:port)或 host+port,以及 token;或 name 选用已记住的目标别名。校验 rsp/1、打开画面流与操控通道,并把目标记入跨会话共享的目标库(同基址再连可省略 token)。无参数时重连本会话记住的目标。每个会话独立连接,互不抢画面。',
|
|
182
|
+
inputSchema: {
|
|
183
|
+
type: 'object',
|
|
184
|
+
properties: {
|
|
185
|
+
url: { type: 'string', description: '被控端基址,如 http://192.168.1.5:8765' },
|
|
186
|
+
host: { type: 'string', description: '主机名/IP(与 url 二选一)' },
|
|
187
|
+
port: { type: 'integer', description: '端口,默认 8765' },
|
|
188
|
+
token: { type: 'string', description: '访问令牌(bearer;新目标必填,已记住的同基址目标可省略)' },
|
|
189
|
+
name: { type: 'string', description: '目标别名:单独传=选用已记住目标;与 url/host 同传=给新目标起名' },
|
|
190
|
+
persist: { type: 'boolean', description: '是否持久化目标,默认 true' },
|
|
191
|
+
},
|
|
192
|
+
additionalProperties: false,
|
|
193
|
+
},
|
|
194
|
+
handler: async (args, ctx) => {
|
|
195
|
+
try {
|
|
196
|
+
const { info, status } = await manager.connect(args || {}, sessionFromExec(ctx))
|
|
197
|
+
return ok(JSON.stringify({ ok: true, info: { protocol: info.protocol, service: info.service, serviceVersion: info.serviceVersion, screen: info.screen, control: info.control, engine: info.engine }, status }, null, 2))
|
|
198
|
+
} catch (e) { return errToResult(e) }
|
|
199
|
+
},
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
const disconnectTool = defineTool({
|
|
203
|
+
name: 'rsp_disconnect', kind: 'control', since,
|
|
204
|
+
description: '断开本会话的被控端连接(停止画面采集与操控,不影响其它会话)。forget=true 同时解除本会话与目标的记忆绑定(目标无其它引用时从库中删除)。',
|
|
205
|
+
inputSchema: { type: 'object', properties: { forget: { type: 'boolean', description: '是否清除本会话的目标记忆,默认 false' } }, additionalProperties: false },
|
|
206
|
+
handler: async (args, ctx) => { try { return ok(JSON.stringify(await manager.disconnect(args || {}, sessionFromExec(ctx)), null, 2)) } catch (e) { return errToResult(e) } },
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
const statusTool = defineTool({
|
|
210
|
+
name: 'rsp_status', kind: 'read', since,
|
|
211
|
+
description: '查看本会话连接状态:目标、画面/操控通道状态、hello 逻辑尺寸、最近帧尺寸/时延、观众数、引擎权限诊断、当前按下的键/钮;并附 remembered(跨会话记住的目标库,令牌掩码)与 sessions 绑定。',
|
|
212
|
+
inputSchema: { type: 'object', properties: {}, additionalProperties: false },
|
|
213
|
+
handler: async (args, ctx) => ok(JSON.stringify(manager.status(sessionFromExec(ctx)), null, 2)),
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
const screenTool = defineTool({
|
|
217
|
+
name: 'rsp_screen', kind: 'read', since,
|
|
218
|
+
description: '获取被控端当前屏幕帧(JPEG 内联回模型 + 落盘路径 + 帧/逻辑尺寸)。fresh=true 等待一帧新画面(动作后验证用)。返回的帧像素坐标可直接用于 rsp_mouse/rsp_drag(默认 space=frame)。',
|
|
219
|
+
inputSchema: {
|
|
220
|
+
type: 'object',
|
|
221
|
+
properties: {
|
|
222
|
+
fresh: { type: 'boolean', description: '等待比调用时刻更新的一帧,默认 false(取最近帧)' },
|
|
223
|
+
waitMs: { type: 'integer', description: 'fresh 等待上限毫秒,默认 2000' },
|
|
224
|
+
save: { type: 'boolean', description: '是否落盘 JPEG,默认 true' },
|
|
225
|
+
},
|
|
226
|
+
additionalProperties: false,
|
|
227
|
+
},
|
|
228
|
+
handler: async (args, ctx) => {
|
|
229
|
+
try {
|
|
230
|
+
const client = await manager.requireClient(sessionFromExec(ctx))
|
|
231
|
+
const a = args || {}
|
|
232
|
+
if (a.fresh) await client.waitFrame(Date.now(), a.waitMs ?? 2000)
|
|
233
|
+
else if (!client.lastFrame) await client.waitFrame(Date.now(), a.waitMs ?? 2000)
|
|
234
|
+
// 黑屏自愈:仍无帧且被控端支持强制唤醒 → 唤醒后再等一帧。
|
|
235
|
+
// (新 agent 在观众接入黑屏时已自动唤醒;此处兜底连接时序/旧连接。)
|
|
236
|
+
if (!client.lastFrame && client.info?.features?.wake) {
|
|
237
|
+
try { await client.wake(); await client.waitFrame(Date.now(), a.waitMs ?? 3000) } catch { /* best effort */ }
|
|
238
|
+
}
|
|
239
|
+
return await screenResult(client, manager, { save: a.save })
|
|
240
|
+
} catch (e) { return errToResult(e) }
|
|
241
|
+
},
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
const mouseTool = defineTool({
|
|
245
|
+
name: 'rsp_mouse', kind: 'write', since,
|
|
246
|
+
description: '注入单个鼠标事件。action=move/down/up/click/scroll。x/y 默认按最近帧像素坐标(space=frame),自动换算逻辑点;space=logical 直传。click=原子按下+抬起(clicks=2 双击);scroll 用 dx/dy(dy>0 向上滚)。拖拽请用 rsp_drag 或 down→move→up。',
|
|
247
|
+
inputSchema: {
|
|
248
|
+
type: 'object',
|
|
249
|
+
properties: {
|
|
250
|
+
action: { type: 'string', enum: ['move', 'down', 'up', 'click', 'scroll'], description: '鼠标动作' },
|
|
251
|
+
x: { type: 'number', description: '横坐标(move/down/up/click 必填)' },
|
|
252
|
+
y: { type: 'number', description: '纵坐标(move/down/up/click 必填)' },
|
|
253
|
+
button: { type: 'string', enum: ['left', 'right', 'middle'], description: '按键,默认 left' },
|
|
254
|
+
clicks: { type: 'integer', description: '点击计数 1…3,默认 1(双击=2)' },
|
|
255
|
+
dx: { type: 'integer', description: 'scroll 横向增量(>0 向右)' },
|
|
256
|
+
dy: { type: 'integer', description: 'scroll 纵向增量(>0 向上)' },
|
|
257
|
+
space: { type: 'string', enum: ['frame', 'logical'], description: '坐标空间,默认 frame(最近帧像素)' },
|
|
258
|
+
},
|
|
259
|
+
required: ['action'], additionalProperties: false,
|
|
260
|
+
},
|
|
261
|
+
handler: async (args, ctx) => {
|
|
262
|
+
try {
|
|
263
|
+
const client = await manager.requireClient(sessionFromExec(ctx))
|
|
264
|
+
const ev = buildMouse(args || {}, client)
|
|
265
|
+
const r = await client.sendEvent(ev)
|
|
266
|
+
return ok(JSON.stringify({ ok: true, injected: ev, via: r.via, seq: r.seq ?? null }))
|
|
267
|
+
} catch (e) { return errToResult(e) }
|
|
268
|
+
},
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
const keyTool = defineTool({
|
|
272
|
+
name: 'rsp_key', kind: 'write', since,
|
|
273
|
+
description: '注入物理键事件(DOM KeyboardEvent.code)。action=down/up,必须成对。快捷键用 modifiers(cmd/ctrl/alt/shift),如 Cmd+C:down KeyA modifiers=["cmd"] 再 up。IME/粘贴文本请用 rsp_text。',
|
|
274
|
+
inputSchema: {
|
|
275
|
+
type: 'object',
|
|
276
|
+
properties: {
|
|
277
|
+
action: { type: 'string', enum: ['down', 'up'], description: '按下/抬起' },
|
|
278
|
+
code: { type: 'string', description: '物理键位,如 KeyA/Enter/ArrowLeft/MetaLeft/F5' },
|
|
279
|
+
modifiers: { type: 'array', items: { type: 'string', enum: ['cmd', 'ctrl', 'alt', 'shift'] }, description: '同时按住的修饰键' },
|
|
280
|
+
},
|
|
281
|
+
required: ['action', 'code'], additionalProperties: false,
|
|
282
|
+
},
|
|
283
|
+
handler: async (args, ctx) => {
|
|
284
|
+
try {
|
|
285
|
+
const client = await manager.requireClient(sessionFromExec(ctx))
|
|
286
|
+
const ev = buildKey(args || {})
|
|
287
|
+
const r = await client.sendEvent(ev)
|
|
288
|
+
return ok(JSON.stringify({ ok: true, injected: ev, via: r.via, seq: r.seq ?? null }))
|
|
289
|
+
} catch (e) { return errToResult(e) }
|
|
290
|
+
},
|
|
291
|
+
})
|
|
292
|
+
|
|
293
|
+
const textTool = defineTool({
|
|
294
|
+
name: 'rsp_text', kind: 'write', since,
|
|
295
|
+
description: '以 Unicode 注入通道输入文本(绕过键位布局与输入法),适合 IME 合成结果/粘贴/软键盘。超过 4096 UTF-16 码元自动分片。物理按键/快捷键请用 rsp_key。',
|
|
296
|
+
inputSchema: { type: 'object', properties: { text: { type: 'string', description: '要输入的文本' } }, required: ['text'], additionalProperties: false },
|
|
297
|
+
handler: async (args, ctx) => {
|
|
298
|
+
try {
|
|
299
|
+
const client = await manager.requireClient(sessionFromExec(ctx))
|
|
300
|
+
const text = String(args?.text ?? '')
|
|
301
|
+
const chunks = splitText(text)
|
|
302
|
+
let via = null
|
|
303
|
+
for (const c of chunks) { const r = await client.sendEvent({ cmd: 'text', text: c }); via = r.via }
|
|
304
|
+
return ok(JSON.stringify({ ok: true, chars: text.length, chunks: chunks.length, via }))
|
|
305
|
+
} catch (e) { return errToResult(e) }
|
|
306
|
+
},
|
|
307
|
+
})
|
|
308
|
+
|
|
309
|
+
const dragTool = defineTool({
|
|
310
|
+
name: 'rsp_drag', kind: 'write', since,
|
|
311
|
+
description: '拖拽:从 (fromX,fromY) 按住拖到 (toX,toY) 再抬起,中间插值 move(拖拽语义)。一次批量发送;默认 moveIntervalMs=16 提供约 60Hz 平滑轨迹。坐标默认最近帧像素(space=frame)。steps 默认 12,最大 60。',
|
|
312
|
+
inputSchema: {
|
|
313
|
+
type: 'object',
|
|
314
|
+
properties: {
|
|
315
|
+
fromX: { type: 'number' }, fromY: { type: 'number' }, toX: { type: 'number' }, toY: { type: 'number' },
|
|
316
|
+
steps: { type: 'integer', description: '中间 move 步数 2…60,默认 12' },
|
|
317
|
+
button: { type: 'string', enum: ['left', 'right', 'middle'], description: '默认 left' },
|
|
318
|
+
moveIntervalMs: { type: 'integer', description: '每个中间 move 后的被控端等待,0–100ms;默认 16ms,最长累计等待 2s' },
|
|
319
|
+
space: { type: 'string', enum: ['frame', 'logical'], description: '默认 frame' },
|
|
320
|
+
},
|
|
321
|
+
required: ['fromX', 'fromY', 'toX', 'toY'], additionalProperties: false,
|
|
322
|
+
},
|
|
323
|
+
handler: async (args, ctx) => {
|
|
324
|
+
try {
|
|
325
|
+
const client = await manager.requireClient(sessionFromExec(ctx))
|
|
326
|
+
const a = args || {}
|
|
327
|
+
const space = a.space === 'logical' ? 'logical' : 'frame'
|
|
328
|
+
const from = toLogical(client, a.fromX, a.fromY, space)
|
|
329
|
+
const to = toLogical(client, a.toX, a.toY, space)
|
|
330
|
+
const steps = clamp(Math.trunc(a.steps ?? 12), 2, 60)
|
|
331
|
+
const button = a.button || 'left'
|
|
332
|
+
const moveIntervalMs = a.moveIntervalMs ?? 16
|
|
333
|
+
if (!Number.isInteger(moveIntervalMs) || moveIntervalMs < 0 || moveIntervalMs > 100) return fail('bad_event', 'moveIntervalMs 必须是 0–100 的整数')
|
|
334
|
+
if (steps * moveIntervalMs > 2000) return fail('bad_event', 'drag pacing duration exceeds 2000ms')
|
|
335
|
+
const events = [
|
|
336
|
+
{ cmd: 'mouse', action: 'down', x: from.x, y: from.y, button },
|
|
337
|
+
...Array.from({ length: steps }, (_, i) => {
|
|
338
|
+
const t = (i + 1) / steps
|
|
339
|
+
return { cmd: 'mouse', action: 'move', x: from.x + (to.x - from.x) * t, y: from.y + (to.y - from.y) * t, button }
|
|
340
|
+
}),
|
|
341
|
+
{ cmd: 'mouse', action: 'up', x: to.x, y: to.y, button },
|
|
342
|
+
]
|
|
343
|
+
const r = await client.sendBatch(events, { moveIntervalMs })
|
|
344
|
+
return ok(JSON.stringify({ ok: true, from: { x: from.x, y: from.y }, to: { x: to.x, y: to.y }, steps, button, moveIntervalMs, batched: r.batched }))
|
|
345
|
+
} catch (e) { return errToResult(e) }
|
|
346
|
+
},
|
|
347
|
+
})
|
|
348
|
+
|
|
349
|
+
const batchTool = defineTool({
|
|
350
|
+
name: 'rsp_batch', kind: 'write', since,
|
|
351
|
+
description: '按序提交多个输入事件,通常一次控制确认。连续鼠标轨迹可设 moveIntervalMs(0–100ms)让被控端按节奏注入;最多 64 个事件、总节奏等待不超过 2s。gapMs>0 仍可选逐事件 ACK 间隔;screenshot=true 末尾抓帧。',
|
|
352
|
+
inputSchema: {
|
|
353
|
+
type: 'object',
|
|
354
|
+
properties: {
|
|
355
|
+
events: { type: 'array', description: '事件数组(mouse/key/text)', items: { type: 'object' } },
|
|
356
|
+
moveIntervalMs: { type: 'integer', description: 'batch 内每个鼠标 move 后的等待,0–100ms;最多累计 2s。用于连续轨迹,默认 0' },
|
|
357
|
+
gapMs: { type: 'integer', description: '兼容模式:逐事件发送时的间隔毫秒,默认 0' },
|
|
358
|
+
screenshot: { type: 'boolean', description: '末尾抓一帧新画面,默认 false' },
|
|
359
|
+
space: { type: 'string', enum: ['frame', 'logical'], description: 'mouse 坐标空间默认值,默认 frame' },
|
|
360
|
+
},
|
|
361
|
+
required: ['events'], additionalProperties: false,
|
|
362
|
+
},
|
|
363
|
+
handler: async (args, ctx) => {
|
|
364
|
+
try {
|
|
365
|
+
const client = await manager.requireClient(sessionFromExec(ctx))
|
|
366
|
+
const a = args || {}
|
|
367
|
+
const events = Array.isArray(a.events) ? a.events : []
|
|
368
|
+
if (!events.length) return fail('bad_event', 'events 不能为空')
|
|
369
|
+
const gap = Math.max(0, Math.trunc(a.gapMs ?? 0))
|
|
370
|
+
const moveIntervalMs = a.moveIntervalMs ?? 0
|
|
371
|
+
if (!Number.isInteger(moveIntervalMs) || moveIntervalMs < 0 || moveIntervalMs > 100) return fail('bad_event', 'moveIntervalMs 必须是 0–100 的整数')
|
|
372
|
+
const defaultSpace = a.space === 'logical' ? 'logical' : 'frame'
|
|
373
|
+
const injected = []
|
|
374
|
+
const normalized = []
|
|
375
|
+
if (events.length > 64) return fail('bad_event', 'batch 最多 64 个事件')
|
|
376
|
+
for (const raw of events) {
|
|
377
|
+
const withSpace = (raw && raw.cmd !== 'key' && raw.cmd !== 'text' && raw.space === undefined) ? { ...raw, space: defaultSpace } : raw
|
|
378
|
+
const ev = normalizeBatchEvent(withSpace, client)
|
|
379
|
+
if (ev.cmd === 'text') {
|
|
380
|
+
for (const c of splitText(ev.text)) normalized.push({ cmd: 'text', text: c })
|
|
381
|
+
} else normalized.push(ev)
|
|
382
|
+
injected.push(ev.cmd + (ev.action ? ':' + ev.action : ''))
|
|
383
|
+
}
|
|
384
|
+
if (gap > 0 && moveIntervalMs > 0) return fail('bad_event', 'gapMs 与 moveIntervalMs 不能同时使用')
|
|
385
|
+
if (gap > 0) {
|
|
386
|
+
for (const ev of normalized) {
|
|
387
|
+
await client.sendEvent(ev)
|
|
388
|
+
await new Promise((r) => setTimeout(r, gap))
|
|
389
|
+
}
|
|
390
|
+
injected.splice(0, injected.length, ...normalized.map((ev) => ev.cmd + (ev.action ? ':' + ev.action : '')))
|
|
391
|
+
} else {
|
|
392
|
+
if (normalized.filter((ev) => ev.cmd === 'mouse' && ev.action === 'move').length * moveIntervalMs > 2000) return fail('bad_event', 'batch pacing duration exceeds 2000ms')
|
|
393
|
+
await client.sendBatch(normalized, { moveIntervalMs })
|
|
394
|
+
}
|
|
395
|
+
if (a.screenshot) {
|
|
396
|
+
await client.waitFrame(Date.now(), 2000)
|
|
397
|
+
const sr = await screenResult(client, manager, { save: true })
|
|
398
|
+
return okBlocks([{ type: 'text', text: JSON.stringify({ ok: true, count: injected.length, injected }) }, ...sr.content])
|
|
399
|
+
}
|
|
400
|
+
return ok(JSON.stringify({ ok: true, count: injected.length, injected }))
|
|
401
|
+
} catch (e) { return errToResult(e) }
|
|
402
|
+
},
|
|
403
|
+
})
|
|
404
|
+
|
|
405
|
+
const qualityTool = defineTool({
|
|
406
|
+
name: 'rsp_quality', kind: 'control', since,
|
|
407
|
+
description: '运行时调节被控端画质(原子换档,画面不中断)。preset 选档(low/smooth/balanced/hd/uhd),或用显式 bitrateKbps/h264Fps/h264MaxWidth/jpegFps/jpegQuality/maxWidth 覆盖。auto=true 开启按操控 RTT 自动降档(持续高延迟降一档、持续健康升回、不超基线),auto=false 关闭。需被控端支持 features.quality(新版 agent)。返回生效画质快照 + 当前 RTT。',
|
|
408
|
+
inputSchema: {
|
|
409
|
+
type: 'object',
|
|
410
|
+
properties: {
|
|
411
|
+
preset: { type: 'string', enum: ['low', 'smooth', 'balanced', 'hd', 'uhd'], description: '画质档位' },
|
|
412
|
+
bitrateKbps: { type: 'number', description: 'h264 码率 100–50000 kbps' },
|
|
413
|
+
h264Fps: { type: 'number', description: 'h264 帧率 1–120' },
|
|
414
|
+
h264MaxWidth: { type: 'number', description: 'h264 最大宽 320–7680(gpuDirect 原生分辨率下忽略)' },
|
|
415
|
+
jpegFps: { type: 'number', description: 'JPEG 帧率 1–120' },
|
|
416
|
+
jpegQuality: { type: 'number', description: 'JPEG 质量 1–31(越小越好)' },
|
|
417
|
+
maxWidth: { type: 'number', description: 'JPEG 最大宽 320–7680' },
|
|
418
|
+
auto: { type: 'boolean', description: 'true=开启自动降档,false=关闭;省略则不变' },
|
|
419
|
+
},
|
|
420
|
+
additionalProperties: false,
|
|
421
|
+
},
|
|
422
|
+
handler: async (args, ctx) => {
|
|
423
|
+
try {
|
|
424
|
+
const client = await manager.requireClient(sessionFromExec(ctx))
|
|
425
|
+
const a = args || {}
|
|
426
|
+
if (a.auto === true) client.enableAutoQuality()
|
|
427
|
+
else if (a.auto === false) client.disableAutoQuality()
|
|
428
|
+
const params = { ...(a.preset ? QUALITY_PRESETS[a.preset] : {}) }
|
|
429
|
+
for (const k of QUALITY_KNOBS) if (typeof a[k] === 'number') params[k] = a[k]
|
|
430
|
+
let quality
|
|
431
|
+
if (Object.keys(params).length) { const r = await client.setQuality(params); quality = r.quality ?? null }
|
|
432
|
+
else { const fresh = await client.fetchInfo(); quality = fresh.quality ?? null }
|
|
433
|
+
const st = client.status()
|
|
434
|
+
return ok(JSON.stringify({ ok: true, quality, autoQuality: st.autoQuality, controlRttMs: st.controlRttMs }))
|
|
435
|
+
} catch (e) { return errToResult(e) }
|
|
436
|
+
},
|
|
437
|
+
})
|
|
438
|
+
|
|
439
|
+
const wakeTool = defineTool({
|
|
440
|
+
name: 'rsp_wake', kind: 'control', since,
|
|
441
|
+
description: '强制唤醒被控端显示器:点亮已息屏/睡眠的屏幕(macOS caffeinate -u / Windows 一次性 SetThreadExecutionState),随后保持防熄屏。与「防熄屏」不同——它能唤不醒已经黑屏的设备。需被控端 features.wake(新版 agent),旧 agent 报 unsupported。holdMs=点亮后保持唤醒毫秒数(0–30000,默认 2000)。抓帧前若画面黑屏可先调它;新 agent 在观众接入黑屏时也会自动唤醒。screenshot=true 唤醒后抓帧验证。返回唤醒结果快照。',
|
|
442
|
+
inputSchema: {
|
|
443
|
+
type: 'object',
|
|
444
|
+
properties: {
|
|
445
|
+
holdMs: { type: 'integer', description: '点亮后保持唤醒的毫秒数 0–30000,默认 2000' },
|
|
446
|
+
screenshot: { type: 'boolean', description: '唤醒后抓一帧新画面验证,默认 false' },
|
|
447
|
+
waitMs: { type: 'integer', description: 'screenshot 时等待新帧的上限毫秒,默认 3000' },
|
|
448
|
+
},
|
|
449
|
+
additionalProperties: false,
|
|
450
|
+
},
|
|
451
|
+
handler: async (args, ctx) => {
|
|
452
|
+
try {
|
|
453
|
+
const client = await manager.requireClient(sessionFromExec(ctx))
|
|
454
|
+
const a = args || {}
|
|
455
|
+
const r = await client.wake({ holdMs: a.holdMs })
|
|
456
|
+
if (a.screenshot) {
|
|
457
|
+
await client.waitFrame(Date.now(), a.waitMs ?? 3000)
|
|
458
|
+
const sr = await screenResult(client, manager, { save: true })
|
|
459
|
+
return okBlocks([{ type: 'text', text: JSON.stringify({ ok: r.ok, wake: r.wake, via: r.via }) }, ...sr.content])
|
|
460
|
+
}
|
|
461
|
+
return ok(JSON.stringify({ ok: r.ok, wake: r.wake, via: r.via }))
|
|
462
|
+
} catch (e) { return errToResult(e) }
|
|
463
|
+
},
|
|
464
|
+
})
|
|
465
|
+
|
|
466
|
+
return [
|
|
467
|
+
defineCapability({
|
|
468
|
+
id: 'rsp.session', title: 'RSP 会话', description: '连接/断开被控端、查看契约与状态。',
|
|
469
|
+
tags: ['rsp', 'remote-screen', 'session'], requires: [], provides: {},
|
|
470
|
+
features: ['connect', 'disconnect', 'status', 'capabilities'],
|
|
471
|
+
tools: [capabilitiesTool, connectTool, disconnectTool, statusTool],
|
|
472
|
+
}),
|
|
473
|
+
defineCapability({
|
|
474
|
+
id: 'rsp.screen', title: 'RSP 画面', description: '读取被控端实时屏幕帧(只读)。',
|
|
475
|
+
tags: ['rsp', 'remote-screen', 'screen'], requires: [], provides: {},
|
|
476
|
+
features: ['screen'], tools: [screenTool],
|
|
477
|
+
}),
|
|
478
|
+
defineCapability({
|
|
479
|
+
id: 'rsp.control', title: 'RSP 操控', description: '向被控端注入鼠标/键盘/文本/拖拽/批量输入(只写),运行时调节画质,并强制唤醒已息屏的显示器。',
|
|
480
|
+
tags: ['rsp', 'remote-screen', 'control'], requires: [], provides: {},
|
|
481
|
+
features: ['mouse', 'key', 'text', 'drag', 'batch', 'quality', 'wake'],
|
|
482
|
+
tools: [mouseTool, keyTool, textTool, dragTool, batchTool, qualityTool, wakeTool],
|
|
483
|
+
}),
|
|
484
|
+
]
|
|
485
|
+
}
|