@wbohui123/blueprint-studio 0.0.0-stage → 2.0.0
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 +661 -0
- package/README.md +72 -2
- package/package.json +33 -4
- package/src/DeepSeek/344/275/231/351/242/235.js +33 -0
- package/src/index.js +5307 -0
- package/src//344/272/247/347/211/251.js +386 -0
- package/src//344/273/273/345/212/241/345/273/212/351/242/204/350/247/210.js +119 -0
- package/src//344/274/232/350/257/235/345/277/253/347/205/247/350/257/273/345/217/226.js +14 -0
- package/src//345/200/237/346/235/245/347/232/204//344/272/247/347/211/251.js +87 -0
- package/src//345/200/237/346/235/245/347/232/204//345/252/222/344/275/223/346/234/215/345/212/241.js +485 -0
- package/src//345/200/237/346/235/245/347/232/204//345/274/200/347/273/210/347/253/257.js +44 -0
- package/src//345/200/237/346/235/245/347/232/204//346/235/202/351/241/271.js +67 -0
- package/src//345/200/237/346/235/245/347/232/204//346/256/213/347/225/231/350/277/233/347/250/213.js +181 -0
- package/src//345/200/237/346/235/245/347/232/204//346/266/210/346/201/257/345/215/217/350/256/256.js +48 -0
- package/src//345/200/237/346/235/245/347/232/204//347/225/231/344/270/213/347/232/204/350/277/233/347/250/213.js +35 -0
- package/src//345/200/237/346/235/245/347/232/204//347/273/210/347/253/257.js +20 -0
- package/src//345/200/237/346/235/245/347/232/204//350/243/205/346/217/220/344/276/233/346/226/271.js +26 -0
- package/src//345/200/237/346/235/245/347/232/204//350/267/257/345/276/204.js +21 -0
- package/src//345/200/237/346/235/245/347/232/204//351/227/256/347/255/224.js +48 -0
- package/src//345/200/237/346/235/245/347/232/204//351/241/271/347/233/256/345/210/240/351/231/244/347/212/266/346/200/201.js +5 -0
- package/src//345/200/237/346/235/245/347/232/204//351/241/271/347/233/256/345/220/215/347/247/260.js +116 -0
- package/src//345/200/237/346/235/245/347/232/204//351/241/271/347/233/256/345/255/230/345/202/250.js +92 -0
- package/src//345/200/237/346/235/245/347/232/204//351/241/271/347/233/256/351/231/204/344/273/266.js +55 -0
- package/src//345/201/234/346/255/242/345/220/216/345/217/260.js +18 -0
- package/src//345/212/251/347/220/206.js +157 -0
- package/src//345/220/215/345/206/214/350/247/206/345/233/276.js +251 -0
- package/src//345/220/215/345/206/214/350/257/273/347/274/223/345/255/230.js +70 -0
- package/src//345/233/236/350/257/235/346/217/220/351/206/222.js +38 -0
- package/src//345/233/276/347/272/270/345/256/236/346/227/266.js +91 -0
- package/src//345/244/226/351/203/250run/344/272/247/347/211/251.js +75 -0
- package/src//345/244/226/351/203/250run/350/247/206/345/233/276.js +86 -0
- package/src//345/244/226/351/203/250/345/215/217/345/212/251.js +101 -0
- package/src//345/252/222/344/275/223/350/256/276/347/275/256.js +12 -0
- package/src//345/255/220/344/273/243/347/220/206.js +337 -0
- package/src//345/256/236/346/227/266/350/276/223/345/207/272.js +90 -0
- package/src//345/267/245/344/275/234/346/227/266/351/227/264.js +170 -0
- package/src//345/271/263/345/217/260/345/205/245/345/217/243.js +703 -0
- package/src//346/211/247/350/241/214/350/203/275/345/212/233.js +2 -0
- package/src//346/214/201/347/273/255/347/233/256/346/240/207.js +3 -0
- package/src//346/217/220/347/244/272/347/273/237/350/256/241.js +24 -0
- package/src//346/226/207/344/273/266/345/244/271.js +26 -0
- package/src//346/226/260/345/220/215/345/206/214.js +145 -0
- package/src//346/226/260/351/241/271/347/233/256.js +203 -0
- package/src//346/227/247/345/212/237/350/203/275/346/241/251.js +34 -0
- package/src//346/235/220/346/226/231.js +97 -0
- package/src//346/240/221/346/221/230/350/246/201/347/233/230.js +37 -0
- package/src//346/240/221/350/264/246/346/234/254.js +11 -0
- package/src//347/225/214/351/235/242/350/257/255/350/250/200.js +25 -0
- package/src//347/273/210/347/253/257.js +128 -0
- package/src//350/212/202/347/202/271/344/277/241/346/201/257.js +56 -0
- package/src//350/256/260/345/277/206/345/205/245/345/217/243.js +51 -0
- package/src//350/275/257/344/273/266.js +227 -0
- package/src//350/277/220/350/241/214/347/212/266/346/200/201.js +38 -0
- package/src//350/277/236/346/216/245.js +385 -0
- package/src//351/227/256/347/255/224/351/223/276.js +160 -0
- package/src//351/241/271/347/233/256/345/210/206/347/273/204.js +67 -0
- package/src//351/241/271/347/233/256/345/220/215/347/247/260/345/205/245/345/217/243.js +23 -0
- package/src//351/241/271/347/233/256/345/255/230/345/202/250/345/205/245/345/217/243.js +30 -0
- package/src//351/241/271/347/233/256/346/223/215/344/275/234.js +34 -0
- package/src//351/241/271/347/233/256/350/207/252/345/212/250/345/201/234/346/255/242.js +107 -0
- package/src//351/241/271/347/233/256/350/256/241/351/207/217.js +114 -0
- package/src//351/242/204/350/247/210.js +157 -0
- package/viewer//347/225/214/351/235/242/350/257/255/350/250/200.js +97 -0
- package/viewer//350/213/261/346/226/207.json +1535 -0
- package//345/215/225/344/273/267.json +126 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { watch, watchFile, unwatchFile } from 'node:fs'
|
|
2
|
+
import { stat, readFile } from 'node:fs/promises'
|
|
3
|
+
import { createHash } from 'node:crypto'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import { 文档夹名, 名册文件名 } from './新名册.js'
|
|
6
|
+
|
|
7
|
+
const fileStamp = async path => {
|
|
8
|
+
try {
|
|
9
|
+
const s = await stat(path, { bigint: true })
|
|
10
|
+
return [s.dev, s.ino, s.size, s.mtimeNs, s.ctimeNs].join(':')
|
|
11
|
+
} catch (error) { if (error.code === 'ENOENT') return ''; throw error }
|
|
12
|
+
}
|
|
13
|
+
const contentHash = async path => {
|
|
14
|
+
try { return createHash('sha256').update(await readFile(path)).digest('hex') }
|
|
15
|
+
catch (error) { if (error.code === 'ENOENT') return ''; throw error }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** 图纸的树通过现有 stream 推送(11-22 起按项目文件夹盯:`root` 是项目文件夹,树是 `{ 根们, 节点们 }`)。
|
|
19
|
+
* 节点跑着时系统文档一直在变:一阵变动并成一次读,同一项目最多 `间隔` 读一次;读出来跟上次推的一样就不推(11-09)。
|
|
20
|
+
* 节点的会话在跑/停了(`update(会话)`)也重读一次:卡上的状态跟着变。 */
|
|
21
|
+
const 会话们Of = tree => new Set(Object.values(tree?.节点们 || {}).map(节 => 节.会话).filter(Boolean))
|
|
22
|
+
export function 创建图纸实时({ read, send, 间隔 = 1000, 合并 = 250, now = Date.now }) {
|
|
23
|
+
const projects = new Map()
|
|
24
|
+
function schedule(item) {
|
|
25
|
+
if (item.timer) return // 已排上的那一趟开读时读的就是最新
|
|
26
|
+
const wait = Math.max(合并, 间隔 - (now() - (item.readAt ?? -Infinity)))
|
|
27
|
+
item.timer = setTimeout(run, wait, item)
|
|
28
|
+
}
|
|
29
|
+
async function run(item) {
|
|
30
|
+
item.timer = null
|
|
31
|
+
if (item.reading) { item.again = true; return }
|
|
32
|
+
item.reading = true
|
|
33
|
+
item.readAt = now()
|
|
34
|
+
try {
|
|
35
|
+
const tree = await read(item.root, item.cwd)
|
|
36
|
+
if (projects.get(item.root) !== item) return
|
|
37
|
+
item.tree = tree
|
|
38
|
+
item.ids = 会话们Of(tree)
|
|
39
|
+
const text = JSON.stringify(tree)
|
|
40
|
+
if (text === item.sent) return
|
|
41
|
+
item.sent = text
|
|
42
|
+
send({ type: 'blueprint.tree', 项目: item.root, root: item.root, tree })
|
|
43
|
+
} catch (error) {
|
|
44
|
+
item.sent = undefined // 报过错,下一份好树照推
|
|
45
|
+
send({ type: 'blueprint.tree_error', root: item.root, message: error.message })
|
|
46
|
+
} finally { item.reading = false; if (item.again) { item.again = false; schedule(item) } }
|
|
47
|
+
}
|
|
48
|
+
function remove(item) {
|
|
49
|
+
clearTimeout(item.timer); item.watcher?.close()
|
|
50
|
+
if (item.checkRoster) unwatchFile(item.path, item.checkRoster)
|
|
51
|
+
projects.delete(item.root)
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
async track(root, cwd, tree, rows = null, supplement = false) {
|
|
55
|
+
const ids = rows ? new Set(rows.map(r => r.id)) : 会话们Of(tree)
|
|
56
|
+
const prior = projects.get(root)
|
|
57
|
+
if (prior) { prior.tree = tree; prior.ids = ids; if (supplement) schedule(prior); return }
|
|
58
|
+
// 名册在 `系统文档/信息.db`(SQLite,每次提交都改主文件),照旧按文件签和内容盯着它。
|
|
59
|
+
const directory = join(cwd, 文档夹名), path = join(directory, 名册文件名)
|
|
60
|
+
const item = { root, cwd, tree, path, ids, stamp: await fileStamp(path), hash: await contentHash(path) }
|
|
61
|
+
projects.set(root, item)
|
|
62
|
+
item.checkRoster = () => {
|
|
63
|
+
void fileStamp(path).then(async stamp => {
|
|
64
|
+
if (projects.get(root) !== item || stamp === item.stamp) return
|
|
65
|
+
item.stamp = stamp
|
|
66
|
+
const hash = await contentHash(path)
|
|
67
|
+
if (projects.get(root) !== item) return
|
|
68
|
+
if (hash !== item.hash) { item.hash = hash; send({ type: 'blueprint.roster_changed', root }) }
|
|
69
|
+
}).catch(error => send({ type: 'blueprint.tree_error', root, message: error.message }))
|
|
70
|
+
}
|
|
71
|
+
// 名册单文件签轮询也覆盖 sandbox 中不投递原生目录事件的环境。
|
|
72
|
+
watchFile(path, { persistent: false, interval: 250 }, item.checkRoster)
|
|
73
|
+
try {
|
|
74
|
+
item.watcher = watch(directory, { recursive: true }, () => {
|
|
75
|
+
item.checkRoster()
|
|
76
|
+
schedule(item) // 总图景、纸条、模型等只读投影也随文件变化推送。
|
|
77
|
+
})
|
|
78
|
+
item.watcher.on('error', error => send({ type: 'blueprint.tree_error', root, message: error.message }))
|
|
79
|
+
} catch (error) { send({ type: 'blueprint.tree_error', root, message: error.message }) }
|
|
80
|
+
if (supplement) schedule(item)
|
|
81
|
+
while (projects.size > 16) remove(projects.values().next().value)
|
|
82
|
+
},
|
|
83
|
+
update(session) {
|
|
84
|
+
// 平台入口改完节点传的是项目文件夹:根本身也认。
|
|
85
|
+
for (const item of projects.values()) if (!session || item.ids.has(String(session)) || item.root === String(session)) schedule(item)
|
|
86
|
+
},
|
|
87
|
+
forget(root) { const item = projects.get(root); if (item) remove(item) },
|
|
88
|
+
snapshots() { return [...projects.values()].map(item => ({ type: 'blueprint.tree', 项目: item.root, root: item.root, tree: item.tree })) },
|
|
89
|
+
dispose() { for (const item of [...projects.values()]) remove(item) },
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** 外部节点(codex/claude-code)做的过程中动过的文件;文件存在不等于已经交付或验证。
|
|
2
|
+
* 1.1.8 是从它自己的工作目录(git 空间)算的;新结构在项目里做、没有各自的空间,改成照它这一次的过程记录里报的改文件那几步列(跑命令改的不在里面)。 */
|
|
3
|
+
import { readFile, stat, realpath } from 'node:fs/promises'
|
|
4
|
+
import { join, basename, isAbsolute } from 'node:path'
|
|
5
|
+
import { 产物路径, 产物类型, 安全产物文件, 汇集产物 } from './产物.js'
|
|
6
|
+
import { 开信息库, 节点Of } from '../../blueprint-defaults/src/index.js'
|
|
7
|
+
import { 是外部worker, 外部worker在跑 } from '../../blueprint-defaults/src/外部agent/外部worker.js'
|
|
8
|
+
import { 过程步骤, 解析过程记录 } from '../../blueprint-defaults/src/外部agent/过程.js'
|
|
9
|
+
import { 读Codex对话 } from '../../blueprint-defaults/src/外部agent/Codex会话.js'
|
|
10
|
+
import { 材料分页 } from './材料.js'
|
|
11
|
+
import { 译 } from './界面语言.js'
|
|
12
|
+
|
|
13
|
+
/** 外部节点没有会话;用项目会话授权、节点表定位,沿普通文件廊的卡片协议返回。 */
|
|
14
|
+
export async function 外部run文件页(root, { session, id, ...filter }) {
|
|
15
|
+
const 库 = 开信息库(root)
|
|
16
|
+
if (!库) throw new Error('这个项目没有节点表')
|
|
17
|
+
const 节 = 节点Of(库, String(id))
|
|
18
|
+
if (!是外部worker(节)) throw new Error('请选择 Codex/Claude Code 节点')
|
|
19
|
+
const live = await 外部run实时产物(root, 节.编号)
|
|
20
|
+
const refs = live.文件们.filter(file => !file.已删除).map(file => ({ path: file.位置, title: basename(file.名字), kind: file.类型 || 产物类型(file.位置),
|
|
21
|
+
session, time: file.修改于 || 0, seq: 0, source: '实时文件' }))
|
|
22
|
+
const items = (await 汇集产物(root, refs, [], [])).map(item => ({ ...item, live: true,
|
|
23
|
+
history: [], nodeId: 节.编号, nodeName: 节.名字 }))
|
|
24
|
+
return { ...材料分页(items, filter), view: 'live', path: '', shared: false,
|
|
25
|
+
warnings: [live.可用 ? !外部worker在跑(root, 节.编号) && 节.外部?.state === 'done' ? 译('这里是本次工作目录中的文件,交付结论见执行记录。')
|
|
26
|
+
: 译('自动读取工作目录中的新建和改动文件,仍在制作,可能尚未写完整。')
|
|
27
|
+
: 译('实时文件暂不可读取,执行记录仍会更新。')] }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** 外部节点一句话里点名的文件(原样路径):[字](路径)、[字](<路径>)、反引号里的,还有 Codex 内嵌组件 visualize 的 path
|
|
31
|
+
(U+E200 名字 U+E202 JSON U+E201,11-26)。链接末尾的行号(`:21`、`:21:5`、`#L21`、`#L21-L30`)去掉(11-26 截图:带行号的找不到文件)。 */
|
|
32
|
+
export function 外部话里点名(文) {
|
|
33
|
+
const s = String(文 || ''), 们 = []
|
|
34
|
+
const 正文 = s.replace(/([^]*)([^]*)/g, (_, 名, json) => {
|
|
35
|
+
if (名.trim() === 'visualize') try { const path = JSON.parse(json)?.path; if (typeof path === 'string' && path.trim()) 们.push(path.trim()) } catch { /* 坏的 JSON 不算 */ }
|
|
36
|
+
return ' '
|
|
37
|
+
})
|
|
38
|
+
for (const m of 正文.matchAll(/\]\s*\(<([^>\n]+)>\)|\]\s*\(([^)\s]+)\)|`([^`\n]+)`/g)) 们.push(m[1] || m[2] || m[3])
|
|
39
|
+
return 们.map(路 => String(路 || '').trim().replace(/(?:#L\d+(?:C\d+)?(?:-L?\d+(?:C\d+)?)?|:\d+(?::\d+)?)$/, '')).filter(Boolean)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function 外部run实时产物(root, id) {
|
|
43
|
+
try {
|
|
44
|
+
const 库 = 开信息库(root), 节 = 库 && 节点Of(库, String(id)), log = 节?.外部?.log
|
|
45
|
+
// Codex 节点(11-25 起是一条会话)、Claude Code 节点(11-26 起同一种记录,谁=claude)改的文件、出的图记在 对话.jsonl(Codex 给的是绝对路径,在项目里的折成相对);
|
|
46
|
+
// 11-25 用户:「codex 节点的文件廊里面没有正常显示文件」——原来只读一次性 exec 的过程记录(外部.log),Codex 节点没有它。
|
|
47
|
+
const 对话 = 节 ? await 读Codex对话(root, 节.编号).catch(() => []) : []
|
|
48
|
+
// 它跑命令拷进项目的(比如把生成的图 cp 进 产出/)不记成改文件;它在话里链出来、用反引号点名的项目里的文件也算(和普通节点正文里点名的文件一样),不存在的不列。
|
|
49
|
+
const 话里的 = new Set(对话.filter(条 => (条.谁 === 'codex' || 条.谁 === 'claude') && 条.类 === '话').flatMap(条 =>
|
|
50
|
+
外部话里点名(条.文))
|
|
51
|
+
.map(路 => 产物路径(root, String(路 || ''), { any: true })?.path).filter(Boolean))
|
|
52
|
+
const 对话里的 = [...对话.flatMap(条 => 条.类 === '改文件' ? (条.文件们 || []).map(x => x.路径) : 条.类 === '图' ? [条.文件] : [])
|
|
53
|
+
.map(路 => 产物路径(root, String(路 || ''), { any: true })?.path).filter(Boolean), ...话里的]
|
|
54
|
+
if (!log && !对话里的.length) return { 可用: !!对话.length, 文件们: [] }
|
|
55
|
+
const 行们 = log ? 解析过程记录(await readFile(join(root, log), 'utf8').catch(() => '')) : []
|
|
56
|
+
const 空间 = await realpath(root).catch(() => root)
|
|
57
|
+
const names = [...new Set([...过程步骤(行们, { 空间 }).filter(步 => 步.类 === '改文件').flatMap(步 => 步.文.split('、')).map(名 => 名.trim()).filter(名 => 名 && !isAbsolute(名)), ...对话里的])]
|
|
58
|
+
const files = []
|
|
59
|
+
for (let start = 0; start < names.length; start += 16) {
|
|
60
|
+
const batch = await Promise.all(names.slice(start, start + 16).map(async name => {
|
|
61
|
+
const entry = 产物路径(root, name, { any: true })
|
|
62
|
+
if (!entry) return null
|
|
63
|
+
try {
|
|
64
|
+
const info = await stat(await 安全产物文件(root, name, { preview: true }))
|
|
65
|
+
if (!info.isFile()) return null
|
|
66
|
+
return { 名字: name, 位置: entry.path, 类型: 产物类型(name), 字节: info.size, 修改于: info.mtimeMs }
|
|
67
|
+
} catch (error) {
|
|
68
|
+
return error.code === 'ENOENT' && !话里的.has(entry.path) ? { 名字: name, 位置: entry.path, 已删除: true } : null
|
|
69
|
+
}
|
|
70
|
+
}))
|
|
71
|
+
files.push(...batch.filter(Boolean))
|
|
72
|
+
}
|
|
73
|
+
return { 可用: true, 文件们: files.sort((a, b) => (b.修改于 || 0) - (a.修改于 || 0) || a.名字.localeCompare(b.名字)) }
|
|
74
|
+
} catch { return { 可用: false, 文件们: [] } }
|
|
75
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/** 外部节点(类型是 codex/claude-code,交给它们的程序跑)的 Chat:历次实际启动输入与执行过程,只读。
|
|
2
|
+
* GET /studio/api/external-run?项目=<项目文件夹>|session=<项目里任一会话>&id=<节点编号>
|
|
3
|
+
* 11-22:不再有任务表;节点按类型认,状态看进程在不在跑、有没有交回(defaults 的 外部agent/外部worker.js 记在节点的「外部」那一栏)。 */
|
|
4
|
+
import { readFile, readdir, realpath } from 'node:fs/promises'
|
|
5
|
+
import { join } from 'node:path'
|
|
6
|
+
import { 开信息库, 节点Of } from '../../blueprint-defaults/src/index.js'
|
|
7
|
+
import { 外部执行者Of, 外部worker在跑, 外部worker收尾中, 外部记录夹相对, 系统补线 } from '../../blueprint-defaults/src/外部agent/外部worker.js'
|
|
8
|
+
import { 过程步骤, 解析过程记录 } from '../../blueprint-defaults/src/外部agent/过程.js'
|
|
9
|
+
import { 外部run实时产物 } from './外部run产物.js'
|
|
10
|
+
import { 读子代理开关 } from '../../blueprint-defaults/src/外部agent/开关.js'
|
|
11
|
+
|
|
12
|
+
/** 页面认的三档:在跑 → 开工;做完了(state done)→ 完成;跑过、停着 → 开工(停着的原因另写);没跑过 → 待做。 */
|
|
13
|
+
const 三档 = (在跑, e) => 在跑 ? '开工' : e.state === 'done' ? '完成' : e.attempt ? '开工' : '待做'
|
|
14
|
+
|
|
15
|
+
/** 只读已落盘的输入快照,不用当前请求或提示模板重建历史。 */
|
|
16
|
+
async function 历次过程(根, 节, 空间) {
|
|
17
|
+
const e = 节.外部 || {}, 夹 = join(根, 外部记录夹相对(节.编号))
|
|
18
|
+
const 文件们 = await readdir(夹, { withFileTypes: true }).catch(error => { if (error.code === 'ENOENT') return []; throw error })
|
|
19
|
+
const 次数们 = 文件们.filter(file => file.isFile() && /^第[1-9]\d*次\.jsonl$/.test(file.name)).map(file => Number(file.name.slice(1, -7)))
|
|
20
|
+
if (e.attempt && !次数们.includes(e.attempt)) 次数们.push(e.attempt)
|
|
21
|
+
return Promise.all(次数们.sort((a, b) => a - b).map(async 次 => {
|
|
22
|
+
const 记录 = await readFile(join(夹, `第${次}次.jsonl`), 'utf8').catch(error => { if (error.code === 'ENOENT') return ''; throw error })
|
|
23
|
+
const 行们 = 解析过程记录(记录), 输入 = 行们.find(row => row.blueprint === 'input' && typeof row.prompt === 'string')
|
|
24
|
+
const 当前 = 次 === e.attempt
|
|
25
|
+
const 开始 = 输入?.startedAt || (当前 ? e.startedAt : undefined)
|
|
26
|
+
return { 次, 执行者: 输入?.executor || (当前 ? 外部执行者Of(节).名字 : ''),
|
|
27
|
+
model: 输入?.model ?? (当前 ? e.model || '' : ''), effort: 输入?.effort ?? (当前 ? e.effort || '' : ''),
|
|
28
|
+
输入: 输入 ? { prompt: 输入.prompt, 交回格式: 输入.outputSchema || null } : null,
|
|
29
|
+
任务: 输入?.task && typeof 输入.task.name === 'string' && typeof 输入.task.goal === 'string' ? { 名字: 输入.task.name, 目标: 输入.task.goal } : null,
|
|
30
|
+
步骤: 过程步骤(行们, { 开始, 空间 }),
|
|
31
|
+
正文步骤: 过程步骤(行们, { 开始, 空间, 完整: true }) }
|
|
32
|
+
}))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** 一个外部节点此刻的样子:头一行的事实、每一步、交回、停着的原因、额度、接在谁后面。 */
|
|
36
|
+
export async function 外部run过程(根, id) {
|
|
37
|
+
const 库 = 开信息库(根)
|
|
38
|
+
if (!库) throw new Error('这个项目没有节点表')
|
|
39
|
+
const 节 = 节点Of(库, String(id)), 执行者 = 外部执行者Of(节)
|
|
40
|
+
if (!执行者) throw new Error(`${id} 不是 Codex/Claude Code 节点`)
|
|
41
|
+
const e = 节.外部 || {}
|
|
42
|
+
const 空间 = await realpath(根).catch(() => 根)
|
|
43
|
+
const [历次, 实时产物] = await Promise.all([历次过程(根, 节, 空间), 外部run实时产物(根, 节.编号)])
|
|
44
|
+
const 在跑 = 外部worker在跑(根, 节.编号)
|
|
45
|
+
const 起 = Date.parse(e.startedAt || ''), 止 = 在跑 ? Date.now() : Date.parse(e.endedAt || '')
|
|
46
|
+
const 爹 = 节.上一层 ? 节点Of(库, 节.上一层) : null
|
|
47
|
+
const 交了 = !在跑 && e.state === 'done'
|
|
48
|
+
// 交回的那一段记在节点的「外部」那一栏;系统补的接在补线后面。
|
|
49
|
+
const 交回文 = String(e.lastHandoff || e.lastReport || '')
|
|
50
|
+
const 正文 = 交回文.split(`\n\n${系统补线}\n`)[0], 补 = 交回文.split(`\n\n${系统补线}\n`)[1] || ''
|
|
51
|
+
const 请求 = 节.描述 || ''
|
|
52
|
+
return {
|
|
53
|
+
号: 节.编号, 名字: 节.名字, 执行者: 执行者.名字, 短名: 执行者.短名, model: e.model || '', effort: e.effort || '', 次: e.attempt || 0,
|
|
54
|
+
// 对话页输入框的模型、强度(11-26):节点自己选的(外部.模型,没有=跟项目),和项目「Agent 选择」那一格。
|
|
55
|
+
选模型: e.模型 || null, 项目模型: (() => { try { return 读子代理开关(根).模型?.[执行者.开关] || null } catch { return null } })(),
|
|
56
|
+
// 停着等处理(登录、额度、模型)的,节点状态是停了;页面照 blocked 画「停着:原因」,所以这里的三档算开工。
|
|
57
|
+
state: e.state || '', 在跑, 收尾: 外部worker收尾中(根, 节.编号), 状态: 三档(在跑, e), result: e.result || '', endedAt: e.endedAt || '',
|
|
58
|
+
任务: { 名字: 节.名字, 目标: 请求 }, 实时产物,
|
|
59
|
+
用时: Number.isFinite(起) && Number.isFinite(止) ? Math.max(0, 止 - 起) : null,
|
|
60
|
+
历次, 步骤: 历次.find(次 => 次.次 === e.attempt)?.步骤 || [],
|
|
61
|
+
交回: 交了 ? { 结论: e.result === 'achieved' ? '已交回·达成' : e.result === 'unmet' ? '已交回·未达成' : '已交回', 正文: (正文 || '').trim(), 系统补: (补 || '').trim() } : null,
|
|
62
|
+
问题: 交了 ? e.lastQuestion || '' : '', 原因: e.reason || '', 停因: e.stopReason || '', 额度: e.quota || null,
|
|
63
|
+
已验证: 交了 ? e.lastChecked || '' : '', 未验证: '',
|
|
64
|
+
交付异常: null,
|
|
65
|
+
母节点: 爹 ? { 号: 爹.编号, 名字: 爹.名字, 会话: 爹.会话 || '', 文档: '' } : null,
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** 路由:项目文件夹或会话认项目,号认那个节点。 */
|
|
70
|
+
export function 外部run视图HTTP(json, { 项目根Of }) {
|
|
71
|
+
return async (req, res, url) => {
|
|
72
|
+
if (req.method !== 'GET') return json(res, 405, { ok: false, message: '只能读' })
|
|
73
|
+
try {
|
|
74
|
+
const 根 = await 项目根Of({ 项目: url.searchParams.get('项目'), session: url.searchParams.get('session') })
|
|
75
|
+
const value = await 外部run过程(根, url.searchParams.get('id'))
|
|
76
|
+
// 工作界面只接收可阅读的任务与执行记录;原始输入接口继续供诊断调用方使用。
|
|
77
|
+
const result = url.searchParams.get('视图') === '工作' ? { ...value,
|
|
78
|
+
历次: value.历次.map(({ 输入, 正文步骤, 步骤, ...attempt }) => ({ ...attempt, 步骤: 正文步骤 })),
|
|
79
|
+
步骤: value.历次.find(attempt => attempt.次 === value.次)?.正文步骤 || [],
|
|
80
|
+
交回: value.交回 ? { 结论: value.交回.结论, 正文: value.交回.正文 } : null } : value
|
|
81
|
+
return json(res, 200, { ok: true, value: result })
|
|
82
|
+
} catch (error) {
|
|
83
|
+
return json(res, 200, { ok: false, message: String(error?.message || error) })
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { isAbsolute } from 'node:path'
|
|
2
|
+
import { 会话观察 } from './实时输出.js'
|
|
3
|
+
import { 工具结果失败 } from './借来的/消息协议.js'
|
|
4
|
+
import { 项目操作会话 } from './项目操作.js'
|
|
5
|
+
|
|
6
|
+
export const 外部运行状态 = new Set(['running', 'stopping', 'settling'])
|
|
7
|
+
const textOf = content => (content || []).filter(block => block?.type === 'text').map(block => block.text).join('\n')
|
|
8
|
+
const receiptOf = event => event.type === 'tool/result' && !工具结果失败(event)
|
|
9
|
+
? event.data?.meta?.blueprintExternal : null
|
|
10
|
+
const recorded = value => value && typeof value.id === 'string' && value.id
|
|
11
|
+
&& typeof value.provider === 'string' && value.provider && typeof value.cwd === 'string' && isAbsolute(value.cwd)
|
|
12
|
+
const settled = message => message?.source?.kind === 'subagent-settled'
|
|
13
|
+
&& typeof message.source.senderSessionId === 'string'
|
|
14
|
+
|
|
15
|
+
// catalog 决定直父归属;meta 是启动目录/提供方,Inbox 和已消费消息是原生报告。
|
|
16
|
+
// 不从工具名称、英文通知或没有本地 Session 推断提供方与成功/失败。
|
|
17
|
+
export function 外部协助投影(catalog, events, inbox, live, parentSessionId, inheritedEventCount = 0) {
|
|
18
|
+
const own = events.filter(event => event.seq >= inheritedEventCount)
|
|
19
|
+
const receipts = new Map(), reports = new Map(), accepted = new Map()
|
|
20
|
+
for (const event of own) {
|
|
21
|
+
const receipt = receiptOf(event)
|
|
22
|
+
if (recorded(receipt)) receipts.set(receipt.id, receipt)
|
|
23
|
+
if (event.type === 'agent/inbox/spliced') {
|
|
24
|
+
for (const message of event.data?.inserted || []) if (settled(message)) accepted.set(message.id, event.seq)
|
|
25
|
+
}
|
|
26
|
+
if (event.type === 'user/message' && settled(event.data)) {
|
|
27
|
+
const message = event.data
|
|
28
|
+
reports.set(message.source.senderSessionId, { summary: message.source.summary || '',
|
|
29
|
+
text: textOf(message.content), seq: event.seq, messageId: message.id, pending: false })
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
for (const message of [...(inbox?.['next-turn'] || []), ...(inbox?.['next-step'] || [])]) {
|
|
33
|
+
if (!settled(message) || reports.get(message.source.senderSessionId)?.messageId === message.id) continue
|
|
34
|
+
reports.set(message.source.senderSessionId, { summary: message.source.summary || '',
|
|
35
|
+
text: textOf(message.content), seq: accepted.get(message.id), messageId: message.id, pending: true })
|
|
36
|
+
}
|
|
37
|
+
const active = new Map((live || []).filter(row => row.parentSessionId === parentSessionId
|
|
38
|
+
&& 外部运行状态.has(row.status)).map(row => [row.id, row]))
|
|
39
|
+
return catalog.filter(row => row.mode === 'external').map(row => {
|
|
40
|
+
const execution = active.get(row.id), receipt = receipts.get(row.id), report = reports.get(row.id)
|
|
41
|
+
const identity = recorded(execution) ? execution : receipt
|
|
42
|
+
return { id: row.id, parentSessionId, label: row.label || row.id, createdAt: row.createdAt,
|
|
43
|
+
...(identity ? { provider: identity.provider, cwd: identity.cwd } : {}),
|
|
44
|
+
status: execution?.status || (report ? 'reported' : 'unknown'),
|
|
45
|
+
canStop: !!execution,
|
|
46
|
+
...(report ? { report } : {}) }
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function 原生外部运行(ctx, parentSessionId) {
|
|
51
|
+
const subagents = ctx.get('subagents')
|
|
52
|
+
if (typeof subagents?.listExternalActivations !== 'function') throw new Error('原生外部任务运行查询不可用')
|
|
53
|
+
return subagents.listExternalActivations(parentSessionId)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 与普通会话名单取同一项目成员;先读原生 live 对象,只核对活任务直父目录。
|
|
57
|
+
// 无活任务不准备整个项目的冷账本,也不把 external 伪装成 Session。
|
|
58
|
+
export async function 项目外部目录(ctx, members, projectSessionId, signal) {
|
|
59
|
+
const subagents = ctx.get('subagents')
|
|
60
|
+
if (!subagents?.listChildren) return []
|
|
61
|
+
const parents = new Set(members.map(parent => String(parent.sessionId)))
|
|
62
|
+
const live = 原生外部运行(ctx).filter(row => parents.has(String(row.parentSessionId)))
|
|
63
|
+
const catalogs = new Map(await Promise.all([...new Set(live.map(row => row.parentSessionId))]
|
|
64
|
+
.map(async parent => [parent, await subagents.listChildren(parent, signal)])))
|
|
65
|
+
return live.filter(row => catalogs.get(row.parentSessionId).some(child => child.mode === 'external' && child.id === row.id))
|
|
66
|
+
.map(row => ({ id: row.id, parentSessionId: row.parentSessionId, projectSessionId: String(projectSessionId), status: row.status }))
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export async function 读取外部协助(ctx, parentSessionId, { signal, live } = {}) {
|
|
70
|
+
const subagents = ctx.get('subagents')
|
|
71
|
+
if (!subagents?.listChildren) throw new Error('原生子任务目录不可用')
|
|
72
|
+
const catalog = await subagents.listChildren(parentSessionId, signal)
|
|
73
|
+
if (!catalog.some(row => row.mode === 'external')) return { rows: [] }
|
|
74
|
+
let missing
|
|
75
|
+
if (!live) {
|
|
76
|
+
try { live = 原生外部运行(ctx, parentSessionId) }
|
|
77
|
+
catch (error) { live = []; missing = error.message }
|
|
78
|
+
}
|
|
79
|
+
const rows = await 会话观察(ctx.get('sessionQuery'), parentSessionId, source => {
|
|
80
|
+
const inbox = source.projections?.values?.inbox
|
|
81
|
+
if (!inbox) throw new Error('原生 Inbox 投影不可用')
|
|
82
|
+
return 外部协助投影(catalog, source.events, inbox, live, parentSessionId, source.inheritedEventCount)
|
|
83
|
+
}, { signal, projectionMode: 'all' })
|
|
84
|
+
return { rows, ...(missing ? { missing } : {}) }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export async function 停止外部协助(ctx, items, payload) {
|
|
88
|
+
const { projectSessionId, parentSessionId, childSessionId } = payload
|
|
89
|
+
const members = 项目操作会话(items, projectSessionId)
|
|
90
|
+
if (!parentSessionId || !members.some(row => String(row.sessionId) === String(parentSessionId))) {
|
|
91
|
+
throw new Error('外部任务的父会话不属于当前项目,未执行操作')
|
|
92
|
+
}
|
|
93
|
+
const subagents = ctx.get('subagents')
|
|
94
|
+
if (!childSessionId || !subagents?.listChildren || !subagents?.interrupt) throw new Error('外部任务停止入口不可用')
|
|
95
|
+
const catalog = await subagents.listChildren(String(parentSessionId))
|
|
96
|
+
if (!catalog.some(row => row.mode === 'external' && String(row.id) === String(childSessionId))) {
|
|
97
|
+
throw new Error('该父会话未登记这个外部任务,未执行操作')
|
|
98
|
+
}
|
|
99
|
+
subagents.interrupt(String(childSessionId), { kind: 'user', parentSessionId: String(parentSessionId) })
|
|
100
|
+
return { accepted: true }
|
|
101
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** 媒体连接使用原生 Loader 配置,沿 blueprint-media 的 profile patch 保存。 */
|
|
2
|
+
import z from '@deepseek-ai/schemastery'
|
|
3
|
+
import { normalizeMedia } from './借来的/媒体服务.js'
|
|
4
|
+
|
|
5
|
+
export const Config = z.object({
|
|
6
|
+
connections: z.transform(z.dict(z.any()).default({}), connections => {
|
|
7
|
+
for (const [id, profile] of Object.entries(connections)) normalizeMedia({ ...profile, id })
|
|
8
|
+
return connections
|
|
9
|
+
}).volatile(),
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
export function apply() {}
|