@dsmm/dsmm 0.3.13 → 0.3.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -3552,6 +3552,10 @@ var ProfilesController = class {
3552
3552
  sessionUnconfirmed: false,
3553
3553
  session: null,
3554
3554
  sessionChoice: null,
3555
+ sessionWorkspaces: [],
3556
+ sessionWorkspaceId: null,
3557
+ sessionPreparationAvailable: false,
3558
+ sessionPreparationPending: false,
3555
3559
  sessionBusy: null,
3556
3560
  sessionIssue: null,
3557
3561
  sessionNotice: null,
@@ -3564,6 +3568,9 @@ var ProfilesController = class {
3564
3568
  generation = 0;
3565
3569
  disposed = false;
3566
3570
  sessionGeneration = 0;
3571
+ blankNative = null;
3572
+ stopWorkspaces = null;
3573
+ preparation = null;
3567
3574
  pendingSessionSelections = /* @__PURE__ */ new Set();
3568
3575
  connection = null;
3569
3576
  connectionBaseline;
@@ -3586,6 +3593,9 @@ var ProfilesController = class {
3586
3593
  modelEventsWatermark = -1;
3587
3594
  modeEventsWatermark = -1;
3588
3595
  modeRefreshPending = false;
3596
+ sessionSource = null;
3597
+ sessionSourceId = null;
3598
+ stopSessionSource = null;
3589
3599
  stopModelEvents = null;
3590
3600
  modelInteraction = null;
3591
3601
  modelInteractionSessionId = null;
@@ -3622,6 +3632,7 @@ var ProfilesController = class {
3622
3632
  chooseSessionProfile: (id2) => {
3623
3633
  if (!this.disposed && this.connectionCurrent() && !this.current.sessionUnconfirmed && this.current.sessionBusy === null && this.current.busy === null && !this.current.dirty && this.current.pendingEditor === null && this.current.invalidFields.length === 0) this.publish({ sessionChoice: id2, sessionNotice: null });
3624
3634
  },
3635
+ chooseSessionWorkspace: (id2) => this.chooseSessionWorkspace(id2),
3625
3636
  applySession: (options) => this.selectSession(false, options),
3626
3637
  resetSession: () => this.selectSession(true),
3627
3638
  setDeepwork: (active) => this.setDeepwork(active),
@@ -3644,9 +3655,13 @@ var ProfilesController = class {
3644
3655
  };
3645
3656
  numberDrafts = /* @__PURE__ */ new Map();
3646
3657
  dispose() {
3658
+ this.releasePreparation();
3659
+ this.stopWorkspaces?.();
3647
3660
  this.releaseComposerBlock();
3648
3661
  this.numberDrafts.clear();
3649
3662
  this.stopConnection?.();
3663
+ this.stopSessionSource?.();
3664
+ this.sessionSource = null;
3650
3665
  this.disposed = true;
3651
3666
  this.generation += 1;
3652
3667
  this.sessionGeneration += 1;
@@ -3674,9 +3689,11 @@ var ProfilesController = class {
3674
3689
  this.connectionBound = true;
3675
3690
  this.connectionBaseline = source?.getSnapshot();
3676
3691
  const invalidate = () => {
3692
+ this.releasePreparation();
3677
3693
  this.connectionBaseline = source?.getSnapshot();
3678
3694
  this.generation += 1;
3679
3695
  this.sessionGeneration += 1;
3696
+ this.modeRefreshPending = false;
3680
3697
  this.modelSelectorGeneration += 1;
3681
3698
  this.publish({
3682
3699
  session: null,
@@ -3684,6 +3701,8 @@ var ProfilesController = class {
3684
3701
  sessionNotice: null,
3685
3702
  sessionUnconfirmed: false,
3686
3703
  sessionViewEpoch: this.current.sessionViewEpoch + 1,
3704
+ sessionWorkspaceId: null,
3705
+ sessionPreparationPending: false,
3687
3706
  busy: null,
3688
3707
  issue: { kind: "transport", code: "unavailable" }
3689
3708
  });
@@ -3700,12 +3719,188 @@ var ProfilesController = class {
3700
3719
  connectionCurrent() {
3701
3720
  return !this.connectionBound || this.connectionBaseline !== void 0 && this.connection?.getSnapshot() === this.connectionBaseline;
3702
3721
  }
3722
+ attachBlankNative(native) {
3723
+ if (this.disposed) return;
3724
+ this.cancelPreparation();
3725
+ this.stopWorkspaces?.();
3726
+ this.blankNative = native;
3727
+ const update = () => {
3728
+ const sessionWorkspaces = native?.workspaces.getSnapshot() ?? [];
3729
+ const sessionWorkspaceId = sessionWorkspaces.some((item) => item.id === this.current.sessionWorkspaceId) ? this.current.sessionWorkspaceId : null;
3730
+ if (this.preparation !== null && sessionWorkspaceId !== this.preparation.workspaceId) this.cancelPreparation();
3731
+ this.publish({ sessionWorkspaces, sessionWorkspaceId, sessionPreparationAvailable: native !== null && this.composerBlocks !== null });
3732
+ };
3733
+ this.stopWorkspaces = native?.workspaces.subscribe(update) ?? null;
3734
+ update();
3735
+ }
3736
+ releasePreparation() {
3737
+ const task = this.preparation;
3738
+ this.preparation = null;
3739
+ if (task === null) return;
3740
+ task.stop();
3741
+ const held = task.held;
3742
+ if (held !== null && task.id !== null && held.blocks.storeFor(task.id) === held.store && held.store.getSnapshot() === held.block) held.blocks.set(task.id, void 0);
3743
+ task.reference?.release();
3744
+ }
3745
+ cancelPreparation() {
3746
+ if (this.preparation === null) return;
3747
+ this.releasePreparation();
3748
+ this.sessionGeneration += 1;
3749
+ this.publish({ sessionBusy: null, sessionUnconfirmed: false, sessionPreparationPending: false, sessionNotice: null });
3750
+ }
3751
+ async chooseSessionWorkspace(id2) {
3752
+ if (this.disposed || !this.connectionCurrent() || this.current.currentSessionId !== null || !this.current.sessionWorkspaces.some((item) => item.id === id2) || this.current.dirty || this.current.invalidFields.length > 0 || this.current.pendingEditor !== null || this.current.busy !== null) return;
3753
+ const pending = this.current.sessionPreparationPending;
3754
+ if (id2 !== this.current.sessionWorkspaceId) this.cancelPreparation();
3755
+ this.publish({ sessionWorkspaceId: id2, sessionIssue: null });
3756
+ if (pending) await this.prepareSession();
3757
+ }
3758
+ preparationOwned(task) {
3759
+ return !this.disposed && this.connectionCurrent() && this.preparation === task && this.current.currentSessionId === null && this.current.sessionWorkspaceId === task.workspaceId;
3760
+ }
3761
+ preparationCurrent(task) {
3762
+ return this.preparationOwned(task) && !task.navigation.aborted;
3763
+ }
3764
+ preparationConfirmed(task, session) {
3765
+ const selection = session.admittedSelection;
3766
+ return selection !== void 0 && !selection.refreshRequired && session.sessionId === task.id && !session.refreshRequired && !session.selection.refreshRequired && writableSelectionVersion(session.selection.selectionRevision) && selection.selectedId === task.selectedId && selection.appliedRevision === task.revision && session.selection.selectedId === task.selectedId && session.selection.appliedRevision === task.revision;
3767
+ }
3768
+ openPrepared(task, explicit = false) {
3769
+ if (!this.preparationOwned(task) || !explicit && task.navigation.aborted || task.id === null || this.current.busy !== null || this.current.dirty || this.current.invalidFields.length > 0 || this.current.pendingEditor !== null) return;
3770
+ task.opening = true;
3771
+ try {
3772
+ this.publish({ sessionUnconfirmed: true });
3773
+ if (this.preparationOwned(task)) task.native.openSession(task.id);
3774
+ } finally {
3775
+ task.opening = false;
3776
+ }
3777
+ }
3778
+ async prepareSession(refreshOnly = false) {
3779
+ const { sessionWorkspaceId: workspaceId, sessionChoice: selectedId, snapshot: snapshot4 } = this.current;
3780
+ const native = this.blankNative;
3781
+ if (this.disposed || !this.connectionCurrent() || native === null || this.composerBlocks === null || this.composerReason === null || this.current.currentSessionId !== null || this.current.sessionBusy !== null || this.current.busy !== null || this.current.dirty || this.current.invalidFields.length > 0 || this.current.pendingEditor !== null || snapshot4 === null) return;
3782
+ if (workspaceId === null) {
3783
+ if (!refreshOnly) this.publish({ sessionPreparationPending: true });
3784
+ return;
3785
+ }
3786
+ if (this.current.sessionUnconfirmed && !refreshOnly) return;
3787
+ const profile = snapshot4.profiles.find((item) => item.id === selectedId), revision2 = selectedId === null ? null : profile?.revision;
3788
+ if (!refreshOnly && selectedId !== null && (!isConfigRevision(revision2) || profile?.error !== void 0)) return;
3789
+ let task = this.preparation;
3790
+ const openOnly = !refreshOnly && task?.confirmed === true && task.selectedId === selectedId && task.revision === (revision2 ?? null);
3791
+ if (task === null) {
3792
+ if (refreshOnly) return;
3793
+ const navigation = native.beginNavigation();
3794
+ task = { native, navigation, workspaceId, selectedId, revision: revision2 ?? null, id: null, reference: null, held: null, confirmed: false, opening: false, stop: () => {
3795
+ } };
3796
+ this.preparation = task;
3797
+ } else if (!refreshOnly && !openOnly) {
3798
+ task.selectedId = selectedId;
3799
+ task.revision = revision2 ?? null;
3800
+ task.confirmed = false;
3801
+ }
3802
+ if (!refreshOnly && !openOnly) {
3803
+ task.stop();
3804
+ if (task.navigation.aborted) task.navigation = native.beginNavigation();
3805
+ const navigation = task.navigation;
3806
+ const owned2 = task;
3807
+ const abort = () => {
3808
+ if (this.preparation === owned2 && !owned2.opening) this.cancelPreparation();
3809
+ };
3810
+ navigation.addEventListener("abort", abort, { once: true });
3811
+ task.stop = () => navigation.removeEventListener("abort", abort);
3812
+ }
3813
+ const owned = task;
3814
+ const live = () => refreshOnly ? this.preparationOwned(owned) : this.preparationCurrent(owned);
3815
+ this.publish({ sessionBusy: refreshOnly ? "read" : "apply", sessionPreparationPending: false, sessionIssue: null, sessionNotice: null });
3816
+ try {
3817
+ if (openOnly) {
3818
+ this.openPrepared(task, true);
3819
+ return;
3820
+ }
3821
+ if (!live()) return;
3822
+ if (task.id === null) {
3823
+ if (refreshOnly) throw { kind: "transport", code: "unavailable" };
3824
+ const id3 = await native.connectWorkspace(workspaceId);
3825
+ if (!live()) return;
3826
+ task.id = id3;
3827
+ }
3828
+ const id2 = task.id;
3829
+ if (task.reference === null) {
3830
+ task.reference = native.retain(id2);
3831
+ if (!live()) {
3832
+ task.reference.release();
3833
+ return;
3834
+ }
3835
+ if (task.reference.sessionId !== id2) throw { kind: "assembly", code: "unavailable" };
3836
+ }
3837
+ if (task.held === null) {
3838
+ const blocks = this.composerBlocks, store = blocks.storeFor(id2);
3839
+ if (store.getSnapshot() !== void 0) throw { kind: "domain", code: "busy" };
3840
+ const block = { reason: this.composerReason() };
3841
+ task.held = { blocks, store, block };
3842
+ blocks.set(id2, block);
3843
+ }
3844
+ const binding = await task.reference.ready;
3845
+ if (!live()) return;
3846
+ if (binding.sessionId !== id2) throw { kind: "assembly", code: "unavailable" };
3847
+ const session = await this.unwrap(this.remote.describeSession(id2));
3848
+ if (!live()) return;
3849
+ if (session.sessionId !== id2) throw { kind: "assembly", code: "unavailable" };
3850
+ if (refreshOnly) {
3851
+ task.confirmed = this.preparationConfirmed(task, session);
3852
+ if (task.confirmed) {
3853
+ this.publish({ sessionUnconfirmed: false });
3854
+ this.openPrepared(task);
3855
+ return;
3856
+ }
3857
+ const uncertain = session.refreshRequired === true || session.selection.refreshRequired === true;
3858
+ this.publish({ sessionUnconfirmed: uncertain, sessionIssue: { kind: "domain", code: uncertain ? "unavailable" : "conflict" } });
3859
+ return;
3860
+ }
3861
+ if (session.refreshRequired || session.selection.refreshRequired || !writableSelectionVersion(session.selection.selectionRevision)) throw { kind: "domain", code: "conflict" };
3862
+ if (session.canApplyOverlay !== true || session.applyOverlayUnavailableReason === "new-session-required") throw { kind: "domain", code: session.applyOverlayUnavailableReason ?? "unavailable" };
3863
+ const held = task.held;
3864
+ if (held === null || held.blocks.storeFor(id2) !== held.store || held.store.getSnapshot() !== held.block) throw { kind: "domain", code: "busy" };
3865
+ if (this.current.dirty || this.current.invalidFields.length > 0 || this.current.pendingEditor !== null) throw { kind: "domain", code: "conflict" };
3866
+ this.pendingSessionSelections.add(id2);
3867
+ const accepted = await this.unwrap(this.remote.selectSession(id2, {
3868
+ sessionId: id2,
3869
+ id: task.selectedId,
3870
+ ...task.selectedId === null ? {} : { expectedRevision: task.revision },
3871
+ expectedSelectionRevision: session.selection.selectionRevision,
3872
+ expectedAdmissionEpoch: session.admissionEpoch
3873
+ }));
3874
+ if (!live()) return;
3875
+ if (!this.preparationConfirmed(task, accepted)) {
3876
+ this.publish({ sessionUnconfirmed: true });
3877
+ return;
3878
+ }
3879
+ task.confirmed = true;
3880
+ this.openPrepared(task);
3881
+ } catch (error) {
3882
+ if (this.preparationOwned(task)) {
3883
+ const issue = this.issue(error), uncertain = task.confirmed || issue.kind !== "domain" || issue.code === "cancelled";
3884
+ this.publish({ sessionIssue: task.id === null && uncertain ? { kind: "assembly", code: "blank-identity-unconfirmed" } : issue, sessionUnconfirmed: uncertain });
3885
+ if (!uncertain) this.releasePreparation();
3886
+ }
3887
+ } finally {
3888
+ if (task.id !== null) this.pendingSessionSelections.delete(task.id);
3889
+ if (this.preparationOwned(task)) this.publish({ sessionBusy: null });
3890
+ else if (!this.disposed && this.current.currentSessionId === null && this.preparation === null) this.publish({ sessionBusy: null });
3891
+ else if (!this.disposed && this.connectionCurrent() && task.id === this.current.currentSessionId) {
3892
+ this.modeRefreshPending = true;
3893
+ this.refreshObservedMode();
3894
+ }
3895
+ }
3896
+ }
3703
3897
  attachComposerBlocks(blocks, reason) {
3704
3898
  if (this.disposed) return;
3899
+ if (blocks !== this.composerBlocks && this.preparation !== null) this.cancelPreparation();
3705
3900
  this.releaseComposerBlock();
3706
3901
  this.composerBlocks = blocks;
3707
3902
  this.composerReason = reason ?? null;
3708
- this.syncComposerBlock();
3903
+ this.publish({ sessionPreparationAvailable: this.blankNative !== null && blocks !== null });
3709
3904
  }
3710
3905
  releaseComposerBlock() {
3711
3906
  const held = this.composerBlock;
@@ -3738,6 +3933,34 @@ var ProfilesController = class {
3738
3933
  this.modelSelectionGeneration += 1;
3739
3934
  }) ?? null;
3740
3935
  }
3936
+ attachSessionSource(sessionId2, source) {
3937
+ if (this.disposed || sessionId2 === this.sessionSourceId && source === this.sessionSource) return;
3938
+ this.stopSessionSource?.();
3939
+ this.sessionSourceId = sessionId2;
3940
+ this.sessionSource = source;
3941
+ let running = source?.getSnapshot().running;
3942
+ const current = () => !this.disposed && sessionId2 !== null && sessionId2 === this.current.currentSessionId && source === this.sessionSource;
3943
+ this.stopSessionSource = source?.subscribe(() => {
3944
+ if (!current()) return;
3945
+ const next = source.getSnapshot().running;
3946
+ if (next === running) return;
3947
+ running = next;
3948
+ this.modeRefreshPending = true;
3949
+ this.refreshObservedMode();
3950
+ }) ?? null;
3951
+ if (current()) {
3952
+ this.sessionGeneration += 1;
3953
+ this.modeRefreshPending = source !== null;
3954
+ this.publish({
3955
+ session: null,
3956
+ sessionBusy: null,
3957
+ sessionNotice: null,
3958
+ sessionViewEpoch: this.current.sessionViewEpoch + 1,
3959
+ sessionUnconfirmed: this.pendingSessionSelections.has(sessionId2)
3960
+ });
3961
+ this.refreshObservedMode();
3962
+ }
3963
+ }
3741
3964
  attachModelEventSource(sessionId2, source) {
3742
3965
  if (this.disposed || sessionId2 === this.modelEventsSessionId && source === this.modelEvents) return;
3743
3966
  this.modelEventsGeneration += 1;
@@ -3785,12 +4008,20 @@ var ProfilesController = class {
3785
4008
  }
3786
4009
  setSession(id2) {
3787
4010
  if (this.disposed || id2 === this.current.currentSessionId) return;
4011
+ const task = this.preparation;
4012
+ const preparationUnconfirmed = task?.id === id2 && this.current.sessionUnconfirmed;
4013
+ if (task?.id === id2 && task.held !== null && id2 !== null) {
4014
+ this.composerBlock = { id: id2, store: task.held.store, block: task.held.block };
4015
+ task.held = null;
4016
+ }
4017
+ this.releasePreparation();
3788
4018
  this.sessionGeneration += 1;
3789
4019
  this.modeRefreshPending = false;
4020
+ if (id2 !== this.sessionSourceId) this.attachSessionSource(null, null);
3790
4021
  if (id2 !== this.modelSelectionSessionId) this.attachModelSelectionSource(null, null);
3791
4022
  if (id2 !== this.modelEventsSessionId) this.attachModelEventSource(null, null);
3792
4023
  if (id2 !== this.modelInteractionSessionId) this.attachModelInteractionSource(null, null);
3793
- this.publish({ currentSessionId: id2, sessionViewEpoch: this.current.sessionViewEpoch + 1, sessionUnconfirmed: id2 !== null && this.pendingSessionSelections.has(id2), session: null, sessionChoice: null, sessionBusy: null, sessionIssue: null, sessionNotice: null });
4024
+ this.publish({ currentSessionId: id2, sessionViewEpoch: this.current.sessionViewEpoch + 1, sessionPreparationPending: false, sessionUnconfirmed: id2 !== null && (preparationUnconfirmed || this.pendingSessionSelections.has(id2)), session: null, sessionChoice: null, sessionBusy: null, sessionIssue: null, sessionNotice: null });
3794
4025
  if (id2 !== null) void this.refreshSession();
3795
4026
  }
3796
4027
  async refreshCatalog() {
@@ -3811,7 +4042,11 @@ var ProfilesController = class {
3811
4042
  }
3812
4043
  async refreshSession(preserveFeedback = false) {
3813
4044
  const id2 = this.current.currentSessionId;
3814
- if (this.disposed || !this.connectionCurrent() || id2 === null || this.current.sessionBusy !== null) return;
4045
+ if (id2 === null && this.preparation !== null) {
4046
+ await this.prepareSession(true);
4047
+ return;
4048
+ }
4049
+ if (this.disposed || !this.connectionCurrent() || id2 === null || this.current.sessionBusy !== null || this.sessionSourceId === id2 && this.sessionSource === null) return;
3815
4050
  this.modeRefreshPending = false;
3816
4051
  const generation = ++this.sessionGeneration;
3817
4052
  const live = () => !this.disposed && this.connectionCurrent() && generation === this.sessionGeneration && id2 === this.current.currentSessionId;
@@ -3846,16 +4081,27 @@ var ProfilesController = class {
3846
4081
  if (accepted.sessionId !== id2 || accepted.deepwork?.active !== active || !accepted.deepwork.explicit) throw { kind: "assembly", code: "unavailable" };
3847
4082
  if (live()) this.publish({ session: accepted, sessionNotice: active ? "mode-on" : "mode-off" });
3848
4083
  } catch (error) {
3849
- if (live()) this.publish({ sessionIssue: this.issue(error) });
4084
+ if (live()) {
4085
+ const issue = this.issue(error);
4086
+ if (["busy", "maintenance", "conflict"].includes(issue.code)) this.modeRefreshPending = true;
4087
+ this.publish({ sessionIssue: issue });
4088
+ }
3850
4089
  } finally {
3851
4090
  if (live()) {
3852
4091
  this.publish({ sessionBusy: null });
3853
4092
  this.refreshObservedMode();
4093
+ } else if (!this.disposed && this.connectionCurrent() && id2 === this.current.currentSessionId) {
4094
+ this.modeRefreshPending = true;
4095
+ this.refreshObservedMode();
3854
4096
  }
3855
4097
  }
3856
4098
  }
3857
4099
  async selectSession(reset, options, modelOnly = false) {
3858
4100
  const { currentSessionId: id2, session, sessionChoice, snapshot: snapshot4 } = this.current;
4101
+ if (id2 === null && !reset && !modelOnly && options?.useProfileModel !== true) {
4102
+ await this.prepareSession();
4103
+ return;
4104
+ }
3859
4105
  if (this.disposed || !this.connectionCurrent() || this.current.sessionUnconfirmed || id2 === null || session === null || session.refreshRequired || session.selection.refreshRequired || !writableSelectionVersion(session.selection.selectionRevision) || (modelOnly ? session.canSelectModel !== true : session.canApplyOverlay !== true || session.applyOverlayUnavailableReason === "new-session-required") || this.current.sessionBusy !== null || this.current.busy !== null || this.current.dirty || this.current.invalidFields.length > 0 || this.current.pendingEditor !== null) return;
3860
4106
  const selectedId = reset ? null : sessionChoice;
3861
4107
  const profile = snapshot4?.profiles.find((profile2) => profile2.id === selectedId), revision2 = profile?.revision;
@@ -3935,6 +4181,7 @@ var ProfilesController = class {
3935
4181
  } catch (error) {
3936
4182
  if (live()) {
3937
4183
  const issue = this.issue(error);
4184
+ if (["busy", "maintenance", "conflict"].includes(issue.code)) this.modeRefreshPending = true;
3938
4185
  this.publish({ sessionIssue: issue, sessionUnconfirmed: !modelOnly && (issue.kind !== "domain" || issue.code === "cancelled") });
3939
4186
  }
3940
4187
  } finally {
@@ -4142,7 +4389,15 @@ var ProfilesController = class {
4142
4389
  // src/client/locales.ts
4143
4390
  var NS = "settings.dsmm-profiles";
4144
4391
  var en = {
4145
- sessionChooseWorkspace: "Choose a workspace to start a session, then choose its configuration before sending.",
4392
+ sessionChooseWorkspace: "Choose a workspace and profile here. A blank session is prepared only when you confirm a profile choice.",
4393
+ sessionWorkspace: "Workspace",
4394
+ sessionWorkspacePlaceholder: "Choose a workspace…",
4395
+ sessionPrepare: "Open with this profile",
4396
+ sessionPrepareHint: "Choose a profile to prepare and open a blank session. The native model stays unchanged.",
4397
+ sessionPendingProfile: "Choose a workspace for: {profile}",
4398
+ sessionNoWorkspaces: "No workspaces available. Add or reconnect a workspace using native workspace navigation, then refresh.",
4399
+ sessionPreparationUnavailable: "Native workspace preparation is unavailable. Open a workspace using native navigation, then choose this session's profile.",
4400
+ sessionPreparationUnknown: "The Host did not return a session ID. Inspect the workspace using native navigation; this action will not automatically create or select again.",
4146
4401
  sessionSelectionBlock: "Finish choosing this session's configuration to continue typing.",
4147
4402
  sessionCommittedRefresh: "Saved. Refresh to confirm it.",
4148
4403
  sessionUnconfirmedRefresh: "The result is unknown. Refresh before choosing or sending again.",
@@ -4441,7 +4696,15 @@ var en = {
4441
4696
  inheritRouteDesc: "Inherit defaults"
4442
4697
  };
4443
4698
  var zh = {
4444
- sessionChooseWorkspace: "请先选择工作区新建会话,发送前再选择本次会话的配置。",
4699
+ sessionChooseWorkspace: "在此选择工作区与方案;仅明确确认方案选择时才会准备空白会话。",
4700
+ sessionWorkspace: "工作区",
4701
+ sessionWorkspacePlaceholder: "请选择工作区…",
4702
+ sessionPrepare: "使用此方案打开",
4703
+ sessionPrepareHint: "选择方案后将准备并打开空白会话,保留原生模型。",
4704
+ sessionPendingProfile: "请为「{profile}」选择工作区",
4705
+ sessionNoWorkspaces: "暂无可用工作区。请通过原生工作区导航添加或重新连接工作区,然后刷新。",
4706
+ sessionPreparationUnavailable: "当前无法准备原生空白会话。请通过原生导航打开工作区,再选择本次会话方案。",
4707
+ sessionPreparationUnknown: "Host 未返回会话 ID。请通过原生导航检查工作区;本入口不会自动重复创建或提交选择。",
4445
4708
  sessionSelectionBlock: "请先完成本次会话的配置选择,然后即可继续输入。",
4446
4709
  sessionCommittedRefresh: "已保存,请刷新确认。",
4447
4710
  sessionUnconfirmedRefresh: "结果未知,请刷新后再选择或发送。",
@@ -5202,12 +5465,14 @@ function ProfileModelsDialog({
5202
5465
  targetField,
5203
5466
  onTargetLocated,
5204
5467
  onJumpToJsonc,
5468
+ canSave: canSaveProp,
5205
5469
  t
5206
5470
  }) {
5207
5471
  const prefix = (0, import_react3.useId)();
5208
5472
  const [searchQuery, setSearchQuery] = (0, import_react3.useState)("");
5209
5473
  const [filterExplicitOnly, setFilterExplicitOnly] = (0, import_react3.useState)(false);
5210
5474
  const pendingFallbackFocusRef = (0, import_react3.useRef)(null);
5475
+ const dialogTopBarRef = (0, import_react3.useRef)(null);
5211
5476
  const wasOpenRef = (0, import_react3.useRef)(open);
5212
5477
  (0, import_react3.useEffect)(() => {
5213
5478
  if (wasOpenRef.current && !open) {
@@ -5330,6 +5595,8 @@ function ProfileModelsDialog({
5330
5595
  const roles2 = state.snapshot?.roles ?? [];
5331
5596
  const effectiveDisabled = disabled || isInvalidProjection || doc === null;
5332
5597
  const baseline = state.snapshot?.editorDefaults;
5598
+ const canSave = canSaveProp ?? (!disabled && !isInvalidProjection && doc !== null && state.dirty && state.snapshot !== null && state.invalidFields.length === 0);
5599
+ const isSaveLocked = (state.dirty || state.invalidFields.length > 0) && !disabled && doc !== null && state.snapshot !== null && (state.invalidFields.length > 0 || Boolean(isInvalidProjection));
5333
5600
  const filteredRoles = roles2.filter((role3) => {
5334
5601
  if (searchQuery.trim()) {
5335
5602
  const q = searchQuery.trim().toLowerCase();
@@ -5342,6 +5609,34 @@ function ProfileModelsDialog({
5342
5609
  }
5343
5610
  return true;
5344
5611
  });
5612
+ (0, import_react3.useEffect)(() => {
5613
+ if (!open) return;
5614
+ const el = dialogTopBarRef.current;
5615
+ if (!el) return;
5616
+ const parent = el.closest(".dsmm-profile-models-dialog-content");
5617
+ const update = () => {
5618
+ const height = el.offsetHeight;
5619
+ if (parent) {
5620
+ parent.style.setProperty("--dsmm-dialog-bar-offset", `${height}px`);
5621
+ }
5622
+ };
5623
+ update();
5624
+ if (typeof ResizeObserver !== "undefined") {
5625
+ const ro = new ResizeObserver(update);
5626
+ ro.observe(el);
5627
+ return () => {
5628
+ ro.disconnect();
5629
+ if (parent) {
5630
+ parent.style.removeProperty("--dsmm-dialog-bar-offset");
5631
+ }
5632
+ };
5633
+ }
5634
+ return () => {
5635
+ if (parent) {
5636
+ parent.style.removeProperty("--dsmm-dialog-bar-offset");
5637
+ }
5638
+ };
5639
+ }, [open, state.dirty, isSaveLocked, state.busy]);
5345
5640
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
5346
5641
  import_dsh_client_ui_primitives3.Modal,
5347
5642
  {
@@ -5354,6 +5649,33 @@ function ProfileModelsDialog({
5354
5649
  contentClassName: "dsmm-profile-models-dialog-content",
5355
5650
  onKeyDownCapture: handleKeyDownCapture,
5356
5651
  children: [
5652
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { ref: dialogTopBarRef, className: "dsmm-dialog-top-bar", children: [
5653
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "dsmm-actions", children: [
5654
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5655
+ import_dsh_client_ui_primitives3.Button,
5656
+ {
5657
+ type: "button",
5658
+ variant: "primary",
5659
+ disabled: !canSave,
5660
+ onClick: () => {
5661
+ void actions3.save();
5662
+ },
5663
+ children: t(state.busy === "save" ? "saving" : "save")
5664
+ }
5665
+ ),
5666
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5667
+ import_dsh_client_ui_primitives3.Button,
5668
+ {
5669
+ type: "button",
5670
+ variant: "outline",
5671
+ onClick: onClose,
5672
+ children: t("cancel")
5673
+ }
5674
+ )
5675
+ ] }),
5676
+ state.busy === "save" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "dsmm-status", role: "status", "aria-live": "polite", children: t("saving") }) : state.dirty ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "dsmm-status", role: "status", "aria-live": "polite", children: t("dirty") }) : null,
5677
+ isSaveLocked && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "dsmm-save-lock-reason", role: "status", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "dsmm-save-lock-text", children: isInvalidProjection ? t("rawInvalid") : t("saveLockedReason", { count: state.invalidFields.length }) }) })
5678
+ ] }),
5357
5679
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "dsmm-models-filter-bar dsmm-dialog-filter-bar", children: [
5358
5680
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "dsmm-field dsmm-filter-search", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5359
5681
  import_dsh_client_ui_primitives3.Input,
@@ -5762,7 +6084,7 @@ function SessionScopeFeedback({ state, t }) {
5762
6084
  ] }) : null,
5763
6085
  state.dirty && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "dsmm-hint", children: t("sessionDirty") }),
5764
6086
  (session?.refreshRequired || session?.selection.refreshRequired) && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { role: "status", children: t("sessionCommittedRefresh") }),
5765
- state.sessionUnconfirmed && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { role: "status", children: t("sessionUnconfirmedRefresh") }),
6087
+ state.sessionUnconfirmed && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { role: "status", children: t(state.sessionIssue?.code === "blank-identity-unconfirmed" ? "sessionPreparationUnknown" : "sessionUnconfirmedRefresh") }),
5766
6088
  state.sessionIssue !== null && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
5767
6089
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { role: "alert", children: state.sessionIssue.source === "profile-model" ? t(state.sessionIssue.code === "model-unconfigured" ? "headerNoProfileModel" : state.sessionIssue.code === "model-choice-changed" ? "headerModelChoiceChanged" : "headerModelUnconfirmed") : state.sessionIssue.code === "conflict" ? t("sessionConflict") : ["busy", "maintenance", "disposed", "not-owned"].includes(state.sessionIssue.code) ? t("sessionBusy", { reason: state.sessionIssue.code }) : t(state.sessionIssue.code === "validation" ? "validation" : "sessionUnavailable") }),
5768
6090
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(IssueDetails, { issue: state.sessionIssue, t })
@@ -5791,7 +6113,36 @@ function SessionScope({ state, actions: actions3, t, compact = false, showFeedba
5791
6113
  }
5792
6114
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "dsmm-session-scope", "aria-busy": state.sessionBusy !== null, "data-dsmm-session-scope": true, children: [
5793
6115
  !compact && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("h3", { children: t("sessionScope") }),
5794
- state.currentSessionId === null ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "dsmm-hint", children: t("sessionChooseWorkspace") }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
6116
+ state.currentSessionId === null ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
6117
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "dsmm-hint", children: t(state.sessionPreparationAvailable ? "sessionChooseWorkspace" : "sessionPreparationUnavailable") }),
6118
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "dsmm-field", children: [
6119
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("label", { htmlFor: `${prefix}-workspace`, children: t("sessionWorkspace") }),
6120
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("select", { id: `${prefix}-workspace`, value: state.sessionWorkspaceId ?? "", disabled: !state.sessionPreparationAvailable || disabled, onChange: (event) => {
6121
+ if (current()) void actions3.chooseSessionWorkspace(event.currentTarget.value);
6122
+ }, children: [
6123
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("option", { value: "", children: t("sessionWorkspacePlaceholder") }),
6124
+ state.sessionWorkspaces.map((workspace) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("option", { value: workspace.id, children: workspace.label }, workspace.id))
6125
+ ] })
6126
+ ] }),
6127
+ state.sessionWorkspaces.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "dsmm-hint", children: t("sessionNoWorkspaces") }),
6128
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "dsmm-field", children: [
6129
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("label", { htmlFor: `${prefix}-choice`, children: t("sessionSelect") }),
6130
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("select", { id: `${prefix}-choice`, value: state.sessionChoice ?? "", disabled: !state.sessionPreparationAvailable || disabled || state.sessionUnconfirmed, onChange: (event) => {
6131
+ if (current()) actions3.chooseSessionProfile(event.currentTarget.value || null);
6132
+ }, children: [
6133
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("option", { value: "", children: t("sessionBaseline") }),
6134
+ state.snapshot?.profiles.map((profile) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("option", { value: profile.id, disabled: !isConfigRevision(profile.revision) || profile.error !== void 0, children: profile.label?.trim() || profile.id }, profile.id))
6135
+ ] })
6136
+ ] }),
6137
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "dsmm-actions", children: [
6138
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_dsh_client_ui_primitives4.Button, { type: "button", variant: "outline", disabled: !state.sessionPreparationAvailable || disabled || state.sessionUnconfirmed || state.snapshot === null, onClick: () => {
6139
+ if (current()) void actions3.applySession();
6140
+ }, children: t("sessionPrepare") }),
6141
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_dsh_client_ui_primitives4.Button, { type: "button", variant: "outline", disabled: state.sessionBusy !== null || state.busy !== null || state.pendingEditor !== null, onClick: () => {
6142
+ if (current()) void actions3.refreshSession();
6143
+ }, children: t("sessionRefresh") })
6144
+ ] })
6145
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
5795
6146
  labels !== null && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { "data-dsmm-session-state": true, children: labels.admitted }),
5796
6147
  labels !== null && !compact && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "dsmm-hint", "data-dsmm-session-future-default": true, children: labels.futureDefault }),
5797
6148
  session === null && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "dsmm-hint", id: `${prefix}-overlay-reason`, children: t("sessionUnavailable") }),
@@ -5865,14 +6216,15 @@ function SessionProfiles(props) {
5865
6216
  const committing = state.sessionBusy !== null;
5866
6217
  const unavailable = id2 === null || committing || state.busy !== null || state.sessionUnconfirmed || session === null || session.refreshRequired === true || session.selection.refreshRequired === true;
5867
6218
  const profileDisabled = unavailable || state.pendingEditor !== null || state.dirty || state.invalidFields.length > 0 || session === null || !writableSelectionVersion(session.selection.selectionRevision);
5868
- const disabled = profileDisabled || session?.canApplyOverlay !== true || session?.applyOverlayUnavailableReason === "new-session-required" || state.snapshot === null;
6219
+ const sessionlessDisabled = !state.sessionPreparationAvailable || committing || state.busy !== null || state.sessionUnconfirmed || state.pendingEditor !== null || state.dirty || state.invalidFields.length > 0 || state.snapshot === null;
6220
+ const disabled = id2 === null ? sessionlessDisabled : profileDisabled || session?.canApplyOverlay !== true || session?.applyOverlayUnavailableReason === "new-session-required" || state.snapshot === null;
5869
6221
  let feedback = "";
5870
- if (state.sessionUnconfirmed) feedback = t("sessionUnconfirmedRefresh");
6222
+ if (state.sessionUnconfirmed) feedback = t(state.sessionIssue?.code === "blank-identity-unconfirmed" ? "sessionPreparationUnknown" : "sessionUnconfirmedRefresh");
5871
6223
  else if (session?.refreshRequired || session?.selection.refreshRequired) feedback = t("sessionCommittedRefresh");
5872
6224
  else if (state.sessionIssue !== null) feedback = t(state.sessionIssue.source === "profile-model" ? state.sessionIssue.code === "model-unconfigured" ? "headerNoProfileModel" : state.sessionIssue.code === "model-choice-changed" ? "headerModelChoiceChanged" : "headerModelUnconfirmed" : state.sessionIssue.code === "conflict" ? "headerConflict" : state.sessionIssue.code === "activation" ? "headerActivationRefused" : state.sessionIssue.code === "maintenance" ? "headerMaintenanceRefused" : state.sessionIssue.code === "busy" ? "headerBusyRefused" : state.sessionIssue.code === "cancelled" ? "headerCancelledRefused" : state.sessionIssue.code === "unavailable" || state.sessionIssue.kind === "assembly" ? "headerUnavailableRefused" : "headerSelectionRefused");
5873
6225
  else if (committing || state.busy !== null) feedback = t(state.sessionBusy === "apply" || state.sessionBusy === "reset" ? "headerApplying" : "headerLoading");
5874
6226
  else if (state.dirty || state.invalidFields.length > 0 || state.pendingEditor !== null) feedback = t("headerDraft");
5875
- else if (id2 === null) feedback = t("sessionChooseWorkspace");
6227
+ else if (id2 === null) feedback = t(!state.sessionPreparationAvailable ? "sessionPreparationUnavailable" : state.sessionWorkspaceId === null ? "sessionChooseWorkspace" : "sessionPrepareHint");
5876
6228
  else if (session === null || state.snapshot === null) feedback = t("headerUnavailable");
5877
6229
  else if (state.sessionNotice !== null) feedback = t(state.sessionNotice === "mode-on" ? "headerModeOn" : state.sessionNotice === "mode-off" ? "headerModeOff" : state.sessionNotice === "applied-with-model" ? "headerAppliedWithModel" : "headerApplied");
5878
6230
  const profileName = unknownCaptured ? t("headerCaptured") : admission !== void 0 && sourceRelationship(admission, currentSaved?.revision) === "current" && currentSaved?.label?.trim() ? currentSaved.label : admission?.selectedId ?? t("sessionBaseline");
@@ -5894,6 +6246,11 @@ function SessionProfiles(props) {
5894
6246
  if (diagnostic2 !== null) entries.push({ type: "label", id: "@diagnostic", text: diagnosticText }, { type: "label", id: "@retry", text: retryHint });
5895
6247
  if (admission?.selectedId != null && currentSaved === void 0) entries.push({ id: admission.selectedId, label: `${admission.selectedId} — ${t("headerSavedUnavailable")}`, disabled: true });
5896
6248
  if (unknownCaptured) entries.push({ id: "__dsmm_captured_default__", label: t("headerCaptured"), disabled: true });
6249
+ if (id2 === null) {
6250
+ entries.push({ type: "separator", id: "@workspace-separator" }, { type: "label", id: "@workspace-heading", text: state.sessionPreparationPending ? t("sessionPendingProfile", { profile: profiles.find((profile) => profile.id === state.sessionChoice)?.label?.trim() || state.sessionChoice || t("sessionBaseline") }) : t("sessionWorkspace") });
6251
+ for (const workspace of state.sessionWorkspaces) entries.push({ id: `@workspace:${workspace.id}`, label: `${workspace.id === state.sessionWorkspaceId ? "✓ " : ""}${workspace.label}`, disabled: !state.sessionPreparationAvailable || state.dirty || state.invalidFields.length > 0 || state.pendingEditor !== null || state.busy !== null });
6252
+ if (state.sessionWorkspaces.length === 0) entries.push({ type: "label", id: "@no-workspaces", text: t("sessionNoWorkspaces") });
6253
+ }
5897
6254
  entries.push({ type: "separator", id: "@keep-separator" }, { type: "label", id: "@keep-heading", text: t("headerCompactProfiles") }, { id: "", label: t("sessionBaseline"), disabled });
5898
6255
  if (session !== null && (session.canApplyOverlay !== true || session.applyOverlayUnavailableReason === "new-session-required")) entries.push({ type: "label", id: "@overlay-reason", text: capabilityReason(session.applyOverlayUnavailableReason, t) });
5899
6256
  for (const profile of profiles) entries.push({ id: profile.id, label: (profile.label?.trim() ? profile.label : profile.id) + (profile.error === void 0 && isConfigRevision(profile.revision) ? "" : ` — ${t("headerSavedUnavailable")}`) + (profileWarnings(profile.warnings).length ? ` — ${t("warningProfile")}` : ""), disabled: disabled || !isConfigRevision(profile.revision) || profile.error !== void 0 });
@@ -5922,17 +6279,22 @@ function SessionProfiles(props) {
5922
6279
  if (committing || state.busy !== null) return;
5923
6280
  void (async () => {
5924
6281
  await props.refresh();
5925
- if (id2 !== null && props.readProfileView().currentSessionId === id2 && props.readProfileView().sessionViewEpoch === state.sessionViewEpoch) await props.refreshSession();
6282
+ if (props.readProfileView().currentSessionId === id2 && props.readProfileView().sessionViewEpoch === state.sessionViewEpoch) await props.refreshSession();
5926
6283
  })();
5927
6284
  } else {
5928
6285
  const row = entries.find((entry) => entry.id === value && !("type" in entry));
5929
6286
  if (row === void 0 || !("disabled" in row) || row.disabled) return;
6287
+ if (value.startsWith("@workspace:")) {
6288
+ void props.chooseSessionWorkspace(value.slice("@workspace:".length));
6289
+ return;
6290
+ }
5930
6291
  if (value === "@mode") {
5931
6292
  if (mode !== void 0) void props.setDeepwork(!mode.active);
5932
6293
  } else if (value === "@use-model") void props.useSessionProfileModel();
5933
6294
  else {
5934
6295
  props.chooseSessionProfile(value || null);
5935
6296
  void props.applySession();
6297
+ if (id2 === null && state.sessionWorkspaceId === null) return;
5936
6298
  }
5937
6299
  }
5938
6300
  setOpenFor(void 0);
@@ -5976,6 +6338,7 @@ function ProfilesSection(props) {
5976
6338
  const hadConfirmation = (0, import_react5.useRef)(false);
5977
6339
  const initiatorRef = (0, import_react5.useRef)(null);
5978
6340
  const dialogInitiatorRef = (0, import_react5.useRef)(null);
6341
+ const saveBarRef = (0, import_react5.useRef)(null);
5979
6342
  const orchestratorRef = (0, import_react5.useRef)(null);
5980
6343
  const sessionScopeRef = (0, import_react5.useRef)(null);
5981
6344
  const [modelsDialogOpen, setModelsDialogOpen] = (0, import_react5.useState)(false);
@@ -6002,6 +6365,7 @@ function ProfilesSection(props) {
6002
6365
  }
6003
6366
  const basicDoc = structuredDoc ?? (lastValidBasicDocRef.current !== null && lastValidBasicDocRef.current.id === editor?.id && lastValidBasicDocRef.current.epoch === state.editorEpoch ? lastValidBasicDocRef.current.doc : null);
6004
6367
  const rawInvalid = editor !== null && structuredDoc === null;
6368
+ const canSave = !editorDisabled && state.dirty && snapshot4 !== null && state.invalidFields.length === 0 && !rawInvalid;
6005
6369
  function focusJsonc(location) {
6006
6370
  if (advancedRef.current !== null) {
6007
6371
  advancedRef.current.open = true;
@@ -6100,6 +6464,33 @@ function ProfilesSection(props) {
6100
6464
  if (snapshot4?.selectionError !== void 0 && !selectionConflict) selection = t("appliedInvalid");
6101
6465
  else if (snapshot4?.selectedId !== null && snapshot4?.selectedId !== void 0) selection = t("appliedProfile", { id: snapshot4.selectedId, revision: t(configurationVersionState(snapshot4.sourceRevision)) });
6102
6466
  const notice = state.notice === null ? "" : t(state.notice.key === "reset" ? "resetDone" : state.notice.key, { id: state.notice.id });
6467
+ (0, import_react5.useEffect)(() => {
6468
+ const el = saveBarRef.current;
6469
+ if (!el) return;
6470
+ const parent = el.closest(".dsmm-editor");
6471
+ const update = () => {
6472
+ const height = el.offsetHeight;
6473
+ if (parent) {
6474
+ parent.style.setProperty("--dsmm-save-bar-offset", `${height}px`);
6475
+ }
6476
+ };
6477
+ update();
6478
+ if (typeof ResizeObserver !== "undefined") {
6479
+ const ro = new ResizeObserver(update);
6480
+ ro.observe(el);
6481
+ return () => {
6482
+ ro.disconnect();
6483
+ if (parent) {
6484
+ parent.style.removeProperty("--dsmm-save-bar-offset");
6485
+ }
6486
+ };
6487
+ }
6488
+ return () => {
6489
+ if (parent) {
6490
+ parent.style.removeProperty("--dsmm-save-bar-offset");
6491
+ }
6492
+ };
6493
+ }, [editor?.id, state.dirty, state.invalidFields.length, rawInvalid, invalid2]);
6103
6494
  const warnings2 = editor === null ? [] : draftWarnings(editor.content);
6104
6495
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("section", { className: "dsmm-profiles dsmm-named-profiles", "aria-label": t("title"), "aria-busy": state.busy !== null, children: [
6105
6496
  readOnly && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { role: "status", className: "dsmm-hint", children: t("readOnlyOrigin") }),
@@ -6205,6 +6596,157 @@ function ProfilesSection(props) {
6205
6596
  ] }),
6206
6597
  editor === null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "dsmm-hint", children: t("noEditor") }),
6207
6598
  editor !== null && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "dsmm-editor", children: [
6599
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { ref: saveBarRef, className: "dsmm-save-bar", children: [
6600
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "dsmm-actions", children: [
6601
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_dsh_client_ui_primitives5.Button, { type: "button", variant: "primary", disabled: !canSave, onClick: () => {
6602
+ void props.save();
6603
+ }, children: t(state.busy === "save" ? "saving" : "save") }),
6604
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_dsh_client_ui_primitives5.Button, { type: "button", variant: "outline", disabled: editorDisabled || !state.dirty && state.invalidFields.length === 0, onClick: (event) => {
6605
+ initiatorRef.current = event.currentTarget;
6606
+ props.discard();
6607
+ }, children: t("discard") }),
6608
+ editor.revision !== null && !state.dirty && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_dsh_client_ui_primitives5.Button, { type: "button", variant: "outline", disabled, onClick: (event) => {
6609
+ initiatorRef.current = event.currentTarget;
6610
+ void props.reload();
6611
+ }, children: t("reload") }),
6612
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "dsmm-status", role: "status", "aria-live": "polite", "aria-atomic": "true", children: state.busy === "refresh" && snapshot4 === null ? t("loading") : state.busy === "read" ? t("reading") : notice })
6613
+ ] }),
6614
+ (() => {
6615
+ const isSaveLocked = (state.dirty || state.invalidFields.length > 0) && !editorDisabled && snapshot4 !== null && (state.invalidFields.length > 0 || rawInvalid || invalid2);
6616
+ if (!isSaveLocked) return null;
6617
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "dsmm-save-lock-reason", role: "status", children: [
6618
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "dsmm-save-lock-text", children: rawInvalid ? t("rawInvalid") : state.invalidFields.length > 0 ? t("saveLockedReason", { count: state.invalidFields.length }) : t("validation") }),
6619
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "dsmm-save-lock-action", children: [
6620
+ rawInvalid && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
6621
+ import_dsh_client_ui_primitives5.Button,
6622
+ {
6623
+ type: "button",
6624
+ variant: "outline",
6625
+ size: "sm",
6626
+ onClick: () => {
6627
+ if (advancedRef.current !== null) {
6628
+ advancedRef.current.open = true;
6629
+ jsoncOpenRef.current = true;
6630
+ }
6631
+ const reducedMotion = typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
6632
+ editorRef.current?.scrollIntoView({ behavior: reducedMotion ? "auto" : "smooth" });
6633
+ editorRef.current?.focus();
6634
+ },
6635
+ children: t("jumpToJsonc")
6636
+ }
6637
+ ),
6638
+ !rawInvalid && state.invalidFields.length > 0 && (() => {
6639
+ const firstInvalid = state.invalidFields[0];
6640
+ const roleMatch = /^(?:settings\.)?(?:roleRouting|roles)\.([a-zA-Z0-9_-]+)(?:\.|$)/.exec(firstInvalid);
6641
+ const roleId2 = roleMatch?.[1];
6642
+ if (roleId2) {
6643
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
6644
+ import_dsh_client_ui_primitives5.Button,
6645
+ {
6646
+ type: "button",
6647
+ variant: "outline",
6648
+ size: "sm",
6649
+ onClick: (e) => {
6650
+ dialogInitiatorRef.current = e.currentTarget;
6651
+ setTargetRole(roleId2);
6652
+ setTargetRoleField(firstInvalid);
6653
+ setModelsDialogOpen(true);
6654
+ },
6655
+ children: [
6656
+ t("jumpToField"),
6657
+ ": ",
6658
+ firstInvalid
6659
+ ]
6660
+ }
6661
+ );
6662
+ }
6663
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
6664
+ import_dsh_client_ui_primitives5.Button,
6665
+ {
6666
+ type: "button",
6667
+ variant: "outline",
6668
+ size: "sm",
6669
+ onClick: () => {
6670
+ if (!focusGlobalField(firstInvalid)) focusJsonc(state.issue?.location);
6671
+ },
6672
+ children: [
6673
+ t("jumpToField"),
6674
+ ": ",
6675
+ firstInvalid
6676
+ ]
6677
+ }
6678
+ );
6679
+ })(),
6680
+ !rawInvalid && state.invalidFields.length === 0 && invalid2 && (() => {
6681
+ if (state.issue?.field === "id" || state.issue?.field === "newId") {
6682
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
6683
+ import_dsh_client_ui_primitives5.Button,
6684
+ {
6685
+ type: "button",
6686
+ variant: "outline",
6687
+ size: "sm",
6688
+ onClick: () => {
6689
+ const reducedMotion = typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
6690
+ inputRef.current?.scrollIntoView({ behavior: reducedMotion ? "auto" : "smooth" });
6691
+ inputRef.current?.focus();
6692
+ },
6693
+ children: [
6694
+ t("jumpToField"),
6695
+ ": ID"
6696
+ ]
6697
+ }
6698
+ );
6699
+ }
6700
+ const roleMatch = /^(?:settings\.)?(?:roleRouting|roles)\.([a-zA-Z0-9_-]+)(?:\.|$)/.exec(state.issue?.field ?? "");
6701
+ const roleId2 = roleMatch?.[1];
6702
+ if (roleId2 && snapshot4?.roles?.some((r) => r.id === roleId2)) {
6703
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
6704
+ import_dsh_client_ui_primitives5.Button,
6705
+ {
6706
+ type: "button",
6707
+ variant: "outline",
6708
+ size: "sm",
6709
+ onClick: (e) => {
6710
+ dialogInitiatorRef.current = e.currentTarget;
6711
+ setTargetRole(roleId2);
6712
+ setTargetRoleField(state.issue?.field ?? null);
6713
+ setModelsDialogOpen(true);
6714
+ },
6715
+ children: [
6716
+ t("jumpToRole"),
6717
+ ": ",
6718
+ roleId2
6719
+ ]
6720
+ }
6721
+ );
6722
+ }
6723
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
6724
+ import_dsh_client_ui_primitives5.Button,
6725
+ {
6726
+ type: "button",
6727
+ variant: "outline",
6728
+ size: "sm",
6729
+ onClick: () => {
6730
+ if (advancedRef.current !== null) {
6731
+ advancedRef.current.open = true;
6732
+ jsoncOpenRef.current = true;
6733
+ }
6734
+ const reducedMotion = typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
6735
+ editorRef.current?.scrollIntoView({ behavior: reducedMotion ? "auto" : "smooth" });
6736
+ editorRef.current?.focus();
6737
+ const location = state.issue?.location;
6738
+ if (location !== void 0 && editorRef.current && location.offset + location.length <= editorRef.current.value.length) {
6739
+ editorRef.current.setSelectionRange(location.offset, location.offset + location.length);
6740
+ }
6741
+ },
6742
+ children: t("jumpToJsonc")
6743
+ }
6744
+ );
6745
+ })()
6746
+ ] })
6747
+ ] });
6748
+ })()
6749
+ ] }),
6208
6750
  warnings2.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { children: [
6209
6751
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: t("draftWarnings") }),
6210
6752
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ProfileWarnings, { warnings: warnings2, t })
@@ -6439,165 +6981,16 @@ function ProfilesSection(props) {
6439
6981
  setTargetRoleField(null);
6440
6982
  },
6441
6983
  onJumpToJsonc: () => closeModelsDialog("jsonc"),
6984
+ canSave,
6442
6985
  t
6443
6986
  }
6444
- ),
6445
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "dsmm-save-bar", children: [
6446
- (() => {
6447
- const isSaveLocked = (state.dirty || state.invalidFields.length > 0) && !editorDisabled && snapshot4 !== null && (state.invalidFields.length > 0 || rawInvalid || invalid2);
6448
- if (!isSaveLocked) return null;
6449
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "dsmm-save-lock-reason", role: "status", children: [
6450
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "dsmm-save-lock-text", children: rawInvalid ? t("rawInvalid") : state.invalidFields.length > 0 ? t("saveLockedReason", { count: state.invalidFields.length }) : t("validation") }),
6451
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "dsmm-save-lock-action", children: [
6452
- rawInvalid && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
6453
- import_dsh_client_ui_primitives5.Button,
6454
- {
6455
- type: "button",
6456
- variant: "outline",
6457
- size: "sm",
6458
- onClick: () => {
6459
- if (advancedRef.current !== null) {
6460
- advancedRef.current.open = true;
6461
- jsoncOpenRef.current = true;
6462
- }
6463
- const reducedMotion = typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
6464
- editorRef.current?.scrollIntoView({ behavior: reducedMotion ? "auto" : "smooth" });
6465
- editorRef.current?.focus();
6466
- },
6467
- children: t("jumpToJsonc")
6468
- }
6469
- ),
6470
- !rawInvalid && state.invalidFields.length > 0 && (() => {
6471
- const firstInvalid = state.invalidFields[0];
6472
- const roleMatch = /^(?:settings\.)?(?:roleRouting|roles)\.([a-zA-Z0-9_-]+)(?:\.|$)/.exec(firstInvalid);
6473
- const roleId2 = roleMatch?.[1];
6474
- if (roleId2) {
6475
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
6476
- import_dsh_client_ui_primitives5.Button,
6477
- {
6478
- type: "button",
6479
- variant: "outline",
6480
- size: "sm",
6481
- onClick: (e) => {
6482
- dialogInitiatorRef.current = e.currentTarget;
6483
- setTargetRole(roleId2);
6484
- setTargetRoleField(firstInvalid);
6485
- setModelsDialogOpen(true);
6486
- },
6487
- children: [
6488
- t("jumpToField"),
6489
- ": ",
6490
- firstInvalid
6491
- ]
6492
- }
6493
- );
6494
- }
6495
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
6496
- import_dsh_client_ui_primitives5.Button,
6497
- {
6498
- type: "button",
6499
- variant: "outline",
6500
- size: "sm",
6501
- onClick: () => {
6502
- if (!focusGlobalField(firstInvalid)) focusJsonc(state.issue?.location);
6503
- },
6504
- children: [
6505
- t("jumpToField"),
6506
- ": ",
6507
- firstInvalid
6508
- ]
6509
- }
6510
- );
6511
- })(),
6512
- !rawInvalid && state.invalidFields.length === 0 && invalid2 && (() => {
6513
- if (state.issue?.field === "id" || state.issue?.field === "newId") {
6514
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
6515
- import_dsh_client_ui_primitives5.Button,
6516
- {
6517
- type: "button",
6518
- variant: "outline",
6519
- size: "sm",
6520
- onClick: () => {
6521
- const reducedMotion = typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
6522
- inputRef.current?.scrollIntoView({ behavior: reducedMotion ? "auto" : "smooth" });
6523
- inputRef.current?.focus();
6524
- },
6525
- children: [
6526
- t("jumpToField"),
6527
- ": ID"
6528
- ]
6529
- }
6530
- );
6531
- }
6532
- const roleMatch = /^(?:settings\.)?(?:roleRouting|roles)\.([a-zA-Z0-9_-]+)(?:\.|$)/.exec(state.issue?.field ?? "");
6533
- const roleId2 = roleMatch?.[1];
6534
- if (roleId2 && snapshot4?.roles?.some((r) => r.id === roleId2)) {
6535
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
6536
- import_dsh_client_ui_primitives5.Button,
6537
- {
6538
- type: "button",
6539
- variant: "outline",
6540
- size: "sm",
6541
- onClick: (e) => {
6542
- dialogInitiatorRef.current = e.currentTarget;
6543
- setTargetRole(roleId2);
6544
- setTargetRoleField(state.issue?.field ?? null);
6545
- setModelsDialogOpen(true);
6546
- },
6547
- children: [
6548
- t("jumpToRole"),
6549
- ": ",
6550
- roleId2
6551
- ]
6552
- }
6553
- );
6554
- }
6555
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
6556
- import_dsh_client_ui_primitives5.Button,
6557
- {
6558
- type: "button",
6559
- variant: "outline",
6560
- size: "sm",
6561
- onClick: () => {
6562
- if (advancedRef.current !== null) {
6563
- advancedRef.current.open = true;
6564
- jsoncOpenRef.current = true;
6565
- }
6566
- const reducedMotion = typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
6567
- editorRef.current?.scrollIntoView({ behavior: reducedMotion ? "auto" : "smooth" });
6568
- editorRef.current?.focus();
6569
- const location = state.issue?.location;
6570
- if (location !== void 0 && editorRef.current && location.offset + location.length <= editorRef.current.value.length) {
6571
- editorRef.current.setSelectionRange(location.offset, location.offset + location.length);
6572
- }
6573
- },
6574
- children: t("jumpToJsonc")
6575
- }
6576
- );
6577
- })()
6578
- ] })
6579
- ] });
6580
- })(),
6581
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "dsmm-actions", children: [
6582
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_dsh_client_ui_primitives5.Button, { type: "button", variant: "primary", disabled: editorDisabled || !state.dirty || snapshot4 === null || state.invalidFields.length > 0 || rawInvalid, onClick: () => {
6583
- void props.save();
6584
- }, children: t(state.busy === "save" ? "saving" : "save") }),
6585
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_dsh_client_ui_primitives5.Button, { type: "button", variant: "outline", disabled: editorDisabled || !state.dirty && state.invalidFields.length === 0, onClick: (event) => {
6586
- initiatorRef.current = event.currentTarget;
6587
- props.discard();
6588
- }, children: t("discard") }),
6589
- editor.revision !== null && !state.dirty && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_dsh_client_ui_primitives5.Button, { type: "button", variant: "outline", disabled, onClick: (event) => {
6590
- initiatorRef.current = event.currentTarget;
6591
- void props.reload();
6592
- }, children: t("reload") })
6593
- ] })
6594
- ] })
6987
+ )
6595
6988
  ] }),
6596
6989
  state.issue !== null && !modelsDialogOpen && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "dsmm-issue", id: `${prefix}-issue`, role: "alert", children: [
6597
6990
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: t(issueKey(state.issue)) }),
6598
6991
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(IssueDetails, { issue: state.issue, t })
6599
6992
  ] }),
6600
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "dsmm-status", role: "status", "aria-live": "polite", "aria-atomic": "true", children: state.busy === "refresh" && snapshot4 === null ? t("loading") : state.busy === "read" ? t("reading") : notice })
6993
+ editor === null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "dsmm-status", role: "status", "aria-live": "polite", "aria-atomic": "true", children: state.busy === "refresh" && snapshot4 === null ? t("loading") : state.busy === "read" ? t("reading") : notice })
6601
6994
  ] });
6602
6995
  }
6603
6996
 
@@ -6665,7 +7058,8 @@ var PROFILE_STYLES = `
6665
7058
  .dsmm-panel-heading{display:flex;flex-wrap:wrap;gap:8px;justify-content:space-between;align-items:center;min-width:0}
6666
7059
  .dsmm-panel-heading h2:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:2px}
6667
7060
  .dsmm-rules-transaction{padding-top:16px}
6668
- .dsmm-scope-save{display:flex;flex-direction:column;gap:8px;padding-top:16px;border-top:1px solid var(--dsw-alias-border-l4)}
7061
+ .dsmm-scope-save{position:sticky;top:0;z-index:4;display:flex;flex-direction:column;gap:8px;padding:8px 0 12px;background:var(--dsw-alias-bg-module-platform,var(--dsw-alias-bg-layer-1));border-bottom:1px solid var(--dsw-alias-border-l4);margin-bottom:8px}
7062
+ .dsmm-rules-save-bar{position:sticky;top:var(--dsmm-scope-save-offset,0px);z-index:3;display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:8px;padding:8px 0;background:var(--dsw-alias-bg-module-platform,var(--dsw-alias-bg-layer-1));border-bottom:1px solid var(--dsw-alias-border-l4);margin-bottom:8px}
6669
7063
  .dsmm-deployment .dsmm-deployment-group{border-top:1px solid var(--dsw-alias-border-l4);padding-top:8px;min-width:0}
6670
7064
  .dsmm-deployment .dsmm-deployment-group>div{display:flex;flex-direction:column;gap:8px;padding-top:8px}
6671
7065
  .dsmm-deployment .dsmm-deployment-group>summary.dsmm-group-summary-row{display:flex;align-items:center;gap:8px;list-style:none}
@@ -6711,7 +7105,11 @@ var PROFILE_STYLES = `
6711
7105
  .dsmm-named-profiles .dsmm-advanced-settings[open]{padding-bottom:12px}
6712
7106
  .dsmm-named-profiles .dsmm-advanced-settings>summary{font-weight:500}
6713
7107
  .dsmm-named-profiles .dsmm-advanced-settings>div{margin-top:12px;display:flex;flex-direction:column;gap:12px}
6714
- .dsmm-named-profiles .dsmm-save-bar{display:flex;flex-direction:column;gap:8px;padding-top:12px;border-top:1px solid var(--dsw-alias-border-l4)}
7108
+ .dsmm-named-profiles .dsmm-save-bar{position:sticky;top:0;z-index:5;display:flex;flex-direction:column;gap:8px;padding:8px 0 12px;background:var(--dsw-alias-bg-module-platform);border-bottom:1px solid var(--dsw-alias-border-l4);margin-bottom:4px}
7109
+ .dsmm-dialog-top-bar{position:sticky;top:0;z-index:10;display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:8px;padding:8px 0 12px;background:var(--dsw-alias-bg-layer-1,var(--dsw-alias-bg-module-platform));border-bottom:1px solid var(--dsw-alias-border-l4);flex-shrink:0}
7110
+ .dsmm-profiles :is(.dsmm-field, fieldset, details, .dsmm-zone, input, select, textarea){scroll-margin-top:calc(var(--dsmm-save-bar-offset, 48px) + 12px)}
7111
+ .dsmm-profile-models-dialog :is(.dsmm-field, .dsmm-dialog-role-card, fieldset, details, .dsmm-zone, input, select, textarea){scroll-margin-top:calc(var(--dsmm-dialog-bar-offset, 48px) + 12px)}
7112
+ .dsmm-deployment :is(.dsmm-field, fieldset, details, .dsmm-zone, input, select, textarea){scroll-margin-top:calc(var(--dsmm-scope-save-offset, 48px) + 12px)}
6715
7113
  .dsmm-named-profiles .dsmm-save-lock-reason{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:8px;padding:8px 12px;border:1px solid var(--dsw-alias-state-warn-primary);border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-module-platform)}
6716
7114
  .dsmm-named-profiles .dsmm-save-lock-text{font-weight:500;color:var(--dsw-alias-state-warn-primary)}
6717
7115
  .dsmm-named-profiles .dsmm-save-lock-action{display:flex;align-items:center;gap:8px}
@@ -8865,6 +9263,14 @@ function PermissionRulesEditor({ controller, state, t }) {
8865
9263
  const id2 = (0, import_react9.useId)(), draft2 = state.draft, disabled = !controller.canEdit(state.generation), value = observedRules(state), observedPolicy = value?.snapshot ?? null;
8866
9264
  const writable = state.scope === "root" && state.connected;
8867
9265
  return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("section", { className: "dsmm-zone", "aria-label": t("rules"), children: [
9266
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "dsmm-rules-save-bar", children: [
9267
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "dsmm-actions", children: [
9268
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_dsh_client_ui_primitives9.Button, { type: "button", variant: "primary", disabled: !controller.canSave(state.generation), onClick: () => void controller.save(state.generation), children: t("save") }),
9269
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_dsh_client_ui_primitives9.Button, { type: "button", variant: "outline", disabled: !writable || state.reading || state.busy !== null, onClick: () => void controller.refresh(state.generation), children: t("refresh") }),
9270
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_dsh_client_ui_primitives9.Button, { type: "button", variant: "outline", disabled: !writable || state.reading || state.busy !== null || !state.dirty && state.rulesIssue === null, onClick: () => void controller.refresh(state.generation, true), children: t("discard") })
9271
+ ] }),
9272
+ state.dirty && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { className: "dsmm-status", role: "status", "aria-live": "polite", children: t("dirty") })
9273
+ ] }),
8868
9274
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("h3", { children: t("rules") }),
8869
9275
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { className: "dsmm-hint", children: t("rulesHint") }),
8870
9276
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Issue, { value: state.rulesIssue, t }),
@@ -8944,13 +9350,7 @@ function PermissionRulesEditor({ controller, state, t }) {
8944
9350
  ] }, ruleId))
8945
9351
  ] })
8946
9352
  ] }),
8947
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(RuleRecords, { state, controller, t }),
8948
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "dsmm-actions", children: [
8949
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_dsh_client_ui_primitives9.Button, { type: "button", variant: "primary", disabled: !controller.canSave(state.generation), onClick: () => void controller.save(state.generation), children: t("save") }),
8950
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_dsh_client_ui_primitives9.Button, { type: "button", variant: "outline", disabled: !writable || state.reading || state.busy !== null, onClick: () => void controller.refresh(state.generation), children: t("refresh") }),
8951
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_dsh_client_ui_primitives9.Button, { type: "button", variant: "outline", disabled: !writable || state.reading || state.busy !== null || !state.dirty && state.rulesIssue === null, onClick: () => void controller.refresh(state.generation, true), children: t("discard") })
8952
- ] }),
8953
- state.dirty && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { children: t("dirty") })
9353
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(RuleRecords, { state, controller, t })
8954
9354
  ] });
8955
9355
  }
8956
9356
  function PermissionsPanel({ controller, t, sessionId: sessionId2 }) {
@@ -8975,7 +9375,35 @@ var import_jsx_runtime12 = require("react/jsx-runtime");
8975
9375
  function ScopeSave({ controller, workspace, refreshOnly = false, t }) {
8976
9376
  const state = (0, import_react10.useSyncExternalStore)(controller.subscribe, controller.getSnapshot);
8977
9377
  const pending = [...new Set(controller.pendingPaths().map(moduleFor))];
8978
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("section", { className: "dsmm-scope-save", "aria-label": t("saveScope"), children: [
9378
+ const ref = (0, import_react10.useRef)(null);
9379
+ (0, import_react10.useEffect)(() => {
9380
+ const el = ref.current;
9381
+ if (!el) return;
9382
+ const parent = el.closest(".dsmm-section-panel");
9383
+ const update = () => {
9384
+ const height = el.offsetHeight;
9385
+ if (parent) {
9386
+ parent.style.setProperty("--dsmm-scope-save-offset", `${height}px`);
9387
+ }
9388
+ };
9389
+ update();
9390
+ if (typeof ResizeObserver !== "undefined") {
9391
+ const ro = new ResizeObserver(update);
9392
+ ro.observe(el);
9393
+ return () => {
9394
+ ro.disconnect();
9395
+ if (parent) {
9396
+ parent.style.removeProperty("--dsmm-scope-save-offset");
9397
+ }
9398
+ };
9399
+ }
9400
+ return () => {
9401
+ if (parent) {
9402
+ parent.style.removeProperty("--dsmm-scope-save-offset");
9403
+ }
9404
+ };
9405
+ }, []);
9406
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("section", { ref, className: "dsmm-scope-save", "aria-label": t("saveScope"), children: [
8979
9407
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("p", { className: "dsmm-status", role: "status", "aria-live": "polite", children: refreshOnly ? state.busy ? t("loading") : "" : state.busy ? t("saving") : state.refreshRequired ? t("savedRefreshRequired") : state.saved ? t("saved") : state.dirty ? t("dirty") : "" }),
8980
9408
  !refreshOnly && pending.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("p", { children: [
8981
9409
  t("pendingModules"),
@@ -9182,16 +9610,13 @@ function DeploymentPage(props) {
9182
9610
  )) }),
9183
9611
  active !== null && /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("section", { id: `${id2}-panel`, role: "tabpanel", className: "dsmm-section-panel", "aria-labelledby": `${id2}-tab-${active}`, "data-dsmm-module": active, children: [
9184
9612
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "dsmm-panel-heading", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("h2", { id: `${id2}-heading`, ref: heading, tabIndex: -1, children: t(moduleTitle(active)) }) }),
9185
- active === "state" ? /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
9186
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(StateInspector, { controller: props.core, t }),
9187
- scopeActions
9188
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
9613
+ scopeActions,
9614
+ active === "state" ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(StateInspector, { controller: props.core, t }) : /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
9189
9615
  navigation.scope === "profile" && navigation.native === null ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("p", { children: t("unavailableForm") }) : state.snapshot === null ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("p", { children: t(state.busy ? "loading" : "unavailable") }) : /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { "data-dsmm-layer": controller.layer, "aria-busy": state.busy, className: "dsmm-structured", children: [
9190
9616
  fields.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("p", { className: "dsmm-hint", children: t("noModuleFields") }),
9191
9617
  fields.map(([key, schema]) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Field, { schema, path: [key], controller, initiallyOpen: fields.length === 1 && active !== "permissions", disclosures: disclosures.current[navigation.scope], t }, `${navigation.scope}:${key}`)),
9192
9618
  active === "run" && controller.layer === "profile" && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(NativeRuntimeState, { value: state.snapshot.subagentRuntime, t })
9193
9619
  ] }),
9194
- scopeActions,
9195
9620
  active === "permissions" && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("section", { className: "dsmm-zone dsmm-rules-transaction", "aria-label": t("rootRules"), children: workspace.permissions === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("p", { children: t("rootRulesUnavailable") }) : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(PermissionsPanel, { controller: workspace.permissions, t: props.permissionsT ?? ((key) => Object.hasOwn(permissionEn, key) ? permissionText(t)(key) : key) }) })
9196
9621
  ] })
9197
9622
  ] }),
@@ -9799,6 +10224,28 @@ function registerRoleToolViews(ctx) {
9799
10224
  });
9800
10225
  }
9801
10226
 
10227
+ // src/client/profile-blank.ts
10228
+ function profileBlankNative(services) {
10229
+ const list = services.workspaces.list;
10230
+ return {
10231
+ workspaces: {
10232
+ getSnapshot: () => {
10233
+ const state = list.getSnapshot();
10234
+ return state.phase === "ready" ? state.items.map((item) => ({ id: item.workspaceId, label: item.title || item.path })) : [];
10235
+ },
10236
+ subscribe: (listener) => list.subscribe(listener)
10237
+ },
10238
+ beginNavigation: () => services.layout.beginNavigation(),
10239
+ connectWorkspace: (id2) => {
10240
+ const state = list.getSnapshot(), workspace = state.phase === "ready" ? state.items.find((item) => item.workspaceId === id2) : void 0;
10241
+ if (workspace === void 0) return Promise.reject(new Error("Workspace unavailable"));
10242
+ return services.uiWorkspace.connectWorkspace(workspace.workspaceId);
10243
+ },
10244
+ retain: (id2) => services.sessions.retain(id2, { source: "controllerOperation" }),
10245
+ openSession: (id2) => services.uiWorkspace.openSession(id2)
10246
+ };
10247
+ }
10248
+
9802
10249
  // src/client/children-controller.ts
9803
10250
  var EMPTY_CHILD_DRAFT = { text: "", delivery: "queue", images: [], imageBusy: false, uncertain: false };
9804
10251
  var childActionKey = (childId) => `child:${childId}`;
@@ -10476,6 +10923,7 @@ async function apply(ctx) {
10476
10923
  void profileCtx.inject(["connection"], (connectionCtx) => {
10477
10924
  controller.bindConnection(connectionCtx.connection.generation);
10478
10925
  void controller.refresh();
10926
+ void controller.refreshSession();
10479
10927
  connectionCtx.effect(() => () => controller.bindConnection(null), "dsmm: profile connection withdrawal");
10480
10928
  });
10481
10929
  profiles = controller;
@@ -10500,6 +10948,10 @@ async function apply(ctx) {
10500
10948
  controller.attachComposerBlocks(conversationCtx.conversation.blocks, () => t("sessionSelectionBlock"));
10501
10949
  conversationCtx.effect(() => () => controller.attachComposerBlocks(null), "dsmm: profile composer block lifetime");
10502
10950
  });
10951
+ void profileCtx.inject(["uiWorkspace", "workspaces", "layout", "sessions", "uiSession"], (blankCtx) => {
10952
+ controller.attachBlankNative(profileBlankNative(blankCtx));
10953
+ blankCtx.effect(() => () => controller.attachBlankNative(null), "dsmm: native blank preparation lifetime");
10954
+ });
10503
10955
  profileCtx.slots.inject("settings.section", () => profileCtx.slots.register({
10504
10956
  name: "settings.section",
10505
10957
  id: "dsmm-profiles",
@@ -10527,9 +10979,11 @@ async function apply(ctx) {
10527
10979
  const nativeSessions = sessionCtx.sessions;
10528
10980
  const update = () => {
10529
10981
  const binding = source.getSnapshot();
10982
+ const nativeBinding = binding.key === void 0 ? void 0 : nativeSessions.binding(binding.key);
10983
+ controller.attachSessionSource(binding.key ?? null, nativeBinding?.session ?? null);
10530
10984
  controller.setSession(binding.key ?? null);
10531
10985
  controller.attachModelSelectionSource(binding.key ?? null, binding.key === void 0 ? null : binding.keyedHooks.projection?.("modelSelection") ?? null);
10532
- controller.attachModelEventSource(binding.key ?? null, binding.key === void 0 ? null : nativeSessions.binding(binding.key)?.eventSource ?? null);
10986
+ controller.attachModelEventSource(binding.key ?? null, nativeBinding?.eventSource ?? null);
10533
10987
  };
10534
10988
  update();
10535
10989
  sessionCtx.effect(() => source.subscribe(update), "dsmm: current native session");
@@ -10538,6 +10992,7 @@ async function apply(ctx) {
10538
10992
  controller.attachModelEventSource(null, null);
10539
10993
  controller.attachModelInteractionSource(null, null);
10540
10994
  controller.setSession(null);
10995
+ controller.attachSessionSource(null, null);
10541
10996
  }, "dsmm: native session withdrawal");
10542
10997
  void sessionCtx.inject(["modelDirectories", "remote.session"], (modelCtx) => {
10543
10998
  const updateInteraction = () => {