@fish-under-sea/dsh-agent-teams-fish 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -181,18 +181,18 @@ export function outputLimitTurn(event) {
181
181
  return record.data.turn;
182
182
  }
183
183
  }
184
- /** 读取宿主冻结的会话策略,旧版没有投影服务时检查本会话日志。 */
185
- export function assertMemberModelSelection(ctx, captain, route) {
184
+ /** 读取官方 subagent 冻结在本会话的允许模型名单;没有策略时返回 undefined。 */
185
+ export function memberModelSelectionPolicy(ctx, session) {
186
186
  const projections = ctx.get?.('sessionProjections');
187
- const session = captain.session;
188
- const projected = projections?.stateOf(captain.session, 'subagentModelSelectionPolicy');
187
+ const hostSession = session;
188
+ const projected = projections?.stateOf(session, 'subagentModelSelectionPolicy');
189
189
  const policy = projected === undefined
190
- ? (typeof session.ownEvents === 'function' || Array.isArray(session.events))
191
- ? sessionOwnEvents(captain.session).find(event => event.type === 'subagent/model-selection-policy')?.data
190
+ ? (typeof hostSession.ownEvents === 'function' || Array.isArray(hostSession.events))
191
+ ? sessionOwnEvents(session).find(event => event.type === 'subagent/model-selection-policy')?.data
192
192
  : undefined
193
193
  : projected;
194
194
  if (policy === undefined || policy === null)
195
- return;
195
+ return undefined;
196
196
  const routes = projected === undefined
197
197
  ? policy.allowedModels
198
198
  : policy;
@@ -200,6 +200,13 @@ export function assertMemberModelSelection(ctx, captain, route) {
200
200
  || !('provider' in candidate) || typeof candidate.provider !== 'string' || candidate.provider.length === 0
201
201
  || !('model' in candidate) || typeof candidate.model !== 'string' || candidate.model.length === 0)))
202
202
  throw new Error('agent-teams: invalid captured subagent model selection policy');
203
+ return routes.map(candidate => ({ provider: candidate.provider, model: candidate.model }));
204
+ }
205
+ /** 读取宿主冻结的会话策略,旧版没有投影服务时检查本会话日志。 */
206
+ export function assertMemberModelSelection(ctx, captain, route) {
207
+ const routes = memberModelSelectionPolicy(ctx, captain.session);
208
+ if (routes === undefined)
209
+ return;
203
210
  if (!routes.some(candidate => candidate.provider === route.provider && candidate.model === route.model)) {
204
211
  throw new Error(`agent-teams: child LLM route "${route.provider}/${route.model}" is not allowed for this Session; choose a route from list_subagent_models`);
205
212
  }
package/lib/index.js CHANGED
@@ -30,7 +30,7 @@ import { leadIdentityOfAsync } from "./lineage.js";
30
30
  import { formatProfilesForPrompt } from "./profiles.js";
31
31
  import { parseToolPolicies } from "./tool-policies.js";
32
32
  import { installTeamCapabilities } from "./capabilities.js";
33
- import { agentTeamsSource, observedSessionFormatVersion } from "./harness-compat.js";
33
+ import { agentTeamsSource, memberModelSelectionPolicy, observedSessionFormatVersion } from "./harness-compat.js";
34
34
  import { TEAM_TOOL_NAMES } from "./tool-names.js";
35
35
  import { artworkCandidates, findCustomArtwork, findPackagedArtwork } from "./artwork-source.js";
36
36
  import { authenticatedWebRoutes, readJsonRequest, RequestBodyError, writeJsonWithEtag } from "./web-routes.js";
@@ -314,6 +314,39 @@ export function apply(ctx, config) {
314
314
  }
315
315
  },
316
316
  }), 'agent-teams: halt route');
317
+ // Read-only view of the official subagent allowed-model policy for this
318
+ // captain session. The plan editor filters its model picker with this so a
319
+ // member route can only be chosen from the same allowlist the host will
320
+ // enforce at spawn time.
321
+ ctx.effect(() => webServer.register({
322
+ kind: 'exact',
323
+ path: '/plugins/dsh-agent-teams/model-policy',
324
+ handler: async (req, res) => {
325
+ const url = new URL(req.url ?? '/', 'http://x');
326
+ const sessionId = url.searchParams.get('session')?.trim() || undefined;
327
+ if (sessionId === undefined) {
328
+ res.writeHead(400, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' });
329
+ res.end(JSON.stringify({ error: 'session is required' }));
330
+ return;
331
+ }
332
+ const captain = ctx.agents.get(sessionId);
333
+ if (captain === undefined) {
334
+ res.writeHead(409, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' });
335
+ res.end(JSON.stringify({ error: 'captain session is not attached' }));
336
+ return;
337
+ }
338
+ try {
339
+ const allowedModels = memberModelSelectionPolicy(ctx, captain.session);
340
+ res.writeHead(200, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' });
341
+ res.end(JSON.stringify({ enabled: allowedModels !== undefined, allowedModels: allowedModels ?? null }));
342
+ }
343
+ catch (error) {
344
+ ctx.logger.warn(`agent-teams: model-policy read failed: ${String(error)}`);
345
+ res.writeHead(500, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' });
346
+ res.end(JSON.stringify({ error: 'failed to read model policy' }));
347
+ }
348
+ },
349
+ }), 'agent-teams: model policy route');
317
350
  ctx.effect(() => webServer.register({
318
351
  kind: 'exact',
319
352
  path: '/plugins/dsh-agent-teams/plan',
@@ -129,6 +129,11 @@ export declare function onAgentReady(ctx: Context, listener: (agent: Agent, veto
129
129
  export declare function sessionOwnEvents(session: Session): readonly SessionEvent[];
130
130
  /** Legacy hosts log each chunk separately; current hosts embed the committed stream. */
131
131
  export declare function outputLimitTurn(event: SessionEvent): number | undefined;
132
+ /** 读取官方 subagent 冻结在本会话的允许模型名单;没有策略时返回 undefined。 */
133
+ export declare function memberModelSelectionPolicy(ctx: Context, session: Session): {
134
+ provider: string;
135
+ model: string;
136
+ }[] | undefined;
132
137
  /** 读取宿主冻结的会话策略,旧版没有投影服务时检查本会话日志。 */
133
138
  export declare function assertMemberModelSelection(ctx: Context, captain: Agent, route: {
134
139
  provider: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fish-under-sea/dsh-agent-teams-fish",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "AgentTeams 多智能体团队协作(DeepSeek Harness 插件):自然语言组队、成员与任务依赖 DAG、信箱通信、右侧栏树状监测 —— 上游 NanmiCoder/dsh-agent-teams 的补充版,新增自定义美术目录、十八厂商头像(十个有厂商 × 岗位全套)与厂商商标徽标。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -260,4 +260,4 @@
260
260
  "bin": {
261
261
  "dsh-agent-teams-doctor": "scripts/doctor.mjs"
262
262
  }
263
- }
263
+ }
@@ -113,6 +113,7 @@ function effortMenuId(effort: string): string {
113
113
  */
114
114
  function StagedModelPicker({
115
115
  directory,
116
+ sessionId,
116
117
  provider,
117
118
  model,
118
119
  reasoningEffort,
@@ -121,6 +122,7 @@ function StagedModelPicker({
121
122
  t,
122
123
  }: {
123
124
  readonly directory: ModelDirectory
125
+ readonly sessionId: string
124
126
  readonly provider: string
125
127
  readonly model: string
126
128
  readonly reasoningEffort: string
@@ -131,7 +133,36 @@ function StagedModelPicker({
131
133
  const state = useSyncExternalStore(directory.store.subscribe, directory.store.getSnapshot)
132
134
  const [open, setOpen] = useState(false)
133
135
  const [pane, setPane] = useState<ModelMenuPane>('root')
134
- const catalogRoutes = state.groups.flatMap((group) => group.models.map((candidate) => ({
136
+ // null = no official policy captured for this session: keep the full catalog.
137
+ const [allowedModels, setAllowedModels] = useState<readonly { provider: string; model: string }[] | null>(null)
138
+ useEffect(() => {
139
+ if (sessionId === '') return
140
+ let cancelled = false
141
+ void fetch(`/plugins/dsh-agent-teams/model-policy?session=${encodeURIComponent(sessionId)}`, { credentials: 'same-origin' })
142
+ .then((response) => response.ok ? response.json() as Promise<unknown> : undefined)
143
+ .then((data) => {
144
+ if (cancelled) return
145
+ const models = (data as { allowedModels?: unknown } | undefined)?.allowedModels
146
+ setAllowedModels(Array.isArray(models)
147
+ ? models.filter((candidate): candidate is { provider: string; model: string } => (
148
+ typeof candidate === 'object' && candidate !== null
149
+ && typeof (candidate as { provider?: unknown }).provider === 'string'
150
+ && typeof (candidate as { model?: unknown }).model === 'string'
151
+ ))
152
+ : null)
153
+ })
154
+ .catch(() => {})
155
+ return () => { cancelled = true }
156
+ }, [sessionId])
157
+ const visibleGroups = allowedModels === null
158
+ ? state.groups
159
+ : state.groups
160
+ .map((group) => ({
161
+ ...group,
162
+ models: group.models.filter((candidate) => allowedModels.some((route) => route.provider === group.id && route.model === candidate.id)),
163
+ }))
164
+ .filter((group) => group.models.length > 0)
165
+ const catalogRoutes = visibleGroups.flatMap((group) => group.models.map((candidate) => ({
135
166
  key: routeKey(group.id, candidate.id),
136
167
  provider: group.id,
137
168
  providerName: group.name,
@@ -201,7 +232,7 @@ function StagedModelPicker({
201
232
  disabled: true,
202
233
  })
203
234
  } else {
204
- for (const group of state.groups) {
235
+ for (const group of visibleGroups) {
205
236
  modelItems.push({ type: 'label', id: `provider:${group.id}`, text: group.name })
206
237
  for (const candidate of group.models) {
207
238
  modelItems.push({
@@ -453,6 +484,7 @@ function StagedMemberEditor({ team, member, modelDirectory, onPendingChange, t }
453
484
  <label>{t('plan.member.role')}<input name="role" value={role} onChange={(event) => { setRole(event.currentTarget.value); markEdited() }} /></label>
454
485
  <StagedModelPicker
455
486
  directory={modelDirectory}
487
+ sessionId={team.captainSessionId}
456
488
  provider={provider}
457
489
  model={model}
458
490
  reasoningEffort={reasoningEffort}
@@ -259,19 +259,19 @@ export function outputLimitTurn(event: SessionEvent): number | undefined {
259
259
  }
260
260
  }
261
261
 
262
- /** 读取宿主冻结的会话策略,旧版没有投影服务时检查本会话日志。 */
263
- export function assertMemberModelSelection(ctx: Context, captain: Agent, route: { provider: string; model: string }): void {
262
+ /** 读取官方 subagent 冻结在本会话的允许模型名单;没有策略时返回 undefined。 */
263
+ export function memberModelSelectionPolicy(ctx: Context, session: Session): { provider: string; model: string }[] | undefined {
264
264
  const projections = ctx.get?.('sessionProjections') as {
265
265
  stateOf(session: Session, key: string): unknown
266
266
  } | undefined
267
- const session = captain.session as unknown as { ownEvents?: () => readonly SessionEvent[]; events?: readonly SessionEvent[] }
268
- const projected = projections?.stateOf(captain.session, 'subagentModelSelectionPolicy')
267
+ const hostSession = session as unknown as { ownEvents?: () => readonly SessionEvent[]; events?: readonly SessionEvent[] }
268
+ const projected = projections?.stateOf(session, 'subagentModelSelectionPolicy')
269
269
  const policy = projected === undefined
270
- ? (typeof session.ownEvents === 'function' || Array.isArray(session.events))
271
- ? (sessionOwnEvents(captain.session) as readonly { type: string; data: unknown }[]).find(event => event.type === 'subagent/model-selection-policy')?.data
270
+ ? (typeof hostSession.ownEvents === 'function' || Array.isArray(hostSession.events))
271
+ ? (sessionOwnEvents(session) as readonly { type: string; data: unknown }[]).find(event => event.type === 'subagent/model-selection-policy')?.data
272
272
  : undefined
273
273
  : projected
274
- if (policy === undefined || policy === null) return
274
+ if (policy === undefined || policy === null) return undefined
275
275
  const routes: unknown = projected === undefined
276
276
  ? (policy as { allowedModels?: unknown }).allowedModels
277
277
  : policy
@@ -280,6 +280,13 @@ export function assertMemberModelSelection(ctx: Context, captain: Agent, route:
280
280
  || !('provider' in candidate) || typeof candidate.provider !== 'string' || candidate.provider.length === 0
281
281
  || !('model' in candidate) || typeof candidate.model !== 'string' || candidate.model.length === 0
282
282
  ))) throw new Error('agent-teams: invalid captured subagent model selection policy')
283
+ return routes.map(candidate => ({ provider: candidate.provider, model: candidate.model }))
284
+ }
285
+
286
+ /** 读取宿主冻结的会话策略,旧版没有投影服务时检查本会话日志。 */
287
+ export function assertMemberModelSelection(ctx: Context, captain: Agent, route: { provider: string; model: string }): void {
288
+ const routes = memberModelSelectionPolicy(ctx, captain.session)
289
+ if (routes === undefined) return
283
290
  if (!routes.some(candidate => candidate.provider === route.provider && candidate.model === route.model)) {
284
291
  throw new Error(`agent-teams: child LLM route "${route.provider}/${route.model}" is not allowed for this Session; choose a route from list_subagent_models`)
285
292
  }
package/src/index.ts CHANGED
@@ -42,7 +42,7 @@ import { leadIdentityOfAsync } from './lineage.ts'
42
42
  import { formatProfilesForPrompt, type TeamProfileConfig } from './profiles.ts'
43
43
  import { parseToolPolicies, type MemberToolPolicy } from './tool-policies.ts'
44
44
  import { installTeamCapabilities } from './capabilities.ts'
45
- import { agentTeamsSource, observedSessionFormatVersion } from './harness-compat.ts'
45
+ import { agentTeamsSource, memberModelSelectionPolicy, observedSessionFormatVersion } from './harness-compat.ts'
46
46
  import { TEAM_TOOL_NAMES } from './tool-names.ts'
47
47
  import { artworkCandidates, findCustomArtwork, findPackagedArtwork } from './artwork-source.ts'
48
48
 
@@ -410,6 +410,39 @@ export function apply(ctx: Context, config: Config): void {
410
410
  },
411
411
  }), 'agent-teams: halt route')
412
412
 
413
+ // Read-only view of the official subagent allowed-model policy for this
414
+ // captain session. The plan editor filters its model picker with this so a
415
+ // member route can only be chosen from the same allowlist the host will
416
+ // enforce at spawn time.
417
+ ctx.effect(() => webServer.register({
418
+ kind: 'exact',
419
+ path: '/plugins/dsh-agent-teams/model-policy',
420
+ handler: async (req, res) => {
421
+ const url = new URL(req.url ?? '/', 'http://x')
422
+ const sessionId = url.searchParams.get('session')?.trim() || undefined
423
+ if (sessionId === undefined) {
424
+ res.writeHead(400, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
425
+ res.end(JSON.stringify({ error: 'session is required' }))
426
+ return
427
+ }
428
+ const captain = ctx.agents.get(sessionId as import('@deepseek-ai/dsh-session').SessionId)
429
+ if (captain === undefined) {
430
+ res.writeHead(409, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
431
+ res.end(JSON.stringify({ error: 'captain session is not attached' }))
432
+ return
433
+ }
434
+ try {
435
+ const allowedModels = memberModelSelectionPolicy(ctx, captain.session)
436
+ res.writeHead(200, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
437
+ res.end(JSON.stringify({ enabled: allowedModels !== undefined, allowedModels: allowedModels ?? null }))
438
+ } catch (error: unknown) {
439
+ ctx.logger.warn(`agent-teams: model-policy read failed: ${String(error)}`)
440
+ res.writeHead(500, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
441
+ res.end(JSON.stringify({ error: 'failed to read model policy' }))
442
+ }
443
+ },
444
+ }), 'agent-teams: model policy route')
445
+
413
446
  ctx.effect(() => webServer.register({
414
447
  kind: 'exact',
415
448
  path: '/plugins/dsh-agent-teams/plan',