@haitang-hub/dsh-3d-director-desk 0.3.21 → 0.3.23
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/bridge/index.js +8 -1
- package/bridge/src/server/http.js +18 -5
- package/bridge/src/server/mcp.js +34 -4
- package/lib/client.js +49 -5
- package/package.json +8 -7
- package/site/assets/{editor-page-DQfRuAlQ.js → editor-page-DWCcT8p7.js} +17 -17
- package/site/assets/index-BqWc6NAd.css +1 -0
- package/site/assets/index-v9ngTdIA.js +4440 -0
- package/site/index.html +2 -2
- package/site/assets/index-8Z0rEin5.js +0 -4442
- package/site/assets/index-BGaYavDD.css +0 -1
package/bridge/index.js
CHANGED
|
@@ -61,7 +61,14 @@ async function runDoctor() {
|
|
|
61
61
|
else fail(`桥不在线:${BRIDGE_URL} —— 在 director-mcp 目录运行 node index.js(或用 start.bat 启动)`);
|
|
62
62
|
|
|
63
63
|
if (health?.body?.ok) {
|
|
64
|
-
|
|
64
|
+
// /director/status 在 token 鉴权范围内:env 固定值或桥落盘的 data/bridge-token.txt,与桥同源解析
|
|
65
|
+
let token = process.env.DIRECTOR_BRIDGE_TOKEN?.trim() || "";
|
|
66
|
+
if (!token) {
|
|
67
|
+
try {
|
|
68
|
+
token = fs.readFileSync(join(DATA_DIR, "bridge-token.txt"), "utf8").trim();
|
|
69
|
+
} catch { /* 桥还没写过 token 文件 */ }
|
|
70
|
+
}
|
|
71
|
+
const status = await getJson(`${BRIDGE_URL}/director/status${token ? `?token=${encodeURIComponent(token)}` : ""}`);
|
|
65
72
|
const ready = (status?.body?.executors || []).filter((item) => item.ready);
|
|
66
73
|
if (ready.length) pass(`executor 在线 ${ready.length} 个:${ready.map((item) => item.deskId || "(未指定 desk)").join(", ")}`);
|
|
67
74
|
else fail("没有已就绪的导演台页面 —— 打开 http://127.0.0.1:17372 并进入一个导演台编辑器后重试");
|
|
@@ -39,6 +39,8 @@ import { DIRECTOR_PROTOCOL_VERSION, SERVER_NAME, SERVER_VERSION } from "../proto
|
|
|
39
39
|
|
|
40
40
|
const PORT = Number(process.env.STORE_PORT || 17372);
|
|
41
41
|
const HOST = process.env.STORE_HOST || "127.0.0.1";
|
|
42
|
+
// MCP 门面进程内直调桥时透传的 desk 标识(与 mcp.js 的 DESK 同源)
|
|
43
|
+
const DESK = process.env.DIRECTOR_DESK || "";
|
|
42
44
|
const DATA_DIR = resolve(process.env.DIRECTOR_STORE_DIR?.trim() || join(dirname(fileURLToPath(import.meta.url)), "..", "..", "..", "data"));
|
|
43
45
|
|
|
44
46
|
// 站点伺服(阶段二):让桥直接承载导演台 Web 构建产物,Desktop 工作台面板的 iframe
|
|
@@ -283,17 +285,24 @@ const server = http.createServer(async (req, res) => {
|
|
|
283
285
|
|
|
284
286
|
if (group === "events" && req.method === "GET") return bridge.openEvents(url, res);
|
|
285
287
|
|
|
286
|
-
// MCP over HTTP(streamable HTTP 的无状态子集):外部 harness 无法拉起 stdio
|
|
288
|
+
// MCP over HTTP(streamable HTTP 的无状态子集):外部 harness 无法拉起 stdio 进程时用这个门面。
|
|
289
|
+
// 无 Origin 的调用方(harness/脚本)放行;带跨站 Origin 的浏览器请求拒绝——
|
|
290
|
+
// CORS * 会让公网网页能读回环响应,/mcp 又免 token,必须挡掉这一条后门。
|
|
287
291
|
if (group === "mcp") {
|
|
288
292
|
if (req.method !== "POST") {
|
|
289
293
|
res.setHeader("allow", "POST");
|
|
290
294
|
return sendJson(res, 405, { ok: false, error: "POST JSON-RPC 2.0 messages to /mcp" });
|
|
291
295
|
}
|
|
296
|
+
const origin = req.headers.origin || "";
|
|
297
|
+
if (origin && !LOOPBACK_ORIGIN.test(origin)) return sendJson(res, 403, { ok: false, error: "cross-origin /mcp denied" });
|
|
292
298
|
const message = JSON.parse((await readBody(req)).toString("utf8") || "{}");
|
|
293
299
|
if (!message || typeof message !== "object") return sendJson(res, 400, { ok: false, error: "bad json-rpc message" });
|
|
294
300
|
if (message.id === undefined || message.id === null) return send(res, 202, "");
|
|
295
301
|
try {
|
|
296
|
-
|
|
302
|
+
// 进程内直调桥(tools/call 不再经 callBridge 回环 HTTP 自调用,绕开 /director/tool 的 token 校验)
|
|
303
|
+
const result = await handleMcpMethod(String(message.method || ""), message.params || {}, {
|
|
304
|
+
callTool: (name, input) => bridge.callTool(name, input, DESK),
|
|
305
|
+
});
|
|
297
306
|
return sendJson(res, 200, { jsonrpc: "2.0", id: message.id, result });
|
|
298
307
|
} catch (error) {
|
|
299
308
|
const payload = error && typeof error === "object" ? error : {};
|
|
@@ -313,8 +322,9 @@ const server = http.createServer(async (req, res) => {
|
|
|
313
322
|
return sendJson(res, 200, { ok: true, skills: names });
|
|
314
323
|
}
|
|
315
324
|
if (key && req.method === "GET") {
|
|
316
|
-
|
|
317
|
-
|
|
325
|
+
// key 是单段目录名:越界(..%2F 等归一化逃逸)直接拒绝,与站点文件的 startsWith 校验同口径
|
|
326
|
+
const file = resolve(skillsDir, key, "SKILL.md");
|
|
327
|
+
if (!file.startsWith(resolve(skillsDir) + sep) || !fs.existsSync(file)) return sendJson(res, 404, { ok: false, error: "skill not found" });
|
|
318
328
|
return send(res, 200, fs.readFileSync(file), { "content-type": "text/markdown; charset=utf-8" });
|
|
319
329
|
}
|
|
320
330
|
}
|
|
@@ -426,7 +436,10 @@ export function startHttpServer() {
|
|
|
426
436
|
console.log(`[director-mcp] listening on http://${HOST}:${PORT}, data dir: ${DATA_DIR}`);
|
|
427
437
|
console.log(`[director-mcp] bridge protocol v${DIRECTOR_PROTOCOL_VERSION}; MCP stdio: node index.js mcp; self-check: node index.js doctor`);
|
|
428
438
|
// 手动连接时用户要从运行窗口抄 token;回环网页仍走 /bootstrap 零配置自动领取。
|
|
429
|
-
|
|
439
|
+
// 仅交互终端打印:插件托管时 stdout 会 pipe 进宿主日志,密钥不落日志。
|
|
440
|
+
if (process.stdout.isTTY) {
|
|
441
|
+
console.log(`[director-mcp] connect token: ${TOKEN} (pin via DIRECTOR_BRIDGE_TOKEN; web pages get it from /bootstrap automatically)`);
|
|
442
|
+
}
|
|
430
443
|
});
|
|
431
444
|
return server;
|
|
432
445
|
}
|
package/bridge/src/server/mcp.js
CHANGED
|
@@ -14,6 +14,23 @@ const SUPPORTED_PROTOCOL_VERSIONS = ["2025-06-18", "2025-03-26", "2024-11-05"];
|
|
|
14
14
|
const BRIDGE_URL = (process.env.DIRECTOR_BRIDGE_URL || "http://127.0.0.1:17372").replace(/\/$/, "");
|
|
15
15
|
const DESK = process.env.DIRECTOR_DESK || "";
|
|
16
16
|
|
|
17
|
+
// /director/tool 要求连接 token:DIRECTOR_BRIDGE_TOKEN 固定值优先,否则经 /bootstrap 领取
|
|
18
|
+
// (本进程 fetch 不带 Origin,桥会把 token 下发给无 Origin 的本机调用方)。缓存后随调用复用。
|
|
19
|
+
let cachedBridgeToken = "";
|
|
20
|
+
async function resolveBridgeToken() {
|
|
21
|
+
const fixed = process.env.DIRECTOR_BRIDGE_TOKEN?.trim();
|
|
22
|
+
if (fixed) return fixed;
|
|
23
|
+
if (cachedBridgeToken) return cachedBridgeToken;
|
|
24
|
+
try {
|
|
25
|
+
const res = await fetch(`${BRIDGE_URL}/bootstrap`, { signal: AbortSignal.timeout(2000) });
|
|
26
|
+
const body = await res.json().catch(() => null);
|
|
27
|
+
cachedBridgeToken = String(body?.token || "").trim();
|
|
28
|
+
} catch {
|
|
29
|
+
// 桥不在线时拿不到 token,callBridge 会走 bridge_offline 分支。
|
|
30
|
+
}
|
|
31
|
+
return cachedBridgeToken;
|
|
32
|
+
}
|
|
33
|
+
|
|
17
34
|
/** 启动 stdio MCP 服务。 */
|
|
18
35
|
export async function startMcpServer() {
|
|
19
36
|
let buffer = "";
|
|
@@ -77,7 +94,8 @@ async function respondTo(message) {
|
|
|
77
94
|
}
|
|
78
95
|
}
|
|
79
96
|
|
|
80
|
-
|
|
97
|
+
/** context.callTool:宿主进程内已有的桥实例可直接注入(HTTP 门面),免去回环 HTTP 自调用。 */
|
|
98
|
+
export async function handleMethod(method, params, context = {}) {
|
|
81
99
|
switch (method) {
|
|
82
100
|
case "initialize":
|
|
83
101
|
return {
|
|
@@ -95,8 +113,14 @@ export async function handleMethod(method, params) {
|
|
|
95
113
|
case "tools/call": {
|
|
96
114
|
const name = String(params.name || "");
|
|
97
115
|
const input = params.arguments && typeof params.arguments === "object" ? params.arguments : {};
|
|
98
|
-
|
|
99
|
-
|
|
116
|
+
let result;
|
|
117
|
+
try {
|
|
118
|
+
result = context.callTool ? await context.callTool(name, input) : await callBridge(name, input);
|
|
119
|
+
} catch (error) {
|
|
120
|
+
const payload = error && typeof error === "object" ? error : {};
|
|
121
|
+
result = errorResult({ error: payload.message || String(error), ...(payload.code ? { code: payload.code } : {}), ...(payload.hint ? { hint: payload.hint } : {}) });
|
|
122
|
+
}
|
|
123
|
+
// 错误结果已是 MCP 形态(content + isError),直接透传
|
|
100
124
|
if (result && typeof result === "object" && Array.isArray(result.content)) return result;
|
|
101
125
|
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
102
126
|
}
|
|
@@ -107,11 +131,12 @@ export async function handleMethod(method, params) {
|
|
|
107
131
|
|
|
108
132
|
/** 把工具调用转发到常驻桥;bridge 侧结构化错误转为 MCP isError 结果。 */
|
|
109
133
|
async function callBridge(name, input) {
|
|
134
|
+
const token = await resolveBridgeToken();
|
|
110
135
|
let res;
|
|
111
136
|
try {
|
|
112
137
|
res = await fetch(`${BRIDGE_URL}/director/tool`, {
|
|
113
138
|
method: "POST",
|
|
114
|
-
headers: { "content-type": "application/json" },
|
|
139
|
+
headers: { "content-type": "application/json", ...(token ? { "x-director-token": token } : {}) },
|
|
115
140
|
body: JSON.stringify({ name, input, desk: DESK }),
|
|
116
141
|
});
|
|
117
142
|
} catch {
|
|
@@ -120,6 +145,11 @@ async function callBridge(name, input) {
|
|
|
120
145
|
hint: `director-mcp 常驻服务未运行(${BRIDGE_URL})。先运行 start.bat 或在 director-mcp 目录执行 node index.js`,
|
|
121
146
|
});
|
|
122
147
|
}
|
|
148
|
+
if (res.status === 401) {
|
|
149
|
+
// token 失效(桥换了数据目录/重启生成新 token):清缓存,下次调用重新领取
|
|
150
|
+
cachedBridgeToken = "";
|
|
151
|
+
return errorResult({ error: "invalid token", hint: "桥的连接 token 已变化,重试一次即可自动重新领取" });
|
|
152
|
+
}
|
|
123
153
|
const body = await res.json().catch(() => ({}));
|
|
124
154
|
if (!body.ok) return errorResult({ error: body.error || "tool call failed", ...(body.code ? { code: body.code } : {}), ...(body.hint ? { hint: body.hint } : {}) });
|
|
125
155
|
return body.result ?? { ok: true };
|
package/lib/client.js
CHANGED
|
@@ -128,10 +128,13 @@ window.__ModuleLoader__.load({
|
|
|
128
128
|
function DirectorDeskTab({ useTabInfo }) {
|
|
129
129
|
const info = useBridgeInfo()
|
|
130
130
|
const iframeRef = useRef(null)
|
|
131
|
-
// 画布插件经 sidebarRight.openTab('director-desk', { params: { instanceId } }) 打开本标签时,
|
|
132
|
-
//
|
|
131
|
+
// 画布插件经 sidebarRight.openTab('director-desk', { params: { instanceId, fromCanvas?, fromNode? } }) 打开本标签时,
|
|
132
|
+
// 导航参数带目标实例与导入定位:iframe 据此加载 /director/editor?instanceId=...&fromCanvas=...&fromNode=...
|
|
133
|
+
// (无参保持根路径旧行为)。
|
|
133
134
|
const tabInfo = useTabInfo()
|
|
134
135
|
const instanceId = tabInfo?.tab?.navigation?.params?.instanceId
|
|
136
|
+
const fromCanvas = tabInfo?.tab?.navigation?.params?.fromCanvas
|
|
137
|
+
const fromNode = tabInfo?.tab?.navigation?.params?.fromNode
|
|
135
138
|
const [nonce, setNonce] = useState(0)
|
|
136
139
|
// 设置同步令牌:写进 iframe URL,只有携带它的消息才会被接受/回发。
|
|
137
140
|
// 独立打开的页面没有令牌,设置桥保持惰性。
|
|
@@ -301,9 +304,16 @@ window.__ModuleLoader__.load({
|
|
|
301
304
|
}
|
|
302
305
|
|
|
303
306
|
// 新窗口带 dshWindow=1:页面经同源 BroadcastChannel 跟随本 iframe 的共享设置、Harness 模型与实例。
|
|
307
|
+
const editorQuery = () => {
|
|
308
|
+
if (!instanceId) return ''
|
|
309
|
+
const params = [`instanceId=${encodeURIComponent(instanceId)}`]
|
|
310
|
+
if (fromCanvas) params.push(`fromCanvas=${encodeURIComponent(fromCanvas)}`)
|
|
311
|
+
if (fromNode) params.push(`fromNode=${encodeURIComponent(fromNode)}`)
|
|
312
|
+
return `director/editor?${params.join('&')}`
|
|
313
|
+
}
|
|
304
314
|
const openExternal = () => {
|
|
305
315
|
if (!info?.port) return
|
|
306
|
-
const base = `${bridgeOrigin(info)}/${
|
|
316
|
+
const base = `${bridgeOrigin(info)}/${editorQuery()}`
|
|
307
317
|
const query = `dshWindow=1&dshSettingsProject=${SHARED_PROJECT_ID}`
|
|
308
318
|
window.open(`${base}${base.includes('?') ? '&' : '?'}${query}`, '_blank', 'noopener')
|
|
309
319
|
}
|
|
@@ -339,7 +349,7 @@ window.__ModuleLoader__.load({
|
|
|
339
349
|
key: `${instanceId || 'root'}#${nonce}`,
|
|
340
350
|
ref: iframeRef,
|
|
341
351
|
src: (() => {
|
|
342
|
-
const base = `${bridgeOrigin(info)}/${
|
|
352
|
+
const base = `${bridgeOrigin(info)}/${editorQuery()}`
|
|
343
353
|
const query = `dshSettingsToken=${encodeURIComponent(settingsToken)}&dshSettingsProject=${SHARED_PROJECT_ID}`
|
|
344
354
|
return `${base}${base.includes('?') ? '&' : '?'}${query}`
|
|
345
355
|
})(),
|
|
@@ -411,6 +421,11 @@ window.__ModuleLoader__.load({
|
|
|
411
421
|
'.dsh-aigc-cfg__flabel{color:var(--dsw-alias-label-secondary);font-size:12px}',
|
|
412
422
|
'.dsh-aigc-cfg__inp{box-sizing:border-box;width:100%;min-height:28px;padding:4px 10px;border:1px solid var(--dsw-alias-border-l2);border-radius:8px;background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;outline:none}',
|
|
413
423
|
'.dsh-aigc-cfg__inp:focus{border-color:var(--dsw-alias-state-business-primary)}',
|
|
424
|
+
'.dsh-aigc-cfg__secret{position:relative;display:flex;min-width:0}',
|
|
425
|
+
'.dsh-aigc-cfg__secret .dsh-aigc-cfg__inp{flex:1;min-width:0;padding-right:32px}',
|
|
426
|
+
'.dsh-aigc-cfg__secret .dsh-aigc-cfg__inp::-ms-reveal{display:none}',
|
|
427
|
+
'.dsh-aigc-cfg__eye{position:absolute;right:4px;top:50%;transform:translateY(-50%);width:24px;height:24px;display:inline-flex;align-items:center;justify-content:center;padding:0;border:none;border-radius:6px;background:transparent;color:var(--dsw-alias-label-secondary);cursor:pointer}',
|
|
428
|
+
'.dsh-aigc-cfg__eye:hover{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover)}',
|
|
414
429
|
'.dsh-aigc-cfg__toggle{display:flex;align-items:center;gap:8px;font-size:13px;cursor:pointer;min-width:0}',
|
|
415
430
|
'.dsh-aigc-cfg__toggle input{flex:none;width:16px;height:16px;margin:0;accent-color:var(--dsw-alias-state-business-primary);cursor:pointer}',
|
|
416
431
|
'.dsh-aigc-cfg__btn{height:28px;padding:0 12px;border:1px solid var(--dsw-alias-border-l2);border-radius:8px;background:transparent;color:var(--dsw-alias-label-primary);font:inherit;font-size:12px;cursor:pointer;white-space:nowrap}',
|
|
@@ -521,6 +536,35 @@ window.__ModuleLoader__.load({
|
|
|
521
536
|
})
|
|
522
537
|
}
|
|
523
538
|
|
|
539
|
+
// 密码态输入 + 眼睛图标切换:默认打点显示斜杠眼,点击切换明文(用于 Connect token 等敏感值)
|
|
540
|
+
function secretInput({ value, onChange, placeholder }) {
|
|
541
|
+
const [visible, setVisible] = useState(false)
|
|
542
|
+
const eyeProps = { width: 16, height: 16, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true }
|
|
543
|
+
return h('div', { className: 'dsh-aigc-cfg__secret' },
|
|
544
|
+
h('input', {
|
|
545
|
+
className: 'dsh-aigc-cfg__inp',
|
|
546
|
+
type: visible ? 'text' : 'password',
|
|
547
|
+
value: value ?? '',
|
|
548
|
+
placeholder: placeholder || '',
|
|
549
|
+
autoComplete: 'off',
|
|
550
|
+
spellCheck: false,
|
|
551
|
+
onChange: event => onChange(event.target.value),
|
|
552
|
+
}),
|
|
553
|
+
h('button', {
|
|
554
|
+
type: 'button',
|
|
555
|
+
className: 'dsh-aigc-cfg__eye',
|
|
556
|
+
'aria-label': visible ? '隐藏' : '显示',
|
|
557
|
+
onClick: () => setVisible(v => !v),
|
|
558
|
+
}, visible
|
|
559
|
+
? h('svg', eyeProps,
|
|
560
|
+
h('path', { d: 'M1 12s4-7 11-7 11 7 11 7-4 7-11 7-11-7-11-7z' }),
|
|
561
|
+
h('circle', { cx: 12, cy: 12, r: 3 }))
|
|
562
|
+
: h('svg', eyeProps,
|
|
563
|
+
h('path', { d: 'M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24' }),
|
|
564
|
+
h('line', { x1: 1, y1: 1, x2: 23, y2: 23 }))),
|
|
565
|
+
)
|
|
566
|
+
}
|
|
567
|
+
|
|
524
568
|
function selectControl(options, value, onChange) {
|
|
525
569
|
const current = value ?? ''
|
|
526
570
|
const list = options.slice()
|
|
@@ -870,7 +914,7 @@ window.__ModuleLoader__.load({
|
|
|
870
914
|
h('div', { className: 'dsh-aigc-cfg__card' },
|
|
871
915
|
cardHead('连接 Token', '网页与脚本访问本地服务用的 Connect token'),
|
|
872
916
|
h('div', { className: 'dsh-aigc-cfg__grid2' },
|
|
873
|
-
settingsField('Connect token',
|
|
917
|
+
settingsField('Connect token', h(secretInput, { value: project.bridgeToken || '', onChange: value => updateProject('bridgeToken', value.trim()), placeholder: '留空 = 自动(已默认填充当前 token)' })),
|
|
874
918
|
),
|
|
875
919
|
h('p', { className: 'dsh-aigc-cfg__note' },
|
|
876
920
|
'服务启动后会把当前 token 默认填充到这里。改成自定义值并「重启服务」后,插件以固定 token 拉起服务;清空再重启则恢复自动 token。网页端始终经 /bootstrap 自动领取,无需手动填写。'),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haitang-hub/dsh-3d-director-desk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.23",
|
|
4
4
|
"description": "3D导演台:基于 three.js 的 3D 场景导演台,摆放角色、运镜、时间轴预演与镜头导出,AI Agent 经本地零依赖 MCP 桥实时编排场景,支持从无限画布跨项目导入",
|
|
5
5
|
"icon": "./icon.png",
|
|
6
6
|
"type": "module",
|
|
@@ -54,14 +54,15 @@
|
|
|
54
54
|
]
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
|
-
"dependencies": {
|
|
58
|
-
"@deepseek-ai/schemastery": "3.18.5"
|
|
59
|
-
},
|
|
60
57
|
"peerDependencies": {
|
|
61
58
|
"@deepseek-ai/cordis": "^4.0.2",
|
|
62
|
-
"@deepseek-ai/dsh-client-connection": "
|
|
63
|
-
"@deepseek-ai/dsh-client-ui-sidebar-right": "
|
|
64
|
-
"@deepseek-ai/dsh-mcp-client": "
|
|
59
|
+
"@deepseek-ai/dsh-client-connection": ">=0.2.0-rc.1 <0.3.0",
|
|
60
|
+
"@deepseek-ai/dsh-client-ui-sidebar-right": ">=0.2.0-rc.1 <0.3.0",
|
|
61
|
+
"@deepseek-ai/dsh-mcp-client": ">=0.2.0-rc.1 <0.3.0",
|
|
62
|
+
"@deepseek-ai/schemastery": "^3.18.5",
|
|
65
63
|
"react": "^18.2.0"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@deepseek-ai/schemastery": "3.18.5"
|
|
66
67
|
}
|
|
67
68
|
}
|