@dsmm/dsmm 0.1.1 → 0.1.5

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 (108) hide show
  1. package/README.md +26 -15
  2. package/agent-presets/dsmm-builder/agent.cordis.yml +14 -12
  3. package/agent-presets/dsmm-builder/preset.yml +1 -1
  4. package/agent-presets/dsmm-clarifier/agent.cordis.yml +4 -2
  5. package/agent-presets/dsmm-clarifier/preset.yml +1 -1
  6. package/agent-presets/dsmm-code-search/agent.cordis.yml +4 -2
  7. package/agent-presets/dsmm-code-search/preset.yml +1 -1
  8. package/agent-presets/dsmm-creative/agent.cordis.yml +3 -1
  9. package/agent-presets/dsmm-creative/preset.yml +1 -1
  10. package/agent-presets/dsmm-doc-search/agent.cordis.yml +4 -2
  11. package/agent-presets/dsmm-doc-search/preset.yml +1 -1
  12. package/agent-presets/dsmm-media-reader/agent.cordis.yml +4 -2
  13. package/agent-presets/dsmm-media-reader/preset.yml +1 -1
  14. package/agent-presets/dsmm-oracle/agent.cordis.yml +3 -1
  15. package/agent-presets/dsmm-oracle/preset.yml +1 -1
  16. package/agent-presets/dsmm-oracle-2nd/agent.cordis.yml +3 -1
  17. package/agent-presets/dsmm-oracle-2nd/preset.yml +1 -1
  18. package/agent-presets/dsmm-orchestrator/agent.cordis.yml +15 -13
  19. package/agent-presets/dsmm-orchestrator/preset.yml +2 -2
  20. package/agent-presets/dsmm-plan-critic/agent.cordis.yml +4 -2
  21. package/agent-presets/dsmm-plan-critic/preset.yml +1 -1
  22. package/agent-presets/dsmm-planner/agent.cordis.yml +4 -2
  23. package/agent-presets/dsmm-planner/preset.yml +1 -1
  24. package/agent-presets/dsmm-reviewer/agent.cordis.yml +4 -2
  25. package/agent-presets/dsmm-reviewer/preset.yml +1 -1
  26. package/docs/agent-presets.md +15 -5
  27. package/docs/compatibility.md +66 -11
  28. package/docs/migration-from-ocmm.md +8 -0
  29. package/docs/model-routing.md +25 -7
  30. package/docs/profiles.md +95 -0
  31. package/docs/releasing.md +66 -19
  32. package/docs/runtime-recovery.md +39 -14
  33. package/docs/settings-status.md +13 -5
  34. package/lib/client/ProfilesSection.d.ts +11 -0
  35. package/lib/client/ProfilesSection.js +66 -0
  36. package/lib/client/SessionProfiles.d.ts +19 -0
  37. package/lib/client/SessionProfiles.js +24 -0
  38. package/lib/client/StructuredEditor.d.ts +11 -0
  39. package/lib/client/StructuredEditor.js +74 -0
  40. package/lib/client/controller.d.ts +115 -0
  41. package/lib/client/controller.js +340 -0
  42. package/lib/client/index.d.ts +13 -0
  43. package/lib/client/index.js +54 -0
  44. package/lib/client/locales.d.ts +145 -0
  45. package/lib/client/locales.js +91 -0
  46. package/lib/client/session-labels.d.ts +8 -0
  47. package/lib/client/session-labels.js +13 -0
  48. package/lib/client/structured.d.ts +18 -0
  49. package/lib/client/structured.js +98 -0
  50. package/lib/client/styles.d.ts +3 -0
  51. package/lib/client/styles.js +36 -0
  52. package/lib/client.js +2825 -0
  53. package/lib/commands.d.ts +3 -3
  54. package/lib/commands.js +5 -4
  55. package/lib/dsh-types.d.ts +20 -0
  56. package/lib/guards.d.ts +2 -2
  57. package/lib/guards.js +3 -2
  58. package/lib/index.d.ts +12 -4
  59. package/lib/index.js +98 -20
  60. package/lib/mode.d.ts +2 -2
  61. package/lib/mode.js +1 -1
  62. package/lib/model-routing.d.ts +2 -2
  63. package/lib/model-routing.js +100 -15
  64. package/lib/preset-registry.js +5 -3
  65. package/lib/profile-remote.d.ts +37 -0
  66. package/lib/profile-remote.js +219 -0
  67. package/lib/profile-rpc.d.ts +35 -0
  68. package/lib/profile-rpc.js +187 -0
  69. package/lib/profile-runtime.d.ts +63 -0
  70. package/lib/profile-runtime.js +310 -0
  71. package/lib/profile-store.d.ts +60 -0
  72. package/lib/profile-store.js +588 -0
  73. package/lib/profile-types.d.ts +80 -0
  74. package/lib/profile-types.js +2 -0
  75. package/lib/profiles.d.ts +26 -0
  76. package/lib/profiles.js +269 -0
  77. package/lib/prompts.d.ts +2 -2
  78. package/lib/prompts.js +4 -4
  79. package/lib/role-providers.d.ts +2 -2
  80. package/lib/role-providers.js +49 -6
  81. package/lib/role-routing.d.ts +37 -3
  82. package/lib/role-routing.js +110 -35
  83. package/lib/role-subagents.d.ts +2 -2
  84. package/lib/role-subagents.js +6 -4
  85. package/lib/roles.d.ts +4 -0
  86. package/lib/roles.js +43 -27
  87. package/lib/routing-policy.d.ts +32 -0
  88. package/lib/routing-policy.js +92 -0
  89. package/lib/runtime-recovery.d.ts +2 -2
  90. package/lib/runtime-recovery.js +215 -54
  91. package/lib/session-metadata.d.ts +13 -0
  92. package/lib/session-metadata.js +34 -0
  93. package/lib/session-persistence.d.ts +35 -0
  94. package/lib/session-persistence.js +304 -0
  95. package/lib/settings.d.ts +34 -1
  96. package/lib/settings.js +33 -7
  97. package/lib/state.d.ts +1 -0
  98. package/lib/state.js +4 -0
  99. package/lib/status.d.ts +9 -1
  100. package/lib/status.js +34 -12
  101. package/locale/en.json +6 -0
  102. package/locale/zh.json +6 -0
  103. package/package.json +66 -15
  104. package/patches/agent-presets-root.example.cordis.patch.yml +6 -10
  105. package/prompts/deepseek-v4-pro.md +1 -1
  106. package/prompts/deepwork.md +3 -3
  107. package/scripts/repair-session-log.mjs +476 -0
  108. package/scripts/session-repair-native-verifier.mjs +367 -0
@@ -1,8 +1,25 @@
1
- # Runtime recovery
1
+ # Runtime recovery and route strategies (0.1.5)
2
2
 
3
- ## Scope and defaults
3
+ ## Two independent role strategies
4
4
 
5
- Runtime recovery is an opt-in, restart-scoped DSMM setting. Its complete default is:
5
+ Every enabled DSMM role in each profile independently selects `startup-lock` (default) or `rate-limit-fallback`. Optional `runtimePolicy` supplies inherited defaults; a role's `strategy` / `rateLimit` overrides only explicit fields. Different profiles can assign different strategies to the same role. No profile contains native account/auth configuration.
6
+
7
+ Native preparation admits the primary or first resolvable ordered candidate without sending a sacrificial completion. Catalog listing is advisory, not account/network health. `startup-lock` then retains that exact route/effort across turns and bounded RATE_LIMIT retries. `rate-limit-fallback` may advance the ordered chain after its threshold of distinct safe RATE_LIMIT failures. Success resets consecutive counts; duplicate delivery does not count twice and exhausted chains never wrap.
8
+
9
+ | Policy field | Default | Strict integer bound |
10
+ | --- | --- | --- |
11
+ | `maxRetries` | 3 | 0–10 |
12
+ | `initialDelayMs` | 500 | 0–30000 |
13
+ | `maxDelayMs` | 10000 | 0–30000 |
14
+ | `maxTotalDelayMs` | 30000 | 0–120000 |
15
+ | `switchAfterRateLimits` | 3 | 1–10 |
16
+ | `maxSwitches` | 2 | 0–10 |
17
+
18
+ `maxRetries` counts requests after the first on a route; the threshold includes that first distinct failed attempt. If retry budget runs out before threshold, stop. A switch starts fresh same-route counters but consumes the admission epoch's switch cap. Malformed, unknown, fractional or nonfinite values fail instead of becoming different defaults.
19
+
20
+ ## Legacy defaults and migration
21
+
22
+ The legacy continuation/configuration block remains parse-compatible, with this complete default:
6
23
 
7
24
  ```yaml
8
25
  runtimeRecovery:
@@ -17,23 +34,31 @@ runtimeRecovery:
17
34
  prompt: "Continue the current task from the durable goal or unfinished todo list. Do not repeat completed work."
18
35
  ```
19
36
 
20
- `maxFallbackAttempts` and `idleContinuation.maxContinuations` are finite integer caps floored and clamped to `0..10`. An empty `fallbackRoutes` list is valid and supplies no provider/model fallback. When runtime recovery is disabled (`enabled` is false), recovery is isolated: it does not disable or alter DSMM prompts, skills, guards, LSP, or model routing.
37
+ `maxFallbackAttempts` and `idleContinuation.maxContinuations` retain their legacy finite cap grammar. An empty `fallbackRoutes` list is valid and supplies no alternatives. The legacy `runtimeRecovery.enabled` flag is not the strategy selector and does not gate the new scoped finite RATE_LIMIT policy.
21
38
 
22
- ## Role-specific chains (0.1.1)
39
+ 0.1.4 documents remain loadable without rewriting drafts, deployment patches or history. The migration is behavioral: omitted strategy now means safer `startup-lock`, so retained generic `SERVER`, `TIMEOUT`, `TRANSPORT` or status-based retry lists do not imply later automatic channel hopping. Explicitly choose `rate-limit-fallback` only where rate-limit rollover is intended. This release supplies no inferred generic-behavior opt-in. Inspect normalized effective role policy before upgrading a deployment that depended on the old automatic behavior.
23
40
 
24
- `roleRouting.<role>.fallbackRoutes` uses the same route shape, with optional exact native `reasoningEffort`. The existing `runtimeRecovery.enabled` gate is required for both role and global fallback; configuring a primary or a chain does not implicitly enable recovery or idle continuation.
41
+ ## Role-specific chains
42
+
43
+ `roleRouting.<role>.fallbackRoutes` uses the same route shape, with optional exact native `reasoningEffort`. The resolved strategy/retry policy, not legacy enabled state, controls scoped RATE_LIMIT behavior. Configuring a chain does not enable idle continuation.
25
44
 
26
45
  For a known enabled role, an explicitly supplied chain takes precedence over the global list. `[]` suppresses global fallback for that role; an omitted chain preserves legacy global behavior. Routes retain configured order and deduplicate by provider/model identity, so changing effort does not create additional retry opportunities. Unrecognized children never inherit their parent's role chain.
27
46
 
28
- To migrate only explicit ocmm role chains, set `runtimeRecovery.enabled:true`, keep its global `fallbackRoutes:[]`, and leave `idleContinuation.enabled:false`. This deliberately enables role fallback without enabling a generic model chain or autonomous continuation. Provider retry remains host-owned.
47
+ To migrate explicit role chains, choose each role's strategy deliberately, keep inherited/global alternatives explicit where needed, and leave `idleContinuation.enabled:false`. Omission resolves to startup lock, not legacy generic recovery. Exact effort omission clears stale adapter-owned effort while preserving unrelated native parameters.
48
+
49
+ ## Universal no-output fence and one retry owner
50
+
51
+ Every DSMM retry or switch requires positive no-output proof, even when staying on the same model. Exact Agent/admission epoch/lock generation, live attempt ID, turn/step, accepted header and committed assistant settlement must match. Dense live chunks must agree with the validated durable compact stream and its exact terminal failure. Missing, stale, mismatched, ambiguous, abandoned or duplicate evidence refuses before spending budget or waiting.
52
+
53
+ Any accepted text, reasoning, tool-call fragment, block start/end or executed tool forbids replay. Both strategies' deterministic partial-text → RATE_LIMIT and partial-tool-fragment → RATE_LIMIT cases require one provider request, zero tools and terminal refusal. Already completed earlier tools stay unchanged. Same-route retries are not exempt.
29
54
 
30
- ## Host retry and fallback routes
55
+ Inside the scoped DSMM RATE_LIMIT/unavailable branch, DSMM owns the native `agent/request-error` decision. Refusal is terminal and never falls through to native `mode:always` or another competing retry handler. Outside that branch, native host-first behavior and exact downstream result identity remain unchanged. All provider calls and step retries stay inside the native loop; DSMM neither calls a provider directly nor synthesizes a prompt, restarts a turn or replays tools.
31
56
 
32
- The host `agent/request-error` decision wins by identity. DSMM calls downstream first and acts only after the host declines to retry. It classifies failures using exact integer status membership and lowercased exact code membership only; it performs no message parsing or provider-message classification.
57
+ Only exact native `NO_ADAPTER` or adapter-proven `UNKNOWN_MODEL` on the first actual no-output request may advance a remaining startup candidate. Contradictory 401/403/402/429 facts, authorization, quota/payment, context, cancellation, transport/server ambiguity or error-message text do not establish availability. Later generic failures cannot hop.
33
58
 
34
- For a host-declined, retryable failure, the failed provider must match the latest request header before DSMM can select a route. Attempted routes are reconstructed from durable request headers: the latest valid header before the target `step/start` is inherited, then valid route changes within that same turn and step are appended. DSMM chooses only the first unattempted, non-failed fallback in configured order. It does not discover providers, infer a heuristic chain, or reorder the configured list.
59
+ One finite abortable middleware delay may honor valid `providerRetryAfterMs` only within per-delay and total budgets. Invalid or too-large values refuse instead of causing infinite waiting or uncontrolled retry. Abort/disposal/epoch/header/provider replacement and closed/superseded boundaries cancel or invalidate pending work. No independent timer-driven request exists.
35
60
 
36
- `maxFallbackAttempts` counts selected fallback routes after the primary route. A cap of zero selects none; an exhausted cap, invalid route, missing header, provider mismatch, disabled setting, aborted signal, or non-retryable failure leaves the host decision unchanged. The selected route is held in process-local state behind a one-shot `(agent, turn, step)` fence. DSMM makes no timer or provider call itself and does not replace the host retry backoff policy.
61
+ Fresh native `model/selection` intent also invalidates old reservations, even when provider/model/effort is unchanged. DSMM captures the exact typed user intent at native prompt-assembly start and correlates it with the native-selected request; a concurrently newer choice is for the next assembly, never a retrofit of the current frame. Explicit user provider/model/effort outranks profile primary/defaults on later turns and cold resume. Profile apply advances the admission epoch and policy without silently clearing native user intent. A parent's manual choice is not authority to overwrite a configured child's own role route.
37
62
 
38
63
  ## Request ordering
39
64
 
@@ -41,7 +66,7 @@ The recovery request path applies a matching pending fallback route after native
41
66
 
42
67
  Model routing evaluates the final route. Legacy calibration still recognizes only exact V4 Pro or native V41 Flash routes; a fallback does not broaden those matches. Explicit configured efforts bypass legacy degradation and are checked through the native model capability seam. DSMM does not set temperature or create a second capability registry, and the final adapter remains responsible for supported call parameters.
43
68
 
44
- Duplicate failure delivery cannot select a second pending fallback. Closed or superseded turn/step boundaries, aborted signals, and expired pending routes are ignored. HTTP 402 requires explicit membership in `retryOnStatusCodes`; generic retry-code membership cannot silently authorize a paid-route change. No real billing/rate-limit error is manufactured for testing.
69
+ Duplicate failure delivery cannot select a second pending route. Closed/superseded turn/step boundaries and aborted signals cannot commit a late route. HTTP 402 never authorizes strategy rollover. No real billing/rate-limit error is manufactured for testing.
45
70
 
46
71
  ## Durable continuation
47
72
 
@@ -55,7 +80,7 @@ Steering failure consumes an attempt and produces a sanitized warn/fail-open res
55
80
 
56
81
  ## Cold restart
57
82
 
58
- Durable route/header work can be reconstructed after a cold restart from session events. Process-local pending-route and continuation-count state cannot. There is no continuation until the user or host resumes a turn, which prevents DSMM from fabricating a cross-process retry or continuation loop.
83
+ An explicit session sidecar pins its exact immutable profile/baseline on cold resume; absent sidecars retain the historical global-current contract. Process-local attempts, waits, counters and locks do not resurrect from old headers alone. New admission epochs fence old reservations and route folds while the audited `dsmm/role-policy` event retains its exact grammar. There is no continuation until the user/native host resumes activity. See [profiles](profiles.md).
59
84
 
60
85
  ## Subagent recovery
61
86
 
@@ -66,7 +91,7 @@ To investigate an interrupted child, use the native durable descriptor and child
66
91
  ## Non-goals and logging
67
92
 
68
93
  - No fake or extended `llm/retry` events.
69
- - No retry timer or backoff replacement, no timers, no session aborts, and no background polling.
94
+ - No independent retry timer/request engine, session aborts, or background polling; only finite abortable delay in the existing native error middleware.
70
95
  - No cross-process automatic retry.
71
96
  - No provider discovery or heuristic fallback chain.
72
97
  - No provider-message parsing or classification, and no provider calls outside the host request loop.
@@ -1,14 +1,16 @@
1
- # Settings and status
1
+ # Deepwork settings and status
2
2
 
3
3
  ## Commands and inspection
4
4
 
5
5
  `/deepwork [off|message]` changes the receiving session's mode. `/dsmm-status` reports bounded normalized state; `/dsmm-status json` returns a defensive JSON snapshot with version 1. Other input returns `Usage: /dsmm-status [json]`.
6
6
 
7
+ Human-facing status/mode copy uses Deepwork. The technical commands, JSON fields, namespace and configurable `modeName` remain unchanged in 0.1.5.
8
+
7
9
  Commands belong to the native command adapter. Headless task text is not a slash-command invocation.
8
10
 
9
- ## DSH 0.2 configuration
11
+ ## DSH 0.2 deployment configuration
10
12
 
11
- DSMM's configuration remains **restart-scoped** and is resolved from the Loader plugin entry. The removed `settings.register()` service and old `$DSH_HOME/settings.yaml` namespace are not used by DSH 0.2. Copy the desired DSMM values manually into the profile's `cordis.patch.yml`, restart, and inspect `--dump-config` and status:
13
+ The Loader plugin entry remains the deployment baseline. Structural fields are **restart-scoped**; the 0.1.5 source contract includes runtime-only file overlays for newly admitted Agents. The removed `settings.register()` service and old `$DSH_HOME/settings.yaml` namespace are not used by DSH 0.2. Copy deployment values into the profile's `cordis.patch.yml`, restart, and inspect `--dump-config` and status:
12
14
 
13
15
  ```yaml
14
16
  - id: dsmm
@@ -28,7 +30,9 @@ DSMM's configuration remains **restart-scoped** and is resolved from the Loader
28
30
  enabled: false
29
31
  ```
30
32
 
31
- DSH's new SettingsForms only projects explicitly volatile fields; DSMM does not silently turn restart-only values into live references merely to display a settings form. There is no custom settings panel.
33
+ The 0.1.5 source contract includes the additive native Settings **Deepwork Profiles** / **Deepwork 配置档** section through the native client/authorized RPC surface. It is not a volatile SettingsForms projection and does not turn structural fields into live references. Create/read/edit/save/apply/reset operate on independent files under `<profileContext.dir>/dsmm-profiles/`; neither a Settings schema nor these docs prove completed Desktop activation. See [runtime profiles](profiles.md) for the exact allowlist, file formats and pending acceptance boundary.
34
+
35
+ Save changes only the draft. Global Apply pins an immutable revision for **new unscoped Agents only**; existing even-blank Agents retain their admissions. The separate current-session selector uses the native view's actual session ID and idle maintenance/CAS/epoch fences. It changes only that ordinary root and future children; old children retain their old epoch. Cold resume honors an explicit sidecar or, when absent, the current global default. Global reset and session baseline pinning are distinct and leave drafts intact.
32
36
 
33
37
  ## Workflow compatibility
34
38
 
@@ -38,10 +42,12 @@ Risk-based behavior scales discovery, planning, and review to uncertainty and in
38
42
 
39
43
  ## Other settings
40
44
 
41
- `roleRouting` defaults to an empty restart-scoped map. Each canonical role accepts an optional fixed `primary` and an optional ordered `fallbackRoutes` list of `{provider, model, reasoningEffort?}`. It is separate from the boolean `roles` enable map. Unknown role keys and malformed explicit routes fail closed; omitted chains and explicit empty chains have different meanings. See [model routing](model-routing.md) and [runtime recovery](runtime-recovery.md).
45
+ `roleRouting` defaults to an empty map. Each canonical role accepts optional `primary`, ordered `fallbackRoutes`, `strategy` and bounded `rateLimit` fields. Profile-level `runtimePolicy` supplies inherited strategy/retry defaults. Startup lock is the default; rate-limit rollover is explicit per role. Native catalog/form controls edit JSONC paths without changing native global model defaults. The deployment-only `roles` enable map remains separate. Unknown keys/malformed routes fail; omitted and explicit empty chains differ. See [model routing](model-routing.md) and [runtime recovery](runtime-recovery.md).
42
46
 
43
47
  The public schema and exported `DEFAULT_DSMM_SETTINGS` are the complete defaults. Seven core skill toggles and all twelve role toggles default on; effective application is scoped to active mode or a selected DSMM role, not global task policy. Managed preset-directory materialization remains off by default and is an export facility rather than native discovery.
44
48
 
49
+ Runtime overlays allow only `defaultActive`, `roleRouting`, `runtimePolicy`, `workflow`, `guards`, `runtimeRecovery`, and both `deepseekV4Pro*`/`deepseekFlash*` Calibration, DefaultReasoningEffort and MaxReasoningPresets fields. `roles`, `skills`, `modeName`, `promptOrder`, `section`, `presets`, `lsp`, `sessionPersistence`, native provider/account/install controls, embedded profiles and unknown fields are rejected. Defaults resolve before deployment settings, then the admitted immutable overlay. A missing global selection leaves the deployment baseline unchanged.
50
+
45
51
  Existing `deepseekV4ProCalibration`, `deepseekV4ProDefaultReasoningEffort`, and `deepseekV4ProMaxReasoningPresets` remain compatible. Flash has independent corresponding `deepseekFlash*` settings; calibration modes are off/auto/strict. Auto preserves explicit effort, strict chooses supported policy effort, and unsupported capabilities never justify guessed parameters.
46
52
 
47
53
  Guard scope defaults to `deepwork-or-dsmm-agent`; shell safety and helpers remain enabled and Git writes require host approval. LSP and runtime recovery default off. Recovery caps are finite; an empty fallback list does not enable automatic model discovery or substitution.
@@ -53,3 +59,5 @@ The snapshot reports `mode`, `route`, `calibration`, `runtimeRecovery`, and `eff
53
59
  Status does not perform capability/network queries, expose credentials or provider errors, or report process-local pending retries. Model calibration is enforced in the actual request waterfall, not by status or prompt text.
54
60
 
55
61
  Configured role policy/chain and the actual persisted current route are distinct facts. The normalized settings snapshot defensively copies nested role routes and lists; configuration presence is not a claim of successful provider authentication or a completed fallback.
62
+
63
+ Status describes the receiving Agent's admitted profile/revision/epoch, resolved strategy/retry policy and actual route state separately from future global defaults. Settings and the header selector display those scopes distinctly; a global change can intentionally differ from a live Agent. `--dump-config` shows deployment composition, not proof of runtime-profile application or authenticated UI behavior.
@@ -0,0 +1,11 @@
1
+ import type { InjectFace, PropsLocale } from "@deepseek-ai/dsh-client-ui-slots";
2
+ import type { ProfilesActions, ProfilesController } from "./controller.js";
3
+ export type ProfilesInjected = ProfilesActions & {
4
+ hooks: {
5
+ profiles: ProfilesController["store"];
6
+ };
7
+ };
8
+ export type ProfilesSectionProps = InjectFace<ProfilesInjected> & PropsLocale<"settings.dsmm-profiles">;
9
+ /** One native settings.section; policy selection is never coupled to browsing. */
10
+ export declare function ProfilesSection(props: ProfilesSectionProps): import("react").JSX.Element;
11
+ //# sourceMappingURL=ProfilesSection.d.ts.map
@@ -0,0 +1,66 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useId, useRef } from "react";
3
+ import { Button, Input } from "@deepseek-ai/dsh-client-ui-primitives";
4
+ import { canReconcileSelection } from "./controller.js";
5
+ import { StructuredEditor } from "./StructuredEditor.js";
6
+ import { SessionScope } from "./SessionProfiles.js";
7
+ import { structuredDocument } from "./structured.js";
8
+ function issueKey(issue) {
9
+ if (issue.source === "selection")
10
+ return issue.code === "conflict" ? "selectionConflict" : "appliedInvalid";
11
+ if (issue.kind === "assembly")
12
+ return "unavailable";
13
+ if (issue.kind === "transport")
14
+ return "transport";
15
+ return issue.code === "conflict" || issue.code === "validation" ? issue.code : "io";
16
+ }
17
+ /** One native settings.section; policy selection is never coupled to browsing. */
18
+ export function ProfilesSection(props) {
19
+ const { t } = props;
20
+ const state = props.useProfiles((snapshot) => snapshot);
21
+ const prefix = useId();
22
+ const selectRef = useRef(null);
23
+ const inputRef = useRef(null);
24
+ const editorRef = useRef(null);
25
+ const cancelRef = useRef(null);
26
+ const hadConfirmation = useRef(false);
27
+ const disabled = state.busy !== null || state.pendingEditor !== null || state.sessionBusy === "apply" || state.sessionBusy === "reset";
28
+ const snapshot = state.snapshot;
29
+ const editor = state.editor;
30
+ const reconcilable = canReconcileSelection(snapshot);
31
+ const selectionConflict = reconcilable && snapshot?.selectionError?.code === "conflict";
32
+ const invalid = state.issue?.kind === "domain" && state.issue.code === "validation";
33
+ const idInvalid = invalid && state.issue?.field === "id";
34
+ const rawInvalid = editor !== null && structuredDocument(editor.content) === null;
35
+ useEffect(() => {
36
+ if (state.pendingEditor !== null) {
37
+ cancelRef.current?.focus();
38
+ hadConfirmation.current = true;
39
+ }
40
+ else if (hadConfirmation.current) {
41
+ selectRef.current?.focus();
42
+ hadConfirmation.current = false;
43
+ }
44
+ }, [state.pendingEditor]);
45
+ useEffect(() => {
46
+ if (state.issue?.kind === "domain" && state.issue.code === "validation") {
47
+ if (state.issue.field === "id")
48
+ inputRef.current?.focus();
49
+ else
50
+ editorRef.current?.focus();
51
+ }
52
+ }, [state.issue]);
53
+ const applied = editor?.revision !== null && editor?.id === snapshot?.selectedId && editor?.revision === snapshot?.appliedRevision;
54
+ let selection = t("baseline");
55
+ if (snapshot?.selectionError !== undefined && !selectionConflict)
56
+ selection = t("appliedInvalid");
57
+ else if (snapshot?.selectedId !== null && snapshot?.selectedId !== undefined)
58
+ selection = t("appliedProfile", { id: snapshot.selectedId, revision: snapshot.appliedRevision?.slice(0, 12) ?? "—" });
59
+ const notice = state.notice === null ? "" : t(state.notice.key === "reset" ? "resetDone" : state.notice.key, { id: state.notice.id });
60
+ return _jsxs("section", { className: "dsmm-profiles", "aria-labelledby": `${prefix}-title`, "aria-busy": state.busy !== null, children: [_jsx("h2", { id: `${prefix}-title`, children: t("title") }), _jsx("p", { children: t("description") }), _jsx("h3", { id: `${prefix}-global`, children: t("globalScope") }), _jsx("p", { className: "dsmm-hint", children: t("newSessions") }), _jsx("p", { "data-dsmm-selection": true, children: selection }), _jsxs("div", { className: "dsmm-actions", children: [_jsx(Button, { type: "button", variant: "outline", disabled: disabled || snapshot === null, onClick: () => { void props.create(); }, children: t("new") }), _jsx(Button, { type: "button", variant: "outline", disabled: disabled, onClick: () => { void props.refresh(); }, children: t(state.busy === "refresh" ? "refreshing" : "refresh") }), _jsx(Button, { type: "button", variant: "outline", disabled: disabled || !reconcilable || (snapshot?.selectedId === null && !selectionConflict), onClick: () => { void props.reset(); }, children: t(state.busy === "reset" ? "resetting" : "reset") })] }), snapshot !== null && _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-select`, children: t("editorSelect") }), _jsxs("select", { ref: selectRef, id: `${prefix}-select`, disabled: disabled, value: editor?.revision == null ? "" : editor.id, onChange: (event) => { if (event.currentTarget.value)
61
+ void props.open(event.currentTarget.value); }, children: [_jsx("option", { value: "", children: t(editor?.revision === null ? "newDraft" : "choose") }), snapshot.profiles.map((profile, index) => _jsxs("option", { value: profile.id, children: [profile.label === undefined ? profile.id : `${profile.label} (${profile.id})`, profile.error === undefined ? "" : ` — ${t("invalidProfile", { id: profile.id })}`] }, `${index}:${profile.id}`))] }), snapshot.profiles.length === 0 && _jsx("p", { className: "dsmm-hint", children: t("empty") })] }), state.pendingEditor !== null && _jsxs("div", { className: "dsmm-confirm", role: "group", "aria-labelledby": `${prefix}-confirm`, onKeyDown: (event) => { if (event.key === "Escape") {
62
+ event.preventDefault();
63
+ props.cancelDiscard();
64
+ } }, children: [_jsx("p", { id: `${prefix}-confirm`, children: t("discardPrompt") }), _jsxs("div", { className: "dsmm-actions", children: [_jsx(Button, { type: "button", variant: "outline", onClick: () => { void props.discardAndOpen(); }, children: t("discard") }), _jsx(Button, { ref: cancelRef, type: "button", variant: "primary", onClick: props.cancelDiscard, children: t("cancel") })] })] }), _jsx(SessionScope, { state: state, actions: props, t: t }), _jsxs("div", { className: "dsmm-catalog", children: [_jsx("h3", { children: t("catalogTitle") }), _jsx("p", { className: "dsmm-hint", children: t("catalogHint") }), state.catalogUnavailable && _jsx("p", { className: "dsmm-hint", children: t("catalogUnavailable") }), state.catalog?.failures.map((failure) => _jsx("p", { className: "dsmm-hint", children: t("catalogFailure", { name: failure.name, id: failure.id }) }, failure.id)), _jsx(Button, { type: "button", variant: "outline", disabled: state.catalogBusy, onClick: () => { void props.refreshCatalog(); }, children: t(state.catalogBusy ? "catalogRefreshing" : "catalogRefresh") })] }), editor !== null && _jsxs("div", { className: "dsmm-editor", children: [_jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-id`, children: t("profileId") }), _jsx(Input, { ref: inputRef, id: `${prefix}-id`, className: "dsmm-input", value: editor.id, disabled: disabled || editor.revision !== null, "aria-invalid": idInvalid || undefined, "aria-describedby": `${prefix}-id-hint${idInvalid ? ` ${prefix}-issue` : ""}`, onChange: (event) => props.editId(event.currentTarget.value) }), _jsx("p", { id: `${prefix}-id-hint`, className: "dsmm-hint", children: t("idHint") })] }), _jsx(StructuredEditor, { state: state, actions: props, disabled: disabled, t: t }, state.editorEpoch), _jsxs("details", { className: "dsmm-advanced", open: true, children: [_jsx("summary", { children: t("advanced") }), _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-content`, children: t("configuration") }), _jsx("textarea", { ref: editorRef, id: `${prefix}-content`, rows: 12, spellCheck: false, value: editor.content, disabled: disabled, "aria-invalid": rawInvalid || (invalid && !idInvalid) || undefined, "aria-describedby": `${prefix}-content-hint ${prefix}-structural-hint${invalid && !idInvalid ? ` ${prefix}-issue` : ""}`, onChange: (event) => props.editContent(event.currentTarget.value) }), _jsx("p", { id: `${prefix}-content-hint`, className: "dsmm-hint", children: t("configurationHint") }), _jsx("p", { id: `${prefix}-structural-hint`, className: "dsmm-hint", children: t("structuralHint") })] })] }), _jsx("p", { "data-dsmm-editor-state": true, children: t(state.dirty ? "dirty" : applied ? "savedApplied" : "savedNotApplied") }), _jsx("p", { id: `${prefix}-global-action`, className: "dsmm-hint", children: t("globalActionHint") }), _jsxs("div", { className: "dsmm-actions", children: [_jsx(Button, { type: "button", variant: "primary", disabled: disabled || !state.dirty || snapshot === null || state.invalidFields.length > 0, onClick: () => { void props.save(); }, children: t(state.busy === "save" ? "saving" : "save") }), _jsx(Button, { type: "button", variant: "outline", "aria-describedby": `${prefix}-global-action`, disabled: disabled || state.dirty || editor.revision === null || !reconcilable || (applied && !selectionConflict), onClick: () => { void props.apply(); }, children: t(state.busy === "apply" ? "applying" : "apply") }), editor.revision !== null && _jsx(Button, { type: "button", variant: "outline", disabled: disabled, onClick: () => { void props.reload(); }, children: t("reload") })] })] }), state.issue !== null && _jsxs("div", { className: "dsmm-issue", id: `${prefix}-issue`, role: "alert", children: [_jsx("p", { children: t(issueKey(state.issue)) }), state.issue.kind === "domain" && state.issue.message !== undefined && _jsxs("p", { children: [t("details"), ": ", state.issue.message] })] }), snapshot?.selectionError !== undefined && _jsxs("div", { className: "dsmm-issue", children: [_jsxs("p", { children: [t("details"), ": ", snapshot.selectionError.message] }), _jsx("p", { children: t(selectionConflict ? "selectionConflict" : "retry") })] }), _jsx("p", { className: "dsmm-status", role: "status", "aria-live": "polite", "aria-atomic": "true", children: state.busy === "refresh" && snapshot === null ? t("loading") : state.busy === "read" ? t("reading") : notice })] });
65
+ }
66
+ //# sourceMappingURL=ProfilesSection.js.map
@@ -0,0 +1,19 @@
1
+ import type { InjectFace, PropsLocale } from "@deepseek-ai/dsh-client-ui-slots";
2
+ import type { ProfilesActions, ProfilesController, ProfilesViewSnapshot } from "./controller.js";
3
+ type Injected = ProfilesActions & {
4
+ hooks: {
5
+ profiles: ProfilesController["store"];
6
+ };
7
+ };
8
+ export type SessionProfilesProps = InjectFace<Injected> & PropsLocale<"settings.dsmm-profiles"> & {
9
+ sessionId?: string;
10
+ };
11
+ export declare function SessionScope({ state, actions, t, compact }: PropsLocale<"settings.dsmm-profiles"> & {
12
+ state: ProfilesViewSnapshot;
13
+ actions: ProfilesActions;
14
+ compact?: boolean;
15
+ }): import("react").JSX.Element;
16
+ /** Additive native header contribution; never operates on a different view seat. */
17
+ export declare function SessionProfiles(props: SessionProfilesProps): import("react").JSX.Element | null;
18
+ export {};
19
+ //# sourceMappingURL=SessionProfiles.d.ts.map
@@ -0,0 +1,24 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useId } from "react";
3
+ import { Button } from "@deepseek-ai/dsh-client-ui-primitives";
4
+ import { sessionProfileLabels } from "./session-labels.js";
5
+ export function SessionScope({ state, actions, t, compact = false }) {
6
+ const prefix = useId();
7
+ const session = state.session;
8
+ const labels = session === null ? null : sessionProfileLabels(session, t);
9
+ const selected = state.snapshot?.profiles.find((profile) => profile.id === state.sessionChoice);
10
+ const disabled = state.busy !== null || state.pendingEditor !== null || state.sessionBusy !== null || state.dirty;
11
+ const allowed = session !== null && session.switchAllowed && /^[a-f0-9]{64}$|^absent$/u.test(session.selection.selectionRevision);
12
+ const status = state.sessionNotice === null ? "" : t(state.sessionNotice === "applied" ? "sessionApplied" : "sessionResetDone");
13
+ return _jsxs("div", { className: "dsmm-session-scope", "aria-busy": state.sessionBusy !== null, "data-dsmm-session-scope": true, children: [!compact && _jsx("h3", { children: t("sessionScope") }), state.currentSessionId === null ? _jsx("p", { className: "dsmm-hint", children: t("noSession") }) : _jsxs(_Fragment, { children: [labels !== null && _jsx("p", { "data-dsmm-session-state": true, children: labels.admitted }), labels !== null && !compact && _jsx("p", { className: "dsmm-hint", "data-dsmm-session-future-default": true, children: labels.futureDefault }), session !== null && !session.switchAllowed && _jsx("p", { className: "dsmm-hint", children: t("sessionBusy", { reason: session.switchUnavailableReason ?? "unavailable" }) }), _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-choice`, children: t("sessionSelect") }), _jsxs("select", { id: `${prefix}-choice`, value: state.sessionChoice ?? "", disabled: disabled || !allowed, onChange: (event) => actions.chooseSessionProfile(event.currentTarget.value || null), children: [_jsx("option", { value: "", children: t("sessionBaseline") }), state.sessionChoice !== null && selected === undefined && _jsx("option", { value: state.sessionChoice, children: state.sessionChoice }), state.snapshot?.profiles.map((profile) => _jsx("option", { value: profile.id, disabled: profile.revision === null || profile.error !== undefined, children: profile.label === undefined ? profile.id : `${profile.label} (${profile.id})` }, profile.id))] })] }), state.dirty && _jsx("p", { className: "dsmm-hint", children: t("sessionDirty") }), _jsxs("div", { className: "dsmm-actions", children: [_jsx(Button, { type: "button", variant: "outline", disabled: disabled || !allowed || (state.sessionChoice !== null && selected?.revision == null), onClick: () => { void actions.applySession(); }, children: t(state.sessionBusy === "apply" ? "sessionApplying" : "sessionApply") }), !compact && _jsx(Button, { type: "button", variant: "outline", disabled: disabled || !allowed, onClick: () => { void actions.resetSession(); }, children: t(state.sessionBusy === "reset" ? "sessionResetting" : "sessionReset") }), _jsx(Button, { type: "button", variant: "outline", disabled: state.sessionBusy !== null || state.busy !== null || state.pendingEditor !== null, onClick: () => { void actions.refreshSession(); }, children: t("sessionRefresh") })] }), !compact && session?.rolePolicy !== undefined && _jsx("p", { "data-dsmm-session-policy": true, children: t("roleState", { route: session.rolePolicy.route === undefined ? t("inheritRoute") : `${session.rolePolicy.route.provider}/${session.rolePolicy.route.model}${session.rolePolicy.route.reasoningEffort === undefined ? "" : ` (${session.rolePolicy.route.reasoningEffort})`}`, strategy: session.rolePolicy.strategy, retries: session.rolePolicy.retries, failures: session.rolePolicy.rateLimitFailures, switches: session.rolePolicy.switches, delay: session.rolePolicy.totalDelayMs }) })] }), state.sessionIssue !== null && _jsx("p", { role: "alert", children: state.sessionIssue.code === "conflict" ? t("sessionConflict")
14
+ : ["busy", "maintenance", "disposed", "not-owned"].includes(state.sessionIssue.code) ? t("sessionBusy", { reason: state.sessionIssue.code })
15
+ : t(state.sessionIssue.code === "validation" ? "validation" : "sessionUnavailable") }), _jsx("p", { className: "dsmm-status", role: "status", "aria-live": "polite", "aria-atomic": "true", children: state.sessionBusy === "read" ? t("reading") : status })] });
16
+ }
17
+ /** Additive native header contribution; never operates on a different view seat. */
18
+ export function SessionProfiles(props) {
19
+ const state = props.useProfiles((snapshot) => snapshot);
20
+ if (props.sessionId !== state.currentSessionId)
21
+ return null;
22
+ return _jsx("div", { className: "dsmm-profiles dsmm-header-profiles", children: _jsxs("details", { children: [_jsx("summary", { children: props.t("title") }), _jsx(SessionScope, { state: state, actions: props, t: props.t, compact: true })] }) });
23
+ }
24
+ //# sourceMappingURL=SessionProfiles.js.map
@@ -0,0 +1,11 @@
1
+ import type { PropsLocale } from "@deepseek-ai/dsh-client-ui-slots";
2
+ import type { ProfilesActions, ProfilesViewSnapshot } from "./controller.js";
3
+ type Locale = PropsLocale<"settings.dsmm-profiles">;
4
+ /** The same raw draft drives every control; there is no form-to-document rewrite. */
5
+ export declare function StructuredEditor({ state, actions, disabled, t }: Locale & {
6
+ state: ProfilesViewSnapshot;
7
+ actions: ProfilesActions;
8
+ disabled: boolean;
9
+ }): import("react").JSX.Element;
10
+ export {};
11
+ //# sourceMappingURL=StructuredEditor.d.ts.map
@@ -0,0 +1,74 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useId, useState } from "react";
3
+ import { Button, Input } from "@deepseek-ai/dsh-client-ui-primitives";
4
+ import { DSMM_RATE_LIMIT_BOUNDS, normalizeRateLimitPolicy } from "../routing-policy.js";
5
+ import { structuredDocument } from "./structured.js";
6
+ import { RETRY_FIELD_LABEL_KEYS } from "./locales.js";
7
+ const MANUAL = "__dsmm_manual__";
8
+ function RetryNumber({ id, name, field, value, inherited, path, disabled, actions, t }) {
9
+ const [draft, setDraft] = useState(value === undefined ? "" : String(value));
10
+ const [invalid, setInvalid] = useState(false);
11
+ const [min, max] = DSMM_RATE_LIMIT_BOUNDS[field];
12
+ const key = path.join(".");
13
+ useEffect(() => { setDraft(value === undefined ? "" : String(value)); setInvalid(false); }, [value]);
14
+ useEffect(() => { actions.setFieldInvalid(key, invalid); return () => actions.setFieldInvalid(key, false); }, [actions.setFieldInvalid, key, invalid]);
15
+ return _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: id, children: t("retryField", { name, field: t(RETRY_FIELD_LABEL_KEYS[field]) }) }), _jsx(Input, { id: id, "data-dsmm-policy-field": field, className: "dsmm-input", type: "number", inputMode: "numeric", min: min, max: max, step: 1, disabled: disabled, value: draft, placeholder: inherited === undefined ? t("unknownDefault") : t("inheritNumber", { value: inherited }), "aria-invalid": invalid || undefined, "aria-describedby": `${id}-hint${invalid ? ` ${id}-invalid` : ""}`, onChange: (event) => {
16
+ const input = event.currentTarget;
17
+ setDraft(input.value);
18
+ const valid = input.validity.valid && (input.value === "" || Number.isSafeInteger(input.valueAsNumber));
19
+ setInvalid(!valid);
20
+ actions.setFieldInvalid(key, !valid);
21
+ if (valid)
22
+ actions.editPath(path, input.value === "" ? undefined : input.valueAsNumber);
23
+ } }), _jsx("p", { className: "dsmm-hint", id: `${id}-hint`, children: t("retryBounds", { min, max, value: inherited ?? t("unknownDefault") }) }), invalid && _jsx("p", { id: `${id}-invalid`, children: t("invalidNumber") })] });
24
+ }
25
+ function RouteFields({ value, path, name, catalog, disabled, edit, editRoute, t }) {
26
+ const prefix = useId();
27
+ const providers = catalog?.groups ?? [];
28
+ const group = providers.find((candidate) => candidate.id === value.provider);
29
+ const model = group?.models.find((candidate) => candidate.id === value.model);
30
+ const efforts = model?.reasoning?.efforts ?? [];
31
+ const providerListed = group !== undefined;
32
+ const modelListed = model !== undefined;
33
+ const updateModel = (provider, modelId) => {
34
+ // This is an explicit user change, not a catalog refresh. Clear only this
35
+ // route's adapter-owned effort; do not save or touch the native model default.
36
+ editRoute(path, provider, modelId);
37
+ };
38
+ return _jsxs("div", { className: "dsmm-route-fields", children: [_jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-provider`, children: t("routeProvider", { name }) }), _jsxs("select", { id: `${prefix}-provider`, disabled: disabled, value: providerListed ? value.provider : MANUAL, onChange: (event) => updateModel(event.currentTarget.value === MANUAL ? "" : event.currentTarget.value, ""), children: [_jsx("option", { value: MANUAL, children: providerListed ? t("manual") : t("manualValue", { value: value.provider || t("unset") }) }), providers.map((provider) => _jsxs("option", { value: provider.id, children: [provider.name, " (", provider.id, ")"] }, provider.id))] }), !providerListed && _jsx(Input, { "aria-label": t("manualProvider", { name }), className: "dsmm-input", value: value.provider, disabled: disabled, onChange: (event) => updateModel(event.currentTarget.value, value.model) })] }), _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-model`, children: t("routeModel", { name }) }), _jsxs("select", { id: `${prefix}-model`, disabled: disabled, value: modelListed ? value.model : MANUAL, onChange: (event) => updateModel(value.provider, event.currentTarget.value === MANUAL ? "" : event.currentTarget.value), children: [_jsx("option", { value: MANUAL, children: modelListed ? t("manual") : t("manualValue", { value: value.model || t("unset") }) }), group?.models.map((candidate) => _jsxs("option", { value: candidate.id, children: [candidate.name, " (", candidate.id, ")"] }, candidate.id))] }), !modelListed && _jsx(Input, { "aria-label": t("manualModel", { name }), className: "dsmm-input", value: value.model, disabled: disabled, onChange: (event) => updateModel(value.provider, event.currentTarget.value) })] }), _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-effort`, children: t("routeEffort", { name }) }), _jsxs("select", { id: `${prefix}-effort`, disabled: disabled, value: value.reasoningEffort ?? "", onChange: (event) => edit([...path, "reasoningEffort"], event.currentTarget.value || undefined), children: [_jsx("option", { value: "", children: t("effortDefault") }), value.reasoningEffort !== undefined && !efforts.some((effort) => effort.id === value.reasoningEffort) && _jsx("option", { value: value.reasoningEffort, children: t("manualValue", { value: value.reasoningEffort }) }), efforts.map((effort) => _jsxs("option", { value: effort.id, children: [effort.name, " (", effort.id, ")"] }, effort.id))] }), _jsx(Input, { "aria-label": t("manualEffort", { name }), className: "dsmm-input", value: value.reasoningEffort ?? "", disabled: disabled, placeholder: t("effortDefault"), onChange: (event) => edit([...path, "reasoningEffort"], event.currentTarget.value || undefined) })] })] });
39
+ }
40
+ function PolicyFields({ value, inherited, path, name, disabled, actions, t }) {
41
+ const prefix = useId();
42
+ return _jsxs("div", { className: "dsmm-policy-fields", children: [_jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-strategy`, children: t("strategy", { name }) }), _jsxs("select", { id: `${prefix}-strategy`, disabled: disabled, value: value.strategy ?? "", onChange: (event) => actions.editPath([...path, "strategy"], event.currentTarget.value || undefined), children: [_jsx("option", { value: "", children: t("inheritStrategy", { value: inherited?.strategy ?? t("unknownDefault") }) }), _jsx("option", { value: "startup-lock", children: t("startupLock") }), _jsx("option", { value: "rate-limit-fallback", children: t("rateFallback") })] })] }), _jsx("p", { className: "dsmm-hint", children: t("strategyHint") }), _jsx("div", { className: "dsmm-route-fields", children: Object.keys(DSMM_RATE_LIMIT_BOUNDS).map((field) => _jsx(RetryNumber, { id: `${prefix}-${field}`, t: t, name: name, field: field, value: value.rateLimit?.[field], inherited: inherited?.rateLimit[field], path: [...path, "rateLimit", field], disabled: disabled, actions: actions }, field)) })] });
43
+ }
44
+ /** The same raw draft drives every control; there is no form-to-document rewrite. */
45
+ export function StructuredEditor({ state, actions, disabled, t }) {
46
+ const prefix = useId();
47
+ const [selectedRole, setSelectedRole] = useState("dsmm-orchestrator");
48
+ const document = state.editor === null ? null : structuredDocument(state.editor.content);
49
+ if (document === null)
50
+ return _jsx("p", { className: "dsmm-hint", "data-dsmm-structured-invalid": true, children: t("rawInvalid") });
51
+ const roles = state.snapshot?.roles ?? [];
52
+ const role = roles.find((candidate) => candidate.id === selectedRole) ?? roles[0];
53
+ const policy = role === undefined ? undefined : document.roleRouting[role.id] ?? {};
54
+ const baseline = state.snapshot?.editorDefaults;
55
+ let inherited;
56
+ try {
57
+ if (baseline !== undefined) {
58
+ const profileDefaults = { strategy: document.runtimePolicy.strategy ?? baseline.strategy, rateLimit: normalizeRateLimitPolicy(document.runtimePolicy.rateLimit, baseline.rateLimit) };
59
+ inherited = { strategy: role?.runtimePolicy?.strategy ?? profileDefaults.strategy, rateLimit: normalizeRateLimitPolicy(role?.runtimePolicy?.rateLimit, profileDefaults.rateLimit) };
60
+ }
61
+ }
62
+ catch { /* Invalid effective values remain a raw/Host validation error. */ }
63
+ const rolePath = ["settings", "roleRouting", role?.id ?? ""];
64
+ return _jsxs("div", { className: "dsmm-structured", "data-dsmm-structured": true, children: [_jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-label`, children: t("profileLabel") }), _jsx(Input, { id: `${prefix}-label`, className: "dsmm-input", value: document.label ?? "", disabled: disabled, onChange: (event) => actions.editPath(["label"], event.currentTarget.value || undefined) })] }), _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-active`, children: t("defaultActive") }), _jsxs("select", { id: `${prefix}-active`, disabled: disabled, value: document.settings.defaultActive === undefined ? "" : String(document.settings.defaultActive), onChange: (event) => actions.editPath(["settings", "defaultActive"], event.currentTarget.value === "" ? undefined : event.currentTarget.value === "true"), children: [_jsx("option", { value: "", children: t("inherit") }), _jsx("option", { value: "true", children: t("enabled") }), _jsx("option", { value: "false", children: t("disabled") })] }), _jsx("p", { className: "dsmm-hint", children: t("activeHint") })] }), _jsxs("fieldset", { children: [_jsx("legend", { children: t("profileDefaults") }), _jsx(PolicyFields, { t: t, value: document.runtimePolicy, inherited: baseline, path: ["settings", "runtimePolicy"], name: t("profileDefaults"), disabled: disabled, actions: actions })] }), _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-role`, children: t("roleSelect") }), _jsxs("select", { id: `${prefix}-role`, disabled: disabled || roles.length === 0 || state.invalidFields.length > 0, value: role?.id ?? "", onChange: (event) => setSelectedRole(event.currentTarget.value), children: [roles.length === 0 && _jsx("option", { value: "", children: t("rolesUnavailable") }), roles.map((candidate) => _jsxs("option", { value: candidate.id, children: [candidate.label, candidate.enabled ? "" : ` — ${t("roleDisabled")}`] }, candidate.id))] })] }), role !== undefined && policy !== undefined && _jsxs("fieldset", { "data-dsmm-role": role.id, children: [_jsx("legend", { children: role.label }), _jsx("p", { className: "dsmm-hint", children: t(role.enabled ? "roleEnabled" : "roleDisabled") }), _jsx(PolicyFields, { t: t, value: policy, inherited: inherited, path: rolePath, name: role.label, disabled: disabled, actions: actions }), _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-primary-mode`, children: t("primaryMode", { name: role.label }) }), _jsxs("select", { id: `${prefix}-primary-mode`, disabled: disabled, value: policy.primary === undefined ? "inherit" : "explicit", onChange: (event) => actions.editPath([...rolePath, "primary"], event.currentTarget.value === "inherit" ? undefined : { provider: "", model: "" }), children: [_jsx("option", { value: "inherit", children: t("inheritRoute") }), _jsx("option", { value: "explicit", children: t("configuredRoute") })] })] }), policy.primary !== undefined && _jsx(RouteFields, { t: t, value: policy.primary, path: [...rolePath, "primary"], name: t("primaryName", { name: role.label }), catalog: state.catalog, disabled: disabled, edit: actions.editPath, editRoute: actions.editRoute }), _jsx("p", { className: "dsmm-hint", children: t("effortChangeHint") }), _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-fallback-mode`, children: t("fallbackMode", { name: role.label }) }), _jsxs("select", { id: `${prefix}-fallback-mode`, disabled: disabled, value: policy.fallbackRoutes === undefined ? "inherit" : "explicit", onChange: (event) => actions.editPath([...rolePath, "fallbackRoutes"], event.currentTarget.value === "inherit" ? undefined : []), children: [_jsx("option", { value: "inherit", children: t("inheritChain") }), _jsx("option", { value: "explicit", children: t("configuredChain") })] })] }), policy.fallbackRoutes?.length === 0 && _jsx("p", { className: "dsmm-hint", children: t("emptyChain") }), policy.fallbackRoutes?.map((candidate, index) => {
65
+ const name = t("fallbackName", { name: role.label, index: index + 1 });
66
+ return _jsxs("fieldset", { children: [_jsx("legend", { children: name }), _jsx(RouteFields, { t: t, value: candidate, path: [...rolePath, "fallbackRoutes", index], name: name, catalog: state.catalog, disabled: disabled, edit: actions.editPath, editRoute: actions.editRoute }), _jsxs("div", { className: "dsmm-actions", children: [_jsx(Button, { type: "button", variant: "outline", disabled: disabled || index === 0, onClick: () => actions.moveFallback(role.id, index, index - 1), children: t("moveUp", { name }) }), _jsx(Button, { type: "button", variant: "outline", disabled: disabled || index === policy.fallbackRoutes.length - 1, onClick: () => actions.moveFallback(role.id, index, index + 1), children: t("moveDown", { name }) }), _jsx(Button, { type: "button", variant: "outline", disabled: disabled, onClick: () => actions.editPath([...rolePath, "fallbackRoutes", index], undefined), children: t("removeFallback", { name }) })] })] }, index);
67
+ }), _jsx(Button, { type: "button", variant: "outline", disabled: disabled || (policy.fallbackRoutes?.length ?? 0) >= 32, onClick: () => {
68
+ if (policy.fallbackRoutes === undefined)
69
+ actions.editPath([...rolePath, "fallbackRoutes"], [{ provider: "", model: "" }]);
70
+ else
71
+ actions.editPath([...rolePath, "fallbackRoutes", policy.fallbackRoutes.length], { provider: "", model: "" });
72
+ }, children: t("addFallback", { name: role.label }) })] })] });
73
+ }
74
+ //# sourceMappingURL=StructuredEditor.js.map
@@ -0,0 +1,115 @@
1
+ import type { RemoteResult } from "@deepseek-ai/dsh-typert-protocol";
2
+ import type { DsmmProfilesRemote } from "../profile-remote.js";
3
+ import type { ProfileErrorInfo, ProfileReadResult, ProfileSnapshot } from "../profile-types.js";
4
+ import type { SessionProfileSnapshot } from "../profile-types.js";
5
+ import type { ModelCatalog } from "@deepseek-ai/dsh-api-session-controller";
6
+ import type { JsonPath } from "./structured.js";
7
+ export interface ProfileEditor {
8
+ id: string;
9
+ content: string;
10
+ revision: string | null;
11
+ }
12
+ export interface ProfilesNotice {
13
+ key: "saved" | "applied" | "reset";
14
+ id?: string;
15
+ }
16
+ export interface ProfilesIssue {
17
+ kind: "domain" | "transport" | "assembly";
18
+ code: string;
19
+ message?: string;
20
+ field?: string;
21
+ source?: "selection";
22
+ }
23
+ export interface ProfilesViewSnapshot {
24
+ snapshot: ProfileSnapshot | null;
25
+ editor: ProfileEditor | null;
26
+ dirty: boolean;
27
+ busy: "refresh" | "read" | "save" | "apply" | "reset" | null;
28
+ issue: ProfilesIssue | null;
29
+ notice: ProfilesNotice | null;
30
+ pendingEditor: string | null;
31
+ catalog: ModelCatalog | null;
32
+ catalogBusy: boolean;
33
+ catalogUnavailable: boolean;
34
+ currentSessionId: string | null;
35
+ session: SessionProfileSnapshot | null;
36
+ sessionChoice: string | null;
37
+ sessionBusy: "read" | "apply" | "reset" | null;
38
+ sessionIssue: ProfilesIssue | null;
39
+ sessionNotice: "applied" | "reset" | null;
40
+ invalidFields: string[];
41
+ editorEpoch: number;
42
+ }
43
+ export interface ProfilesActions {
44
+ refresh(): Promise<void>;
45
+ open(id: string): Promise<void>;
46
+ create(): Promise<void>;
47
+ reload(): Promise<void>;
48
+ editId(id: string): void;
49
+ editContent(content: string): void;
50
+ save(): Promise<void>;
51
+ apply(): Promise<void>;
52
+ reset(): Promise<void>;
53
+ discardAndOpen(): Promise<void>;
54
+ cancelDiscard(): void;
55
+ editPath(path: JsonPath, value: unknown): void;
56
+ editRoute(path: JsonPath, provider: string, model: string): void;
57
+ moveFallback(role: string, from: number, to: number): void;
58
+ refreshCatalog(): Promise<void>;
59
+ refreshSession(): Promise<void>;
60
+ chooseSessionProfile(id: string | null): void;
61
+ applySession(): Promise<void>;
62
+ resetSession(): Promise<void>;
63
+ setFieldInvalid(field: string, invalid: boolean): void;
64
+ }
65
+ export interface ModelCatalogRemote {
66
+ modelCatalog(): Promise<RemoteResult<ModelCatalog>>;
67
+ }
68
+ export declare const NEW_PROFILE_CONTENT = "{\n \"version\": 1,\n \"id\": \"new-profile\",\n \"label\": \"New profile\",\n \"settings\": {\n // Runtime overlay only. Omitted fields inherit the deployment baseline.\n \"defaultActive\": true\n }\n}\n";
69
+ /** A valid external CAS conflict is reconcilable; corruption is never reset implicitly. */
70
+ export declare function canReconcileSelection(snapshot: ProfileSnapshot | null): boolean;
71
+ /** Stable native Store seat, with no filesystem or transport authority. */
72
+ export declare class ProfilesController {
73
+ private readonly remote;
74
+ private current;
75
+ private accepted;
76
+ private listeners;
77
+ private generation;
78
+ private disposed;
79
+ private sessionGeneration;
80
+ private catalogGeneration;
81
+ private catalogRemote;
82
+ readonly store: {
83
+ getSnapshot: () => ProfilesViewSnapshot;
84
+ subscribe: (listener: () => void) => (() => void);
85
+ };
86
+ readonly actions: ProfilesActions;
87
+ constructor(remote: DsmmProfilesRemote);
88
+ dispose(): void;
89
+ attachCatalog(remote: ModelCatalogRemote | null): void;
90
+ setSession(id: string | null): void;
91
+ refreshCatalog(): Promise<void>;
92
+ refreshSession(): Promise<void>;
93
+ private selectSession;
94
+ private publish;
95
+ private accept;
96
+ private unwrap;
97
+ private issue;
98
+ private perform;
99
+ refresh(): Promise<void>;
100
+ open(id: string): Promise<void>;
101
+ reload(): Promise<void>;
102
+ private loadEditor;
103
+ discardAndOpen(): Promise<void>;
104
+ private editId;
105
+ private editContent;
106
+ private editPath;
107
+ private editRoute;
108
+ private editFallbackOrder;
109
+ save(): Promise<void>;
110
+ apply(): Promise<void>;
111
+ reset(): Promise<void>;
112
+ private acceptSelection;
113
+ }
114
+ export type { ProfileErrorInfo, ProfileReadResult };
115
+ //# sourceMappingURL=controller.d.ts.map