@yankeguo/dsh-devlead 0.2.2 → 0.2.3

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.
Files changed (2) hide show
  1. package/lib/index.js +301 -5
  2. package/package.json +2 -2
package/lib/index.js CHANGED
@@ -9,6 +9,7 @@ var __export = (target, all) => {
9
9
  import { mkdir } from "node:fs/promises";
10
10
  import { Service } from "@deepseek-ai/cordis";
11
11
  import z2 from "@deepseek-ai/schemastery";
12
+ import { ReasoningEffortId } from "@deepseek-ai/dsh-llm";
12
13
  import { appendPluginRecord as appendPluginRecord2 } from "@deepseek-ai/dsh-session";
13
14
  import "@deepseek-ai/dsh-session";
14
15
  import { DEVLEAD_DEFAULT_MAX_WATCHED as DEVLEAD_DEFAULT_MAX_WATCHED2 } from "@yankeguo/dsh-devlead-protocol";
@@ -235,6 +236,138 @@ function assistantExcerpt(blocks) {
235
236
  return excerptLine(text, DEVLEAD_ERROR_EXCERPT_MAX);
236
237
  }
237
238
 
239
+ // packages/devlead/src/dispatch.ts
240
+ function stringField(value) {
241
+ return typeof value === "string" ? value : "";
242
+ }
243
+ function recordOf(value) {
244
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
245
+ }
246
+ function itemsOf(value) {
247
+ return Array.isArray(value) ? value : [];
248
+ }
249
+ function modelViewOf(value) {
250
+ const record2 = recordOf(value);
251
+ if (record2 === void 0) return void 0;
252
+ const id = stringField(record2.id);
253
+ if (id.length === 0) return void 0;
254
+ const name = stringField(record2.name);
255
+ const reasoningRecord = recordOf(record2.reasoning);
256
+ if (reasoningRecord === void 0) {
257
+ return { id, name: name.length === 0 ? id : name };
258
+ }
259
+ const efforts = itemsOf(reasoningRecord.efforts).map((effort) => {
260
+ const effortRecord = recordOf(effort);
261
+ if (effortRecord === void 0) return void 0;
262
+ const effortId = stringField(effortRecord.id);
263
+ if (effortId.length === 0) return void 0;
264
+ const effortName = stringField(effortRecord.name);
265
+ return { id: effortId, name: effortName.length === 0 ? effortId : effortName };
266
+ }).filter((effort) => effort !== void 0);
267
+ const defaultEffort = stringField(reasoningRecord.defaultEffort);
268
+ return {
269
+ id,
270
+ name: name.length === 0 ? id : name,
271
+ reasoning: {
272
+ efforts,
273
+ ...defaultEffort.length === 0 ? {} : { defaultEffort }
274
+ }
275
+ };
276
+ }
277
+ function devLeadModelCatalogOf(value) {
278
+ const record2 = recordOf(value) ?? {};
279
+ const defaultRecord = recordOf(record2.default) ?? {};
280
+ const defaultProvider = stringField(defaultRecord.provider);
281
+ const defaultModel = stringField(defaultRecord.model);
282
+ const defaultEffort = stringField(defaultRecord.reasoningEffort);
283
+ const defaultSelection = {
284
+ provider: defaultProvider,
285
+ model: defaultModel,
286
+ ...defaultEffort.length === 0 ? {} : { reasoningEffort: defaultEffort }
287
+ };
288
+ const routableProviders = itemsOf(record2.routableProviders).filter((provider) => typeof provider === "string" && provider.length > 0);
289
+ const providers = [];
290
+ for (const group of itemsOf(record2.groups)) {
291
+ const groupRecord = recordOf(group);
292
+ if (groupRecord === void 0) continue;
293
+ const id = stringField(groupRecord.id);
294
+ if (id.length === 0) continue;
295
+ const name = stringField(groupRecord.name);
296
+ const models = itemsOf(groupRecord.models).map(modelViewOf).filter((model) => model !== void 0);
297
+ providers.push({ id, name: name.length === 0 ? id : name, models });
298
+ }
299
+ const failures = [];
300
+ for (const failure of itemsOf(record2.failures)) {
301
+ const failureRecord = recordOf(failure);
302
+ if (failureRecord === void 0) continue;
303
+ const id = stringField(failureRecord.id);
304
+ if (id.length === 0) continue;
305
+ const name = stringField(failureRecord.name);
306
+ failures.push({
307
+ id,
308
+ name: name.length === 0 ? id : name,
309
+ message: stringField(failureRecord.message)
310
+ });
311
+ }
312
+ return { default: defaultSelection, routableProviders, providers, failures };
313
+ }
314
+ function modelCatalogCapabilityOf(ctx) {
315
+ const candidate = ctx.get("sessionController");
316
+ if (typeof candidate !== "object" || candidate === null) return void 0;
317
+ const modelCatalog = candidate.modelCatalog;
318
+ if (typeof modelCatalog !== "function") return void 0;
319
+ return candidate;
320
+ }
321
+ function modelSelectionLabel(selection) {
322
+ const base = `${selection.provider}/${selection.model}`;
323
+ return selection.reasoningEffort === void 0 ? base : `${base} (reasoning effort "${selection.reasoningEffort}")`;
324
+ }
325
+ function normalizeModelSelection(value) {
326
+ if (value === void 0) return void 0;
327
+ const provider = typeof value.provider === "string" ? value.provider.trim() : "";
328
+ const model = typeof value.model === "string" ? value.model.trim() : "";
329
+ const effort = typeof value.reasoningEffort === "string" ? value.reasoningEffort.trim() : "";
330
+ if (provider.length === 0 && model.length === 0) {
331
+ if (effort.length > 0) {
332
+ throw new DevLeadError(
333
+ "reasoningEffort requires an explicit provider and model; the Host default model has no dispatch-time effort override",
334
+ "DEVLEAD_INVALID_INPUT"
335
+ );
336
+ }
337
+ return void 0;
338
+ }
339
+ if (provider.length === 0 || model.length === 0) {
340
+ throw new DevLeadError(
341
+ "provider and model must be provided together",
342
+ "DEVLEAD_INVALID_INPUT"
343
+ );
344
+ }
345
+ return {
346
+ provider,
347
+ model,
348
+ ...effort.length === 0 ? {} : { reasoningEffort: effort }
349
+ };
350
+ }
351
+ function modelValidatorOf(ctx) {
352
+ const candidate = ctx.get("llm");
353
+ if (typeof candidate !== "object" || candidate === null) return void 0;
354
+ const listProviders = candidate.listProviders;
355
+ const listModels = candidate.listModels;
356
+ const resolve = candidate.resolveCallConfig;
357
+ if (typeof listProviders !== "function" || typeof listModels !== "function" || typeof resolve !== "function") {
358
+ return void 0;
359
+ }
360
+ return candidate;
361
+ }
362
+ function agentTeamsCapabilityOf(ctx) {
363
+ const candidate = ctx.get("agentTeams");
364
+ if (typeof candidate !== "object" || candidate === null) return void 0;
365
+ const isEnabled = candidate.isEnabled;
366
+ const setEnabled = candidate.setEnabled;
367
+ if (typeof isEnabled !== "function" || typeof setEnabled !== "function") return void 0;
368
+ return candidate;
369
+ }
370
+
238
371
  // packages/devlead/src/fold.ts
239
372
  import { pluginRecordOf } from "@deepseek-ai/dsh-session";
240
373
 
@@ -16478,6 +16611,43 @@ var DevLeadService = class extends Service {
16478
16611
  const retained = rankSessionIds(deps, ids, facts, limit);
16479
16612
  return await devLeadSessionViews(deps, retained, false, facts);
16480
16613
  }
16614
+ /**
16615
+ * Read the Host's model catalog for dispatch-time selection.
16616
+ *
16617
+ * The view reports the Host default selection, routable providers, each
16618
+ * provider's advertised models and reasoning efforts, and catalog lookup
16619
+ * failures. It is read-only: no Session, profile default, or Team state is
16620
+ * changed. The controller's catalog method takes no cancellation token, so
16621
+ * the signal is checked before and after the read.
16622
+ * @param agent - exact live lead Agent.
16623
+ * @param signal - cancellation checked before and after the catalog read.
16624
+ * @returns the normalized model catalog view.
16625
+ * @throws {@link DevLeadError} `DEVLEAD_SESSION_UNAVAILABLE` when the Host
16626
+ * composes no Session controller with a model catalog or the read fails.
16627
+ */
16628
+ async listModels(agent, signal) {
16629
+ this.assertReady(agent);
16630
+ signal?.throwIfAborted();
16631
+ const controller = modelCatalogCapabilityOf(this.ctx);
16632
+ if (controller === void 0) {
16633
+ throw new DevLeadError(
16634
+ "this Host cannot list models: no API Session controller with a model catalog is composed",
16635
+ "DEVLEAD_SESSION_UNAVAILABLE"
16636
+ );
16637
+ }
16638
+ let catalog;
16639
+ try {
16640
+ catalog = await controller.modelCatalog();
16641
+ } catch (error51) {
16642
+ signal?.throwIfAborted();
16643
+ throw new DevLeadError(
16644
+ `could not read the model catalog: ${thrownMessage(error51)}`,
16645
+ "DEVLEAD_SESSION_UNAVAILABLE"
16646
+ );
16647
+ }
16648
+ signal?.throwIfAborted();
16649
+ return devLeadModelCatalogOf(catalog);
16650
+ }
16481
16651
  /**
16482
16652
  * Read one Session in detail, including folded turn and assistant facts.
16483
16653
  * @param agent - exact live lead Agent.
@@ -16510,19 +16680,32 @@ var DevLeadService = class extends Service {
16510
16680
  * next side effect, so a cancelled create may leave a watched Session behind
16511
16681
  * without running isolation or admitting the prompt. Session creation itself
16512
16682
  * is not abortable once started.
16683
+ *
16684
+ * A requested model selection and Agent Teams mode are creation-time
16685
+ * settings, applied to the new Session's own Agent immediately after the
16686
+ * Session exists and before its title/watch/isolation/prompt. The model is
16687
+ * validated against the Host's LLM registry first, and it is recorded with
16688
+ * `agent.model.select`, never through the Session controller's `selectModel`
16689
+ * (which would also rewrite the profile default model). An application
16690
+ * failure after creation reports the created Session id and leaves that
16691
+ * Session in place, matching the service's non-rollback creation contract.
16513
16692
  * @param agent - exact live lead Agent.
16514
16693
  * @param request - Workspace, optional title, initial prompt, watch policy,
16515
- * preset, and checkout isolation mode.
16694
+ * preset, checkout isolation mode, creation-time model selection, and
16695
+ * creation-time Agent Teams mode.
16516
16696
  * @param signal - cancellation checked between stages and threaded into the
16517
16697
  * worktree creation.
16518
- * @returns the created Session, the Workspace it joined, and the
16519
- * checkout-isolation outcome.
16698
+ * @returns the created Session, the Workspace it joined, the
16699
+ * checkout-isolation outcome, and any applied model/Team settings.
16520
16700
  * @throws {@link DevLeadError} when the mode is off, the Host cannot create
16521
- * Sessions, or the destination is not usable.
16701
+ * Sessions, the destination is not usable, or a requested model/Team
16702
+ * capability is unavailable.
16522
16703
  */
16523
16704
  async createSession(agent, request, signal) {
16524
16705
  this.assertReady(agent);
16525
16706
  signal?.throwIfAborted();
16707
+ const requestedModel = normalizeModelSelection(request.model);
16708
+ const requestedTeams = request.agentTeams;
16526
16709
  const controller = this.ctx.get("sessionController");
16527
16710
  if (controller === void 0) {
16528
16711
  throw new DevLeadError(
@@ -16530,6 +16713,14 @@ var DevLeadService = class extends Service {
16530
16713
  "DEVLEAD_SESSION_UNAVAILABLE"
16531
16714
  );
16532
16715
  }
16716
+ const teams = requestedTeams === void 0 ? void 0 : agentTeamsCapabilityOf(this.ctx);
16717
+ if (requestedTeams === true && teams === void 0) {
16718
+ throw new DevLeadError(
16719
+ "this Host composes no Agent Teams service, so agent_teams cannot be enabled. Agent Teams is available from DSH 0.2.2-rc.2 (and is included in the default composition there); omit agent_teams or continue without Team mode",
16720
+ "DEVLEAD_TEAM_UNAVAILABLE"
16721
+ );
16722
+ }
16723
+ if (requestedModel !== void 0) await this.assertModelSelectable(requestedModel, signal);
16533
16724
  const watch = request.watch ?? true;
16534
16725
  const releaseWatch = watch ? this.reserveWatchSlot(agent) : void 0;
16535
16726
  try {
@@ -16554,6 +16745,7 @@ var DevLeadService = class extends Service {
16554
16745
  }
16555
16746
  signal?.throwIfAborted();
16556
16747
  const sessionId = String(created.sessionId);
16748
+ const applied = await this.applyDispatchSettings(created, requestedModel, requestedTeams, teams, signal);
16557
16749
  if (request.title !== void 0 && request.title.trim().length > 0) {
16558
16750
  this.tryRename(created.sessionId, request.title.trim());
16559
16751
  }
@@ -16574,7 +16766,9 @@ var DevLeadService = class extends Service {
16574
16766
  session: await devLeadSessionView(deps, sessionId, true),
16575
16767
  workspace: await devLeadWorkspaceView(workspace),
16576
16768
  prompted,
16577
- isolation
16769
+ isolation,
16770
+ ...applied.model === void 0 ? {} : { model: applied.model },
16771
+ ...applied.agentTeams === void 0 ? {} : { agentTeams: applied.agentTeams }
16578
16772
  };
16579
16773
  } finally {
16580
16774
  releaseWatch?.();
@@ -16959,6 +17153,108 @@ var DevLeadService = class extends Service {
16959
17153
  }
16960
17154
  return [...leads].map(([sessionId, watched]) => ({ sessionId, watched }));
16961
17155
  }
17156
+ /**
17157
+ * Validate one requested model selection against the Host's LLM registry.
17158
+ * @param selection - normalized provider/model/effort selection.
17159
+ * @param signal - cancellation checked around the adapter lookup.
17160
+ * @throws {@link DevLeadError} `DEVLEAD_MODEL_UNAVAILABLE` when the Host
17161
+ * composes no validator or the adapter rejects the route/effort.
17162
+ */
17163
+ async assertModelSelectable(selection, signal) {
17164
+ const validator = modelValidatorOf(this.ctx);
17165
+ if (validator === void 0) {
17166
+ throw new DevLeadError(
17167
+ `cannot validate model "${modelSelectionLabel(selection)}": this Host composes no LLM registry. Call devlead_list_models to see available providers, models, and reasoning efforts`,
17168
+ "DEVLEAD_MODEL_UNAVAILABLE"
17169
+ );
17170
+ }
17171
+ try {
17172
+ if (!validator.listProviders().some((provider) => provider.id === selection.provider)) {
17173
+ throw new Error(`provider "${selection.provider}" is not registered`);
17174
+ }
17175
+ const models = await validator.listModels(selection.provider);
17176
+ if (!models.some((model) => model.id === selection.model)) {
17177
+ throw new Error(`model "${selection.model}" is not in provider "${selection.provider}"'s available model list`);
17178
+ }
17179
+ await validator.resolveCallConfig(selection, signal);
17180
+ } catch (error51) {
17181
+ signal?.throwIfAborted();
17182
+ throw new DevLeadError(
17183
+ `model "${modelSelectionLabel(selection)}" is not available: ${thrownMessage(error51)}. Call devlead_list_models to see available providers, models, and reasoning efforts`,
17184
+ "DEVLEAD_MODEL_UNAVAILABLE"
17185
+ );
17186
+ }
17187
+ signal?.throwIfAborted();
17188
+ }
17189
+ /**
17190
+ * Apply creation-time dispatch settings to a freshly created Session.
17191
+ *
17192
+ * The settings are recorded on the child Agent itself: the model through
17193
+ * `agent.model.select` (durable Session-level event, never the profile
17194
+ * default), and Team mode through the optional Team service. A failure here
17195
+ * happens after the Session exists, so the error names its id and the Session
17196
+ * is deliberately left in place (the service's creation contract does not
17197
+ * roll back side effects).
17198
+ * @param created - the controller's create result.
17199
+ * @param model - normalized model selection, when requested.
17200
+ * @param teamsRequested - requested Team mode, when explicitly set.
17201
+ * @param teams - detected Team capability, when one is composed.
17202
+ * @param signal - cancellation checked between applications.
17203
+ * @returns the settings that were actually applied.
17204
+ * @throws {@link DevLeadError} with the created Session id in the message when
17205
+ * the Agent is not live or an application step fails.
17206
+ */
17207
+ async applyDispatchSettings(created, model, teamsRequested, teams, signal) {
17208
+ if (model === void 0 && teamsRequested === void 0) return {};
17209
+ const sessionId = String(created.sessionId);
17210
+ const child = this.ctx.agents.get(created.sessionId);
17211
+ if (child === void 0) {
17212
+ throw new DevLeadError(
17213
+ `Session "${sessionId}" was created but its Agent is not live, so the requested dispatch settings could not be applied; the Session remains and can be continued`,
17214
+ "DEVLEAD_SESSION_UNAVAILABLE"
17215
+ );
17216
+ }
17217
+ const applied = {};
17218
+ if (model !== void 0) {
17219
+ try {
17220
+ child.model.select({
17221
+ provider: model.provider,
17222
+ model: model.model,
17223
+ ...model.reasoningEffort === void 0 ? {} : { reasoningEffort: ReasoningEffortId(model.reasoningEffort) }
17224
+ });
17225
+ } catch (error51) {
17226
+ signal?.throwIfAborted();
17227
+ throw new DevLeadError(
17228
+ `Session "${sessionId}" was created but model "${modelSelectionLabel(model)}" could not be applied; the Session remains: ${thrownMessage(error51)}. Call devlead_list_models to see available providers, models, and reasoning efforts`,
17229
+ "DEVLEAD_MODEL_UNAVAILABLE"
17230
+ );
17231
+ }
17232
+ await this.flushDurably(child.session, `model selection for Session "${sessionId}"`);
17233
+ applied.model = { ...model };
17234
+ }
17235
+ if (teamsRequested !== void 0) {
17236
+ if (teamsRequested === true && teams === void 0) {
17237
+ throw new DevLeadError(
17238
+ `Session "${sessionId}" was created but this Host composes no Agent Teams service, so agent_teams could not be enabled; the Session remains. Agent Teams is available from DSH 0.2.2-rc.2 (included in the default composition there)`,
17239
+ "DEVLEAD_TEAM_UNAVAILABLE"
17240
+ );
17241
+ }
17242
+ if (teams !== void 0) {
17243
+ try {
17244
+ await teams.setEnabled(child, teamsRequested, signal);
17245
+ } catch (error51) {
17246
+ signal?.throwIfAborted();
17247
+ throw new DevLeadError(
17248
+ `Session "${sessionId}" was created but Agent Teams could not be ${teamsRequested ? "enabled" : "disabled"}; the Session remains: ${thrownMessage(error51)}`,
17249
+ "DEVLEAD_TEAM_UNAVAILABLE"
17250
+ );
17251
+ }
17252
+ }
17253
+ applied.agentTeams = teamsRequested;
17254
+ }
17255
+ signal?.throwIfAborted();
17256
+ return applied;
17257
+ }
16962
17258
  /** Require the Workspace registry capability (Workspaces and Session archive state). */
16963
17259
  requireWorkspaceRegistry() {
16964
17260
  const registry2 = this.ctx.get("workspaceRegistry");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yankeguo/dsh-devlead",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "DevLead mode core service for the DeepSeek Harness: durable per-session mode, Workspace and Session orchestration, watched-session notifications, and the `devLead` Session projection.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -43,7 +43,7 @@
43
43
  }
44
44
  },
45
45
  "dependencies": {
46
- "@yankeguo/dsh-devlead-protocol": "0.2.2"
46
+ "@yankeguo/dsh-devlead-protocol": "0.2.3"
47
47
  },
48
48
  "engines": {
49
49
  "dsh": ">=0.2.2-rc.1 <0.3.0"