@suifei/dsh-ai-team 0.4.78 → 0.4.81
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/client.js +110 -6
- package/index.js +2693 -2661
- package/lib/host/model-catalog.js +129 -85
- package/lib/runtime/host-agent.js +182 -174
- package/lib/runtime/subagent-probe.js +35 -0
- package/package.json +1 -1
|
@@ -1,85 +1,129 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Read the model directory from the live DSH `llm` service. The workbench must
|
|
3
|
-
* never ask the user to type provider/model ids: those ids already exist in the
|
|
4
|
-
* Host and can change when accounts/adapters are configured.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
function safeDefault(agentDefaultModel) {
|
|
8
|
-
try {
|
|
9
|
-
const selection = agentDefaultModel?.currentSelection?.();
|
|
10
|
-
if (selection === null || typeof selection !== 'object') return null;
|
|
11
|
-
if (typeof selection.provider !== 'string' || typeof selection.model !== 'string') return null;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Read the model directory from the live DSH `llm` service. The workbench must
|
|
3
|
+
* never ask the user to type provider/model ids: those ids already exist in the
|
|
4
|
+
* Host and can change when accounts/adapters are configured.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
function safeDefault(agentDefaultModel) {
|
|
8
|
+
try {
|
|
9
|
+
const selection = agentDefaultModel?.currentSelection?.();
|
|
10
|
+
if (selection === null || typeof selection !== 'object') return null;
|
|
11
|
+
if (typeof selection.provider !== 'string' || typeof selection.model !== 'string') return null;
|
|
12
|
+
// 宿主默认选择自身也可能带推理等级;没有就不写这个键,客户端据此回退「跟随默认」。
|
|
13
|
+
const effort = selection.reasoningEffort ?? selection.reasoning?.effort ?? null;
|
|
14
|
+
return {
|
|
15
|
+
provider: selection.provider,
|
|
16
|
+
model: selection.model,
|
|
17
|
+
...(typeof effort === 'string' && effort !== '' ? { reasoningEffort: effort } : {}),
|
|
18
|
+
};
|
|
19
|
+
} catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 读取一个 provider/model 路由支持的推理等级(DSH `llm.resolveModelInfo().reasoning`)。
|
|
26
|
+
*
|
|
27
|
+
* 只在用户选定「提供商 + 模型」之后按需调用:`/api/models` 列目录时逐个解析会把
|
|
28
|
+
* 目录接口拖成 N 次适配器往返。返回 `ok:false` 表示**查不到**(服务缺失/适配器报错),
|
|
29
|
+
* 与 `ok:true, efforts: []`(模型确实没有推理等级)是两件事,界面提示也不同。
|
|
30
|
+
*/
|
|
31
|
+
export async function buildModelEfforts(llm, provider, model) {
|
|
32
|
+
const route = { provider: typeof provider === 'string' ? provider.trim() : '', model: typeof model === 'string' ? model.trim() : '' };
|
|
33
|
+
if (route.provider === '' || route.model === '') {
|
|
34
|
+
return { ok: false, ...route, efforts: [], defaultEffort: null, error: { code: 'E_INVALID_ARGUMENT', message: 'provider and model are required' } };
|
|
35
|
+
}
|
|
36
|
+
if (llm === undefined || llm === null || typeof llm.resolveModelInfo !== 'function') {
|
|
37
|
+
return { ok: false, ...route, efforts: [], defaultEffort: null, error: { code: 'E_RUNTIME_UNAVAILABLE', message: 'the DSH llm service is unavailable' } };
|
|
38
|
+
}
|
|
39
|
+
let info;
|
|
40
|
+
try {
|
|
41
|
+
info = await llm.resolveModelInfo(route.provider, route.model);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
return { ok: false, ...route, efforts: [], defaultEffort: null, error: { code: 'E_MODEL_EFFORTS', message: error?.message ?? String(error) } };
|
|
44
|
+
}
|
|
45
|
+
const reasoning = info?.reasoning;
|
|
46
|
+
const seen = new Set();
|
|
47
|
+
const efforts = [];
|
|
48
|
+
for (const effort of Array.isArray(reasoning?.efforts) ? reasoning.efforts : []) {
|
|
49
|
+
const id = typeof effort?.id === 'string' ? effort.id : '';
|
|
50
|
+
if (id === '' || seen.has(id)) continue;
|
|
51
|
+
seen.add(id);
|
|
52
|
+
efforts.push({
|
|
53
|
+
id,
|
|
54
|
+
name: typeof effort?.name === 'string' && effort.name !== '' ? effort.name : id,
|
|
55
|
+
...(typeof effort?.description === 'string' && effort.description !== '' ? { description: effort.description } : {}),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const defaultEffort = typeof reasoning?.defaultEffort === 'string' && reasoning.defaultEffort !== '' ? reasoning.defaultEffort : null;
|
|
59
|
+
return { ok: true, ...route, efforts, defaultEffort };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function modelRows(models) {
|
|
63
|
+
const seen = new Set();
|
|
64
|
+
const rows = [];
|
|
65
|
+
for (const model of Array.isArray(models) ? models : []) {
|
|
66
|
+
if (model === null || typeof model !== 'object' || typeof model.id !== 'string' || model.id === '') continue;
|
|
67
|
+
if (seen.has(model.id)) continue;
|
|
68
|
+
seen.add(model.id);
|
|
69
|
+
rows.push({
|
|
70
|
+
id: model.id,
|
|
71
|
+
name: typeof model.name === 'string' && model.name !== '' ? model.name : model.id,
|
|
72
|
+
...(typeof model.description === 'string' && model.description !== '' ? { description: model.description } : {}),
|
|
73
|
+
...(Array.isArray(model.inputModalities) ? { inputModalities: model.inputModalities } : {}),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return rows;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @param {any} llm live DSH llm service
|
|
81
|
+
* @param {any} agentDefaultModel live DSH default-model service
|
|
82
|
+
*/
|
|
83
|
+
export async function buildModelCatalog(llm, agentDefaultModel) {
|
|
84
|
+
const defaultModel = safeDefault(agentDefaultModel);
|
|
85
|
+
if (llm === undefined || llm === null || typeof llm.listProviders !== 'function') {
|
|
86
|
+
return {
|
|
87
|
+
ok: false,
|
|
88
|
+
defaultModel,
|
|
89
|
+
providers: [],
|
|
90
|
+
error: { code: 'E_RUNTIME_UNAVAILABLE', message: 'the DSH llm service is unavailable' },
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
let providers;
|
|
94
|
+
try {
|
|
95
|
+
providers = llm.listProviders();
|
|
96
|
+
} catch (error) {
|
|
97
|
+
return {
|
|
98
|
+
ok: false,
|
|
99
|
+
defaultModel,
|
|
100
|
+
providers: [],
|
|
101
|
+
error: { code: 'E_MODEL_DIRECTORY', message: error?.message ?? String(error) },
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const rows = await Promise.all((Array.isArray(providers) ? providers : []).map(async (provider) => {
|
|
105
|
+
const id = typeof provider?.id === 'string' ? provider.id : '';
|
|
106
|
+
const name = typeof provider?.name === 'string' && provider.name !== '' ? provider.name : id;
|
|
107
|
+
if (id === '') return null;
|
|
108
|
+
try {
|
|
109
|
+
const models = modelRows(await llm.listModels(id));
|
|
110
|
+
return { id, name, models, modelCount: models.length };
|
|
111
|
+
} catch (error) {
|
|
112
|
+
return {
|
|
113
|
+
id,
|
|
114
|
+
name,
|
|
115
|
+
models: [],
|
|
116
|
+
modelCount: 0,
|
|
117
|
+
error: error?.message ?? String(error),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}));
|
|
121
|
+
const available = rows.filter((row) => row !== null);
|
|
122
|
+
return {
|
|
123
|
+
ok: true,
|
|
124
|
+
defaultModel,
|
|
125
|
+
providers: available,
|
|
126
|
+
providerCount: available.length,
|
|
127
|
+
modelCount: available.reduce((total, row) => total + row.models.length, 0),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
@@ -1,174 +1,182 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Resolve the parent Agent that owns member activations.
|
|
3
|
-
*
|
|
4
|
-
* Preference order:
|
|
5
|
-
* 1. an existing live root Agent (the Human's current session);
|
|
6
|
-
* 2. a lazily created Team Host Agent (the Human owner has no
|
|
7
|
-
* session, e.g. the workbench was opened without a chat).
|
|
8
|
-
*
|
|
9
|
-
* The Host Agent is a runtime root, not a product member: it owns no Task,
|
|
10
|
-
* has no product decision power.
|
|
11
|
-
*
|
|
12
|
-
* IMPORTANT — the Host Agent must never be archived. Members are subagent
|
|
13
|
-
* descendants of it, and `archived-session-gate` (dsh-api-session-controller)
|
|
14
|
-
* rejects every `agent/pre-step` whose Session, or any Session above it in the
|
|
15
|
-
* subagent lineage, is archived. The loop then ends the turn as
|
|
16
|
-
* `{kind:'blocked'}` **without issuing a model request**, so archiving the host
|
|
17
|
-
* silently disables the whole team (observed: 453 blocked turns, 0 completed).
|
|
18
|
-
* Earlier revisions archived it to hide it from the session list; that is
|
|
19
|
-
* repaired here by unarchiving on resolve.
|
|
20
|
-
*/
|
|
21
|
-
import { randomUUID } from 'node:crypto';
|
|
22
|
-
import { reportFail } from '../diaglog.js';
|
|
23
|
-
|
|
24
|
-
/** Windows 路径大小写不敏感,末尾分隔符也不该影响判定。 */
|
|
25
|
-
const samePath = (left, right) => {
|
|
26
|
-
const norm = (value) => String(value).replace(/[\\/]+$/, '').replace(/\\/g, '/').toLowerCase();
|
|
27
|
-
return norm(left) === norm(right);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export class HostAgentError extends Error {
|
|
31
|
-
constructor(code, message, details = {}) {
|
|
32
|
-
super(message);
|
|
33
|
-
this.name = 'HostAgentError';
|
|
34
|
-
this.code = code;
|
|
35
|
-
this.details = details;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @param {{
|
|
41
|
-
* agents: any,
|
|
42
|
-
* agentDefaultModel: any,
|
|
43
|
-
* workspaceRegistry?: any,
|
|
44
|
-
* sessions?: any,
|
|
45
|
-
* cwd: string,
|
|
46
|
-
* newSessionId?: () => string
|
|
47
|
-
* }} options
|
|
48
|
-
*/
|
|
49
|
-
export async function ensureHostAgent(options) {
|
|
50
|
-
const agents = options.agents;
|
|
51
|
-
if (agents === undefined || typeof agents.create !== 'function') {
|
|
52
|
-
throw new HostAgentError('E_RUNTIME_UNAVAILABLE', 'agents service is unavailable');
|
|
53
|
-
}
|
|
54
|
-
// Repair a Host Agent archived by an earlier revision: the archive gate
|
|
55
|
-
// covers the host's whole subagent lineage, so every member turn would end
|
|
56
|
-
// blocked before any model request. `unarchiveSession` resolves without
|
|
57
|
-
// writing when the id is not archived, so no read-back is needed — and
|
|
58
|
-
// gating on the undocumented `archivedSessionIds` accessor is what silently
|
|
59
|
-
// skipped this repair before.
|
|
60
|
-
const unarchiveHost = async (sessionId) => {
|
|
61
|
-
const registry = options.workspaceRegistry;
|
|
62
|
-
if (typeof registry?.unarchiveSession !== 'function') return;
|
|
63
|
-
try {
|
|
64
|
-
await registry.unarchiveSession(sessionId);
|
|
65
|
-
} catch (error) {
|
|
66
|
-
reportFail('host.unarchive.fail', { sessionId: sessionId ?? null }, '[ai-team] could not unarchive Team Host session: ' + (error?.message ?? error));
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
// Persist the resolved route into the session log. Live AgentOptions die
|
|
70
|
-
// with the process; without a recorded selection a restored session renders
|
|
71
|
-
// prompts with an unresolvable {{model}} variable.
|
|
72
|
-
const persistSelection = (sessionId, selection) => {
|
|
73
|
-
try {
|
|
74
|
-
const session = options.sessions?.get?.(sessionId);
|
|
75
|
-
if (session === undefined || session === null || typeof session.append !== 'function') return;
|
|
76
|
-
if (typeof selection?.provider !== 'string' || typeof selection?.model !== 'string') return;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
//
|
|
137
|
-
//
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Resolve the parent Agent that owns member activations.
|
|
3
|
+
*
|
|
4
|
+
* Preference order:
|
|
5
|
+
* 1. an existing live root Agent (the Human's current session);
|
|
6
|
+
* 2. a lazily created Team Host Agent (the Human owner has no
|
|
7
|
+
* session, e.g. the workbench was opened without a chat).
|
|
8
|
+
*
|
|
9
|
+
* The Host Agent is a runtime root, not a product member: it owns no Task,
|
|
10
|
+
* has no product decision power.
|
|
11
|
+
*
|
|
12
|
+
* IMPORTANT — the Host Agent must never be archived. Members are subagent
|
|
13
|
+
* descendants of it, and `archived-session-gate` (dsh-api-session-controller)
|
|
14
|
+
* rejects every `agent/pre-step` whose Session, or any Session above it in the
|
|
15
|
+
* subagent lineage, is archived. The loop then ends the turn as
|
|
16
|
+
* `{kind:'blocked'}` **without issuing a model request**, so archiving the host
|
|
17
|
+
* silently disables the whole team (observed: 453 blocked turns, 0 completed).
|
|
18
|
+
* Earlier revisions archived it to hide it from the session list; that is
|
|
19
|
+
* repaired here by unarchiving on resolve.
|
|
20
|
+
*/
|
|
21
|
+
import { randomUUID } from 'node:crypto';
|
|
22
|
+
import { reportFail } from '../diaglog.js';
|
|
23
|
+
|
|
24
|
+
/** Windows 路径大小写不敏感,末尾分隔符也不该影响判定。 */
|
|
25
|
+
const samePath = (left, right) => {
|
|
26
|
+
const norm = (value) => String(value).replace(/[\\/]+$/, '').replace(/\\/g, '/').toLowerCase();
|
|
27
|
+
return norm(left) === norm(right);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export class HostAgentError extends Error {
|
|
31
|
+
constructor(code, message, details = {}) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.name = 'HostAgentError';
|
|
34
|
+
this.code = code;
|
|
35
|
+
this.details = details;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {{
|
|
41
|
+
* agents: any,
|
|
42
|
+
* agentDefaultModel: any,
|
|
43
|
+
* workspaceRegistry?: any,
|
|
44
|
+
* sessions?: any,
|
|
45
|
+
* cwd: string,
|
|
46
|
+
* newSessionId?: () => string
|
|
47
|
+
* }} options
|
|
48
|
+
*/
|
|
49
|
+
export async function ensureHostAgent(options) {
|
|
50
|
+
const agents = options.agents;
|
|
51
|
+
if (agents === undefined || typeof agents.create !== 'function') {
|
|
52
|
+
throw new HostAgentError('E_RUNTIME_UNAVAILABLE', 'agents service is unavailable');
|
|
53
|
+
}
|
|
54
|
+
// Repair a Host Agent archived by an earlier revision: the archive gate
|
|
55
|
+
// covers the host's whole subagent lineage, so every member turn would end
|
|
56
|
+
// blocked before any model request. `unarchiveSession` resolves without
|
|
57
|
+
// writing when the id is not archived, so no read-back is needed — and
|
|
58
|
+
// gating on the undocumented `archivedSessionIds` accessor is what silently
|
|
59
|
+
// skipped this repair before.
|
|
60
|
+
const unarchiveHost = async (sessionId) => {
|
|
61
|
+
const registry = options.workspaceRegistry;
|
|
62
|
+
if (typeof registry?.unarchiveSession !== 'function') return;
|
|
63
|
+
try {
|
|
64
|
+
await registry.unarchiveSession(sessionId);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
reportFail('host.unarchive.fail', { sessionId: sessionId ?? null }, '[ai-team] could not unarchive Team Host session: ' + (error?.message ?? error));
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
// Persist the resolved route into the session log. Live AgentOptions die
|
|
70
|
+
// with the process; without a recorded selection a restored session renders
|
|
71
|
+
// prompts with an unresolvable {{model}} variable.
|
|
72
|
+
const persistSelection = (sessionId, selection) => {
|
|
73
|
+
try {
|
|
74
|
+
const session = options.sessions?.get?.(sessionId);
|
|
75
|
+
if (session === undefined || session === null || typeof session.append !== 'function') return;
|
|
76
|
+
if (typeof selection?.provider !== 'string' || typeof selection?.model !== 'string') return;
|
|
77
|
+
// 推理等级一并记下,否则恢复出来的会话按模型默认档走。
|
|
78
|
+
const effort = typeof selection.reasoningEffort === 'string' && selection.reasoningEffort !== ''
|
|
79
|
+
? selection.reasoningEffort
|
|
80
|
+
: null;
|
|
81
|
+
session.append('model/selection', {
|
|
82
|
+
provider: selection.provider,
|
|
83
|
+
model: selection.model,
|
|
84
|
+
...(effort === null ? {} : { reasoningEffort: effort }),
|
|
85
|
+
});
|
|
86
|
+
} catch (error) {
|
|
87
|
+
reportFail('host.model.persist.fail', {}, '[ai-team] host model selection persist failed: ' + (error?.message ?? error));
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
if (typeof options.resumeSessionId === 'string' && options.resumeSessionId !== '') {
|
|
91
|
+
const live = typeof agents.get === 'function' ? agents.get(options.resumeSessionId) : undefined;
|
|
92
|
+
if (live !== undefined) {
|
|
93
|
+
await unarchiveHost(options.resumeSessionId);
|
|
94
|
+
const selection = typeof options.agentDefaultModel?.currentSelection === 'function' ? options.agentDefaultModel.currentSelection() : null;
|
|
95
|
+
persistSelection(options.resumeSessionId, selection);
|
|
96
|
+
return { agent: live, created: false, resumed: true, sessionId: options.resumeSessionId, dispose: async () => {} };
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const handle = await agents.resume({ resumeSessionId: options.resumeSessionId });
|
|
100
|
+
await unarchiveHost(options.resumeSessionId);
|
|
101
|
+
// 持久化的 host 会话保留着**创建时的 cwd**,而成员子会话会继承它。
|
|
102
|
+
// 实机事故:2026-11-09 建的 host 记的是 `…/.dsh/ai-team/default`,于是
|
|
103
|
+
// 30 个成员会话全在插件数据目录里干活,`workspace.attachSession` 每天被拒
|
|
104
|
+
// 上百次。cwd 不一致时不能复用这条 host——释放它,落到下面的创建分支。
|
|
105
|
+
const expectedCwd = typeof options.cwd === 'string' ? options.cwd.trim() : '';
|
|
106
|
+
const actualCwd = handle?.agent?.session?.header?.cwd ?? options.sessions?.get?.(options.resumeSessionId)?.header?.cwd ?? null;
|
|
107
|
+
if (expectedCwd !== '' && typeof actualCwd === 'string' && actualCwd !== ''
|
|
108
|
+
&& samePath(actualCwd, expectedCwd) === false) {
|
|
109
|
+
try { await handle.dispose?.(); } catch { /* already gone */ }
|
|
110
|
+
reportFail(
|
|
111
|
+
'host.resume.cwd-mismatch.fail',
|
|
112
|
+
{ sessionId: options.resumeSessionId, expectedCwd, actualCwd },
|
|
113
|
+
'[ai-team] Team Host session cwd does not match the project workspace; creating a fresh host',
|
|
114
|
+
);
|
|
115
|
+
} else {
|
|
116
|
+
const selection = typeof options.agentDefaultModel?.currentSelection === 'function' ? options.agentDefaultModel.currentSelection() : null;
|
|
117
|
+
persistSelection(options.resumeSessionId, selection);
|
|
118
|
+
return {
|
|
119
|
+
agent: handle.agent,
|
|
120
|
+
created: false,
|
|
121
|
+
resumed: true,
|
|
122
|
+
sessionId: options.resumeSessionId,
|
|
123
|
+
dispose: async () => { try { await handle.dispose?.(); } catch { /* already gone */ } },
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
} catch (error) {
|
|
127
|
+
// A persisted host must be resumed: creating another one would break the
|
|
128
|
+
// existing members' direct-child adjacency.
|
|
129
|
+
throw new HostAgentError('E_HOST_AGENT', `Team Host Agent resume failed: ${error?.message ?? error}`, {
|
|
130
|
+
sessionId: options.resumeSessionId,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const roots = typeof agents.roots === 'function' ? agents.roots() : [];
|
|
135
|
+
if (roots.length > 0) {
|
|
136
|
+
// roots() 只保证注册顺序,不保证某个元素是「Human 的根会话」;优先挑一个
|
|
137
|
+
// 真正没有父会话、且不是 subagent 出来的根,避免把成员自己的父链当成
|
|
138
|
+
// Human 通道(那会让成员成为彼此的 parent)。
|
|
139
|
+
const rootAgent = roots.find((candidate) => {
|
|
140
|
+
const header = candidate?.session?.header;
|
|
141
|
+
if (header === undefined) return true;
|
|
142
|
+
return header.origin !== 'subagent' && header.parentSession === undefined;
|
|
143
|
+
}) ?? roots[0];
|
|
144
|
+
// 被选中的 Human 根会话若已归档,成员血缘会被 gate 永久拒绝——这条快路径
|
|
145
|
+
// 也必须解归档,否则 boot 期的 sweep 由于没有 hostSessionId 看不到它。
|
|
146
|
+
await unarchiveHost(rootAgent.id);
|
|
147
|
+
return { agent: rootAgent, created: false, sessionId: rootAgent.id, dispose: async () => {} };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const selection = typeof options.agentDefaultModel?.currentSelection === 'function'
|
|
151
|
+
? options.agentDefaultModel.currentSelection()
|
|
152
|
+
: null;
|
|
153
|
+
if (selection === null || typeof selection.provider !== 'string' || typeof selection.model !== 'string') {
|
|
154
|
+
throw new HostAgentError('E_RUNTIME_UNAVAILABLE', 'no default provider/model is configured for the Team Host Agent');
|
|
155
|
+
}
|
|
156
|
+
const sessionId = options.newSessionId?.() ?? `session-team-host-${randomUUID()}`;
|
|
157
|
+
const agentOptions = { provider: selection.provider, model: selection.model };
|
|
158
|
+
if (typeof selection.reasoningEffort === 'string') agentOptions.reasoningEffort = selection.reasoningEffort;
|
|
159
|
+
let handle;
|
|
160
|
+
try {
|
|
161
|
+
handle = await agents.create({
|
|
162
|
+
sessionId,
|
|
163
|
+
meta: { cwd: options.cwd },
|
|
164
|
+
agentOptions,
|
|
165
|
+
});
|
|
166
|
+
} catch (error) {
|
|
167
|
+
throw new HostAgentError('E_HOST_AGENT', `Team Host Agent creation failed: ${error?.message ?? error}`, {
|
|
168
|
+
cause: error?.code ?? null,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
persistSelection(sessionId, selection);
|
|
172
|
+
const host = handle.agent;
|
|
173
|
+
await unarchiveHost(sessionId);
|
|
174
|
+
return {
|
|
175
|
+
agent: host,
|
|
176
|
+
created: true,
|
|
177
|
+
sessionId,
|
|
178
|
+
dispose: async () => {
|
|
179
|
+
try { await handle.dispose?.(); } catch { /* teardown already started */ }
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SubagentRuntime 的 provider 注册探测。
|
|
3
|
+
*
|
|
4
|
+
* 实机事故(issue #1 借楼报):桌面 DSH 0.2.2-rc.2 的 SubagentRuntime 移除了
|
|
5
|
+
* `list()`(rc.1 还有,返回 providers.keys()),插件用
|
|
6
|
+
* `typeof subagents.list === 'function' ? subagents.list() : []` 判空,把
|
|
7
|
+
* **能力缺失当成了状态为空**——成员激活恒 503、唤醒静默 return,日志里什么都不留。
|
|
8
|
+
*
|
|
9
|
+
* 泛化规则:探测型代码不得把「问不到」当成「没有」。问不到时放行,让真正的调用
|
|
10
|
+
* (startActivation)产生带原因的失败,再记录它。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @returns {'no-service'|'unknown'|'empty'|'ready'}
|
|
15
|
+
* no-service — subagents 服务本身不存在(调用方自会走既有的 E_RUNTIME_UNAVAILABLE);
|
|
16
|
+
* unknown — 宿主没有 list() 这个自省方法(rc.2+),无法判断,视为放行;
|
|
17
|
+
* empty — 确认还没有 provider 注册;
|
|
18
|
+
* ready — 至少一个 provider。
|
|
19
|
+
*/
|
|
20
|
+
export function probeProviderRegistration(subagents) {
|
|
21
|
+
if (subagents === undefined || subagents === null) return 'no-service';
|
|
22
|
+
if (typeof subagents.list !== 'function') return 'unknown';
|
|
23
|
+
let providers;
|
|
24
|
+
try {
|
|
25
|
+
providers = subagents.list();
|
|
26
|
+
} catch {
|
|
27
|
+
return 'unknown';
|
|
28
|
+
}
|
|
29
|
+
return Array.isArray(providers) && providers.length > 0 ? 'ready' : 'empty';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** 探测结果是否应挡住激活/唤醒(只有确认 empty 才挡)。 */
|
|
33
|
+
export function blocksActivation(state) {
|
|
34
|
+
return state === 'empty';
|
|
35
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@suifei/dsh-ai-team",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.81",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "文渊阁 (Wenyuan Pavilion) — AI Team mode for DeepSeek Harness: concurrent projects, owned tasks, threads, inbox and an append-only team ledger",
|
|
6
6
|
"license": "MIT",
|