@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/README.md +1 -1
- package/docs/agent-presets.md +1 -1
- package/docs/compatibility.md +2 -2
- package/docs/deferred-native-approval-risk.md +4 -4
- package/docs/design.md +1 -1
- package/docs/lsp.md +1 -1
- package/docs/model-routing.md +1 -1
- package/docs/native-permissions.md +12 -2
- package/docs/profiles.md +14 -5
- package/docs/roadmap.md +67 -30
- package/docs/runtime-recovery.md +1 -1
- package/docs/safety-guards.md +1 -1
- package/docs/settings-status.md +1 -1
- package/lib/client/DeploymentPage.js +31 -2
- package/lib/client/PermissionsPanel.js +1 -1
- package/lib/client/ProfileModelsDialog.d.ts +2 -1
- package/lib/client/ProfileModelsDialog.js +37 -2
- package/lib/client/ProfilesSection.js +47 -17
- package/lib/client/SessionProfiles.js +24 -6
- package/lib/client/children-locales.d.ts +1 -1
- package/lib/client/controller.d.ts +23 -1
- package/lib/client/controller.js +289 -8
- package/lib/client/index.js +10 -2
- package/lib/client/locales.d.ts +8 -0
- package/lib/client/locales.js +12 -2
- package/lib/client/profile-blank.d.ts +43 -0
- package/lib/client/profile-blank.js +19 -0
- package/lib/client/styles.d.ts +1 -1
- package/lib/client/styles.js +7 -2
- package/lib/client.js +635 -180
- package/lib/command-approval.d.ts +2 -0
- package/lib/command-approval.js +4 -1
- package/lib/index.js +2 -1
- package/lib/native-admission.d.ts +10 -3
- package/lib/native-admission.js +129 -28
- package/lib/profile-runtime.js +3 -5
- package/package.json +1 -1
package/lib/client/controller.js
CHANGED
|
@@ -28,12 +28,15 @@ export function canReconcileSelection(snapshot) {
|
|
|
28
28
|
export class ProfilesController {
|
|
29
29
|
remote;
|
|
30
30
|
current = { snapshot: null, editor: null, dirty: false, busy: null, issue: null, notice: null, pendingEditor: null,
|
|
31
|
-
catalog: null, catalogBusy: false, catalogUnavailable: true, currentSessionId: null, sessionViewEpoch: 0, sessionUnconfirmed: false, session: null, sessionChoice: null, sessionBusy: null, sessionIssue: null, sessionNotice: null, invalidFields: [], editorEpoch: 0, validationEpoch: 0 };
|
|
31
|
+
catalog: null, catalogBusy: false, catalogUnavailable: true, currentSessionId: null, sessionViewEpoch: 0, sessionUnconfirmed: false, session: null, sessionChoice: null, sessionWorkspaces: [], sessionWorkspaceId: null, sessionPreparationAvailable: false, sessionPreparationPending: false, sessionBusy: null, sessionIssue: null, sessionNotice: null, invalidFields: [], editorEpoch: 0, validationEpoch: 0 };
|
|
32
32
|
accepted = null;
|
|
33
33
|
listeners = new Set();
|
|
34
34
|
generation = 0;
|
|
35
35
|
disposed = false;
|
|
36
36
|
sessionGeneration = 0;
|
|
37
|
+
blankNative = null;
|
|
38
|
+
stopWorkspaces = null;
|
|
39
|
+
preparation = null;
|
|
37
40
|
pendingSessionSelections = new Set();
|
|
38
41
|
connection = null;
|
|
39
42
|
connectionBaseline;
|
|
@@ -56,6 +59,9 @@ export class ProfilesController {
|
|
|
56
59
|
modelEventsWatermark = -1;
|
|
57
60
|
modeEventsWatermark = -1;
|
|
58
61
|
modeRefreshPending = false;
|
|
62
|
+
sessionSource = null;
|
|
63
|
+
sessionSourceId = null;
|
|
64
|
+
stopSessionSource = null;
|
|
59
65
|
stopModelEvents = null;
|
|
60
66
|
modelInteraction = null;
|
|
61
67
|
modelInteractionSessionId = null;
|
|
@@ -80,6 +86,7 @@ export class ProfilesController {
|
|
|
80
86
|
refreshCatalog: () => this.refreshCatalog(), refreshSession: () => this.refreshSession(),
|
|
81
87
|
chooseSessionProfile: (id) => { 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)
|
|
82
88
|
this.publish({ sessionChoice: id, sessionNotice: null }); },
|
|
89
|
+
chooseSessionWorkspace: id => this.chooseSessionWorkspace(id),
|
|
83
90
|
applySession: (options) => this.selectSession(false, options), resetSession: () => this.selectSession(true),
|
|
84
91
|
setDeepwork: (active) => this.setDeepwork(active), useSessionProfileModel: () => this.selectSession(false, { useProfileModel: true }, true),
|
|
85
92
|
setFieldInvalid: (field, invalid) => {
|
|
@@ -107,7 +114,7 @@ export class ProfilesController {
|
|
|
107
114
|
constructor(remote) {
|
|
108
115
|
this.remote = remote;
|
|
109
116
|
}
|
|
110
|
-
dispose() { this.releaseComposerBlock(); this.numberDrafts.clear(); this.stopConnection?.(); this.disposed = true; this.generation += 1; this.sessionGeneration += 1; this.catalogGeneration += 1; this.modelSelectorGeneration += 1; this.modelSelectionGeneration += 1; this.stopModelSelection?.(); this.stopModelEvents?.(); this.stopModelInteraction?.(); this.stopModelSelection = null; this.stopModelEvents = null; this.stopModelInteraction = null; this.modelSelectionSource = null; this.modelEvents = null; this.modelInteraction = null; this.catalogRemote = null; this.modelSelector = null; this.listeners.clear(); }
|
|
117
|
+
dispose() { this.releasePreparation(); this.stopWorkspaces?.(); this.releaseComposerBlock(); this.numberDrafts.clear(); this.stopConnection?.(); this.stopSessionSource?.(); this.sessionSource = null; this.disposed = true; this.generation += 1; this.sessionGeneration += 1; this.catalogGeneration += 1; this.modelSelectorGeneration += 1; this.modelSelectionGeneration += 1; this.stopModelSelection?.(); this.stopModelEvents?.(); this.stopModelInteraction?.(); this.stopModelSelection = null; this.stopModelEvents = null; this.stopModelInteraction = null; this.modelSelectionSource = null; this.modelEvents = null; this.modelInteraction = null; this.catalogRemote = null; this.modelSelector = null; this.listeners.clear(); }
|
|
111
118
|
bindConnection(source) {
|
|
112
119
|
if (this.disposed)
|
|
113
120
|
return;
|
|
@@ -117,15 +124,17 @@ export class ProfilesController {
|
|
|
117
124
|
this.connectionBound = true;
|
|
118
125
|
this.connectionBaseline = source?.getSnapshot();
|
|
119
126
|
const invalidate = () => {
|
|
127
|
+
this.releasePreparation();
|
|
120
128
|
this.connectionBaseline = source?.getSnapshot();
|
|
121
129
|
this.generation += 1;
|
|
122
130
|
this.sessionGeneration += 1;
|
|
131
|
+
this.modeRefreshPending = false;
|
|
123
132
|
this.modelSelectorGeneration += 1;
|
|
124
133
|
// A replaced connection only discards what it observed. It never records a
|
|
125
134
|
// durable refusal for the session: an unread configuration is read again
|
|
126
135
|
// by the next refresh, and typing stays available in the meantime.
|
|
127
136
|
this.publish({ session: null, sessionBusy: null, sessionNotice: null, sessionUnconfirmed: false,
|
|
128
|
-
sessionViewEpoch: this.current.sessionViewEpoch + 1, busy: null, issue: { kind: "transport", code: "unavailable" } });
|
|
137
|
+
sessionViewEpoch: this.current.sessionViewEpoch + 1, sessionWorkspaceId: null, sessionPreparationPending: false, busy: null, issue: { kind: "transport", code: "unavailable" } });
|
|
129
138
|
};
|
|
130
139
|
if (replacement || source === null || this.connectionBaseline === undefined)
|
|
131
140
|
invalidate();
|
|
@@ -140,13 +149,229 @@ export class ProfilesController {
|
|
|
140
149
|
connectionCurrent() {
|
|
141
150
|
return !this.connectionBound || this.connectionBaseline !== undefined && this.connection?.getSnapshot() === this.connectionBaseline;
|
|
142
151
|
}
|
|
152
|
+
attachBlankNative(native) {
|
|
153
|
+
if (this.disposed)
|
|
154
|
+
return;
|
|
155
|
+
this.cancelPreparation();
|
|
156
|
+
this.stopWorkspaces?.();
|
|
157
|
+
this.blankNative = native;
|
|
158
|
+
const update = () => {
|
|
159
|
+
const sessionWorkspaces = native?.workspaces.getSnapshot() ?? [];
|
|
160
|
+
const sessionWorkspaceId = sessionWorkspaces.some(item => item.id === this.current.sessionWorkspaceId) ? this.current.sessionWorkspaceId : null;
|
|
161
|
+
if (this.preparation !== null && sessionWorkspaceId !== this.preparation.workspaceId)
|
|
162
|
+
this.cancelPreparation();
|
|
163
|
+
this.publish({ sessionWorkspaces, sessionWorkspaceId, sessionPreparationAvailable: native !== null && this.composerBlocks !== null });
|
|
164
|
+
};
|
|
165
|
+
this.stopWorkspaces = native?.workspaces.subscribe(update) ?? null;
|
|
166
|
+
update();
|
|
167
|
+
}
|
|
168
|
+
releasePreparation() {
|
|
169
|
+
const task = this.preparation;
|
|
170
|
+
this.preparation = null;
|
|
171
|
+
if (task === null)
|
|
172
|
+
return;
|
|
173
|
+
task.stop();
|
|
174
|
+
const held = task.held;
|
|
175
|
+
if (held !== null && task.id !== null && held.blocks.storeFor(task.id) === held.store && held.store.getSnapshot() === held.block)
|
|
176
|
+
held.blocks.set(task.id, undefined);
|
|
177
|
+
task.reference?.release();
|
|
178
|
+
}
|
|
179
|
+
cancelPreparation() {
|
|
180
|
+
if (this.preparation === null)
|
|
181
|
+
return;
|
|
182
|
+
this.releasePreparation();
|
|
183
|
+
this.sessionGeneration += 1;
|
|
184
|
+
this.publish({ sessionBusy: null, sessionUnconfirmed: false, sessionPreparationPending: false, sessionNotice: null });
|
|
185
|
+
}
|
|
186
|
+
async chooseSessionWorkspace(id) {
|
|
187
|
+
if (this.disposed || !this.connectionCurrent() || this.current.currentSessionId !== null || !this.current.sessionWorkspaces.some(item => item.id === id)
|
|
188
|
+
|| this.current.dirty || this.current.invalidFields.length > 0 || this.current.pendingEditor !== null || this.current.busy !== null)
|
|
189
|
+
return;
|
|
190
|
+
const pending = this.current.sessionPreparationPending;
|
|
191
|
+
if (id !== this.current.sessionWorkspaceId)
|
|
192
|
+
this.cancelPreparation();
|
|
193
|
+
this.publish({ sessionWorkspaceId: id, sessionIssue: null });
|
|
194
|
+
if (pending)
|
|
195
|
+
await this.prepareSession();
|
|
196
|
+
}
|
|
197
|
+
preparationOwned(task) {
|
|
198
|
+
return !this.disposed && this.connectionCurrent() && this.preparation === task
|
|
199
|
+
&& this.current.currentSessionId === null && this.current.sessionWorkspaceId === task.workspaceId;
|
|
200
|
+
}
|
|
201
|
+
preparationCurrent(task) {
|
|
202
|
+
return this.preparationOwned(task) && !task.navigation.aborted;
|
|
203
|
+
}
|
|
204
|
+
preparationConfirmed(task, session) {
|
|
205
|
+
const selection = session.admittedSelection;
|
|
206
|
+
return selection !== undefined && !selection.refreshRequired && session.sessionId === task.id && !session.refreshRequired && !session.selection.refreshRequired
|
|
207
|
+
&& writableSelectionVersion(session.selection.selectionRevision) && selection.selectedId === task.selectedId && selection.appliedRevision === task.revision
|
|
208
|
+
&& session.selection.selectedId === task.selectedId && session.selection.appliedRevision === task.revision;
|
|
209
|
+
}
|
|
210
|
+
openPrepared(task, explicit = false) {
|
|
211
|
+
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)
|
|
212
|
+
return;
|
|
213
|
+
task.opening = true;
|
|
214
|
+
try {
|
|
215
|
+
this.publish({ sessionUnconfirmed: true });
|
|
216
|
+
if (this.preparationOwned(task))
|
|
217
|
+
task.native.openSession(task.id);
|
|
218
|
+
}
|
|
219
|
+
finally {
|
|
220
|
+
task.opening = false;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
async prepareSession(refreshOnly = false) {
|
|
224
|
+
const { sessionWorkspaceId: workspaceId, sessionChoice: selectedId, snapshot } = this.current;
|
|
225
|
+
const native = this.blankNative;
|
|
226
|
+
if (this.disposed || !this.connectionCurrent() || native === null || this.composerBlocks === null || this.composerReason === null
|
|
227
|
+
|| this.current.currentSessionId !== null || this.current.sessionBusy !== null || this.current.busy !== null
|
|
228
|
+
|| this.current.dirty || this.current.invalidFields.length > 0 || this.current.pendingEditor !== null || snapshot === null)
|
|
229
|
+
return;
|
|
230
|
+
if (workspaceId === null) {
|
|
231
|
+
if (!refreshOnly)
|
|
232
|
+
this.publish({ sessionPreparationPending: true });
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
if (this.current.sessionUnconfirmed && !refreshOnly)
|
|
236
|
+
return;
|
|
237
|
+
const profile = snapshot.profiles.find(item => item.id === selectedId), revision = selectedId === null ? null : profile?.revision;
|
|
238
|
+
if (!refreshOnly && selectedId !== null && (!isConfigRevision(revision) || profile?.error !== undefined))
|
|
239
|
+
return;
|
|
240
|
+
let task = this.preparation;
|
|
241
|
+
const openOnly = !refreshOnly && task?.confirmed === true && task.selectedId === selectedId && task.revision === (revision ?? null);
|
|
242
|
+
if (task === null) {
|
|
243
|
+
if (refreshOnly)
|
|
244
|
+
return;
|
|
245
|
+
const navigation = native.beginNavigation();
|
|
246
|
+
task = { native, navigation, workspaceId, selectedId, revision: revision ?? null, id: null, reference: null, held: null, confirmed: false, opening: false, stop: () => { } };
|
|
247
|
+
this.preparation = task;
|
|
248
|
+
}
|
|
249
|
+
else if (!refreshOnly && !openOnly) {
|
|
250
|
+
task.selectedId = selectedId;
|
|
251
|
+
task.revision = revision ?? null;
|
|
252
|
+
task.confirmed = false;
|
|
253
|
+
}
|
|
254
|
+
if (!refreshOnly && !openOnly) {
|
|
255
|
+
task.stop();
|
|
256
|
+
if (task.navigation.aborted)
|
|
257
|
+
task.navigation = native.beginNavigation();
|
|
258
|
+
const navigation = task.navigation;
|
|
259
|
+
const owned = task;
|
|
260
|
+
const abort = () => { if (this.preparation === owned && !owned.opening)
|
|
261
|
+
this.cancelPreparation(); };
|
|
262
|
+
navigation.addEventListener("abort", abort, { once: true });
|
|
263
|
+
task.stop = () => navigation.removeEventListener("abort", abort);
|
|
264
|
+
}
|
|
265
|
+
const owned = task;
|
|
266
|
+
const live = () => refreshOnly ? this.preparationOwned(owned) : this.preparationCurrent(owned);
|
|
267
|
+
this.publish({ sessionBusy: refreshOnly ? "read" : "apply", sessionPreparationPending: false, sessionIssue: null, sessionNotice: null });
|
|
268
|
+
try {
|
|
269
|
+
if (openOnly) {
|
|
270
|
+
this.openPrepared(task, true);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (!live())
|
|
274
|
+
return;
|
|
275
|
+
if (task.id === null) {
|
|
276
|
+
if (refreshOnly)
|
|
277
|
+
throw { kind: "transport", code: "unavailable" };
|
|
278
|
+
const id = await native.connectWorkspace(workspaceId);
|
|
279
|
+
if (!live())
|
|
280
|
+
return;
|
|
281
|
+
task.id = id;
|
|
282
|
+
}
|
|
283
|
+
const id = task.id;
|
|
284
|
+
if (task.reference === null) {
|
|
285
|
+
task.reference = native.retain(id);
|
|
286
|
+
if (!live()) {
|
|
287
|
+
task.reference.release();
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
if (task.reference.sessionId !== id)
|
|
291
|
+
throw { kind: "assembly", code: "unavailable" };
|
|
292
|
+
}
|
|
293
|
+
if (task.held === null) {
|
|
294
|
+
// Occupy the empty native seat synchronously, before awaiting readiness.
|
|
295
|
+
const blocks = this.composerBlocks, store = blocks.storeFor(id);
|
|
296
|
+
if (store.getSnapshot() !== undefined)
|
|
297
|
+
throw { kind: "domain", code: "busy" };
|
|
298
|
+
const block = { reason: this.composerReason() };
|
|
299
|
+
task.held = { blocks, store, block };
|
|
300
|
+
blocks.set(id, block);
|
|
301
|
+
}
|
|
302
|
+
const binding = await task.reference.ready;
|
|
303
|
+
if (!live())
|
|
304
|
+
return;
|
|
305
|
+
if (binding.sessionId !== id)
|
|
306
|
+
throw { kind: "assembly", code: "unavailable" };
|
|
307
|
+
const session = await this.unwrap(this.remote.describeSession(id));
|
|
308
|
+
if (!live())
|
|
309
|
+
return;
|
|
310
|
+
if (session.sessionId !== id)
|
|
311
|
+
throw { kind: "assembly", code: "unavailable" };
|
|
312
|
+
if (refreshOnly) {
|
|
313
|
+
task.confirmed = this.preparationConfirmed(task, session);
|
|
314
|
+
if (task.confirmed) {
|
|
315
|
+
this.publish({ sessionUnconfirmed: false });
|
|
316
|
+
this.openPrepared(task);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
const uncertain = session.refreshRequired === true || session.selection.refreshRequired === true;
|
|
320
|
+
this.publish({ sessionUnconfirmed: uncertain, sessionIssue: { kind: "domain", code: uncertain ? "unavailable" : "conflict" } });
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
if (session.refreshRequired || session.selection.refreshRequired || !writableSelectionVersion(session.selection.selectionRevision))
|
|
324
|
+
throw { kind: "domain", code: "conflict" };
|
|
325
|
+
if (session.canApplyOverlay !== true || session.applyOverlayUnavailableReason === "new-session-required")
|
|
326
|
+
throw { kind: "domain", code: session.applyOverlayUnavailableReason ?? "unavailable" };
|
|
327
|
+
const held = task.held;
|
|
328
|
+
if (held === null || held.blocks.storeFor(id) !== held.store || held.store.getSnapshot() !== held.block)
|
|
329
|
+
throw { kind: "domain", code: "busy" };
|
|
330
|
+
if (this.current.dirty || this.current.invalidFields.length > 0 || this.current.pendingEditor !== null)
|
|
331
|
+
throw { kind: "domain", code: "conflict" };
|
|
332
|
+
this.pendingSessionSelections.add(id);
|
|
333
|
+
const accepted = await this.unwrap(this.remote.selectSession(id, { sessionId: id, id: task.selectedId,
|
|
334
|
+
...(task.selectedId === null ? {} : { expectedRevision: task.revision }), expectedSelectionRevision: session.selection.selectionRevision, expectedAdmissionEpoch: session.admissionEpoch }));
|
|
335
|
+
if (!live())
|
|
336
|
+
return;
|
|
337
|
+
if (!this.preparationConfirmed(task, accepted)) {
|
|
338
|
+
this.publish({ sessionUnconfirmed: true });
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
task.confirmed = true;
|
|
342
|
+
this.openPrepared(task);
|
|
343
|
+
}
|
|
344
|
+
catch (error) {
|
|
345
|
+
if (this.preparationOwned(task)) {
|
|
346
|
+
const issue = this.issue(error), uncertain = task.confirmed || issue.kind !== "domain" || issue.code === "cancelled";
|
|
347
|
+
this.publish({ sessionIssue: task.id === null && uncertain ? { kind: "assembly", code: "blank-identity-unconfirmed" } : issue, sessionUnconfirmed: uncertain });
|
|
348
|
+
// A definite pre-commit refusal needs no task-owned send block or retain.
|
|
349
|
+
if (!uncertain)
|
|
350
|
+
this.releasePreparation();
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
finally {
|
|
354
|
+
if (task.id !== null)
|
|
355
|
+
this.pendingSessionSelections.delete(task.id);
|
|
356
|
+
if (this.preparationOwned(task))
|
|
357
|
+
this.publish({ sessionBusy: null });
|
|
358
|
+
else if (!this.disposed && this.current.currentSessionId === null && this.preparation === null)
|
|
359
|
+
this.publish({ sessionBusy: null });
|
|
360
|
+
else if (!this.disposed && this.connectionCurrent() && task.id === this.current.currentSessionId) {
|
|
361
|
+
this.modeRefreshPending = true;
|
|
362
|
+
this.refreshObservedMode();
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
143
366
|
attachComposerBlocks(blocks, reason) {
|
|
144
367
|
if (this.disposed)
|
|
145
368
|
return;
|
|
369
|
+
if (blocks !== this.composerBlocks && this.preparation !== null)
|
|
370
|
+
this.cancelPreparation();
|
|
146
371
|
this.releaseComposerBlock();
|
|
147
372
|
this.composerBlocks = blocks;
|
|
148
373
|
this.composerReason = reason ?? null;
|
|
149
|
-
this.
|
|
374
|
+
this.publish({ sessionPreparationAvailable: this.blankNative !== null && blocks !== null });
|
|
150
375
|
}
|
|
151
376
|
releaseComposerBlock() {
|
|
152
377
|
const held = this.composerBlock;
|
|
@@ -185,6 +410,33 @@ export class ProfilesController {
|
|
|
185
410
|
this.modelSelectionSource = source;
|
|
186
411
|
this.stopModelSelection = source?.subscribe(() => { this.modelSelectionGeneration += 1; }) ?? null;
|
|
187
412
|
}
|
|
413
|
+
attachSessionSource(sessionId, source) {
|
|
414
|
+
if (this.disposed || sessionId === this.sessionSourceId && source === this.sessionSource)
|
|
415
|
+
return;
|
|
416
|
+
this.stopSessionSource?.();
|
|
417
|
+
this.sessionSourceId = sessionId;
|
|
418
|
+
this.sessionSource = source;
|
|
419
|
+
let running = source?.getSnapshot().running;
|
|
420
|
+
const current = () => !this.disposed && sessionId !== null && sessionId === this.current.currentSessionId && source === this.sessionSource;
|
|
421
|
+
this.stopSessionSource = source?.subscribe(() => {
|
|
422
|
+
if (!current())
|
|
423
|
+
return;
|
|
424
|
+
const next = source.getSnapshot().running;
|
|
425
|
+
if (next === running)
|
|
426
|
+
return;
|
|
427
|
+
running = next;
|
|
428
|
+
// Running is an invalidation signal, never permission to apply an overlay.
|
|
429
|
+
this.modeRefreshPending = true;
|
|
430
|
+
this.refreshObservedMode();
|
|
431
|
+
}) ?? null;
|
|
432
|
+
if (current()) {
|
|
433
|
+
this.sessionGeneration += 1;
|
|
434
|
+
this.modeRefreshPending = source !== null;
|
|
435
|
+
this.publish({ session: null, sessionBusy: null, sessionNotice: null, sessionViewEpoch: this.current.sessionViewEpoch + 1,
|
|
436
|
+
sessionUnconfirmed: this.pendingSessionSelections.has(sessionId) });
|
|
437
|
+
this.refreshObservedMode();
|
|
438
|
+
}
|
|
439
|
+
}
|
|
188
440
|
attachModelEventSource(sessionId, source) {
|
|
189
441
|
if (this.disposed || (sessionId === this.modelEventsSessionId && source === this.modelEvents))
|
|
190
442
|
return;
|
|
@@ -241,15 +493,26 @@ export class ProfilesController {
|
|
|
241
493
|
setSession(id) {
|
|
242
494
|
if (this.disposed || id === this.current.currentSessionId)
|
|
243
495
|
return;
|
|
496
|
+
const task = this.preparation;
|
|
497
|
+
const preparationUnconfirmed = task?.id === id && this.current.sessionUnconfirmed;
|
|
498
|
+
if (task?.id === id && task.held !== null && id !== null) {
|
|
499
|
+
// The native current binding has retained this exact target. Transfer our
|
|
500
|
+
// block to the ordinary current-session lifecycle without an empty seat.
|
|
501
|
+
this.composerBlock = { id: id, store: task.held.store, block: task.held.block };
|
|
502
|
+
task.held = null;
|
|
503
|
+
}
|
|
504
|
+
this.releasePreparation();
|
|
244
505
|
this.sessionGeneration += 1;
|
|
245
506
|
this.modeRefreshPending = false;
|
|
507
|
+
if (id !== this.sessionSourceId)
|
|
508
|
+
this.attachSessionSource(null, null);
|
|
246
509
|
if (id !== this.modelSelectionSessionId)
|
|
247
510
|
this.attachModelSelectionSource(null, null);
|
|
248
511
|
if (id !== this.modelEventsSessionId)
|
|
249
512
|
this.attachModelEventSource(null, null);
|
|
250
513
|
if (id !== this.modelInteractionSessionId)
|
|
251
514
|
this.attachModelInteractionSource(null, null);
|
|
252
|
-
this.publish({ currentSessionId: id, sessionViewEpoch: this.current.sessionViewEpoch + 1, sessionUnconfirmed: id !== null && this.pendingSessionSelections.has(id), session: null, sessionChoice: null, sessionBusy: null, sessionIssue: null, sessionNotice: null });
|
|
515
|
+
this.publish({ currentSessionId: id, sessionViewEpoch: this.current.sessionViewEpoch + 1, sessionPreparationPending: false, sessionUnconfirmed: id !== null && (preparationUnconfirmed || this.pendingSessionSelections.has(id)), session: null, sessionChoice: null, sessionBusy: null, sessionIssue: null, sessionNotice: null });
|
|
253
516
|
if (id !== null)
|
|
254
517
|
void this.refreshSession();
|
|
255
518
|
}
|
|
@@ -278,7 +541,11 @@ export class ProfilesController {
|
|
|
278
541
|
}
|
|
279
542
|
async refreshSession(preserveFeedback = false) {
|
|
280
543
|
const id = this.current.currentSessionId;
|
|
281
|
-
if (
|
|
544
|
+
if (id === null && this.preparation !== null) {
|
|
545
|
+
await this.prepareSession(true);
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
if (this.disposed || !this.connectionCurrent() || id === null || this.current.sessionBusy !== null || this.sessionSourceId === id && this.sessionSource === null)
|
|
282
549
|
return;
|
|
283
550
|
this.modeRefreshPending = false;
|
|
284
551
|
const generation = ++this.sessionGeneration;
|
|
@@ -321,18 +588,30 @@ export class ProfilesController {
|
|
|
321
588
|
this.publish({ session: accepted, sessionNotice: active ? "mode-on" : "mode-off" });
|
|
322
589
|
}
|
|
323
590
|
catch (error) {
|
|
324
|
-
if (live())
|
|
325
|
-
|
|
591
|
+
if (live()) {
|
|
592
|
+
const issue = this.issue(error);
|
|
593
|
+
if (["busy", "maintenance", "conflict"].includes(issue.code))
|
|
594
|
+
this.modeRefreshPending = true;
|
|
595
|
+
this.publish({ sessionIssue: issue });
|
|
596
|
+
}
|
|
326
597
|
}
|
|
327
598
|
finally {
|
|
328
599
|
if (live()) {
|
|
329
600
|
this.publish({ sessionBusy: null });
|
|
330
601
|
this.refreshObservedMode();
|
|
331
602
|
}
|
|
603
|
+
else if (!this.disposed && this.connectionCurrent() && id === this.current.currentSessionId) {
|
|
604
|
+
this.modeRefreshPending = true;
|
|
605
|
+
this.refreshObservedMode();
|
|
606
|
+
}
|
|
332
607
|
}
|
|
333
608
|
}
|
|
334
609
|
async selectSession(reset, options, modelOnly = false) {
|
|
335
610
|
const { currentSessionId: id, session, sessionChoice, snapshot } = this.current;
|
|
611
|
+
if (id === null && !reset && !modelOnly && options?.useProfileModel !== true) {
|
|
612
|
+
await this.prepareSession();
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
336
615
|
if (this.disposed || !this.connectionCurrent() || this.current.sessionUnconfirmed || id === null || session === null || session.refreshRequired || session.selection.refreshRequired || !writableSelectionVersion(session.selection.selectionRevision)
|
|
337
616
|
|| (modelOnly ? session.canSelectModel !== true : session.canApplyOverlay !== true || session.applyOverlayUnavailableReason === "new-session-required") || this.current.sessionBusy !== null
|
|
338
617
|
|| this.current.busy !== null || this.current.dirty || this.current.invalidFields.length > 0 || this.current.pendingEditor !== null)
|
|
@@ -426,6 +705,8 @@ export class ProfilesController {
|
|
|
426
705
|
catch (error) {
|
|
427
706
|
if (live()) {
|
|
428
707
|
const issue = this.issue(error);
|
|
708
|
+
if (["busy", "maintenance", "conflict"].includes(issue.code))
|
|
709
|
+
this.modeRefreshPending = true;
|
|
429
710
|
this.publish({ sessionIssue: issue, sessionUnconfirmed: !modelOnly && (issue.kind !== "domain" || issue.code === "cancelled") });
|
|
430
711
|
}
|
|
431
712
|
}
|
package/lib/client/index.js
CHANGED
|
@@ -15,6 +15,7 @@ import { bindPermissionSession } from "./permission-session.js";
|
|
|
15
15
|
import { PermissionController } from "./permission-controller.js";
|
|
16
16
|
import { PERMISSIONS_NS, permissionEn, permissionZh } from "./permission-locales.js";
|
|
17
17
|
import { registerRoleToolViews } from "./RoleToolView.js";
|
|
18
|
+
import { profileBlankNative } from "./profile-blank.js";
|
|
18
19
|
export { ProfilesController, NEW_PROFILE_CONTENT } from "./controller.js";
|
|
19
20
|
export { ProfilesSection } from "./ProfilesSection.js";
|
|
20
21
|
export { NS, en, zh } from "./locales.js";
|
|
@@ -81,6 +82,7 @@ export async function apply(ctx) {
|
|
|
81
82
|
void profileCtx.inject(["connection"], connectionCtx => {
|
|
82
83
|
controller.bindConnection(connectionCtx.connection.generation);
|
|
83
84
|
void controller.refresh();
|
|
85
|
+
void controller.refreshSession();
|
|
84
86
|
connectionCtx.effect(() => () => controller.bindConnection(null), "dsmm: profile connection withdrawal");
|
|
85
87
|
});
|
|
86
88
|
profiles = controller;
|
|
@@ -100,6 +102,10 @@ export async function apply(ctx) {
|
|
|
100
102
|
controller.attachComposerBlocks(conversationCtx.conversation.blocks, () => t("sessionSelectionBlock"));
|
|
101
103
|
conversationCtx.effect(() => () => controller.attachComposerBlocks(null), "dsmm: profile composer block lifetime");
|
|
102
104
|
});
|
|
105
|
+
void profileCtx.inject(["uiWorkspace", "workspaces", "layout", "sessions", "uiSession"], blankCtx => {
|
|
106
|
+
controller.attachBlankNative(profileBlankNative(blankCtx));
|
|
107
|
+
blankCtx.effect(() => () => controller.attachBlankNative(null), "dsmm: native blank preparation lifetime");
|
|
108
|
+
});
|
|
103
109
|
profileCtx.slots.inject("settings.section", () => profileCtx.slots.register({
|
|
104
110
|
name: "settings.section", id: "dsmm-profiles", order: 30,
|
|
105
111
|
label: () => t("title"), locale: NS,
|
|
@@ -125,13 +131,15 @@ export async function apply(ctx) {
|
|
|
125
131
|
const nativeSessions = sessionCtx.sessions;
|
|
126
132
|
const update = () => {
|
|
127
133
|
const binding = source.getSnapshot();
|
|
134
|
+
const nativeBinding = binding.key === undefined ? undefined : nativeSessions.binding(binding.key);
|
|
135
|
+
controller.attachSessionSource(binding.key ?? null, nativeBinding?.session ?? null);
|
|
128
136
|
controller.setSession(binding.key ?? null);
|
|
129
137
|
controller.attachModelSelectionSource(binding.key ?? null, binding.key === undefined ? null : binding.keyedHooks.projection?.("modelSelection") ?? null);
|
|
130
|
-
controller.attachModelEventSource(binding.key ?? null,
|
|
138
|
+
controller.attachModelEventSource(binding.key ?? null, nativeBinding?.eventSource ?? null);
|
|
131
139
|
};
|
|
132
140
|
update();
|
|
133
141
|
sessionCtx.effect(() => source.subscribe(update), "dsmm: current native session");
|
|
134
|
-
sessionCtx.effect(() => () => { controller.attachModelSelectionSource(null, null); controller.attachModelEventSource(null, null); controller.attachModelInteractionSource(null, null); controller.setSession(null); }, "dsmm: native session withdrawal");
|
|
142
|
+
sessionCtx.effect(() => () => { controller.attachModelSelectionSource(null, null); controller.attachModelEventSource(null, null); controller.attachModelInteractionSource(null, null); controller.setSession(null); controller.attachSessionSource(null, null); }, "dsmm: native session withdrawal");
|
|
135
143
|
void sessionCtx.inject(["modelDirectories", "remote.session"], (modelCtx) => {
|
|
136
144
|
const updateInteraction = () => {
|
|
137
145
|
const id = source.getSnapshot().key;
|
package/lib/client/locales.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
export declare const NS = "settings.dsmm-profiles";
|
|
2
2
|
export declare const en: {
|
|
3
3
|
sessionChooseWorkspace: string;
|
|
4
|
+
sessionWorkspace: string;
|
|
5
|
+
sessionWorkspacePlaceholder: string;
|
|
6
|
+
sessionPrepare: string;
|
|
7
|
+
sessionPrepareHint: string;
|
|
8
|
+
sessionPendingProfile: string;
|
|
9
|
+
sessionNoWorkspaces: string;
|
|
10
|
+
sessionPreparationUnavailable: string;
|
|
11
|
+
sessionPreparationUnknown: string;
|
|
4
12
|
sessionSelectionBlock: string;
|
|
5
13
|
sessionCommittedRefresh: string;
|
|
6
14
|
sessionUnconfirmedRefresh: string;
|
package/lib/client/locales.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
export const NS = "settings.dsmm-profiles";
|
|
2
2
|
export const en = {
|
|
3
|
-
sessionChooseWorkspace: "Choose a workspace
|
|
3
|
+
sessionChooseWorkspace: "Choose a workspace and profile here. A blank session is prepared only when you confirm a profile choice.",
|
|
4
|
+
sessionWorkspace: "Workspace", sessionWorkspacePlaceholder: "Choose a workspace…",
|
|
5
|
+
sessionPrepare: "Open with this profile", sessionPrepareHint: "Choose a profile to prepare and open a blank session. The native model stays unchanged.",
|
|
6
|
+
sessionPendingProfile: "Choose a workspace for: {profile}", sessionNoWorkspaces: "No workspaces available. Add or reconnect a workspace using native workspace navigation, then refresh.",
|
|
7
|
+
sessionPreparationUnavailable: "Native workspace preparation is unavailable. Open a workspace using native navigation, then choose this session's profile.",
|
|
8
|
+
sessionPreparationUnknown: "The Host did not return a session ID. Inspect the workspace using native navigation; this action will not automatically create or select again.",
|
|
4
9
|
sessionSelectionBlock: "Finish choosing this session's configuration to continue typing.",
|
|
5
10
|
sessionCommittedRefresh: "Saved. Refresh to confirm it.",
|
|
6
11
|
sessionUnconfirmedRefresh: "The result is unknown. Refresh before choosing or sending again.",
|
|
@@ -113,7 +118,12 @@ export const en = {
|
|
|
113
118
|
inheritRouteDesc: "Inherit defaults",
|
|
114
119
|
};
|
|
115
120
|
export const zh = {
|
|
116
|
-
sessionChooseWorkspace: "
|
|
121
|
+
sessionChooseWorkspace: "在此选择工作区与方案;仅明确确认方案选择时才会准备空白会话。",
|
|
122
|
+
sessionWorkspace: "工作区", sessionWorkspacePlaceholder: "请选择工作区…",
|
|
123
|
+
sessionPrepare: "使用此方案打开", sessionPrepareHint: "选择方案后将准备并打开空白会话,保留原生模型。",
|
|
124
|
+
sessionPendingProfile: "请为「{profile}」选择工作区", sessionNoWorkspaces: "暂无可用工作区。请通过原生工作区导航添加或重新连接工作区,然后刷新。",
|
|
125
|
+
sessionPreparationUnavailable: "当前无法准备原生空白会话。请通过原生导航打开工作区,再选择本次会话方案。",
|
|
126
|
+
sessionPreparationUnknown: "Host 未返回会话 ID。请通过原生导航检查工作区;本入口不会自动重复创建或提交选择。",
|
|
117
127
|
sessionSelectionBlock: "请先完成本次会话的配置选择,然后即可继续输入。",
|
|
118
128
|
sessionCommittedRefresh: "已保存,请刷新确认。",
|
|
119
129
|
sessionUnconfirmedRefresh: "结果未知,请刷新后再选择或发送。",
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ISessions, SessionBinding } from "@deepseek-ai/dsh-api-session-controller/client";
|
|
2
|
+
import type { SessionId } from "@deepseek-ai/dsh-session/types";
|
|
3
|
+
import type { HostObservable } from "@deepseek-ai/dsh-client-ui-slots";
|
|
4
|
+
type WorkspaceId = NonNullable<NonNullable<Parameters<ISessions["create"]>[0]>["workspaceId"]>;
|
|
5
|
+
export interface ProfileWorkspace {
|
|
6
|
+
id: string;
|
|
7
|
+
label: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ProfileBlankNative {
|
|
10
|
+
readonly workspaces: HostObservable<readonly ProfileWorkspace[]>;
|
|
11
|
+
beginNavigation(): AbortSignal;
|
|
12
|
+
connectWorkspace(id: string): Promise<SessionId>;
|
|
13
|
+
retain(id: SessionId): {
|
|
14
|
+
readonly sessionId: SessionId;
|
|
15
|
+
readonly ready: Promise<Pick<SessionBinding, "sessionId">>;
|
|
16
|
+
release(): void;
|
|
17
|
+
};
|
|
18
|
+
openSession(id: SessionId): void;
|
|
19
|
+
}
|
|
20
|
+
/** Public native service subsets; these optional packages are not runtime imports. */
|
|
21
|
+
export interface ProfileBlankServices {
|
|
22
|
+
workspaces: {
|
|
23
|
+
readonly list: HostObservable<{
|
|
24
|
+
readonly phase: string;
|
|
25
|
+
readonly items: readonly {
|
|
26
|
+
readonly workspaceId: WorkspaceId;
|
|
27
|
+
readonly title: string;
|
|
28
|
+
readonly path: string;
|
|
29
|
+
}[];
|
|
30
|
+
}>;
|
|
31
|
+
};
|
|
32
|
+
uiWorkspace: {
|
|
33
|
+
connectWorkspace(id: WorkspaceId): Promise<SessionId>;
|
|
34
|
+
openSession(id: SessionId): void;
|
|
35
|
+
};
|
|
36
|
+
layout: {
|
|
37
|
+
beginNavigation(): AbortSignal;
|
|
38
|
+
};
|
|
39
|
+
sessions: Pick<ISessions, "retain">;
|
|
40
|
+
}
|
|
41
|
+
export declare function profileBlankNative(services: ProfileBlankServices): ProfileBlankNative;
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=profile-blank.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function profileBlankNative(services) {
|
|
2
|
+
const list = services.workspaces.list;
|
|
3
|
+
return {
|
|
4
|
+
workspaces: {
|
|
5
|
+
getSnapshot: () => { const state = list.getSnapshot(); return state.phase === "ready" ? state.items.map(item => ({ id: item.workspaceId, label: item.title || item.path })) : []; },
|
|
6
|
+
subscribe: listener => list.subscribe(listener),
|
|
7
|
+
},
|
|
8
|
+
beginNavigation: () => services.layout.beginNavigation(),
|
|
9
|
+
connectWorkspace: id => {
|
|
10
|
+
const state = list.getSnapshot(), workspace = state.phase === "ready" ? state.items.find(item => item.workspaceId === id) : undefined;
|
|
11
|
+
if (workspace === undefined)
|
|
12
|
+
return Promise.reject(new Error("Workspace unavailable"));
|
|
13
|
+
return services.uiWorkspace.connectWorkspace(workspace.workspaceId);
|
|
14
|
+
},
|
|
15
|
+
retain: id => services.sessions.retain(id, { source: "controllerOperation" }),
|
|
16
|
+
openSession: id => services.uiWorkspace.openSession(id),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=profile-blank.js.map
|