dsh-tool-manager 1.2.11 → 1.2.12

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/dist/dsh.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"dsh.d.ts","sourceRoot":"","sources":["../src/dsh.ts"],"names":[],"mappings":"AAAA,iFAAiF;AAEjF,MAAM,WAAW,WAAW;IAC1B,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC;IAC9C,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GAAG,OAAO,CAAC;IACtE,MAAM,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,OAAO,GAAG,OAAO,CAAC;IAC1E,MAAM,CAAC,CAAC,OAAO,EAAE,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1D;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,gFAAgF;IAChF,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;KAAE,CAAC;IACxC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAAC;CACpD;AAED,MAAM,WAAW,SAAS;IACxB,qCAAqC;IACrC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,WAAW,CAAC;IACjB,OAAO,CAAC,EAAE,gBAAgB,CAAC;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,SAAS,CAEvF;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,CAS9F;AAED,MAAM,WAAW,wBAAwB;IACvC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mFAAmF;IACnF,IAAI,CAAC,EAAE,SAAS,wBAAwB,EAAE,CAAC;CAC5C;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,IAAI,SAAS,EAAE,CAAC;CACrB;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAG5E;AAED,gFAAgF;AAChF,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,gBAAgB,EACzB,KAAK,EAAE,eAAe,EACtB,EAAE,CAAC,EAAE,MAAM,GACV,OAAO,CAAC,cAAc,EAAE,CAAC,CAO3B"}
package/dist/dsh.js CHANGED
@@ -1,4 +1,34 @@
1
1
  /** Structural DSH faces used by this plugin. No @deepseek-ai runtime imports. */
2
+ /**
3
+ * Read one Preset-service source: a fixed instance, or the live one.
4
+ * @param source - the instance or resolver a consumer was given.
5
+ * @returns the service, or `undefined` while DSH has none provided.
6
+ */
7
+ export function resolvePresets(source) {
8
+ return typeof source === "function" ? source() : source;
9
+ }
10
+ /**
11
+ * The preset a Session runs, according to the Session log.
12
+ *
13
+ * Answers even when the live registry holds no binding for the Agent: the log
14
+ * records the preset the Session started in (and every selection since), while
15
+ * bindings belong to the instance that composed the Agent.
16
+ * @param presets - the live registry.
17
+ * @param agent - the Agent whose Session to read.
18
+ * @returns the preset id, or `undefined` when the Host cannot tell.
19
+ */
20
+ export function presetForAgent(presets, agent) {
21
+ const read = presets.presetForSession;
22
+ if (typeof read !== "function")
23
+ return undefined;
24
+ try {
25
+ const declared = read.call(presets, agent.session);
26
+ return typeof declared === "string" && declared !== "" ? declared : undefined;
27
+ }
28
+ catch {
29
+ return undefined;
30
+ }
31
+ }
2
32
  export function asRecord(value) {
3
33
  if (value === null || typeof value !== "object" || Array.isArray(value))
4
34
  return undefined;
package/dist/dsh.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"dsh.js","sourceRoot":"","sources":["../src/dsh.ts"],"names":[],"mappings":"AAAA,iFAAiF;AAiHjF,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAC1F,OAAO,KAAgC,CAAC;AAC1C,CAAC;AAED,gFAAgF;AAChF,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAAyB,EACzB,KAAsB,EACtB,EAAW;IAEX,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;IAC7C,IAAI,CAAC;QACH,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;YAAS,CAAC;QACT,MAAM,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;IACrC,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"dsh.js","sourceRoot":"","sources":["../src/dsh.ts"],"names":[],"mappings":"AAAA,iFAAiF;AAsHjF;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,MAA0B;IACvD,OAAO,OAAO,MAAM,KAAK,UAAU,CAA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sLike, AgentPresetsSource, ContextLike, ToolRuntimeLike, ToolSchemaLike } from "./dsh.js";
2
2
  import { normalizeSettings } from "./policy.js";
3
3
  export declare const name = "dsh-tool-manager";
4
4
  export declare const inject: string[];
@@ -14,9 +14,20 @@ export declare class PresetSchemaProbe {
14
14
  private initialization?;
15
15
  private queue;
16
16
  private disposed;
17
- constructor(context: ContextLike, presets: AgentPresetsLike);
17
+ /** The registry instance this probe's Agent is bound to. */
18
+ private boundTo?;
19
+ constructor(context: ContextLike, presets: AgentPresetsSource);
18
20
  inspect(presetId: string): Promise<ToolSchemaLike[]>;
19
21
  private inspectSerial;
22
+ /**
23
+ * Rebuild the probe Agent when DSH replaced the registry underneath it.
24
+ *
25
+ * The probe Session's scope parent names a generation of the retired
26
+ * instance, which the new one does not know: `recompose()` there would leave
27
+ * the Agent on a composition no live registry owns. Composing a fresh Agent
28
+ * against the new instance is what re-binds it.
29
+ */
30
+ private rebind;
20
31
  private ensure;
21
32
  private initialize;
22
33
  dispose(): Promise<void>;
@@ -50,8 +61,8 @@ export declare class DefaultPresetMount {
50
61
  private readonly presets;
51
62
  private readonly warn;
52
63
  private attempt?;
53
- private ready;
54
- constructor(presets: AgentPresetsLike, warn: (message: string) => void);
64
+ private readyOn?;
65
+ constructor(presets: AgentPresetsSource, warn: (message: string) => void);
55
66
  /**
56
67
  * Resolve once the default preset's standing composition exists, once its
57
68
  * composing attempt settled, or immediately when it already did.
@@ -70,7 +81,7 @@ export interface PresetCatalog {
70
81
  }
71
82
  export interface PresetCatalogOptions {
72
83
  context: ContextLike;
73
- presets: AgentPresetsLike;
84
+ presets: AgentPresetsSource;
74
85
  probe: PresetSchemaProbe;
75
86
  defaultPreset: DefaultPresetMount;
76
87
  /** Schemas observed on live Agents of one Preset, without probing. */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,gBAAgB,EAChB,WAAW,EAEX,eAAe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AE,GAAG,SAAS,CAAC,GAAG,MAAM,EAAE,GAAG,SAAS,GACxF,OAAO,CAAC,IAAI,CAAC,CAoCf;AA6CD,OAAO,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC1E,YAAY,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACtE,mBAAmB,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
- import { asRecord, schemasForPreset } from "./dsh.js";
1
+ import { asRecord, resolvePresets, schemasForPreset } from "./dsh.js";
2
2
  import { CompositionWatch } from "./composition-watch.js";
3
3
  import { ToolManagerConfigStore } from "./config.js";
4
4
  import { groupPolicyIssues, matchesAnyPattern, normalizeSettings, policyFor } from "./policy.js";
5
+ import { userNotices } from "./notices.js";
5
6
  import { ToolPolicyRuntime } from "./runtime.js";
6
7
  import { buildSnapshot, mergeSchemas } from "./snapshot.js";
7
8
  import { DISCOVERY_TOOL_NAME, PTC_TRANSPORT_NAME, TOOL_MANAGER_PROBE_SESSION_ID, } from "./types.js";
@@ -20,6 +21,8 @@ export class PresetSchemaProbe {
20
21
  initialization;
21
22
  queue = Promise.resolve();
22
23
  disposed = false;
24
+ /** The registry instance this probe's Agent is bound to. */
25
+ boundTo;
23
26
  constructor(context, presets) {
24
27
  this.context = context;
25
28
  this.presets = presets;
@@ -32,11 +35,15 @@ export class PresetSchemaProbe {
32
35
  async inspectSerial(presetId) {
33
36
  if (this.disposed)
34
37
  return [];
35
- const handle = await this.ensure(presetId);
38
+ const presets = resolvePresets(this.presets);
39
+ if (!presets)
40
+ return [];
41
+ await this.rebind(presets);
42
+ const handle = await this.ensure(presets, presetId);
36
43
  if (!handle)
37
44
  return [];
38
- if (this.presets.composedPreset(handle.agent.ctx) !== presetId) {
39
- await this.presets.recompose(handle.agent.ctx, presetId);
45
+ if (presets.composedPreset(handle.agent.ctx) !== presetId) {
46
+ await presets.recompose(handle.agent.ctx, presetId);
40
47
  // Dynamic preset plugins reconcile Agent-scoped registrations from the
41
48
  // tools/change event emitted by recompose(). Some disposals complete on
42
49
  // the next event-loop turn, so reading immediately can leak the previous
@@ -45,11 +52,28 @@ export class PresetSchemaProbe {
45
52
  }
46
53
  return handle.agent.ctx.get("tools")?.schemas(handle.agent) ?? [];
47
54
  }
48
- async ensure(initialPresetId) {
55
+ /**
56
+ * Rebuild the probe Agent when DSH replaced the registry underneath it.
57
+ *
58
+ * The probe Session's scope parent names a generation of the retired
59
+ * instance, which the new one does not know: `recompose()` there would leave
60
+ * the Agent on a composition no live registry owns. Composing a fresh Agent
61
+ * against the new instance is what re-binds it.
62
+ */
63
+ async rebind(presets) {
64
+ if (this.boundTo === presets)
65
+ return;
66
+ this.boundTo = presets;
67
+ const handle = this.handle;
68
+ this.handle = undefined;
69
+ if (handle)
70
+ await handle.dispose().catch(() => undefined);
71
+ }
72
+ async ensure(presets, initialPresetId) {
49
73
  if (this.handle)
50
74
  return this.handle;
51
75
  if (!this.initialization) {
52
- this.initialization = this.initialize(initialPresetId).then(async (handle) => {
76
+ this.initialization = this.initialize(presets, initialPresetId).then(async (handle) => {
53
77
  if (!handle)
54
78
  return undefined;
55
79
  if (this.disposed) {
@@ -64,13 +88,13 @@ export class PresetSchemaProbe {
64
88
  }
65
89
  return this.initialization;
66
90
  }
67
- async initialize(initialPresetId) {
91
+ async initialize(presets, initialPresetId) {
68
92
  const agents = this.context.get("agents");
69
93
  const persistence = this.context.get("sessionPersistence");
70
94
  if (!agents || !persistence)
71
95
  return undefined;
72
96
  const setup = async (agentCtx) => {
73
- await this.presets.mount(agentCtx, initialPresetId);
97
+ await presets.mount(agentCtx, initialPresetId);
74
98
  };
75
99
  const existing = await persistence.stat(TOOL_MANAGER_PROBE_SESSION_ID);
76
100
  if (existing) {
@@ -129,7 +153,7 @@ export class DefaultPresetMount {
129
153
  presets;
130
154
  warn;
131
155
  attempt;
132
- ready = false;
156
+ readyOn;
133
157
  constructor(presets, warn) {
134
158
  this.presets = presets;
135
159
  this.warn = warn;
@@ -139,23 +163,35 @@ export class DefaultPresetMount {
139
163
  * composing attempt settled, or immediately when it already did.
140
164
  */
141
165
  async ensure() {
142
- if (this.ready)
166
+ const presets = resolvePresets(this.presets);
167
+ if (!presets)
168
+ return;
169
+ // Readiness is per registry instance. DSH replaces the instance when the
170
+ // registry node reloads, and the new one owns none of the standing
171
+ // compositions the retired one was measured on.
172
+ if (this.readyOn === presets)
143
173
  return;
144
- this.attempt ??= this.compose();
145
- await this.attempt;
174
+ if (this.attempt?.presets === presets)
175
+ return this.attempt.task;
176
+ const attempt = { presets, task: this.compose(presets) };
177
+ this.attempt = attempt;
178
+ try {
179
+ await attempt.task;
180
+ }
181
+ finally {
182
+ if (this.attempt === attempt)
183
+ this.attempt = undefined;
184
+ }
146
185
  }
147
- async compose() {
186
+ async compose(presets) {
148
187
  try {
149
- const lease = await this.presets.acquireScope(undefined);
188
+ const lease = await presets.acquireScope(undefined);
150
189
  await lease[Symbol.asyncDispose]();
151
- this.ready = true;
190
+ this.readyOn = presets;
152
191
  }
153
192
  catch (error) {
154
193
  this.warn(`tool-manager could not compose the default agent preset before other presets: ${errorMessage(error)}`);
155
194
  }
156
- finally {
157
- this.attempt = undefined;
158
- }
159
195
  }
160
196
  }
161
197
  /**
@@ -176,13 +212,31 @@ export function createPresetCatalog(options) {
176
212
  // sample cannot make a real tool alternate between present and orphaned.
177
213
  const catalogedSchemas = new Map();
178
214
  const pendingCatalogs = new Map();
215
+ let instance;
216
+ /**
217
+ * Read the live registry, dropping what the retired instance taught us.
218
+ *
219
+ * A reloaded registry mounts new standing compositions: a schema proven on
220
+ * the old instance describes a composition nothing owns any more, and the
221
+ * Preset ids it was keyed by may not even exist in the new roster.
222
+ */
223
+ const readPresets = () => {
224
+ const next = resolvePresets(presets);
225
+ if (next === instance)
226
+ return next;
227
+ instance = next;
228
+ catalogedSchemas.clear();
229
+ pendingCatalogs.clear();
230
+ return next;
231
+ };
179
232
  const remember = (presetId, schemas) => {
180
233
  const merged = mergeSchemas(catalogedSchemas.get(presetId) ?? [], schemas);
181
234
  catalogedSchemas.set(presetId, merged);
182
235
  return merged;
183
236
  };
184
237
  const catalogSchemas = async (presetId) => {
185
- const live = livePresetSchemas(context, presets, presetId);
238
+ const current = readPresets();
239
+ const live = current ? livePresetSchemas(context, current, presetId) : undefined;
186
240
  if (live)
187
241
  return remember(presetId, live);
188
242
  await defaultPreset.ensure();
@@ -200,30 +254,51 @@ export function createPresetCatalog(options) {
200
254
  await catalogSchemas(presetId);
201
255
  },
202
256
  ensureAll: async () => {
203
- const inventory = await presets.compositionInventory();
257
+ const current = readPresets();
258
+ if (!current)
259
+ return;
260
+ const inventory = await current.compositionInventory();
204
261
  await Promise.all(inventory.filter((item) => !item.broken).map((item) => catalogSchemas(item.id)));
205
262
  },
206
263
  };
207
264
  }
208
265
  export function apply(ctx) {
209
266
  const context = ctx;
210
- const presets = context.get("agentPresets");
211
- const tools = context.get("tools");
212
- if (!presets || !tools) {
267
+ /**
268
+ * Read the services on every use, never at load.
269
+ *
270
+ * DSH reloads a plugin node by re-applying it on the same Fiber, which
271
+ * constructs a new service instance: the preset registry publishes a fresh
272
+ * `definitions` map that every preset re-registers into, and the retired
273
+ * instance keeps the empty map its unregister disposers left. A reference
274
+ * captured here would answer "no Presets" for the rest of the Host run, and
275
+ * `composedPreset()` would return `undefined` for every Agent — silently
276
+ * dropping that Agent's policy — until DSH is restarted.
277
+ */
278
+ const presetsSource = () => context.get("agentPresets");
279
+ const toolsSource = () => context.get("tools");
280
+ if (!presetsSource() || !toolsSource()) {
213
281
  throw new Error("dsh-tool-manager requires agentPresets, agents, and tools");
214
282
  }
283
+ /** The services one request reads, or `undefined` while DSH swaps them. */
284
+ const services = () => {
285
+ const presets = presetsSource();
286
+ const tools = toolsSource();
287
+ return presets && tools ? { presets, tools } : undefined;
288
+ };
215
289
  const config = new ToolManagerConfigStore();
216
- const runtime = new ToolPolicyRuntime(context, presets, config.get());
290
+ const notices = userNotices();
291
+ const runtime = new ToolPolicyRuntime(context, presetsSource, config.get(), (notice) => notices.add(notice));
217
292
  runtime.start();
218
- const probe = new PresetSchemaProbe(context, presets);
219
- const defaultPreset = new DefaultPresetMount(presets, (message) => warn(context, message));
293
+ const probe = new PresetSchemaProbe(context, presetsSource);
294
+ const defaultPreset = new DefaultPresetMount(presetsSource, (message) => warn(context, message));
220
295
  // Compose the default preset now, not on the first page load: the composition
221
296
  // mounted first owns the reconciliation order every later mode switch needs,
222
297
  // and a Session resumed in another preset would otherwise take that place.
223
298
  void defaultPreset.ensure();
224
299
  const catalog = createPresetCatalog({
225
300
  context,
226
- presets,
301
+ presets: presetsSource,
227
302
  probe,
228
303
  defaultPreset,
229
304
  observed: (presetId) => runtime.observedSchemasFor(presetId),
@@ -234,9 +309,9 @@ export function apply(ctx) {
234
309
  // re-calibrates any Session whose mode changed, whatever plugin lost the race
235
310
  // for which tool names (see composition-watch.ts).
236
311
  const compositionWatch = new CompositionWatch({
237
- presets,
312
+ presets: presetsSource,
238
313
  agents: () => context.get("agents")?.list() ?? [],
239
- tools: () => tools,
314
+ tools: toolsSource,
240
315
  probe: (presetId) => probe.inspect(presetId),
241
316
  explainedLoss: (presetId, toolName) => {
242
317
  // This plugin's own tools, plus every name its policy hides on purpose:
@@ -250,6 +325,18 @@ export function apply(ctx) {
250
325
  return policy.groups.some((group) => matchesAnyPattern(toolName, group.patterns));
251
326
  },
252
327
  excludeAgentId: TOOL_MANAGER_PROBE_SESSION_ID,
328
+ onReloaded: (agent, presetId) => {
329
+ // Re-attaching happens on the Session's next step; this only makes the
330
+ // reader aware early, and is dropped again once a repair succeeds.
331
+ notices.add({
332
+ kind: "reloading",
333
+ ...(agent.id === undefined ? {} : { sessionId: agent.id }),
334
+ presetId,
335
+ message: `agent preset 注册表刚被重载:会话「${agent.id ?? "未知"}」的 preset ${presetId} 绑定失效,` +
336
+ "插件会在该会话下一次对话前自动重新挂载(不需要重启)。" +
337
+ "如果下一步工具仍然缺失,这里会出现一条需要重启 DSH 的提示。",
338
+ });
339
+ },
253
340
  warn: (message) => warn(context, message),
254
341
  info: (message) => info(context, message),
255
342
  });
@@ -258,7 +345,43 @@ export function apply(ctx) {
258
345
  const webServer = webCtx.get("webServer");
259
346
  if (!webServer)
260
347
  return;
261
- webServer.register({
348
+ /**
349
+ * Every route this instance owns.
350
+ *
351
+ * `register()` refuses a duplicate path and hands back the disposer that
352
+ * lifts this one. Dropping them leaves a retired instance's handlers in the
353
+ * host's route table: the reloaded plugin then cannot register its own and
354
+ * the page keeps talking to a runtime nobody drives any more. Cordis only
355
+ * collects what the inject callback returns, so hand the disposers back.
356
+ */
357
+ const routes = [];
358
+ const route = (options) => {
359
+ try {
360
+ routes.push(webServer.register(options));
361
+ }
362
+ catch (error) {
363
+ // A refused route must not leave the earlier ones half-registered: the
364
+ // callback is about to fail, and nothing would ever dispose them.
365
+ for (const dispose of routes.splice(0))
366
+ dispose();
367
+ throw error;
368
+ }
369
+ };
370
+ /** Build a snapshot from whatever services are live at this moment. */
371
+ const buildCurrentSnapshot = () => {
372
+ const live = services();
373
+ if (!live)
374
+ throw new Error(SERVICE_RELOADING);
375
+ return buildSnapshot(live.presets, live.tools, config.get(), config.revision, config.path, catalog.schemasFor);
376
+ };
377
+ /**
378
+ * The registry instance whose empty roster this plugin already waited out.
379
+ *
380
+ * A deployment that genuinely declares no Preset must not pay the wait on
381
+ * every page load, while every newly published instance gets one wait.
382
+ */
383
+ let rosterSettled;
384
+ route({
262
385
  kind: "exact",
263
386
  path: "/tool-manager/api/snapshot",
264
387
  handler: (req, res) => {
@@ -266,10 +389,34 @@ export function apply(ctx) {
266
389
  sendJson(res, 405, { ok: false, message: "method not allowed" });
267
390
  return;
268
391
  }
269
- void ensureAllPresetSchemas().then(() => buildSnapshot(presets, tools, config.get(), config.revision, config.path, catalog.schemasFor)).then((snapshot) => sendJson(res, 200, snapshot), (error) => sendJson(res, 500, { ok: false, message: errorMessage(error) }));
392
+ if (!services()) {
393
+ sendJson(res, 503, { ok: false, message: SERVICE_RELOADING });
394
+ return;
395
+ }
396
+ void (async () => {
397
+ let snapshot = await ensureAllPresetSchemas().then(buildCurrentSnapshot);
398
+ // The reload window: DSH publishes the new registry before every
399
+ // preset node has re-registered into it, and this plugin's own node
400
+ // may come back first. A page opened in that gap would otherwise show
401
+ // "no Agent Preset" until the user reloaded it by hand.
402
+ const instance = services()?.presets;
403
+ if (snapshot.presets.length === 0 && instance !== undefined && instance !== rosterSettled) {
404
+ for (let waited = 0; waited < ROSTER_SETTLE_MS; waited += ROSTER_POLL_MS) {
405
+ await delay(ROSTER_POLL_MS);
406
+ if (!services())
407
+ break;
408
+ await ensureAllPresetSchemas();
409
+ snapshot = await buildCurrentSnapshot();
410
+ if (snapshot.presets.length > 0)
411
+ break;
412
+ }
413
+ rosterSettled = services()?.presets ?? rosterSettled;
414
+ }
415
+ return snapshot;
416
+ })().then((snapshot) => sendJson(res, 200, snapshot), (error) => sendJson(res, 500, { ok: false, message: errorMessage(error) }));
270
417
  },
271
418
  });
272
- webServer.register({
419
+ route({
273
420
  kind: "exact",
274
421
  path: "/tool-manager/api/suggest-group",
275
422
  handler: (req, res) => {
@@ -278,6 +425,9 @@ export function apply(ctx) {
278
425
  return;
279
426
  }
280
427
  void (async () => {
428
+ const live = services();
429
+ if (!live)
430
+ throw new Error(SERVICE_RELOADING);
281
431
  const llm = context.get("llm");
282
432
  const defaultModel = context.get("agentDefaultModel");
283
433
  if (!llm || !defaultModel) {
@@ -287,11 +437,11 @@ export function apply(ctx) {
287
437
  const presetId = typeof body?.presetId === "string" ? body.presetId.trim() : "";
288
438
  if (!presetId)
289
439
  throw new Error("presetId is required");
290
- const inventory = await presets.compositionInventory();
440
+ const inventory = await live.presets.compositionInventory();
291
441
  if (!inventory.some((item) => item.id === presetId))
292
442
  throw new Error(`unknown preset ${JSON.stringify(presetId)}`);
293
443
  await defaultPreset.ensure();
294
- const standing = await schemasForPreset(presets, tools, presetId);
444
+ const standing = await schemasForPreset(live.presets, live.tools, presetId);
295
445
  const schemas = mergeSchemas(standing, await catalog.schemasFor(presetId))
296
446
  .filter((schema) => schema.name !== DISCOVERY_TOOL_NAME && schema.name !== PTC_TRANSPORT_NAME);
297
447
  const selected = selectSuggestionTools(schemas, body?.toolNames);
@@ -306,7 +456,7 @@ export function apply(ctx) {
306
456
  })().then((suggestion) => sendJson(res, 200, suggestion), (error) => sendJson(res, 400, { ok: false, message: errorMessage(error) }));
307
457
  },
308
458
  });
309
- webServer.register({
459
+ route({
310
460
  kind: "exact",
311
461
  path: "/tool-manager/api/auto-group",
312
462
  handler: (req, res) => {
@@ -315,6 +465,9 @@ export function apply(ctx) {
315
465
  return;
316
466
  }
317
467
  void (async () => {
468
+ const live = services();
469
+ if (!live)
470
+ throw new Error(SERVICE_RELOADING);
318
471
  const llm = context.get("llm");
319
472
  const defaultModel = context.get("agentDefaultModel");
320
473
  if (!llm || !defaultModel) {
@@ -324,11 +477,11 @@ export function apply(ctx) {
324
477
  const presetId = typeof body?.presetId === "string" ? body.presetId.trim() : "";
325
478
  if (!presetId)
326
479
  throw new Error("presetId is required");
327
- const inventory = await presets.compositionInventory();
480
+ const inventory = await live.presets.compositionInventory();
328
481
  if (!inventory.some((item) => item.id === presetId))
329
482
  throw new Error(`unknown preset ${JSON.stringify(presetId)}`);
330
483
  await defaultPreset.ensure();
331
- const standing = await schemasForPreset(presets, tools, presetId);
484
+ const standing = await schemasForPreset(live.presets, live.tools, presetId);
332
485
  const schemas = mergeSchemas(standing, await catalog.schemasFor(presetId))
333
486
  .filter((schema) => schema.name !== DISCOVERY_TOOL_NAME && schema.name !== PTC_TRANSPORT_NAME);
334
487
  const selected = selectSuggestionTools(schemas, body?.toolNames);
@@ -343,7 +496,37 @@ export function apply(ctx) {
343
496
  })().then((result) => sendJson(res, 200, result), (error) => sendJson(res, 400, { ok: false, message: errorMessage(error) }));
344
497
  },
345
498
  });
346
- webServer.register({
499
+ route({
500
+ kind: "exact",
501
+ path: "/tool-manager/api/repair",
502
+ handler: (_req, res) => {
503
+ sendJson(res, 200, { ...runtime.repairDiagnostics(), presets: presetsSource() !== undefined });
504
+ },
505
+ });
506
+ route({
507
+ kind: "exact",
508
+ path: "/tool-manager/api/notices",
509
+ handler: (req, res) => {
510
+ const method = String(req.method ?? "GET").toUpperCase();
511
+ if (method === "GET") {
512
+ sendJson(res, 200, { notices: notices.list() });
513
+ return;
514
+ }
515
+ if (method !== "POST") {
516
+ sendJson(res, 405, { ok: false, message: "method not allowed" });
517
+ return;
518
+ }
519
+ void (async () => {
520
+ const body = asRecord(await readJsonBody(req));
521
+ const ids = Array.isArray(body?.ids)
522
+ ? body.ids.filter((id) => typeof id === "string")
523
+ : [];
524
+ notices.ack(ids);
525
+ sendJson(res, 200, { notices: notices.list() });
526
+ })().catch((error) => sendJson(res, 400, { ok: false, message: errorMessage(error) }));
527
+ },
528
+ });
529
+ route({
347
530
  kind: "exact",
348
531
  path: "/tool-manager/api/save",
349
532
  handler: (req, res) => {
@@ -352,6 +535,9 @@ export function apply(ctx) {
352
535
  return;
353
536
  }
354
537
  void (async () => {
538
+ const live = services();
539
+ if (!live)
540
+ throw new Error(SERVICE_RELOADING);
355
541
  const body = asRecord(await readJsonBody(req));
356
542
  const expectedRevision = body && typeof body.expectedRevision === "number"
357
543
  ? body.expectedRevision
@@ -363,16 +549,26 @@ export function apply(ctx) {
363
549
  // root Agent, `dsh-tool-subagent` injects `subagent` there — so a
364
550
  // group built from those tools is rejected as empty although the page
365
551
  // lists them and the runtime opens them normally.
366
- await assertNoEmptyGroups(presets, tools, next, () => defaultPreset.ensure(), (presetId) => visiblePresetToolNames(presets, tools, catalog, presetId));
552
+ await assertNoEmptyGroups(live.presets, live.tools, next, () => defaultPreset.ensure(), (presetId) => visiblePresetToolNames(live.presets, live.tools, catalog, presetId));
367
553
  await config.replace(next, expectedRevision);
368
554
  runtime.update(config.get());
369
555
  // `buildSnapshot` mounts every inspectable preset, so the default must
370
556
  // already be composed before it runs (see DefaultPresetMount).
371
557
  await defaultPreset.ensure();
372
- return buildSnapshot(presets, tools, config.get(), config.revision, config.path, catalog.schemasFor);
558
+ return buildCurrentSnapshot();
373
559
  })().then((snapshot) => sendJson(res, 200, snapshot), (error) => sendJson(res, 400, { ok: false, message: errorMessage(error) }));
374
560
  },
375
561
  });
562
+ return () => {
563
+ for (const dispose of routes.splice(0)) {
564
+ try {
565
+ dispose();
566
+ }
567
+ catch {
568
+ // A host that already dropped the table must not block the unload.
569
+ }
570
+ }
571
+ };
376
572
  });
377
573
  context.effect?.(() => async () => {
378
574
  compositionWatch.dispose();
@@ -461,6 +657,21 @@ toolNamesFor) {
461
657
  function nextEventLoopTurn() {
462
658
  return new Promise((resolve) => setImmediate(resolve));
463
659
  }
660
+ /** Answer while DSH holds no instance of a service this plugin reads. */
661
+ const SERVICE_RELOADING = "the agent preset registry is reloading; retry in a moment";
662
+ /**
663
+ * How long the snapshot endpoint waits for a reloaded registry to finish
664
+ * re-registering its presets before it answers with an empty roster.
665
+ *
666
+ * A Preset node re-registers in its own Fiber, so the roster is filled in a
667
+ * different order than the service instance is published. Presets mount whole
668
+ * plugin trees, so the window is longer than one event-loop turn.
669
+ */
670
+ const ROSTER_SETTLE_MS = 1500;
671
+ const ROSTER_POLL_MS = 100;
672
+ function delay(ms) {
673
+ return new Promise((resolve) => setTimeout(resolve, ms));
674
+ }
464
675
  async function readJsonBody(req) {
465
676
  const chunks = [];
466
677
  for await (const chunk of req) {