@wbohui123/blueprint-host 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 +59 -2
- package/package.json +27 -4
- package/src/index.js +17 -0
- package/src/selector.js +103 -0
- package/src//344/270/223/345/256/266.js +69 -0
- package/src//344/274/232/350/257/235.js +124 -0
- package/src//345/210/206/345/267/245MCP.mjs +69 -0
- package/src//345/210/206/345/267/245/345/267/245/345/205/267.js +108 -0
- package/src//345/220/257/345/201/234.js +275 -0
- package/src//345/244/226/351/203/250/345/247/224/346/264/276.js +22 -0
- package/src//345/244/247/345/270/210.js +110 -0
- package/src//345/252/222/344/275/223/345/267/245/345/205/267.js +77 -0
- package/src//345/272/225/345/272/247.js +26 -0
- package/src//345/275/261/345/255/220.js +223 -0
- package/src//346/217/222/344/273/266/347/233/256/345/275/225.js +159 -0
- package/src//346/235/241.js +165 -0
- package/src//346/241/206/346/236/266.js +396 -0
- package/src//346/250/241/345/236/213.js +48 -0
- package/src//346/250/241/346/235/277.js +177 -0
- package/src//350/212/202/347/202/271/346/217/222/344/273/266.js +405 -0
- package/src//350/243/205/351/205/215.js +150 -0
- package/src//351/222/251/345/255/220.js +122 -0
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 宿主接进 dsh 的那一个插件(协议 第五节):挂在节点的 preset 上(`blueprint/agent.cordis.yml`),所有 Blueprint 节点的事件都经过它。
|
|
3
|
+
*
|
|
4
|
+
* 它做的事(11-22 自由蓝图:节点全部平级,什么时候跑只看用户,见 `启停.js`):
|
|
5
|
+
* - 开张时把自带、用户两层里带代码的插件载进来:底座的做法跑一次 `apply`,所有代码插件的工具注册上;
|
|
6
|
+
* 工具调用时再看这个节点能不能用(底座选的是不是这一种、节点装没装这个插件)。另注册一把:分工的 `propose_nodes`(把方案摆给用户),
|
|
7
|
+
* 所有 dsh 节点都有。11-25 撤了 `hand_back`(用户:「我要最简洁的方式」):分段的节点一段做完就自然停下等用户,下一轮开头选择机照他的话挑哪一段。11-25 撤了 `start_nodes`、总 agent 的 `assign_work`
|
|
8
|
+
* (用户:「整个撤掉,assign_work 也撤」):节点只建结构、写说明,开工只有用户在图上点;要 AI 自己带队做,开 team 节点。
|
|
9
|
+
* - 收件箱(11-24 晚撤了 to_user):节点一轮自然跑完停下,收件箱自动挂一件「待回复」(同一节点只挂一件);按停、出错、被重置的不挂。
|
|
10
|
+
* - 用户直接在节点对话里说话:它待用户的几件收件都算回了(内核 `你开口`)。用户在收件箱输入框对总 agent 说的也一样。
|
|
11
|
+
* - 一轮停下(turn-end)的钩子场里多两样信号(段四,记忆插件靠它决定叫不叫影子、叫哪一份):`改了文件`(这一轮有写、改文件的工具调用成功了)、
|
|
12
|
+
* `用户开口`(这一轮由用户的话起头,或这一轮里用户插过话、调过 `你开口`)。
|
|
13
|
+
* - 每一轮开头:会话第一步(和压缩以后)把【开场】放在最前面,后面跟「节点前」的块;结构变了,插【结构变了】(新的分工表);
|
|
14
|
+
* 各块的 turn-start;选择机挑这一轮的页(`selector.js`)。
|
|
15
|
+
* - 每一步、每一轮停、每次调工具,照框架现查该跑哪些钩子(`钩子.js`),把结果落到 dsh 上:追加的话、拒绝、引导、不许、补充。没有关卡(11-22 段二撤了)。
|
|
16
|
+
* - 节点开会话时挂上技能:装的"挂着"插件,加上仓库 `blueprint/技能/` 里的(分工 skill 在这里)。
|
|
17
|
+
* - 影子的会话不跑钩子,它要调工具一律拦下。
|
|
18
|
+
*/
|
|
19
|
+
import { 插件们, 载代码 } from './插件目录.js'
|
|
20
|
+
import { 读装配, 有效专家 } from './装配.js'
|
|
21
|
+
import { 有效块 } from './框架.js'
|
|
22
|
+
import { 跑钩子, 挂着的 } from './钩子.js'
|
|
23
|
+
import { 选的做法, 底座代码, 底座做法们 } from './底座.js'
|
|
24
|
+
import { 会话服务, 话 } from './会话.js'
|
|
25
|
+
import { 开影子, 影子们, 分叉问, 分叉写 } from './影子.js'
|
|
26
|
+
import { 专家们, 自带技能们 } from './专家.js'
|
|
27
|
+
import { 装媒体工具 } from './媒体工具.js'
|
|
28
|
+
import { 挑应对, 忘了上次, 应对来路 } from './selector.js'
|
|
29
|
+
import { 接上, 删掉的会话, 记住 } from './启停.js'
|
|
30
|
+
import { 开信息库, 会话的节点, 节点Of, 记看到结构, 放收件, 待你的, 你开口, 改收件类, 说话算开始, 回纸条们 } from '../../blueprint-defaults/src/内核/index.js'
|
|
31
|
+
import { 简介上限, 分工参数, 分工说明, 摆方案, 可派外置 as 可派外置Of, 纸条参数, 纸条说明, 递纸条 } from './分工工具.js'
|
|
32
|
+
import { 会话器Of } from '../../blueprint-defaults/src/会话器.js'
|
|
33
|
+
import { 开场段, 结构变了话 } from '../../blueprint-defaults/src/看得到.js'
|
|
34
|
+
import { 工具说明 } from '../../blueprint-defaults/src/页.js'
|
|
35
|
+
import { 测试记录文件 } from '../../blueprint-defaults/src/外部agent/可派.js'
|
|
36
|
+
import { 记原话, 记一轮 } from '../../blueprint-defaults/src/记忆/流水.js'
|
|
37
|
+
import { 记快照 } from '../../blueprint-defaults/src/快照.js'
|
|
38
|
+
import { 设做梦的问 } from '../../blueprint-defaults/src/记忆/梦.js'
|
|
39
|
+
import { 项目模型 } from './模型.js'
|
|
40
|
+
import { BlockAssembler } from '@deepseek-ai/dsh-llm'
|
|
41
|
+
import { 文字Of, 这一轮最后说的 } from '../../blueprint-defaults/src/会话事件.js'
|
|
42
|
+
import { 藏外部委派工具 } from './外部委派.js'
|
|
43
|
+
|
|
44
|
+
export const name = 'blueprint-host'
|
|
45
|
+
export const inject = ['tools']
|
|
46
|
+
|
|
47
|
+
const 喊 = (说, e) => console.log(`Blueprint: ⚠️ ${说}${e ? ` —— ${(e && e.message) || e}` : ''}`)
|
|
48
|
+
const 根Of = agent => agent?.session?.header?.cwd || null
|
|
49
|
+
/** 节点简介(卡上那一行)最多几个字(11-25 用户:「简介不超过 12 个字」;11-26 改成 25:「25 个字差不多?」——卡上简介能写满两行,不然第二行空着)。住在 分工工具.js。 */
|
|
50
|
+
export { 简介上限 }
|
|
51
|
+
const 只回一段字 = Object.freeze({
|
|
52
|
+
schema: { type: 'object', additionalProperties: false, required: ['文'], properties: { 文: { type: 'string' } } },
|
|
53
|
+
render: (_参数, 值) => [{ type: 'text', text: String(值.文) }],
|
|
54
|
+
})
|
|
55
|
+
const 用户原话 = 们 => (们 || []).filter(m => ['user', 'api'].includes(m.source?.kind))
|
|
56
|
+
.map(m => (m.content || []).filter(b => b.type === 'text').map(b => b.text).join('')).join('\n').trim()
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 节点正跑着时用户在它的对话里说话:插进这一轮(`steer`,下一步就送到),不排到下一轮(11-21)。排队那次真跑:
|
|
60
|
+
* 回答等了 18 分钟才送到,期间它撤了那道题、问了新的,回答被当成新题的答案。只改节点会话;普通 dsh 会话照 dsh 自己的设置
|
|
61
|
+
* (用户 11-21:装上 dsh 还是原样)。dsh 收用户的话时调会话的 followup(排队)或 steer(插进),这里给节点会话的 followup 套一层。
|
|
62
|
+
*/
|
|
63
|
+
export function 忙时插话(agent) {
|
|
64
|
+
if (typeof agent?.followup !== 'function' || typeof agent.steer !== 'function' || agent.followup.blueprint插话) return
|
|
65
|
+
const 原 = agent.followup.bind(agent)
|
|
66
|
+
const 改 = message => agent.status === 'running' && message?.source?.kind === 'user' ? agent.steer(message) : 原(message)
|
|
67
|
+
改.blueprint插话 = true
|
|
68
|
+
agent.followup = 改
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 给钩子、框架看的节点:编号、类型、名字、上一层、专家。 */
|
|
72
|
+
export const 钩子节点 = 节 => 节 && { 编号: 节.编号, 类型: 节.类型, 名字: 节.名字, 上一层: 节.上一层 ?? null, 专家: 节.专家 ?? null }
|
|
73
|
+
|
|
74
|
+
/** 这个会话是哪个节点(`钩子节点` 那几样);不是 → null。只认节点表里记着的会话。 */
|
|
75
|
+
export function 认节点(agent) {
|
|
76
|
+
const 根 = 根Of(agent)
|
|
77
|
+
const 库 = 根 && 开信息库(根)
|
|
78
|
+
return 钩子节点(库 && 会话的节点(库, agent.session.id)) || null
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 给代码插件用的那一套(插件的 `apply(api)`、`hooks.x(钩)`、工具的 `run(api, 参数, exec)` 都拿到它)。
|
|
84
|
+
* 只读的东西都是现算:插件目录、框架、底座做法每次调用时现读,改了不用重启。
|
|
85
|
+
*/
|
|
86
|
+
export function 宿主api(ctx) {
|
|
87
|
+
const 会话 = 会话服务(ctx)
|
|
88
|
+
const api = {
|
|
89
|
+
ctx, 会话, 喊, 话, 根Of, 插件们, 读装配, 有效块, 有效专家, 选的做法, 底座做法们, 底座代码, 专家们, 认节点,
|
|
90
|
+
/** 从一个节点做完的那几轮分叉出去,照一段话写一页,回它写的字(影子.js 的 分叉写)。 */
|
|
91
|
+
分叉写: 场 => 分叉写(ctx, { 喊, ...场, 收: 场.收 }),
|
|
92
|
+
/** 一个项目的会话器(编号 ↔ 会话:活着的、在跑、拿)。 */
|
|
93
|
+
会话器: 根 => 会话器Of(api, 根),
|
|
94
|
+
/** 这个节点({编号,类型})的框架里有没有某个插件(按声明的名字认)。 */
|
|
95
|
+
装了(根, 节点, _上面们, 插件名) { return 有效块(根, 节点).some(项 => 项.插.名 === 插件名) },
|
|
96
|
+
/** 这个节点框架里某个插件的设置(声明里的默认值合上块里 设置.json 的);没有 → null。 */
|
|
97
|
+
设置Of(根, 节点, _上面们, 插件名) {
|
|
98
|
+
const 项 = 有效块(根, 节点).find(项 => 项.插.名 === 插件名)
|
|
99
|
+
if (!项) return null
|
|
100
|
+
const 默认 = Object.fromEntries(Object.entries(项.插?.设置 || {}).map(([键, 值]) => [键, 值 && typeof 值 === 'object' && !Array.isArray(值) && 'default' in 值 ? 值.default : 值]))
|
|
101
|
+
return { ...默认, ...项.settings }
|
|
102
|
+
},
|
|
103
|
+
/** 节点开会话时要挂的技能:装的"挂着"插件+仓库 `blueprint/技能/` 里的。用户的技能(~/.dsh/skills,Skill 页签那些)由预设里的 dsh skill-filesystem 自己挂(11-23)。 */
|
|
104
|
+
技能们Of(根, 节点, _上面们) {
|
|
105
|
+
let 挂 = []
|
|
106
|
+
try { 挂 = 挂着的({ 根, 节点, 上面们: [] }) } catch (e) { 喊('挂着的技能没算出来', e) }
|
|
107
|
+
return [...挂, ...自带技能们().filter(技 => !挂.some(已 => 已.name === 技.name))]
|
|
108
|
+
},
|
|
109
|
+
}
|
|
110
|
+
return api
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function apply(ctx) {
|
|
114
|
+
const api = 宿主api(ctx)
|
|
115
|
+
藏外部委派工具(ctx)
|
|
116
|
+
const 底座们Of = 根 => Object.keys(底座做法们(根)).map(键 => 选的做法(根, 键)).filter(Boolean)
|
|
117
|
+
接上(api, ctx)
|
|
118
|
+
// dreaming(11-27 段二,要求账记 28):调一次模型,不挂在哪个节点的会话上。模型照这个项目选的,没选照 dsh 的默认;用到时现取 llm。
|
|
119
|
+
设做梦的问(async (根, 系统, 文) => {
|
|
120
|
+
const llm = ctx.get('llm')
|
|
121
|
+
if (!llm) throw new Error('dsh 没有 llm 服务')
|
|
122
|
+
const 选 = 项目模型(根) || ctx.get('agentDefaultModel')?.currentSelection?.()
|
|
123
|
+
if (!选?.provider || !选?.model) throw new Error('不知道用哪个模型')
|
|
124
|
+
const signal = AbortSignal.timeout(10 * 60_000)
|
|
125
|
+
const call = await llm.prepareCall({ provider: 选.provider, model: 选.model, maxTokens: 12_000 }, signal)
|
|
126
|
+
const 组 = new BlockAssembler()
|
|
127
|
+
for await (const 片 of call.stream({ ...call.config, messages: [话(文)], system: 系统, signal })) 组.push(片)
|
|
128
|
+
return 组.blocks().filter(块 => 块.type === 'text').map(块 => 块.text).join('')
|
|
129
|
+
}, 喊)
|
|
130
|
+
|
|
131
|
+
// ── 节点会话开起来时:忙时插话;记下编号 ↔ 会话 ──
|
|
132
|
+
ctx.on('agent/created', async ({ agent }) => {
|
|
133
|
+
try { 挂分工(agent) } catch (e) { 喊('分工工具没挂上', e) }
|
|
134
|
+
try {
|
|
135
|
+
const 节点 = 根Of(agent) && 认节点(agent)
|
|
136
|
+
if (!节点) return
|
|
137
|
+
忙时插话(agent)
|
|
138
|
+
记住(根Of(agent), 节点.编号, agent.session.id)
|
|
139
|
+
} catch (e) { 喊('节点开会话时出错', e) }
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
/** 工具的说明在 `提示词/工具.md`;那一段还没写,先用名字顶着、喊一声(不让整个宿主起不来)。 */
|
|
143
|
+
const 说明Of = 名 => { try { return 工具说明(名) } catch (e) { 喊(`工具 ${名} 没有说明`, e); return 名 } }
|
|
144
|
+
/** 只给 Blueprint 节点的一把工具:认出节点(影子、不是节点的会话用不了),`做(现场, 参数)` 回给模型的字。 */
|
|
145
|
+
const 节点工具定义 = (name, parameters, 做) => ({
|
|
146
|
+
name, description: 说明Of(name), output: 只回一段字, isConcurrencySafe: () => false, parameters,
|
|
147
|
+
execute: async (args, exec) => {
|
|
148
|
+
const agent = exec.agent
|
|
149
|
+
if (影子们.has(agent?.session?.id)) throw new Error('影子只写字,不调工具')
|
|
150
|
+
const 现场 = 现场Of(agent)
|
|
151
|
+
if (!现场) throw new Error('这个会话不是 Blueprint 的节点')
|
|
152
|
+
return { 文: await 做(现场, args || {}) }
|
|
153
|
+
},
|
|
154
|
+
})
|
|
155
|
+
const 节点工具 = (...参) => ctx.tools.register(节点工具定义(...参))
|
|
156
|
+
|
|
157
|
+
// ── 分工(段二,「把拍节点功能变成 skill,所有节点都能自己调用」):系统只做节点做不了的——把方案摆给用户(11-25 起不再让节点开工)。
|
|
158
|
+
// 用户确认以后真的建节点(后台调内核的 确认方案),提的那个节点收到新节点的编号(启停.js 听 确认分工)。
|
|
159
|
+
// 能开哪几种(11-25 用户:「codex 节点和 Claudecode节点只有检测通过三个灯全绿的时候才进入可排节点名单,不然不出现,不然会错派」;
|
|
160
|
+
// 又:「把 1.18 版本的外置节点的页,开关,整个这一页的设计都加回来吧,这里打开就是能用,不打开就是不行」):
|
|
161
|
+
// 普通、专家总有;codex、claude-code 要这个项目在左窗「Agent 选择」页里把它打开(1.18 的规矩:三盏灯全亮才打得开),
|
|
162
|
+
// 并且本机的测试记录还通过(检测查出灯灭了就作废)。defaults 外部agent/可派.js。
|
|
163
|
+
// 项目不同、开关不同,所以这一把挂在每个会话自己的作用域里(会话开起来时,见下面 agent/created),说明和 type 的可选值每次发请求时现算;
|
|
164
|
+
// 调的时候再查一遍,没打开的退回。全局那一份只有普通、专家(不在项目里的会话用)。
|
|
165
|
+
// 说明、参数、校验、回执在 分工工具.js(11-26 抽出来,和 Codex、Claude Code 节点的 MCP 服务共用一份)。
|
|
166
|
+
const 记录文件 = () => { try { return 测试记录文件((ctx.root?.get?.('sessionPersistence') ?? ctx.get?.('sessionPersistence'))?.root) } catch { return null } }
|
|
167
|
+
// 给 Codex、Claude Code 节点开的 MCP 服务也要查同一份测试记录:记在进程环境里,开它们时带过去(外部agent/分工MCP.js)。
|
|
168
|
+
try { const 文件 = 记录文件(); if (文件) process.env.BLUEPRINT_AGENTS_RECORD = 文件 } catch {}
|
|
169
|
+
const 可派外置 = 根 => 可派外置Of(根, 记录文件())
|
|
170
|
+
const 分工Of = 根 => {
|
|
171
|
+
const 定义 = 节点工具定义('propose_nodes', 分工参数([]), (现场, { nodes = [] }) => 摆方案(现场.根, 现场.节点.编号, nodes, 可派外置(现场.根)))
|
|
172
|
+
Object.defineProperties(定义, {
|
|
173
|
+
description: { enumerable: true, get: () => 分工说明(根, 根 ? 可派外置(根) : [], 说明Of) },
|
|
174
|
+
parameters: { enumerable: true, get: () => 分工参数(根 ? 可派外置(根) : []) },
|
|
175
|
+
})
|
|
176
|
+
return 定义
|
|
177
|
+
}
|
|
178
|
+
ctx.tools.register(分工Of(null))
|
|
179
|
+
// 纸条(11-29 构 203;12-01 构 211):递了就送(启停.js 送纸条),reply 选要不要回话。
|
|
180
|
+
const 纸条定义 = 节点工具定义('pass_note', 纸条参数, (现场, 参) => 递纸条(现场.根, 现场.节点.编号, 参))
|
|
181
|
+
Object.defineProperty(纸条定义, 'description', { enumerable: true, get: () => 纸条说明(说明Of) })
|
|
182
|
+
ctx.tools.register(纸条定义)
|
|
183
|
+
/** 会话开起来时:在项目里的(节点、它的分叉、影子都算,同一个项目同一份说明,前缀对得上缓存)在它自己的作用域挂一份认这个项目的。 */
|
|
184
|
+
const 挂了分工 = new WeakSet()
|
|
185
|
+
const 挂分工 = agent => {
|
|
186
|
+
const 根 = 根Of(agent)
|
|
187
|
+
if (!agent || 挂了分工.has(agent) || !根 || !开信息库(根)) return
|
|
188
|
+
const 工具 = agent.ctx?.get?.('tools')
|
|
189
|
+
if (typeof 工具?.register !== 'function') return
|
|
190
|
+
工具.register(分工Of(根))
|
|
191
|
+
挂了分工.add(agent)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// ── 收件箱(段二 2.6;11-24 用户:「所有的都应该直接在对话中显示……让节点变成带协作状态,系统收件箱自动识别……」):
|
|
195
|
+
// 11-24 晚撤了 to_user(调完 dsh 还要给模型一步,节点只好多说一句):节点一轮自然跑完停下,收件箱自动挂一件「待回复」,
|
|
196
|
+
// 见下面「每一轮停」。用户按停、出错、被重置的那一轮 dsh 不走 turn-stopping,不挂。同一节点已经有一件待回复不再挂。用户在它对话里开口就清掉(你开口)。
|
|
197
|
+
// 11-25 用户:分「带回答」和「带确认」——「用问号做吧」:这一轮最后那段话里有问号(? 或 ?)=在问用户,挂「答」;
|
|
198
|
+
// 没有=交出东西请他看,挂「定」。两样都是他看过就算完成(内核 看过;11-26 起「答」也是,用户选甲)。最后那段话读不到当「答」。
|
|
199
|
+
// 同一节点已经挂着一件:类一样不动,不一样换成这一次的(内核 改收件类)。
|
|
200
|
+
const 停下的类 = agent => {
|
|
201
|
+
const 们 = agent?.session?.ownEvents?.() || []
|
|
202
|
+
for (let i = 们.length - 1; i >= 0; i--) {
|
|
203
|
+
if (们[i]?.type === 'turn/start') break
|
|
204
|
+
if (们[i]?.type !== 'assistant/message') continue
|
|
205
|
+
const 文 = (们[i].data?.message?.content || []).filter(块 => 块.type === 'text').map(块 => 块.text).join('').trim()
|
|
206
|
+
if (文) return /[??]/.test(文) ? '答' : '定'
|
|
207
|
+
}
|
|
208
|
+
return '答'
|
|
209
|
+
}
|
|
210
|
+
const 挂待回复 = (根, 编号, 类 = '答') => {
|
|
211
|
+
const 库 = 开信息库(根)
|
|
212
|
+
if (!节点Of(库, 编号)) return null
|
|
213
|
+
const 有 = 待你的(库).find(件 => 件.节点 === 编号)
|
|
214
|
+
if (有) { if (有.类 !== 类) 改收件类(库, 有.号, 类); return 有.号 }
|
|
215
|
+
return 放收件(库, 编号, 类, '')
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
// ── 媒体工具(11-25 搬回 1.1.8 的 media_catalog/media_call:左窗「媒体 API」页配的服务,硅基流动文生图在里面) ──
|
|
220
|
+
装媒体工具(ctx, { 说明Of, 根Of })
|
|
221
|
+
|
|
222
|
+
// ── 带代码的插件:底座的做法跑 apply,工具都注册上 ──
|
|
223
|
+
for (const 插 of 插件们(null).values()) {
|
|
224
|
+
if (插.错们.length) { if (插.名) 喊(`插件 ${插.名} 用不了:${插.错们.join(';')}`); continue }
|
|
225
|
+
if (!插.代码) continue
|
|
226
|
+
let 模块
|
|
227
|
+
try { 模块 = await 载代码(插) } catch (e) { 喊(`插件 ${插.名} 的代码载不进来`, e); continue }
|
|
228
|
+
if (typeof 模块.apply === 'function') {
|
|
229
|
+
try { await 模块.apply({ ...api, 插件: 插 }) } catch (e) { 喊(`插件 ${插.名} 的 apply 出错`, e) }
|
|
230
|
+
}
|
|
231
|
+
for (const 工 of 模块.tools || []) {
|
|
232
|
+
ctx.tools.register({
|
|
233
|
+
name: 工.name,
|
|
234
|
+
description: typeof 工.description === 'function' ? 工.description() : String(工.description ?? ''),
|
|
235
|
+
output: 工.output ?? 只回一段字, isConcurrencySafe: () => false,
|
|
236
|
+
parameters: 工.parameters,
|
|
237
|
+
execute: async (args, exec) => {
|
|
238
|
+
const agent = exec.agent
|
|
239
|
+
if (影子们.has(agent?.session?.id)) throw new Error('影子只写字,不调工具')
|
|
240
|
+
const 根 = 根Of(agent)
|
|
241
|
+
if (!根) throw new Error('这个会话没有工作目录,不是 Blueprint 项目')
|
|
242
|
+
能用吗(插, 根, agent)
|
|
243
|
+
const 回 = await 工.run({ ...api, 插件: 插, 根, agent }, args || {}, exec)
|
|
244
|
+
return typeof 回 === 'string' ? { 文: 回 } : 回
|
|
245
|
+
},
|
|
246
|
+
})
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** 这把工具这个节点能不能用:底座的做法要是这个项目选的那一种;节点插件要装在这个节点上。 */
|
|
251
|
+
function 能用吗(插, 根, agent) {
|
|
252
|
+
if (插.底座) {
|
|
253
|
+
if (选的做法(根, 插.底座)?.名 !== 插.名) throw new Error(`这个项目的「${插.底座}」没选「${插.标题}」,这把工具用不了`)
|
|
254
|
+
return
|
|
255
|
+
}
|
|
256
|
+
const 节点 = 认节点(agent)
|
|
257
|
+
if (!节点) throw new Error('这个会话不是 Blueprint 的节点')
|
|
258
|
+
if (!api.装了(根, 节点, [], 插.名)) throw new Error(`你没装「${插.标题}」,这把工具用不了`)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** 认出这个 agent 是哪个节点;不是 Blueprint 节点(或是影子)→ null。 */
|
|
262
|
+
function 现场Of(agent, 多 = {}) {
|
|
263
|
+
if (!agent || 影子们.has(agent.session?.id)) return null
|
|
264
|
+
const 根 = 根Of(agent)
|
|
265
|
+
const 节点 = 根 && 认节点(agent)
|
|
266
|
+
if (!节点) return null
|
|
267
|
+
return { 根, 节点, 上面们: [], agent, 这一步: {}, ...多 }
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const 运行时 = { api, 喊, 开影子: 场 => { 开影子(ctx, { ...场, 喊 }) } }
|
|
271
|
+
const 选项Of = 现场 => ({ 底座们: 底座们Of(现场.根) })
|
|
272
|
+
/** 选择机判的那一次:从节点会话分叉(和节点看同一份 context);没有模型服务就不判。 */
|
|
273
|
+
const 判Of = (现场, 进来的) => async 题 => {
|
|
274
|
+
try { if (!ctx.get('llm')) return '' } catch { return '' }
|
|
275
|
+
return 分叉问(ctx, { agent: 现场.agent, 根: 现场.根, 进来的, 问: 题, 喊 })
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// ── 这一轮的两样信号(段四):会话 → { 改了文件, 用户开口 };每一轮第一步清零。 ──
|
|
279
|
+
const 改文件的工具 = new Set(['write', 'edit'])
|
|
280
|
+
const 这一轮 = new Map()
|
|
281
|
+
const 信号Of = 会话 => { if (!这一轮.has(会话)) 这一轮.set(会话, { 改了文件: false, 用户开口: false }); return 这一轮.get(会话) }
|
|
282
|
+
|
|
283
|
+
// ── 每一步 ──
|
|
284
|
+
const 看到的压缩 = new Map()
|
|
285
|
+
ctx.on('agent/pre-step', async (payload, next) => {
|
|
286
|
+
const d = await next()
|
|
287
|
+
if (d?.kind !== 'enter') return d
|
|
288
|
+
const agent = payload.agent, 会话 = agent?.session?.id
|
|
289
|
+
// 删了的节点:它这一步之前那一步做完了,不再走。
|
|
290
|
+
if (删掉的会话.has(会话)) return { kind: 'reject' }
|
|
291
|
+
let 现场
|
|
292
|
+
try { 现场 = 现场Of(agent, { turn: payload.turn, step: payload.step, messages: d.messages, 进来的: payload.messages }) } catch (e) { 喊('认不出节点', e); return d }
|
|
293
|
+
if (!现场) return d
|
|
294
|
+
const { 根 } = 现场, 编号 = 现场.节点.编号
|
|
295
|
+
if (payload.step === 1) 这一轮.set(会话, { 改了文件: false, 用户开口: false })
|
|
296
|
+
const 们 = agent.session.ownEvents?.() || []
|
|
297
|
+
const 时机们 = []
|
|
298
|
+
const 开头 = payload.step === 1 && !们.some(e => e.type === 'turn/end')
|
|
299
|
+
const 压 = 们.filter(e => e.type === 'compaction/end').length
|
|
300
|
+
const 压过 = 压 > (看到的压缩.get(会话) ?? 压)
|
|
301
|
+
看到的压缩.set(会话, 压)
|
|
302
|
+
if (压过) 时机们.push('after-compaction')
|
|
303
|
+
if (payload.step === 1) 时机们.push('turn-start')
|
|
304
|
+
// 项目快照(11-29,要求账构 204):每一轮开始前、自然做完时各存一版,不用等。
|
|
305
|
+
if (payload.step === 1) 记快照(根, 编号, '开始前')
|
|
306
|
+
const 新话 = 用户原话(d.messages)
|
|
307
|
+
if (新话) {
|
|
308
|
+
现场.新话 = 新话; 时机们.push('on-content')
|
|
309
|
+
信号Of(会话).用户开口 = true
|
|
310
|
+
try { 你开口(开信息库(根), 编号, 新话) } catch (e) { 喊(`${编号} 没记下用户开口`, e) }
|
|
311
|
+
// 原话流水(11-27,要求账记 25):你说的这句,连同它在你说之前对你说的最后一段话,原样记下。
|
|
312
|
+
try {
|
|
313
|
+
const 它说 = 们.filter(e => e.type === 'assistant/message').map(文字Of).filter(Boolean).at(-1) || ''
|
|
314
|
+
记原话(根, 编号, { 你说: 新话, 它说, 节点名: 节点Of(开信息库(根), 编号)?.名字 || '' })
|
|
315
|
+
} catch (e) { 喊(`${编号} 没记下原话`, e) }
|
|
316
|
+
// 停着的节点被你直接说话叫起来:算点了开始,做完卡上是「交了」不是「停了」(11-26)。
|
|
317
|
+
try { 说话算开始(开信息库(根), 编号) } catch (e) { 喊(`${编号} 没记下开始`, e) }
|
|
318
|
+
}
|
|
319
|
+
时机们.push('step')
|
|
320
|
+
const 前 = [], 加 = []
|
|
321
|
+
// 【开场】在最前面,后面跟「节点前」的块(when: start);会话第一步和压缩以后各放一次。开场里有分工表,结构算看过了。
|
|
322
|
+
if (开头 || 压过) {
|
|
323
|
+
try {
|
|
324
|
+
const 开场 = String((await 开场段(根, 编号)) ?? '').trim()
|
|
325
|
+
if (开场) 前.push(话(开场))
|
|
326
|
+
const 果 = await 跑钩子('start', 现场, 运行时, 选项Of(现场))
|
|
327
|
+
前.push(...果.话们, ...果.追加.map(t => 话(t)))
|
|
328
|
+
记看到结构(开信息库(根), 编号)
|
|
329
|
+
} catch (e) { 喊(`${编号} 的开场没拼出来`, e) }
|
|
330
|
+
} else {
|
|
331
|
+
// 结构变了(开、改、挪、删节点):每一步都查。一轮开头插在最前面;跑到一半的,插在这一步进来的话后面,下一步就读到
|
|
332
|
+
// (11-23 用户:「每一次新建一个节点,代表了一种权责变更,所有平级节点与上级节点都会在下一次任务的时候或者任务进行中时候收到」)。
|
|
333
|
+
try {
|
|
334
|
+
const 变了 = String((await 结构变了话(根, 编号)) ?? '').trim()
|
|
335
|
+
if (变了) { (payload.step === 1 ? 前 : 加).push(话(变了)); 记看到结构(开信息库(根), 编号) }
|
|
336
|
+
} catch (e) { 喊(`${编号} 的分工表没插上`, e) }
|
|
337
|
+
}
|
|
338
|
+
try {
|
|
339
|
+
for (const 时机 of 时机们) {
|
|
340
|
+
const 果 = await 跑钩子(时机, 现场, 运行时, 选项Of(现场))
|
|
341
|
+
if (果.拒绝) return { kind: 'reject' }
|
|
342
|
+
加.push(...果.话们, ...果.追加.map(t => 话(t)))
|
|
343
|
+
if (果.引导.length) agent.steer?.(话(果.引导.join('\n\n')))
|
|
344
|
+
}
|
|
345
|
+
} catch (e) { 喊(`${编号} 这一步的插件出错`, e) }
|
|
346
|
+
// 选择页(每一轮第一步,selector.js):一页就插这一页;两页以上从节点会话分叉问"下一步应该做什么?",选中的接在这一步进来的话后面。
|
|
347
|
+
if (payload.step === 1) {
|
|
348
|
+
try {
|
|
349
|
+
if (压过) 忘了上次(根, 编号)
|
|
350
|
+
const 应 = await 挑应对(现场, { 选项: 选项Of(现场), 判: 判Of(现场, [...前, ...(d.messages || []), ...加]), 喊 })
|
|
351
|
+
// 还在同一段:挑应对回 null,什么都不插(11-26 撤了【还在】提醒,构 192)。
|
|
352
|
+
if (应) 加.push(话(应.文, 应对来路, { 应对: 应.名 }))
|
|
353
|
+
} catch (e) { 喊(`${编号} 的选择机出错`, e) }
|
|
354
|
+
}
|
|
355
|
+
return 前.length || 加.length ? { ...d, messages: [...前, ...(d.messages || []), ...加] } : d
|
|
356
|
+
})
|
|
357
|
+
|
|
358
|
+
// ── 每一轮停:只跑 turn-end 的钩子(要它再跑一步的塞一句进去) ──
|
|
359
|
+
// 没有要它再跑一步的,这一轮就自然跑完了:收件箱挂一件「待回复」(11-24 晚撤 to_user)。
|
|
360
|
+
ctx.on('agent/turn-stopping', async ({ agent, turn, signal }) => {
|
|
361
|
+
let 现场
|
|
362
|
+
try {
|
|
363
|
+
现场 = 现场Of(agent, { turn, ...信号Of(agent.session.id) })
|
|
364
|
+
if (!现场) return
|
|
365
|
+
const 果 = await 跑钩子('turn-end', 现场, 运行时, 选项Of(现场))
|
|
366
|
+
if (果.引导.length) { agent.steer(话(果.引导.join('\n\n'))); return }
|
|
367
|
+
} catch (e) { 喊('这一轮停的时候插件出错', e) }
|
|
368
|
+
if (!现场 || signal?.aborted) return
|
|
369
|
+
记快照(现场.根, 现场.节点.编号, '做完一轮', 这一轮最后说的(agent))
|
|
370
|
+
try { 挂待回复(现场.根, 现场.节点.编号, 停下的类(agent)) } catch (e) { 喊(`${现场.节点.编号} 的待回复没挂上`, e) }
|
|
371
|
+
// 要回话的纸条(12-01 构 211):这一轮做完,最后说的话送回递纸条的节点(宿主听"回纸条"去送)。
|
|
372
|
+
try { 回纸条们(开信息库(现场.根), 现场.节点.编号, 这一轮最后说的(agent)) } catch (e) { 喊(`${现场.节点.编号} 的纸条回话没记上`, e) }
|
|
373
|
+
// 原话流水(11-28,要求账记 25):自然做完的一轮,记它这一轮最后对你说的话,dreaming 读得到进展。
|
|
374
|
+
try { 记一轮(现场.根, 现场.节点.编号, { 它说: 这一轮最后说的(agent), 节点名: 节点Of(开信息库(现场.根), 现场.节点.编号)?.名字 || '' }) } catch (e) { 喊(`${现场.节点.编号} 这一轮没记进流水`, e) }
|
|
375
|
+
})
|
|
376
|
+
|
|
377
|
+
// ── 调工具:按工具触发的钩子(代码插件可以不许)、补充的话 ──
|
|
378
|
+
const 待补 = new Map()
|
|
379
|
+
ctx.on('tools/pre-execute', async (exec, next) => {
|
|
380
|
+
if (影子们.has(exec.agent?.session?.id)) return { kind: 'deny', reason: '影子只写字,不调工具。' }
|
|
381
|
+
const d = await next()
|
|
382
|
+
if (d?.kind !== 'allow') return d
|
|
383
|
+
try {
|
|
384
|
+
const 现场 = 现场Of(exec.agent, { exec, turn: exec.agent?.turn })
|
|
385
|
+
if (!现场) return d
|
|
386
|
+
const 果 = await 跑钩子('on-tool', 现场, 运行时, 选项Of(现场))
|
|
387
|
+
if (果.不许) return { kind: 'deny', reason: 果.不许 }
|
|
388
|
+
if (果.补充.length && exec.callId) 待补.set(exec.callId, 果.补充)
|
|
389
|
+
} catch (e) { 喊('调工具前的插件出错', e) }
|
|
390
|
+
return d
|
|
391
|
+
})
|
|
392
|
+
ctx.on('tools/post-execute', async (exec, result, next) => {
|
|
393
|
+
const d = await next()
|
|
394
|
+
// 写、改文件成功了:这一轮算改了文件(被插件拦下、工具报错的不算)。
|
|
395
|
+
if (改文件的工具.has(exec.name) && d?.kind === 'accept' && !result?.isError && exec.agent?.session?.id && !影子们.has(exec.agent.session.id)) 信号Of(exec.agent.session.id).改了文件 = true
|
|
396
|
+
try {
|
|
397
|
+
const 补 = 待补.get(exec.callId) || []
|
|
398
|
+
待补.delete(exec.callId)
|
|
399
|
+
const 现场 = 现场Of(exec.agent, { exec, result, 之后: true, turn: exec.agent?.turn })
|
|
400
|
+
if (现场) 补.push(...(await 跑钩子('on-tool', 现场, 运行时, 选项Of(现场))).补充)
|
|
401
|
+
if (!补.length || d?.kind !== 'accept') return d
|
|
402
|
+
return { ...d, additionalContexts: [...(d.additionalContexts || []), ...补.map(t => 话(t))] }
|
|
403
|
+
} catch (e) { 喊('调完工具的插件出错', e); return d }
|
|
404
|
+
})
|
|
405
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 装配:这个项目开局用的哪个预设、底座每样选了哪种做法、专家配给了谁(平台说明 四、五)。存在项目的 `系统文档/装配.json`:
|
|
3
|
+
* { version, preset, sockets: { memory: 'dreaming-memory' }, experts: { D1: ['blender'] } }
|
|
4
|
+
* 11-16 起节点身上的块不在这里记:项目的 `系统文档/框架/` 就是全部(框架.js,用户:「前端显示与后端文件就是一个东西」)。
|
|
5
|
+
* 没有装配文件时,照预设建一份(`预设们`);预设里的块是同一个文件夹下的 `框架/`(自带的默认预设用 `blueprint/presets/default/框架/`)。
|
|
6
|
+
*/
|
|
7
|
+
import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from 'node:fs'
|
|
8
|
+
import { homedir } from 'node:os'
|
|
9
|
+
import { dirname, join, resolve } from 'node:path'
|
|
10
|
+
import { parse } from 'yaml'
|
|
11
|
+
import { bundle根 } from './插件目录.js'
|
|
12
|
+
|
|
13
|
+
export const 装配版本 = 1
|
|
14
|
+
export const 装配路径 = 根 => join(resolve(根), '系统文档', '装配.json')
|
|
15
|
+
export const 自带预设夹 = join(bundle根, 'presets')
|
|
16
|
+
/** 用户存的预设。测试时可以用环境变量 BLUEPRINT_PRESETS_DIR 换掉。 */
|
|
17
|
+
export const 用户预设夹 = () => process.env.BLUEPRINT_PRESETS_DIR || join(homedir(), '.blueprint', 'presets')
|
|
18
|
+
|
|
19
|
+
// 11-16 起节点身上的块在项目的框架里(框架.js),装配只剩:开局用的哪个预设、底座选了哪种、专家配给谁。
|
|
20
|
+
const 空装配 = () => ({ version: 装配版本, preset: null, sockets: {}, experts: {} })
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
/** 把读来的(或预设里写的)规整成一样的形状。 */
|
|
24
|
+
export function 规整(原) {
|
|
25
|
+
const 装 = 空装配()
|
|
26
|
+
if (!原 || typeof 原 !== 'object') return 装
|
|
27
|
+
装.preset = 原.preset ?? null
|
|
28
|
+
for (const [键, 值] of Object.entries(原.sockets ?? {})) if (值) 装.sockets[键] = String(值)
|
|
29
|
+
for (const [号, 列] of Object.entries(原.experts ?? {})) 装.experts[号] = (Array.isArray(列) ? 列 : []).map(String).filter(Boolean)
|
|
30
|
+
return 装
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// ── 预设 ─────────────────────────────────────────────────────────────────────
|
|
34
|
+
|
|
35
|
+
/** 读一个预设文件夹(里面一份 PRESET.yaml)。 */
|
|
36
|
+
export function 读预设(夹, 层) {
|
|
37
|
+
const 原 = parse(readFileSync(join(夹, 'PRESET.yaml'), 'utf8')) ?? {}
|
|
38
|
+
return { 名: String(原.name ?? ''), 标题: String(原.title ?? 原.name ?? ''), 一句: String(原.summary ?? ''), 层, 夹, 装配: 规整({ ...原, preset: 原.name }) }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** 看得到的预设:用户的盖自带的。 */
|
|
42
|
+
export function 预设们() {
|
|
43
|
+
const 表 = new Map()
|
|
44
|
+
for (const [层, 夹] of [['自带', 自带预设夹], ['用户', 用户预设夹()]]) {
|
|
45
|
+
if (!existsSync(夹)) continue
|
|
46
|
+
for (const 名 of readdirSync(夹)) {
|
|
47
|
+
if (!existsSync(join(夹, 名, 'PRESET.yaml'))) continue
|
|
48
|
+
try { const 预 = 读预设(join(夹, 名), 层); if (预.名) 表.set(预.名, 预) } catch {}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return 表
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 框架里一种类型的文件夹叫什么(`系统文档/框架/<这个名字>/`);`框架.js` 也从这里拿(11-22 自由蓝图)。
|
|
56
|
+
* 类型四个:普通、专家、codex、claude-code(plan 是专家的一张系统自带大师卡,不是类型);`普通` 没有自己的一夹,只有 `所有节点`。
|
|
57
|
+
*/
|
|
58
|
+
export const 类型夹名 = Object.freeze({ 专家: '专家', codex: 'codex', 'claude-code': 'claude-code' })
|
|
59
|
+
/** 装在整个项目(所有节点)上的那一夹。 */
|
|
60
|
+
export const 全部夹名 = '所有节点'
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 把现在这个项目另存成一个新预设(用户那一层):底座选了什么写进 PRESET.yaml,框架整棵(只拷"所有节点"和各类型的,单个节点的不带)
|
|
64
|
+
* 拷进同一个文件夹的 `框架/`,以后新项目选它就照它找(框架.js 逐层找)。跑着改的不写回原来的(用户 11-12)。
|
|
65
|
+
*/
|
|
66
|
+
export function 存成预设(根, { 名, 标题, 一句 = '' }) {
|
|
67
|
+
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(String(名 ?? ''))) throw new Error('预设的名字用小写字母、数字加连字符')
|
|
68
|
+
const 装 = 读装配(根)
|
|
69
|
+
const 夹 = join(用户预设夹(), 名)
|
|
70
|
+
mkdirSync(夹, { recursive: true })
|
|
71
|
+
const 文 = [`name: ${名}`, `title: ${JSON.stringify(标题 || 名)}`, `summary: ${JSON.stringify(一句)}`, `sockets: ${JSON.stringify(装.sockets)}`].join('\n')
|
|
72
|
+
writeFileSync(join(夹, 'PRESET.yaml'), `${文}\n`)
|
|
73
|
+
// 11-24 起框架逐层找:项目那层只放这个项目改过的,所有项目那层(用户那层的同名预设)放到处改过的;
|
|
74
|
+
// 新预设拿这两层合起来(项目的盖住所有项目的),下面照旧是自带的(框架.js:用户自己存的预设没有自带同名的,用自带的 default)。
|
|
75
|
+
const 位置们 = ['节点前', '轮前', '轮中', '轮后']
|
|
76
|
+
for (const 源 of [join(用户预设夹(), String(装.preset || 'default'), '框架'), join(resolve(根), '系统文档', '框架')]) {
|
|
77
|
+
if (!existsSync(源)) continue
|
|
78
|
+
for (const 范名 of readdirSync(源)) {
|
|
79
|
+
if (范名.startsWith('.') || ![全部夹名, ...Object.values(类型夹名)].includes(范名)) continue
|
|
80
|
+
for (const 位置 of 位置们) {
|
|
81
|
+
const 位夹 = join(源, 范名, 位置)
|
|
82
|
+
if (!existsSync(位夹)) continue
|
|
83
|
+
for (const 名 of readdirSync(位夹)) {
|
|
84
|
+
if (名.startsWith('.')) continue
|
|
85
|
+
for (const 别 of 位置们) rmSync(join(夹, '框架', 范名, 别, 名), { recursive: true, force: true })
|
|
86
|
+
cpSync(join(位夹, 名), join(夹, '框架', 范名, 位置, 名), { recursive: true, dereference: true })
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return 夹
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// ── 读写 ─────────────────────────────────────────────────────────────────────
|
|
95
|
+
|
|
96
|
+
const 缓存 = new Map()
|
|
97
|
+
|
|
98
|
+
/** 读这个项目的装配。没有文件:照 `默认预设` 建一份(预设找不到就是空的)。 */
|
|
99
|
+
export function 读装配(根, { 默认预设 = 'default' } = {}) {
|
|
100
|
+
const 路径 = 装配路径(根)
|
|
101
|
+
if (!existsSync(路径)) {
|
|
102
|
+
const 预 = 预设们().get(默认预设)
|
|
103
|
+
const 装 = 预 ? structuredClone(预.装配) : 空装配()
|
|
104
|
+
写装配(根, 装)
|
|
105
|
+
return structuredClone(装)
|
|
106
|
+
}
|
|
107
|
+
const 文 = readFileSync(路径, 'utf8')
|
|
108
|
+
const 旧 = 缓存.get(路径)
|
|
109
|
+
if (旧 && 旧.文 === 文) return structuredClone(旧.装)
|
|
110
|
+
const 装 = 规整(JSON.parse(文))
|
|
111
|
+
缓存.set(路径, { 文, 装 })
|
|
112
|
+
return structuredClone(装)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** 整份写回(先写临时文件再换名,写一半不会坏)。 */
|
|
116
|
+
export function 写装配(根, 装) {
|
|
117
|
+
const 路径 = 装配路径(根)
|
|
118
|
+
mkdirSync(dirname(路径), { recursive: true })
|
|
119
|
+
const 文 = `${JSON.stringify({ ...规整(装), version: 装配版本 }, null, 2)}\n`
|
|
120
|
+
const 临 = `${路径}.${process.pid}.tmp`
|
|
121
|
+
writeFileSync(临, 文)
|
|
122
|
+
renameSync(临, 路径)
|
|
123
|
+
缓存.delete(路径)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function 选底座(根, 底座, 做法) {
|
|
127
|
+
const 装配 = 读装配(根)
|
|
128
|
+
装配.sockets[String(底座)] = String(做法)
|
|
129
|
+
写装配(根, 装配)
|
|
130
|
+
return 装配
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function 配专家(根, 编号, 专家) {
|
|
134
|
+
const 装配 = 读装配(根), 列 = (装配.experts[String(编号)] ||= [])
|
|
135
|
+
if (!列.includes(String(专家))) 列.push(String(专家))
|
|
136
|
+
写装配(根, 装配)
|
|
137
|
+
return 装配
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function 撤专家(根, 编号, 专家) {
|
|
141
|
+
const 装配 = 读装配(根), 列 = 装配.experts[String(编号)] || []
|
|
142
|
+
装配.experts[String(编号)] = 列.filter(名 => 名 !== String(专家))
|
|
143
|
+
写装配(根, 装配)
|
|
144
|
+
return 装配
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** 一个节点配的专家:它自己的 ∪ 上面每一层的 ∪ 整个项目的(`experts.project`)。 */
|
|
148
|
+
export const 有效专家 = (装, 节点, 上面们 = []) => [...new Set([
|
|
149
|
+
...(装.experts.project || []), ...上面们.flatMap(号 => 装.experts[号] || []), ...(装.experts[节点.编号] || []),
|
|
150
|
+
])]
|