dsh-model-switch 0.4.61 → 0.4.63

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.
@@ -1,4 +1,4 @@
1
- import type { ModelProviderGroup } from '@deepseek-ai/dsh-api-session-controller/types';
1
+ import type { ModelCatalogFailure, ModelProviderGroup } from '@deepseek-ai/dsh-api-session-controller/types';
2
2
  import type { CapabilityRouteView } from '../client-contract.js';
3
3
  import type { ModelSwitchLocaleKey } from './locales.js';
4
4
  export interface Choice {
@@ -25,20 +25,74 @@ export declare function deriveRouteChoices(groups: readonly ModelProviderGroup[]
25
25
  * catalog-only list makes that group unreachable: the row stays stored, no
26
26
  * selection can open it, and nothing can delete it. Union in every configured
27
27
  * group's provider and mark the missing ones unavailable so the editor can still
28
- * open and remove them.
29
- * @param groups - the live model catalog.
28
+ * open and remove them. Feed this the merged list from `withCatalogFailures` so
29
+ * a provider that merely failed to load stays selectable instead of looking
30
+ * deleted.
31
+ * @param groups - the live model catalog merged with the host's load failures.
30
32
  * @param configured - provider ids that still have a stored group.
31
33
  * @param current - the group being edited, kept listed even when it is unknown.
32
34
  * @returns catalog choices first (original order), then the missing providers.
33
35
  */
34
36
  export declare function groupProviderChoices(groups: readonly ModelProviderGroup[], configured: readonly string[], current: string | undefined): Choice[];
37
+ /** One provider whose model catalog lookup failed on the Host (`ModelCatalogFailure`). */
38
+ export type CatalogFailure = ModelCatalogFailure;
39
+ /** What one catalog load resolves with: successful groups plus the host's isolated failures. */
40
+ export interface SettingsCatalogPayload {
41
+ readonly groups: readonly ModelProviderGroup[];
42
+ readonly failures: readonly CatalogFailure[];
43
+ }
44
+ /** How many attempts one catalog load makes before the settings page gives up. */
45
+ export declare const CATALOG_LOAD_ATTEMPTS = 3;
46
+ /** Backoff between catalog retries: a busy Host clears within seconds, not minutes. */
47
+ export declare const CATALOG_RETRY_DELAYS_MS: readonly number[];
48
+ export interface CatalogRetryOptions {
49
+ attempts?: number;
50
+ delaysMs?: readonly number[];
51
+ sleep?: (ms: number) => Promise<void>;
52
+ cancelled?: () => boolean;
53
+ }
54
+ /**
55
+ * Load the model catalog with bounded backoff.
56
+ *
57
+ * The catalog RPC is one read against a live Host; a transient failure (a busy
58
+ * Host, a reconnecting remote, a background task saturating the provider
59
+ * lookups) must recover on its own instead of leaving the settings page stuck
60
+ * on an empty catalog. Each attempt re-runs `load`; a cancelled load rethrows
61
+ * the last error without further attempts.
62
+ */
63
+ export declare function loadCatalogWithRetry(load: () => Promise<SettingsCatalogPayload>, options?: CatalogRetryOptions): Promise<SettingsCatalogPayload>;
64
+ /**
65
+ * Merge the host's load failures into the catalog as model-less groups.
66
+ *
67
+ * A failed provider is KNOWN (the Host listed it) but temporarily unavailable.
68
+ * Rendering it as absent would mark every stored route for it "unavailable ⚠"
69
+ * and lock the provider-group editor while a background task hiccups. A
70
+ * model-less group keeps the provider selectable without inventing model rows;
71
+ * seeding logic skips it because `models[0]` is undefined.
72
+ */
73
+ export declare function withCatalogFailures(groups: readonly ModelProviderGroup[], failures: readonly CatalogFailure[]): ModelProviderGroup[];
74
+ export type SettingsCatalogStatus = 'loading' | 'ready' | 'failed';
75
+ export interface SettingsCatalogState {
76
+ status: SettingsCatalogStatus;
77
+ /** Live groups merged with the host's load failures; the last good list survives a later failure. */
78
+ groups: readonly ModelProviderGroup[];
79
+ failures: readonly CatalogFailure[];
80
+ /** Localized failure message; undefined while loading or ready. */
81
+ error: string | undefined;
82
+ /** Reload now (used by the retry button and provider-order changes). */
83
+ reload(): void;
84
+ }
35
85
  export interface SettingsCatalogInputs {
36
- loadCatalog(): Promise<readonly ModelProviderGroup[]>;
86
+ loadCatalog(): Promise<SettingsCatalogPayload>;
37
87
  subscribeProviderOrder?: (listener: () => void) => () => void;
38
88
  t(key: ModelSwitchLocaleKey): string;
39
89
  }
40
- /** Load the model catalog backing every route editor, reloading on provider-order changes. */
41
- export declare function useSettingsCatalog(input: SettingsCatalogInputs): {
42
- groups: readonly ModelProviderGroup[];
43
- catalogError: string | undefined;
44
- };
90
+ /**
91
+ * Load the model catalog backing every route editor, with bounded retries.
92
+ *
93
+ * A failed load keeps the last successful groups (the editor stays usable and
94
+ * honest via the error hint) instead of collapsing to an empty catalog; a
95
+ * provider-order change or `reload()` starts a fresh attempt, and only the
96
+ * newest attempt may land.
97
+ */
98
+ export declare function useSettingsCatalog(input: SettingsCatalogInputs): SettingsCatalogState;
@@ -0,0 +1,53 @@
1
+ /** Viewport placement result written imperatively onto the portaled menu. */
2
+ /**
3
+ * Viewport-edge clamps are emitted as CSS custom properties; the stylesheet
4
+ * composes them with the env(safe-area-inset-*) floors (see `.menu` in
5
+ * ComposerPicker.module.css):
6
+ *
7
+ * top: max(var(--dsh-menu-top), calc(env(safe-area-inset-top) + gutter));
8
+ * right: max(var(--dsh-menu-right), calc(env(safe-area-inset-right) + gutter));
9
+ * max-height: min(var(--dsh-menu-max-height), calc(100dvh - env(safe-area-inset-bottom) - env(safe-area-inset-top)));
10
+ *
11
+ * Numbers come from innerWidth/innerHeight, which exclude browser chrome but
12
+ * not display cutouts, so the stylesheet side of the max()/min() keeps the
13
+ * popup inside the safe area on notched phones.
14
+ */
15
+ export interface PopupPlacementStyle {
16
+ readonly '--dsh-menu-top': string;
17
+ readonly '--dsh-menu-right': string;
18
+ readonly '--dsh-menu-max-height': string;
19
+ readonly visibility: 'visible';
20
+ }
21
+ export declare function samePlacement(left: PopupPlacementStyle | undefined, right: PopupPlacementStyle): boolean;
22
+ export interface PopupPlacementInput {
23
+ readonly trigger: {
24
+ readonly left: number;
25
+ readonly right: number;
26
+ readonly top: number;
27
+ readonly bottom: number;
28
+ };
29
+ readonly menu: {
30
+ readonly width: number;
31
+ readonly height: number;
32
+ };
33
+ readonly viewport: {
34
+ readonly width: number;
35
+ readonly height: number;
36
+ };
37
+ readonly gutter?: number;
38
+ }
39
+ /**
40
+ * Position the portaled picker menu in viewport coordinates, right-aligned to
41
+ * its trigger and preferring the space above it, clamped to the viewport.
42
+ */
43
+ /**
44
+ * Position the portaled picker menu in viewport coordinates, right-aligned to
45
+ * its trigger and preferring the space above it, clamped to the viewport.
46
+ *
47
+ * The height clamp is the viewport budget only (never a content measurement):
48
+ * the stylesheet caps the box at that budget, so taller menu panes grow into
49
+ * it naturally and a later ResizeObserver pass only re-reads the rendered box
50
+ * to re-anchor the trigger edge. Capping from the measured box would instead
51
+ * lock the menu at whatever height it first rendered with.
52
+ */
53
+ export declare function placeComposerPopup({ trigger, menu, viewport, gutter }: PopupPlacementInput): PopupPlacementStyle;
@@ -1,4 +1,4 @@
1
- import { type CSSProperties, type MouseEvent as ReactMouseEvent, type PointerEvent as ReactPointerEvent, type RefObject } from 'react';
1
+ import { type MouseEvent as ReactMouseEvent, type PointerEvent as ReactPointerEvent, type RefObject } from 'react';
2
2
  import { type PickerInteractionOperations } from './popup-dismissal.ts';
3
3
  export interface ComposerPickerSurfaceOptions {
4
4
  locked: boolean;
@@ -13,7 +13,6 @@ export interface ComposerPickerSurfaceOptions {
13
13
  export interface ComposerPickerSurface {
14
14
  id: string;
15
15
  open: boolean;
16
- menuStyle: CSSProperties;
17
16
  triggerRef: RefObject<HTMLButtonElement>;
18
17
  menuRef: RefObject<HTMLDivElement>;
19
18
  show: () => void;
@@ -21,5 +20,5 @@ export interface ComposerPickerSurface {
21
20
  onTriggerPointerDown: (event: ReactPointerEvent<HTMLButtonElement>) => void;
22
21
  onTriggerClick: (event?: ReactMouseEvent<HTMLButtonElement>) => void;
23
22
  }
24
- /** Own popup activation, positioning, and dismissal behind one internal seam. */
23
+ /** Own popup activation, viewport placement, and dismissal behind one internal seam. */
25
24
  export declare function useComposerPickerSurface(options: ComposerPickerSurfaceOptions): ComposerPickerSurface;
@@ -0,0 +1,34 @@
1
+ import OfficialSubagentRuntime, { type ContinuableStart, type ContinuableStartSpec, type SubagentRun, type SubagentStartRequest } from '@deepseek-ai/dsh-subagent';
2
+ import { type SubagentActivationSpecLike } from './subagent-runtime.js';
3
+ /** Previously published startup error; retained for consumers of this module. */
4
+ export declare class StartupIncompatibilityError extends Error {
5
+ readonly name = "StartupIncompatibilityError";
6
+ readonly surface: string;
7
+ constructor(surfaceOrMessage: string, message?: string);
8
+ }
9
+ export type StartupDisposer = () => void | PromiseLike<void>;
10
+ export type StartupCleanupTracker = (dispose: StartupDisposer) => void;
11
+ export interface MountedStartup<T> {
12
+ readonly value: T;
13
+ readonly dispose: () => Promise<void>;
14
+ }
15
+ export type SubagentSurfaceLine = 'activation' | 'start';
16
+ /** Classify the two published start API generations without version guessing. */
17
+ export declare function subagentSurfaceOf(value: unknown): SubagentSurfaceLine | undefined;
18
+ /** Retain the typed-only startup fallback and reverse, idempotent cleanup contract. */
19
+ export declare function mountWithStartupFallback<T>(candidate: (track: StartupCleanupTracker) => Promise<T>, fallback: (track: StartupCleanupTracker) => Promise<T>): Promise<MountedStartup<T>>;
20
+ export declare function routedRuntimeUnavailableNotice(error: StartupIncompatibilityError): string;
21
+ /** @deprecated Only the legacy subclass needs a mirrored dependency list. */
22
+ export declare function subagentRuntimeInject(officialInject: readonly string[] | undefined): string[];
23
+ /**
24
+ * @deprecated Kept importable for existing consumers, not mounted by the bundle.
25
+ * Install profileSubagentRuntime around the official service instead: the
26
+ * official Loader row must remain enabled to own its strict Typert definitions.
27
+ */
28
+ export declare class ModelSwitchSubagentRuntime extends OfficialSubagentRuntime {
29
+ static inject: string[];
30
+ private routed;
31
+ start(name: string, request: SubagentStartRequest): Promise<SubagentRun>;
32
+ startContinuable(spec: ContinuableStartSpec): Promise<ContinuableStart>;
33
+ startActivation(spec: SubagentActivationSpecLike): Promise<unknown>;
34
+ }
@@ -1,116 +1,51 @@
1
- import { Context } from '@deepseek-ai/cordis';
2
- import OfficialSubagentRuntime, { type ContinuableStart, type ContinuableStartSpec, type SubagentRun, type SubagentStartRequest } from '@deepseek-ai/dsh-subagent';
1
+ import { type Context } from '@deepseek-ai/cordis';
2
+ import type { SubagentStartRequest } from '@deepseek-ai/dsh-subagent';
3
3
  import { type SubagentRoute } from './session-route.js';
4
- /** Raised only when an explicit startup check finds an unsupported public surface. */
5
- export declare class StartupIncompatibilityError extends Error {
6
- readonly name = "StartupIncompatibilityError";
7
- readonly surface: string;
8
- /**
9
- * @param surfaceOrMessage - the incompatible public surface, or the error message.
10
- * @param message - the missing or incompatible requirement.
11
- */
12
- constructor(surfaceOrMessage: string, message?: string);
4
+ export { ModelSwitchSubagentRuntime, StartupIncompatibilityError, mountWithStartupFallback, routedRuntimeUnavailableNotice, subagentRuntimeInject, subagentSurfaceOf, } from './subagent-runtime-legacy.js';
5
+ export type { MountedStartup, StartupCleanupTracker, StartupDisposer, SubagentSurfaceLine, } from './subagent-runtime-legacy.js';
6
+ type RoutableSubagentRequest = Pick<SubagentStartRequest, 'parent' | 'agentOptions'>;
7
+ interface SubagentProviderSurface {
8
+ readonly capabilities?: {
9
+ readonly agentOptions?: boolean;
10
+ };
13
11
  }
14
- /** One idempotent cleanup operation tracked during runtime startup. */
15
- export type StartupDisposer = () => void | PromiseLike<void>;
16
- /** Register one cleanup operation for a startup attempt. */
17
- export type StartupCleanupTracker = (dispose: StartupDisposer) => void;
18
- /** A successfully mounted runtime and its idempotent cleanup operation. */
19
- export interface MountedStartup<T> {
20
- readonly value: T;
21
- readonly dispose: () => Promise<void>;
12
+ interface SubagentRuntimeSurface {
13
+ getProvider?(name: string): SubagentProviderSurface | undefined;
14
+ readonly startActivation?: unknown;
15
+ readonly start?: unknown;
16
+ readonly startContinuable?: unknown;
22
17
  }
23
- type RoutableSubagentRequest = Pick<SubagentStartRequest, 'parent' | 'agentOptions'>;
24
- /**
25
- * The 0.2.1+ activation spec, declared structurally.
26
- *
27
- * The pinned dependency typings predate the activation API, so the modern entry
28
- * is described here and delegated through the base prototype. `request` carries
29
- * the same `parent`/`agentOptions` pair the legacy start request does, which is
30
- * why one route adapter serves both lines.
31
- */
18
+ /** The public 0.2.1+ activation shape used by tools and Agent Teams. */
32
19
  export interface SubagentActivationSpecLike {
33
20
  readonly provider: string;
34
- readonly request: Pick<SubagentStartRequest, 'parent' | 'agentOptions'> & Record<string, unknown>;
21
+ readonly request: RoutableSubagentRequest & Record<string, unknown>;
22
+ readonly [field: string]: unknown;
23
+ }
24
+ /** Structural form of the pre-0.2.1 continuation start API. */
25
+ export interface ContinuableStartSpecLike {
26
+ readonly provider: string;
27
+ readonly request: RoutableSubagentRequest & Record<string, unknown>;
35
28
  readonly [field: string]: unknown;
36
29
  }
37
30
  /**
38
- * Inject one resolved route into a spawn that names none.
39
- *
40
- * A spawn that already names a provider, model, or effort keeps it: the caller's
41
- * explicit selection outranks any profile policy. The route itself is derived
42
- * from the DELEGATING session (its provider selects a saved group, else the flat
43
- * Subagent card in `fixed` mode), so two sessions on different providers route
44
- * their own spawns and neither can rewrite the other's policy.
45
- * @param request - the caller's spawn request.
46
- * @param route - the delegating session's resolved route, or undefined for official inherit.
47
- * @returns The request to hand the official runtime.
31
+ * Inject a parent-session route only when the caller named no provider, model,
32
+ * or reasoning effort. All other request and Agent options pass through.
48
33
  */
49
34
  export declare function routeSubagentRequest<T extends RoutableSubagentRequest>(request: T, route: SubagentRoute | undefined): T;
50
- /** The public start surface one installed Subagent runtime publishes. */
51
- export type SubagentSurfaceLine = 'activation' | 'start';
52
- /**
53
- * Classify the runtime surface this Host publishes.
54
- *
55
- * DSH 0.2.1 replaced `start()` / `startContinuable()` with the activation API
56
- * (`startActivation`), so a version-agnostic adapter has to recognize both
57
- * lines instead of hard-coding one.
58
- *
59
- * @param value - a runtime class's prototype or a mounted runtime instance.
60
- * @returns `activation` (0.2.1+), `start` (0.1.7/0.2.0), or undefined when neither is published.
61
- */
62
- export declare function subagentSurfaceOf(value: unknown): SubagentSurfaceLine | undefined;
35
+ /** Resolve the current public route surface, never retaining a disposed service. */
36
+ export declare function routedSubagentRequest<T extends RoutableSubagentRequest>(ctx: Context, runtime: SubagentRuntimeSurface, providerName: string, request: T): T;
63
37
  /**
64
- * Mount a candidate and use the fallback only for typed startup incompatibility.
65
- *
66
- * Every resource registered by an attempt is disposed in reverse order before a
67
- * fallback starts and again when the mounted result is disposed. Cleanup keeps
68
- * running after failures, and a startup error stays first in any aggregate.
69
- *
70
- * @param candidate - startup callback for the routed candidate.
71
- * @param fallback - startup callback for the untouched official runtime.
72
- * @returns the selected value and an idempotent disposer.
73
- * @throws the candidate error unless it is a StartupIncompatibilityError.
74
- * @throws the fallback startup error when fallback startup fails.
38
+ * Wrap the official service's start entries only. Its identity, prototype,
39
+ * registry, manager, Typert binding and prompt/interrupt methods are untouched.
40
+ * Disposers are idempotent and safe when overlapping adapter fibers unload in
41
+ * either order. Unsupported or sealed surfaces leave the official route usable.
75
42
  */
76
- export declare function mountWithStartupFallback<T>(candidate: (track: StartupCleanupTracker) => Promise<T>, fallback: (track: StartupCleanupTracker) => Promise<T>): Promise<MountedStartup<T>>;
43
+ export declare function installSubagentRouteWrappers(ctx: Context): () => void;
77
44
  /**
78
- * Operator-facing notice for a Host whose Subagent runtime cannot be routed.
79
- *
80
- * DSH 0.2.1 replaced `start()`/`startContinuable()` with the activation API, so
81
- * this adapter's override point is gone; the row then mounts the untouched
82
- * official runtime instead of guessing a new seam.
83
- * @param error - the typed startup incompatibility that rejected the candidate.
84
- * @returns The notice logged once at startup.
45
+ * Wait for the official service without replacing it or copying its dependency
46
+ * list. Model Switch is read optionally per call, so its absence cannot hold a
47
+ * startup fiber or retain a stale settings service. Cordis rebinds this effect
48
+ * when the official service is recreated.
85
49
  */
86
- export declare function routedRuntimeUnavailableNotice(error: StartupIncompatibilityError): string;
87
- /** Profile replacement that selects the routed runtime or the untouched official runtime. */
88
- export declare const profileSubagentRuntime: (ctx: Context) => Promise<() => Promise<void>>;
89
- /**
90
- * The plugin dependency list for the mounted runtime.
91
- *
92
- * Static inheritance does not merge `inject`: cordis reads the static list off
93
- * the class it mounts, so the subclass must repeat every service the official
94
- * runtime's own code reads and add the route surface this adapter uses.
95
- * @param officialInject - the installed runtime's declared dependencies (absent on 0.1.7/0.2.0).
96
- * @returns The deduplicated list, official dependencies first.
97
- */
98
- export declare function subagentRuntimeInject(officialInject: readonly string[] | undefined): string[];
99
- /** Official runtime with only a pre-descriptor route-selection adapter. */
100
- export declare class ModelSwitchSubagentRuntime extends OfficialSubagentRuntime {
101
- static inject: string[];
102
- private routed;
103
- start(name: string, request: SubagentStartRequest): Promise<SubagentRun>;
104
- startContinuable(spec: ContinuableStartSpec): Promise<ContinuableStart>;
105
- /**
106
- * 0.2.1+ activation entry: delegation tools call this instead of
107
- * `start()`/`startContinuable()`, and its spec carries the same
108
- * `request.agentOptions` this adapter already rewrites. Every other spec
109
- * field (label, childId, signal, delivery) passes through untouched.
110
- *
111
- * @param spec - the activation spec published by the installed Host.
112
- * @returns The official activation result.
113
- */
114
- startActivation(spec: SubagentActivationSpecLike): Promise<unknown>;
115
- }
50
+ export declare function profileSubagentRuntime(ctx: Context): void;
116
51
  export default profileSubagentRuntime;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Safe reads of the optional Model Switch settings service for the naming row.
3
+ *
4
+ * The session-naming row must keep the official naming behavior when the
5
+ * `model-switch` row is absent, so `modelSwitch` can never join the row's own
6
+ * `inject` list: Cordis waits for every declared dependency before a fiber
7
+ * loads (there is no "optional" inject), and a never-provided service would
8
+ * leave the row pending forever.
9
+ *
10
+ * Two reads are tried per call, in this order:
11
+ *
12
+ * 1. `ctx.get('modelSwitch')` with Cordis' default strict mode — the active
13
+ * implementation only, or undefined. This is the read the shipped row used
14
+ * and it keeps working across a settings-row rebuild because the store
15
+ * entry is replaced, not cached here.
16
+ * 2. A scoped `ctx.inject(['modelSwitch'])` child fiber, which binds a
17
+ * dependent scope and resets it on dispose. This covers compositions where
18
+ * the strict store read is invisible from the row's own entry context.
19
+ *
20
+ * The returned function identity is stable for the row's lifetime and every
21
+ * call re-reads, so a settings save or a service rebuild needs no remount.
22
+ * Reads never throw: a missing face, a disposed scope, or a throwing read all
23
+ * answer undefined, which means "official behavior" to the caller.
24
+ *
25
+ * @module dsh-model-switch/title-settings-reader
26
+ */
27
+ import type { Context } from '@deepseek-ai/cordis';
28
+ import type { ModelSwitchSettings } from './host-settings.js';
29
+ /**
30
+ * Create the settings reader for one naming row context.
31
+ * @param ctx - this row's context (the row fiber's own scope).
32
+ * @returns The reader: per-request live settings, or undefined when unavailable.
33
+ */
34
+ export declare function titleSettingsReaderOf(ctx: Context): () => ModelSwitchSettings | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-model-switch",
3
- "version": "0.4.61",
3
+ "version": "0.4.63",
4
4
  "description": "Explicit model routing plus composer/Plan picker for DeepSeek Harness",
5
5
  "repository": {
6
6
  "type": "git",
@@ -122,7 +122,8 @@
122
122
  "0.2.0-rc.2": "compatible",
123
123
  "0.2.1-rc.2": "compatible",
124
124
  "0.2.1-rc.3": "compatible",
125
- "0.2.1-rc.5": "compatible"
125
+ "0.2.1-rc.5": "compatible",
126
+ "0.2.2-rc.1": "compatible"
126
127
  }
127
128
  }
128
129
  },