dsh-agent-enhancer 0.0.0-stage → 0.2.0
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/LICENSE +21 -0
- package/README.en.md +181 -0
- package/README.md +180 -2
- package/cordis.patch.yml +3 -0
- package/lib/client/dsh/controls.d.ts +8 -0
- package/lib/client/dsh/controls.d.ts.map +1 -0
- package/lib/client/dsh/conversation.d.ts +11 -0
- package/lib/client/dsh/conversation.d.ts.map +1 -0
- package/lib/client/dsh/editor.d.ts +19 -0
- package/lib/client/dsh/editor.d.ts.map +1 -0
- package/lib/client/dsh/hints.d.ts +7 -0
- package/lib/client/dsh/hints.d.ts.map +1 -0
- package/lib/client/dsh/icons.d.ts +3 -0
- package/lib/client/dsh/icons.d.ts.map +1 -0
- package/lib/client/dsh/model-catalog.d.ts +33 -0
- package/lib/client/dsh/model-catalog.d.ts.map +1 -0
- package/lib/client/dsh/overlay.d.ts +10 -0
- package/lib/client/dsh/overlay.d.ts.map +1 -0
- package/lib/client/dsh/plugin-hints.d.ts +33 -0
- package/lib/client/dsh/plugin-hints.d.ts.map +1 -0
- package/lib/client/dsh/settings-form.d.ts +15 -0
- package/lib/client/dsh/settings-form.d.ts.map +1 -0
- package/lib/client/dsh/settings.d.ts +13 -0
- package/lib/client/dsh/settings.d.ts.map +1 -0
- package/lib/client/dsh/structured.d.ts +6 -0
- package/lib/client/dsh/structured.d.ts.map +1 -0
- package/lib/client/index.d.ts +4 -0
- package/lib/client/index.d.ts.map +1 -0
- package/lib/client/locales.d.ts +194 -0
- package/lib/client/locales.d.ts.map +1 -0
- package/lib/client/prompt/coordinator.d.ts +86 -0
- package/lib/client/prompt/coordinator.d.ts.map +1 -0
- package/lib/client/prompt/history.d.ts +13 -0
- package/lib/client/prompt/history.d.ts.map +1 -0
- package/lib/client/prompt/optimize.d.ts +50 -0
- package/lib/client/prompt/optimize.d.ts.map +1 -0
- package/lib/client/prompt/predict.d.ts +32 -0
- package/lib/client/prompt/predict.d.ts.map +1 -0
- package/lib/client/prompt/session.d.ts +39 -0
- package/lib/client/prompt/session.d.ts.map +1 -0
- package/lib/client/prompt/types.d.ts +38 -0
- package/lib/client/prompt/types.d.ts.map +1 -0
- package/lib/client/remote.d.ts +43 -0
- package/lib/client/remote.d.ts.map +1 -0
- package/lib/client/rollback/actions.d.ts +15 -0
- package/lib/client/rollback/actions.d.ts.map +1 -0
- package/lib/client/rollback/command-ui.d.ts +35 -0
- package/lib/client/rollback/command-ui.d.ts.map +1 -0
- package/lib/client/rollback/content-parts.d.ts +8 -0
- package/lib/client/rollback/content-parts.d.ts.map +1 -0
- package/lib/client/rollback/controller.d.ts +23 -0
- package/lib/client/rollback/controller.d.ts.map +1 -0
- package/lib/client/rollback/marker.d.ts +4 -0
- package/lib/client/rollback/marker.d.ts.map +1 -0
- package/lib/client/rollback/modal-host.d.ts +11 -0
- package/lib/client/rollback/modal-host.d.ts.map +1 -0
- package/lib/client/rollback/preview.d.ts +16 -0
- package/lib/client/rollback/preview.d.ts.map +1 -0
- package/lib/client/rollback/remote.d.ts +34 -0
- package/lib/client/rollback/remote.d.ts.map +1 -0
- package/lib/client/rollback/scope.d.ts +5 -0
- package/lib/client/rollback/scope.d.ts.map +1 -0
- package/lib/client/rollback/transcript-filter.d.ts +9 -0
- package/lib/client/rollback/transcript-filter.d.ts.map +1 -0
- package/lib/client/rollback/transcript.d.ts +27 -0
- package/lib/client/rollback/transcript.d.ts.map +1 -0
- package/lib/client/rollback/turn-outline-filter.d.ts +9 -0
- package/lib/client/rollback/turn-outline-filter.d.ts.map +1 -0
- package/lib/client/rollback/types.d.ts +27 -0
- package/lib/client/rollback/types.d.ts.map +1 -0
- package/lib/client/rollback/undo-tip.d.ts +9 -0
- package/lib/client/rollback/undo-tip.d.ts.map +1 -0
- package/lib/client/rollback/user-node.d.ts +10 -0
- package/lib/client/rollback/user-node.d.ts.map +1 -0
- package/lib/client.js +3597 -0
- package/lib/client.js.map +1 -0
- package/lib/config.d.ts +24 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/errors.d.ts +7 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/host/catalog.d.ts +8 -0
- package/lib/host/catalog.d.ts.map +1 -0
- package/lib/host/checkpoint/availability.d.ts +9 -0
- package/lib/host/checkpoint/availability.d.ts.map +1 -0
- package/lib/host/checkpoint/capture.d.ts +47 -0
- package/lib/host/checkpoint/capture.d.ts.map +1 -0
- package/lib/host/checkpoint/dsh.d.ts +10 -0
- package/lib/host/checkpoint/dsh.d.ts.map +1 -0
- package/lib/host/checkpoint/files.d.ts +69 -0
- package/lib/host/checkpoint/files.d.ts.map +1 -0
- package/lib/host/checkpoint/live.d.ts +34 -0
- package/lib/host/checkpoint/live.d.ts.map +1 -0
- package/lib/host/checkpoint/service.d.ts +98 -0
- package/lib/host/checkpoint/service.d.ts.map +1 -0
- package/lib/host/checkpoint/store.d.ts +28 -0
- package/lib/host/checkpoint/store.d.ts.map +1 -0
- package/lib/host/checkpoint/types.d.ts +47 -0
- package/lib/host/checkpoint/types.d.ts.map +1 -0
- package/lib/host/index.d.ts +88 -0
- package/lib/host/index.d.ts.map +1 -0
- package/lib/host/model.d.ts +21 -0
- package/lib/host/model.d.ts.map +1 -0
- package/lib/host/prompts.d.ts +12 -0
- package/lib/host/prompts.d.ts.map +1 -0
- package/lib/host/rpc.d.ts +135 -0
- package/lib/host/rpc.d.ts.map +1 -0
- package/lib/host/structured.d.ts +12 -0
- package/lib/host/structured.d.ts.map +1 -0
- package/lib/host/types.d.ts +52 -0
- package/lib/host/types.d.ts.map +1 -0
- package/lib/identity.d.ts +17 -0
- package/lib/identity.d.ts.map +1 -0
- package/lib/index.js +2546 -0
- package/lib/index.js.map +7 -0
- package/package.json +152 -4
package/lib/client.js
ADDED
|
@@ -0,0 +1,3597 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({id:"dsh-agent-enhancer",factory:(require)=>{
|
|
2
|
+
var module={exports:{}};var exports=module.exports;
|
|
3
|
+
"use strict";
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// src/client/index.ts
|
|
23
|
+
var index_exports = {};
|
|
24
|
+
__export(index_exports, {
|
|
25
|
+
apply: () => apply,
|
|
26
|
+
inject: () => inject
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
|
+
var import_react8 = require("react");
|
|
30
|
+
|
|
31
|
+
// src/config.ts
|
|
32
|
+
var MODULES = ["history", "optimize", "predict", "rollback"];
|
|
33
|
+
function text(value) {
|
|
34
|
+
return typeof value === "string" ? value : "";
|
|
35
|
+
}
|
|
36
|
+
function resolveSettings(value) {
|
|
37
|
+
return {
|
|
38
|
+
historyEnabled: value?.historyEnabled ?? true,
|
|
39
|
+
optimizeEnabled: value?.optimizeEnabled ?? true,
|
|
40
|
+
predictEnabled: value?.predictEnabled ?? true,
|
|
41
|
+
rollbackEnabled: value?.rollbackEnabled ?? true,
|
|
42
|
+
optimizeProvider: text(value?.optimizeProvider),
|
|
43
|
+
optimizeModel: text(value?.optimizeModel),
|
|
44
|
+
optimizeReasoningEffort: text(value?.optimizeReasoningEffort),
|
|
45
|
+
predictProvider: text(value?.predictProvider),
|
|
46
|
+
predictModel: text(value?.predictModel),
|
|
47
|
+
predictReasoningEffort: text(value?.predictReasoningEffort)
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function auxiliaryModelOf(settings, feature) {
|
|
51
|
+
if (feature === "optimize") {
|
|
52
|
+
return {
|
|
53
|
+
provider: settings.optimizeProvider,
|
|
54
|
+
model: settings.optimizeModel,
|
|
55
|
+
reasoningEffort: settings.optimizeReasoningEffort
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
provider: settings.predictProvider,
|
|
60
|
+
model: settings.predictModel,
|
|
61
|
+
reasoningEffort: settings.predictReasoningEffort
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function isFollowSessionModel(selection) {
|
|
65
|
+
return selection.provider === "" || selection.model === "";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// src/host/prompts.ts
|
|
69
|
+
function resolveUiLocale(id) {
|
|
70
|
+
if (id === void 0 || id === "") return "zh";
|
|
71
|
+
const normalized = id.toLowerCase();
|
|
72
|
+
return normalized === "zh" || normalized.startsWith("zh-") || normalized.startsWith("zh_") ? "zh" : "en";
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/errors.ts
|
|
76
|
+
var MESSAGES = {
|
|
77
|
+
MODEL_UNAVAILABLE: "No model is available for Agent Enhance",
|
|
78
|
+
MODEL_FAILED: "Auxiliary model request failed",
|
|
79
|
+
INVALID_OUTPUT: "Auxiliary model returned invalid output",
|
|
80
|
+
SESSION_CHANGED: "The session changed during the auxiliary request",
|
|
81
|
+
ROLLBACK_FAILED: "The draft could not be restored after a failed write"
|
|
82
|
+
};
|
|
83
|
+
var AuxiliaryError = class extends Error {
|
|
84
|
+
constructor(code) {
|
|
85
|
+
super(MESSAGES[code]);
|
|
86
|
+
this.code = code;
|
|
87
|
+
this.name = "AuxiliaryError";
|
|
88
|
+
}
|
|
89
|
+
code;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// src/client/dsh/structured.ts
|
|
93
|
+
function textSegments(source, occurrences) {
|
|
94
|
+
const segments = [];
|
|
95
|
+
let start = 0;
|
|
96
|
+
for (const occurrence of occurrences) {
|
|
97
|
+
segments.push(source.slice(start, occurrence.offset));
|
|
98
|
+
start = occurrence.offset + occurrence.length;
|
|
99
|
+
}
|
|
100
|
+
segments.push(source.slice(start));
|
|
101
|
+
return segments;
|
|
102
|
+
}
|
|
103
|
+
function detectOffset(offset, occurrences) {
|
|
104
|
+
let result = offset;
|
|
105
|
+
for (const occurrence of occurrences) {
|
|
106
|
+
if (offset <= occurrence.offset) break;
|
|
107
|
+
if (offset < occurrence.offset + occurrence.length) return -1;
|
|
108
|
+
result -= occurrence.length - 1;
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
function replaceAroundOccurrences(actions, source, occurrences, optimizedSegments) {
|
|
113
|
+
if (optimizedSegments.length !== occurrences.length + 1) return false;
|
|
114
|
+
const originalSegments = textSegments(source, occurrences);
|
|
115
|
+
const segmentStarts = [];
|
|
116
|
+
const segmentEnds = [];
|
|
117
|
+
let start = 0;
|
|
118
|
+
for (let i = 0; i < originalSegments.length; i += 1) {
|
|
119
|
+
const occurrence = occurrences[i];
|
|
120
|
+
const end = occurrence === void 0 ? source.length : occurrence.offset;
|
|
121
|
+
segmentStarts.push(start);
|
|
122
|
+
segmentEnds.push(end);
|
|
123
|
+
if (occurrence !== void 0) start = occurrence.offset + occurrence.length;
|
|
124
|
+
}
|
|
125
|
+
for (let i = optimizedSegments.length - 1; i >= 0; i -= 1) {
|
|
126
|
+
const revision = actions.captureInsertion().draftRev;
|
|
127
|
+
if (actions.insertText(optimizedSegments[i], {
|
|
128
|
+
start: detectOffset(segmentStarts[i], occurrences),
|
|
129
|
+
end: detectOffset(segmentEnds[i], occurrences),
|
|
130
|
+
draftRev: revision
|
|
131
|
+
})) continue;
|
|
132
|
+
for (let j = optimizedSegments.length - 1; j > i; j -= 1) {
|
|
133
|
+
let start2 = detectOffset(segmentStarts[j], occurrences);
|
|
134
|
+
for (let k = i + 1; k < j; k += 1) {
|
|
135
|
+
start2 += optimizedSegments[k].length - originalSegments[k].length;
|
|
136
|
+
}
|
|
137
|
+
const rollbackRevision = actions.captureInsertion().draftRev;
|
|
138
|
+
const restored = actions.insertText(originalSegments[j], {
|
|
139
|
+
start: start2,
|
|
140
|
+
end: start2 + optimizedSegments[j].length,
|
|
141
|
+
draftRev: rollbackRevision
|
|
142
|
+
});
|
|
143
|
+
if (!restored) throw new AuxiliaryError("ROLLBACK_FAILED");
|
|
144
|
+
}
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
actions.persistDraft();
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// src/client/prompt/history.ts
|
|
152
|
+
var PromptHistory = class {
|
|
153
|
+
constructor(entries) {
|
|
154
|
+
this.entries = entries;
|
|
155
|
+
const seen = /* @__PURE__ */ new Set();
|
|
156
|
+
this.entries = entries.filter((entry) => {
|
|
157
|
+
if (seen.has(entry.seq)) return false;
|
|
158
|
+
seen.add(entry.seq);
|
|
159
|
+
return true;
|
|
160
|
+
}).sort((a, b) => b.seq - a.seq);
|
|
161
|
+
}
|
|
162
|
+
entries;
|
|
163
|
+
previous(index) {
|
|
164
|
+
if (this.entries.length === 0) return null;
|
|
165
|
+
const nextIndex = index === null ? 0 : Math.min(index + 1, this.entries.length - 1);
|
|
166
|
+
return { text: this.entries[nextIndex].text, index: nextIndex };
|
|
167
|
+
}
|
|
168
|
+
next(index) {
|
|
169
|
+
if (this.entries.length === 0) return null;
|
|
170
|
+
if (index <= 0) return { text: "", index: null };
|
|
171
|
+
const nextIndex = Math.min(index - 1, this.entries.length - 1);
|
|
172
|
+
return { text: this.entries[nextIndex].text, index: nextIndex };
|
|
173
|
+
}
|
|
174
|
+
search(query) {
|
|
175
|
+
const normalized = query.trim().toLocaleLowerCase();
|
|
176
|
+
if (normalized === "") return this.entries;
|
|
177
|
+
return this.entries.filter((entry) => entry.text.toLocaleLowerCase().includes(normalized));
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
// src/client/prompt/coordinator.ts
|
|
182
|
+
var Coordinator = class {
|
|
183
|
+
constructor(writer, switches, clock = Date.now) {
|
|
184
|
+
this.writer = writer;
|
|
185
|
+
this.switches = switches;
|
|
186
|
+
this.clock = clock;
|
|
187
|
+
}
|
|
188
|
+
writer;
|
|
189
|
+
switches;
|
|
190
|
+
clock;
|
|
191
|
+
input = null;
|
|
192
|
+
mode = { kind: "editing" };
|
|
193
|
+
expected = null;
|
|
194
|
+
optimizedEnd = null;
|
|
195
|
+
historyActions = null;
|
|
196
|
+
historyCache = /* @__PURE__ */ new Map();
|
|
197
|
+
historyPending = /* @__PURE__ */ new Map();
|
|
198
|
+
searchEntries = [];
|
|
199
|
+
searchIndex = -1;
|
|
200
|
+
generation = 0;
|
|
201
|
+
disposed = false;
|
|
202
|
+
listeners = /* @__PURE__ */ new Set();
|
|
203
|
+
subscribe(listener) {
|
|
204
|
+
if (this.disposed) return () => {
|
|
205
|
+
};
|
|
206
|
+
this.listeners.add(listener);
|
|
207
|
+
return () => {
|
|
208
|
+
this.listeners.delete(listener);
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
searchSnapshot() {
|
|
212
|
+
if (this.mode.kind !== "search") return null;
|
|
213
|
+
return {
|
|
214
|
+
original: this.mode.original,
|
|
215
|
+
query: this.mode.query,
|
|
216
|
+
entries: this.searchEntries,
|
|
217
|
+
selectedSeq: this.searchEntries[this.searchIndex]?.seq ?? null
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
predictionSnapshot() {
|
|
221
|
+
return this.mode.kind === "prediction" ? this.mode.text : null;
|
|
222
|
+
}
|
|
223
|
+
dismissPrediction() {
|
|
224
|
+
if (this.disposed || this.mode.kind !== "prediction") return;
|
|
225
|
+
this.generation += 1;
|
|
226
|
+
this.resetTransient();
|
|
227
|
+
}
|
|
228
|
+
registerHistory(actions) {
|
|
229
|
+
if (this.disposed) return () => {
|
|
230
|
+
};
|
|
231
|
+
this.generation += 1;
|
|
232
|
+
this.historyActions = actions;
|
|
233
|
+
this.historyCache.clear();
|
|
234
|
+
this.historyPending.clear();
|
|
235
|
+
this.resetTransient();
|
|
236
|
+
return () => {
|
|
237
|
+
if (this.historyActions !== actions) return;
|
|
238
|
+
this.generation += 1;
|
|
239
|
+
this.historyActions = null;
|
|
240
|
+
this.historyPending.clear();
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
refreshSettings() {
|
|
244
|
+
if (this.disposed || this.switches.history()) return;
|
|
245
|
+
if (this.mode.kind !== "history" && this.mode.kind !== "search") return;
|
|
246
|
+
this.generation += 1;
|
|
247
|
+
this.resetTransient();
|
|
248
|
+
}
|
|
249
|
+
sync(input) {
|
|
250
|
+
if (this.disposed) return;
|
|
251
|
+
const previous = this.input;
|
|
252
|
+
const sessionChanged = previous !== null && previous.sessionId !== input.sessionId;
|
|
253
|
+
const revisionChanged = previous !== null && (previous.sessionId !== input.sessionId || previous.draftRev !== input.draftRev);
|
|
254
|
+
const draftChanged = previous !== null && previous.draft !== input.draft;
|
|
255
|
+
const structureChanged = previous !== null && !sameOccurrences(previous.occurrences, input.occurrences);
|
|
256
|
+
const turnStarted = previous !== null && !previous.running && input.running;
|
|
257
|
+
if (sessionChanged || revisionChanged || draftChanged || structureChanged || turnStarted) this.generation += 1;
|
|
258
|
+
const preserve = previous !== null && !sessionChanged && revisionChanged && this.expected !== null && this.expected.sessionId === input.sessionId && this.expected.text === input.draft && this.expected.kind === this.mode.kind;
|
|
259
|
+
this.input = {
|
|
260
|
+
...input,
|
|
261
|
+
selection: { ...input.selection }
|
|
262
|
+
};
|
|
263
|
+
if (!preserve && (sessionChanged || revisionChanged || draftChanged || structureChanged || turnStarted)) this.resetTransient();
|
|
264
|
+
this.expected = null;
|
|
265
|
+
}
|
|
266
|
+
showPrediction(result) {
|
|
267
|
+
if (!this.current(result.guard) || !this.switches.predict() || this.input?.draft !== "") return false;
|
|
268
|
+
this.generation += 1;
|
|
269
|
+
this.mode = { kind: "prediction", text: result.text, guard: result.guard };
|
|
270
|
+
this.expected = null;
|
|
271
|
+
this.emit();
|
|
272
|
+
return true;
|
|
273
|
+
}
|
|
274
|
+
applyOptimization(result) {
|
|
275
|
+
if (!this.current(result.guard) || !this.switches.optimize() || this.input === null) return false;
|
|
276
|
+
if (result.fullDraft === true && this.input.draft !== result.source) return false;
|
|
277
|
+
const selection = result.selection ?? this.selection();
|
|
278
|
+
if (selection.sessionId !== result.guard.sessionId || selection.draftRev !== result.guard.draftRev || selection.start < 0 || selection.end < selection.start || selection.end > this.input.draft.length) return false;
|
|
279
|
+
const source = this.input.draft.slice(selection.start, selection.end);
|
|
280
|
+
if (result.source !== void 0 && result.source !== source) return false;
|
|
281
|
+
const occurrences = selection.occurrences;
|
|
282
|
+
if (selection.structured === true) {
|
|
283
|
+
if (result.fullDraft !== true || selection.start !== 0 || selection.end !== source.length || occurrences === void 0 || result.segments === void 0 || result.segments.length !== occurrences.length + 1 || !sameOccurrences(occurrences, this.input.occurrences)) return false;
|
|
284
|
+
if (result.sourceSegments !== void 0 && !sameSegments(textSegments(source, occurrences), result.sourceSegments)) return false;
|
|
285
|
+
}
|
|
286
|
+
if (!this.writer.replace(result.text, selection, result.segments, source)) return false;
|
|
287
|
+
this.generation += 1;
|
|
288
|
+
const draft = this.input.draft.slice(0, selection.start) + result.text + this.input.draft.slice(selection.end);
|
|
289
|
+
this.mode = {
|
|
290
|
+
kind: "optimized",
|
|
291
|
+
original: selection,
|
|
292
|
+
source,
|
|
293
|
+
sourceSegments: result.sourceSegments,
|
|
294
|
+
optimizedSegments: result.segments
|
|
295
|
+
};
|
|
296
|
+
this.optimizedEnd = selection.start + result.text.length;
|
|
297
|
+
this.expected = { sessionId: selection.sessionId, text: draft, kind: "optimized" };
|
|
298
|
+
this.updateLocalDraft(draft, this.optimizedEnd);
|
|
299
|
+
return true;
|
|
300
|
+
}
|
|
301
|
+
undoOptimization(cache) {
|
|
302
|
+
if (this.disposed || this.input === null || this.input.sessionId !== cache.selection.sessionId) return false;
|
|
303
|
+
const end = cache.selection.start + cache.optimized.length;
|
|
304
|
+
if (this.input.draft.slice(cache.selection.start, end) !== cache.optimized) return false;
|
|
305
|
+
const structured = cache.selection.structured === true;
|
|
306
|
+
if (structured && (cache.sourceSegments === void 0 || cache.optimizedSegments === void 0 || cache.optimizedSegments.length !== this.input.occurrences.length + 1 || !sameOptimizedOccurrences(
|
|
307
|
+
cache.selection.occurrences,
|
|
308
|
+
this.input.occurrences,
|
|
309
|
+
cache.sourceSegments,
|
|
310
|
+
cache.optimizedSegments
|
|
311
|
+
) || !sameSegments(textSegments(this.input.draft, this.input.occurrences), cache.optimizedSegments))) return false;
|
|
312
|
+
const selection = {
|
|
313
|
+
sessionId: this.input.sessionId,
|
|
314
|
+
draftRev: this.input.draftRev,
|
|
315
|
+
start: cache.selection.start,
|
|
316
|
+
end,
|
|
317
|
+
...this.input.occurrences.length > 0 ? { occurrences: this.input.occurrences } : {},
|
|
318
|
+
...structured ? { structured: true } : {}
|
|
319
|
+
};
|
|
320
|
+
if (!this.writer.replace(cache.source, selection, cache.sourceSegments, this.input.draft)) return false;
|
|
321
|
+
const restored = this.input.draft.slice(0, selection.start) + cache.source + this.input.draft.slice(end);
|
|
322
|
+
this.generation += 1;
|
|
323
|
+
this.resetTransient();
|
|
324
|
+
this.updateLocalDraft(restored, selection.start + cache.source.length);
|
|
325
|
+
return true;
|
|
326
|
+
}
|
|
327
|
+
updateSearch(query) {
|
|
328
|
+
if (this.disposed || this.mode.kind !== "search" || this.input === null) return false;
|
|
329
|
+
const entries = this.historyCache.get(this.input.sessionId)?.entries ?? [];
|
|
330
|
+
this.searchEntries = new PromptHistory(entries).search(query);
|
|
331
|
+
this.searchIndex = this.searchEntries.length > 0 ? 0 : -1;
|
|
332
|
+
this.mode = { ...this.mode, query };
|
|
333
|
+
this.emit();
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
handleKey(key, context) {
|
|
337
|
+
if (this.disposed || context.composing || context.systemLayerOpen) return false;
|
|
338
|
+
if (context.officialMenuOpen) {
|
|
339
|
+
if (this.mode.kind === "history" || this.mode.kind === "search") {
|
|
340
|
+
this.generation += 1;
|
|
341
|
+
this.resetTransient();
|
|
342
|
+
}
|
|
343
|
+
return false;
|
|
344
|
+
}
|
|
345
|
+
if (key === "tab" && this.mode.kind === "prediction") return this.acceptPrediction();
|
|
346
|
+
if (key === "escape" && this.dismissTransient()) return true;
|
|
347
|
+
if (this.switches.history() && key === "search") return this.openSearch();
|
|
348
|
+
if (this.switches.history() && key === "up" && context.atFirstLine) return this.historyPrevious();
|
|
349
|
+
if (this.switches.history() && key === "down" && context.atLastLine) return this.historyNext();
|
|
350
|
+
if (key === "enter" && this.mode.kind === "search") return this.acceptSearchCandidate();
|
|
351
|
+
return false;
|
|
352
|
+
}
|
|
353
|
+
dispose() {
|
|
354
|
+
if (this.disposed) return;
|
|
355
|
+
this.disposed = true;
|
|
356
|
+
this.generation += 1;
|
|
357
|
+
this.historyActions = null;
|
|
358
|
+
this.historyPending.clear();
|
|
359
|
+
this.resetTransient();
|
|
360
|
+
}
|
|
361
|
+
current(guard) {
|
|
362
|
+
return !this.disposed && this.input !== null && this.input.sessionId === guard.sessionId && this.input.draftRev === guard.draftRev;
|
|
363
|
+
}
|
|
364
|
+
selection() {
|
|
365
|
+
if (this.input === null) throw new Error("Prompt session is not synchronized");
|
|
366
|
+
return {
|
|
367
|
+
sessionId: this.input.sessionId,
|
|
368
|
+
draftRev: this.input.draftRev,
|
|
369
|
+
start: this.input.selection.start,
|
|
370
|
+
end: this.input.selection.end
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
snapshot() {
|
|
374
|
+
if (this.input === null) throw new Error("Prompt session is not synchronized");
|
|
375
|
+
return { ...this.selection(), text: this.input.draft };
|
|
376
|
+
}
|
|
377
|
+
resetTransient() {
|
|
378
|
+
this.mode = { kind: "editing" };
|
|
379
|
+
this.expected = null;
|
|
380
|
+
this.optimizedEnd = null;
|
|
381
|
+
this.searchEntries = [];
|
|
382
|
+
this.searchIndex = -1;
|
|
383
|
+
this.emit();
|
|
384
|
+
}
|
|
385
|
+
emit() {
|
|
386
|
+
for (const listener of this.listeners) listener();
|
|
387
|
+
}
|
|
388
|
+
updateLocalDraft(text2, caret) {
|
|
389
|
+
if (this.input === null) return;
|
|
390
|
+
this.input = { ...this.input, draft: text2, selection: { start: caret, end: caret } };
|
|
391
|
+
}
|
|
392
|
+
acceptPrediction() {
|
|
393
|
+
if (this.mode.kind !== "prediction" || !this.current(this.mode.guard) || !this.switches.predict()) return false;
|
|
394
|
+
const text2 = this.mode.text;
|
|
395
|
+
this.generation += 1;
|
|
396
|
+
this.mode = { kind: "editing" };
|
|
397
|
+
this.writer.setDraft(text2, text2.length);
|
|
398
|
+
this.updateLocalDraft(text2, text2.length);
|
|
399
|
+
this.emit();
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
402
|
+
acceptHistory(entry, guard) {
|
|
403
|
+
if (this.mode.kind !== "search" || !this.current(guard) || !this.searchEntries.some((candidate) => candidate.seq === entry.seq && candidate.text === entry.text)) return false;
|
|
404
|
+
this.generation += 1;
|
|
405
|
+
this.resetTransient();
|
|
406
|
+
this.writer.setDraft(entry.text, entry.text.length);
|
|
407
|
+
this.updateLocalDraft(entry.text, entry.text.length);
|
|
408
|
+
return true;
|
|
409
|
+
}
|
|
410
|
+
dismissTransient() {
|
|
411
|
+
if (this.input === null || this.mode.kind === "editing") return false;
|
|
412
|
+
if (this.mode.kind === "prediction") {
|
|
413
|
+
this.generation += 1;
|
|
414
|
+
this.resetTransient();
|
|
415
|
+
return true;
|
|
416
|
+
}
|
|
417
|
+
if (this.mode.kind === "history" || this.mode.kind === "search") {
|
|
418
|
+
this.restoreOriginal(this.mode.original);
|
|
419
|
+
return true;
|
|
420
|
+
}
|
|
421
|
+
const mode = this.mode;
|
|
422
|
+
if (this.optimizedEnd === null) return false;
|
|
423
|
+
const structured = mode.original.structured === true;
|
|
424
|
+
if (structured && (mode.sourceSegments === void 0 || mode.optimizedSegments === void 0 || !sameOptimizedOccurrences(
|
|
425
|
+
mode.original.occurrences,
|
|
426
|
+
this.input.occurrences,
|
|
427
|
+
mode.sourceSegments,
|
|
428
|
+
mode.optimizedSegments
|
|
429
|
+
))) return false;
|
|
430
|
+
const end = this.optimizedEnd;
|
|
431
|
+
const selection = {
|
|
432
|
+
sessionId: this.input.sessionId,
|
|
433
|
+
draftRev: this.input.draftRev,
|
|
434
|
+
start: mode.original.start,
|
|
435
|
+
end,
|
|
436
|
+
...this.input.occurrences.length > 0 ? { occurrences: this.input.occurrences } : {},
|
|
437
|
+
...structured ? { structured: true } : {}
|
|
438
|
+
};
|
|
439
|
+
if (!this.writer.replace(mode.source, selection, mode.sourceSegments, this.input.draft)) return false;
|
|
440
|
+
const restored = this.input.draft.slice(0, mode.original.start) + mode.source + this.input.draft.slice(end);
|
|
441
|
+
this.generation += 1;
|
|
442
|
+
this.resetTransient();
|
|
443
|
+
this.updateLocalDraft(restored, mode.original.start + mode.source.length);
|
|
444
|
+
return true;
|
|
445
|
+
}
|
|
446
|
+
restoreOriginal(original) {
|
|
447
|
+
this.generation += 1;
|
|
448
|
+
this.resetTransient();
|
|
449
|
+
this.writer.setDraft(original.text, original.end);
|
|
450
|
+
this.updateLocalDraft(original.text, original.end);
|
|
451
|
+
}
|
|
452
|
+
openSearch() {
|
|
453
|
+
if (this.input === null || this.historyActions === null) return false;
|
|
454
|
+
this.generation += 1;
|
|
455
|
+
const original = this.snapshot();
|
|
456
|
+
const generation = this.generation;
|
|
457
|
+
const guard = guardOf(this.input);
|
|
458
|
+
this.mode = { kind: "search", original, query: "" };
|
|
459
|
+
this.searchEntries = [];
|
|
460
|
+
this.searchIndex = -1;
|
|
461
|
+
this.emit();
|
|
462
|
+
const entries = this.loadHistory(this.input.sessionId);
|
|
463
|
+
if (Array.isArray(entries)) {
|
|
464
|
+
this.updateSearch("");
|
|
465
|
+
} else {
|
|
466
|
+
void Promise.resolve(entries).then((loaded) => {
|
|
467
|
+
if (this.disposed || generation !== this.generation || !this.current(guard) || this.mode.kind !== "search") return;
|
|
468
|
+
this.updateSearch(this.mode.query);
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
return true;
|
|
472
|
+
}
|
|
473
|
+
historyPrevious() {
|
|
474
|
+
if (this.input === null || this.historyActions === null) return false;
|
|
475
|
+
if (this.mode.kind === "search") {
|
|
476
|
+
if (this.searchIndex < 0) return true;
|
|
477
|
+
this.searchIndex = Math.min(this.searchIndex + 1, this.searchEntries.length - 1);
|
|
478
|
+
this.emit();
|
|
479
|
+
return true;
|
|
480
|
+
}
|
|
481
|
+
const original = this.mode.kind === "history" ? this.mode.original : this.snapshot();
|
|
482
|
+
const index = this.mode.kind === "history" ? this.mode.index : null;
|
|
483
|
+
const generation = this.generation;
|
|
484
|
+
const guard = guardOf(this.input);
|
|
485
|
+
const entries = this.loadHistory(this.input.sessionId);
|
|
486
|
+
if (Array.isArray(entries)) {
|
|
487
|
+
this.selectHistory(new PromptHistory(entries).previous(index), original);
|
|
488
|
+
} else {
|
|
489
|
+
void Promise.resolve(entries).then((loaded) => {
|
|
490
|
+
if (this.disposed || generation !== this.generation || !this.current(guard)) return;
|
|
491
|
+
this.selectHistory(new PromptHistory(loaded).previous(index), original);
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
return true;
|
|
495
|
+
}
|
|
496
|
+
historyNext() {
|
|
497
|
+
if (this.input === null) return false;
|
|
498
|
+
if (this.mode.kind === "search") {
|
|
499
|
+
if (this.searchIndex >= 0) {
|
|
500
|
+
this.searchIndex -= 1;
|
|
501
|
+
this.emit();
|
|
502
|
+
}
|
|
503
|
+
return true;
|
|
504
|
+
}
|
|
505
|
+
if (this.mode.kind !== "history") return false;
|
|
506
|
+
const entries = this.historyCache.get(this.input.sessionId)?.entries ?? [];
|
|
507
|
+
const selected = new PromptHistory(entries).next(this.mode.index);
|
|
508
|
+
if (selected === null) return true;
|
|
509
|
+
if (selected.index === null) {
|
|
510
|
+
this.restoreOriginal(this.mode.original);
|
|
511
|
+
return true;
|
|
512
|
+
}
|
|
513
|
+
this.selectHistory(selected, this.mode.original);
|
|
514
|
+
return true;
|
|
515
|
+
}
|
|
516
|
+
selectHistory(selected, original) {
|
|
517
|
+
if (this.input === null || selected === null || selected.index === null) return;
|
|
518
|
+
const selection = {
|
|
519
|
+
sessionId: this.input.sessionId,
|
|
520
|
+
draftRev: this.input.draftRev,
|
|
521
|
+
start: 0,
|
|
522
|
+
end: this.input.draft.length
|
|
523
|
+
};
|
|
524
|
+
if (!this.writer.replace(selected.text, selection)) return;
|
|
525
|
+
this.mode = { kind: "history", original, index: selected.index };
|
|
526
|
+
this.expected = { sessionId: selection.sessionId, text: selected.text, kind: "history" };
|
|
527
|
+
this.updateLocalDraft(selected.text, selected.text.length);
|
|
528
|
+
}
|
|
529
|
+
loadHistory(sessionId) {
|
|
530
|
+
const cached = this.historyCache.get(sessionId);
|
|
531
|
+
if (cached !== void 0) return cached.entries;
|
|
532
|
+
const pending = this.historyPending.get(sessionId);
|
|
533
|
+
if (pending !== void 0) return pending;
|
|
534
|
+
const actions = this.historyActions;
|
|
535
|
+
if (actions === null) return [];
|
|
536
|
+
try {
|
|
537
|
+
const loaded = actions.load(sessionId);
|
|
538
|
+
if (Array.isArray(loaded)) {
|
|
539
|
+
this.historyCache.set(sessionId, { entries: loaded, cachedAt: this.clock() });
|
|
540
|
+
return loaded;
|
|
541
|
+
}
|
|
542
|
+
const request = Promise.resolve(loaded).then((entries) => {
|
|
543
|
+
this.historyPending.delete(sessionId);
|
|
544
|
+
if (!this.disposed && this.historyActions === actions) {
|
|
545
|
+
this.historyCache.set(sessionId, { entries, cachedAt: this.clock() });
|
|
546
|
+
}
|
|
547
|
+
return entries;
|
|
548
|
+
}, () => {
|
|
549
|
+
this.historyPending.delete(sessionId);
|
|
550
|
+
return [];
|
|
551
|
+
});
|
|
552
|
+
this.historyPending.set(sessionId, request);
|
|
553
|
+
return request;
|
|
554
|
+
} catch {
|
|
555
|
+
return [];
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
acceptSearchCandidate() {
|
|
559
|
+
if (this.mode.kind !== "search") return false;
|
|
560
|
+
const entry = this.searchEntries[this.searchIndex];
|
|
561
|
+
if (entry === void 0) return false;
|
|
562
|
+
return this.acceptHistory(entry, this.mode.original);
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
function guardOf(input) {
|
|
566
|
+
return { sessionId: input.sessionId, draftRev: input.draftRev };
|
|
567
|
+
}
|
|
568
|
+
function sameOccurrences(left, right) {
|
|
569
|
+
return left.length === right.length && left.every((occurrence, index) => {
|
|
570
|
+
const other = right[index];
|
|
571
|
+
return occurrence.occurrenceId === other.occurrenceId && occurrence.source === other.source && occurrence.ref === other.ref && occurrence.offset === other.offset && occurrence.length === other.length && occurrence.label === other.label && occurrence.clipboardText === other.clipboardText && occurrence.appearance === other.appearance && occurrence.invalid === other.invalid;
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
function sameOptimizedOccurrences(original, current, sourceSegments, optimizedSegments) {
|
|
575
|
+
if (original === void 0 || sourceSegments.length !== original.length + 1 || optimizedSegments.length !== original.length + 1) return false;
|
|
576
|
+
let shift = 0;
|
|
577
|
+
const expected = original.map((occurrence, index) => {
|
|
578
|
+
shift += optimizedSegments[index].length - sourceSegments[index].length;
|
|
579
|
+
return { ...occurrence, offset: occurrence.offset + shift };
|
|
580
|
+
});
|
|
581
|
+
return sameOccurrences(expected, current);
|
|
582
|
+
}
|
|
583
|
+
function sameSegments(left, right) {
|
|
584
|
+
return left.length === right.length && left.every((segment, index) => segment === right[index]);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// src/client/prompt/optimize.ts
|
|
588
|
+
var OptimizationStore = class {
|
|
589
|
+
value = null;
|
|
590
|
+
read(source) {
|
|
591
|
+
return this.value?.source === source ? this.value : null;
|
|
592
|
+
}
|
|
593
|
+
write(cache) {
|
|
594
|
+
this.value = cache;
|
|
595
|
+
}
|
|
596
|
+
invalidate() {
|
|
597
|
+
this.value = null;
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
var requestSequence = 0;
|
|
601
|
+
var OptimizationController = class {
|
|
602
|
+
constructor(coordinator, generate) {
|
|
603
|
+
this.coordinator = coordinator;
|
|
604
|
+
this.generate = generate;
|
|
605
|
+
}
|
|
606
|
+
coordinator;
|
|
607
|
+
generate;
|
|
608
|
+
store = new OptimizationStore();
|
|
609
|
+
cache = null;
|
|
610
|
+
cacheSourceDraft = null;
|
|
611
|
+
cacheOptimizedDraft = null;
|
|
612
|
+
current = null;
|
|
613
|
+
pending = null;
|
|
614
|
+
view = { status: "optimize", error: null };
|
|
615
|
+
enabled = true;
|
|
616
|
+
disposed = false;
|
|
617
|
+
listeners = /* @__PURE__ */ new Set();
|
|
618
|
+
subscribe(listener) {
|
|
619
|
+
if (this.disposed) return () => {
|
|
620
|
+
};
|
|
621
|
+
this.listeners.add(listener);
|
|
622
|
+
return () => {
|
|
623
|
+
this.listeners.delete(listener);
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
getSnapshot() {
|
|
627
|
+
return this.view;
|
|
628
|
+
}
|
|
629
|
+
sync(snapshot) {
|
|
630
|
+
if (this.disposed) return;
|
|
631
|
+
const sessionChanged = this.current !== null && this.current.sessionId !== snapshot.sessionId;
|
|
632
|
+
if (this.view.error === "ROLLBACK_FAILED" && !sessionChanged) {
|
|
633
|
+
this.current = { ...snapshot };
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
const textChanged = this.current !== null && (this.current.sessionId !== snapshot.sessionId || this.current.text !== snapshot.text);
|
|
637
|
+
this.current = { ...snapshot };
|
|
638
|
+
const cache = this.readCache();
|
|
639
|
+
if (cache !== null) {
|
|
640
|
+
const optimizedVisible = cache.selection.sessionId === snapshot.sessionId && snapshot.text === this.cacheOptimizedDraft;
|
|
641
|
+
const sourceVisible = cache.selection.sessionId === snapshot.sessionId && snapshot.text === this.cacheSourceDraft;
|
|
642
|
+
if (!optimizedVisible && !sourceVisible) this.invalidate();
|
|
643
|
+
else if (this.pending === null) this.setView(optimizedVisible ? "undo" : "optimize", textChanged ? null : this.view.error);
|
|
644
|
+
} else if (this.pending === null && this.view.status === "undo") {
|
|
645
|
+
this.setView("optimize", null);
|
|
646
|
+
}
|
|
647
|
+
if (textChanged && this.view.error) this.setView(this.view.status, null);
|
|
648
|
+
}
|
|
649
|
+
async start(snapshot, context) {
|
|
650
|
+
if (this.disposed || !this.enabled || this.pending !== null || this.view.error === "ROLLBACK_FAILED") return;
|
|
651
|
+
this.current = { ...snapshot };
|
|
652
|
+
const cached = this.readCache();
|
|
653
|
+
if (cached !== null && cached.selection.sessionId === snapshot.sessionId && snapshot.text === this.cacheSourceDraft && cached.selection.structured === true === (snapshot.structured === true) && (snapshot.start === snapshot.end || snapshot.start === cached.selection.start && snapshot.end === cached.selection.end)) {
|
|
654
|
+
try {
|
|
655
|
+
const selection2 = { ...cached.selection, draftRev: snapshot.draftRev };
|
|
656
|
+
const applied = this.coordinator.applyOptimization({
|
|
657
|
+
text: cached.optimized,
|
|
658
|
+
guard: { sessionId: selection2.sessionId, draftRev: selection2.draftRev },
|
|
659
|
+
source: cached.source,
|
|
660
|
+
selection: selection2,
|
|
661
|
+
fullDraft: cached.source === this.cacheSourceDraft,
|
|
662
|
+
segments: cached.optimizedSegments,
|
|
663
|
+
sourceSegments: cached.sourceSegments
|
|
664
|
+
});
|
|
665
|
+
if (applied) this.setView("undo", null);
|
|
666
|
+
} catch (error) {
|
|
667
|
+
this.handleError(error);
|
|
668
|
+
}
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
const selected = snapshot.start !== snapshot.end;
|
|
672
|
+
const structured = !selected && snapshot.structured === true;
|
|
673
|
+
const occurrences = structured ? snapshot.occurrences : void 0;
|
|
674
|
+
if (structured && occurrences === void 0) return;
|
|
675
|
+
const selection = {
|
|
676
|
+
sessionId: snapshot.sessionId,
|
|
677
|
+
draftRev: snapshot.draftRev,
|
|
678
|
+
start: selected ? snapshot.start : 0,
|
|
679
|
+
end: selected ? snapshot.end : snapshot.text.length,
|
|
680
|
+
...snapshot.occurrences === void 0 ? {} : { occurrences: snapshot.occurrences },
|
|
681
|
+
...structured ? { structured: true } : {}
|
|
682
|
+
};
|
|
683
|
+
const source = snapshot.text.slice(selection.start, selection.end);
|
|
684
|
+
if (source.trim() === "") return;
|
|
685
|
+
const sourceSegments = structured ? textSegments(source, occurrences) : void 0;
|
|
686
|
+
this.invalidate();
|
|
687
|
+
const requestId = `optimize-${++requestSequence}`;
|
|
688
|
+
const pending = { requestId, abort: new AbortController() };
|
|
689
|
+
this.pending = pending;
|
|
690
|
+
this.setView("pending", null);
|
|
691
|
+
try {
|
|
692
|
+
const result = await this.generate({
|
|
693
|
+
operation: "optimize",
|
|
694
|
+
requestId,
|
|
695
|
+
sessionId: selection.sessionId,
|
|
696
|
+
source,
|
|
697
|
+
references: occurrences?.map((occurrence) => ({
|
|
698
|
+
offset: occurrence.offset,
|
|
699
|
+
length: occurrence.length,
|
|
700
|
+
text: occurrence.clipboardText
|
|
701
|
+
})) ?? [],
|
|
702
|
+
context
|
|
703
|
+
}, pending.abort.signal);
|
|
704
|
+
if (this.pending !== pending || this.disposed) return;
|
|
705
|
+
this.pending = null;
|
|
706
|
+
if (result === null) {
|
|
707
|
+
this.setView("optimize", "MODEL_FAILED");
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
710
|
+
if (result.requestId !== requestId) {
|
|
711
|
+
this.setView("optimize", null);
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
const optimizedSegments = structured ? result.segments : void 0;
|
|
715
|
+
const applied = this.coordinator.applyOptimization({
|
|
716
|
+
text: result.text,
|
|
717
|
+
guard: { sessionId: selection.sessionId, draftRev: selection.draftRev },
|
|
718
|
+
source,
|
|
719
|
+
selection,
|
|
720
|
+
fullDraft: !selected,
|
|
721
|
+
segments: optimizedSegments,
|
|
722
|
+
sourceSegments
|
|
723
|
+
});
|
|
724
|
+
if (!applied) {
|
|
725
|
+
this.setView("optimize", null);
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
728
|
+
this.cache = { source, optimized: result.text, selection, sourceSegments, optimizedSegments };
|
|
729
|
+
this.cacheSourceDraft = snapshot.text;
|
|
730
|
+
this.cacheOptimizedDraft = snapshot.text.slice(0, selection.start) + result.text + snapshot.text.slice(selection.end);
|
|
731
|
+
this.store.write(this.cache);
|
|
732
|
+
this.setView("undo", null);
|
|
733
|
+
} catch (error) {
|
|
734
|
+
if (this.disposed || this.pending !== null && this.pending !== pending) return;
|
|
735
|
+
const code = error instanceof AuxiliaryError ? error.code : "MODEL_FAILED";
|
|
736
|
+
if (this.pending !== pending && code !== "ROLLBACK_FAILED") return;
|
|
737
|
+
this.pending = null;
|
|
738
|
+
this.setView("optimize", pending.abort.signal.aborted ? null : code);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
handleError(error) {
|
|
742
|
+
if (this.disposed) return;
|
|
743
|
+
this.pending = null;
|
|
744
|
+
this.setView("optimize", error instanceof AuxiliaryError ? error.code : "MODEL_FAILED");
|
|
745
|
+
}
|
|
746
|
+
undo() {
|
|
747
|
+
if (this.disposed || !this.enabled || this.pending !== null) return false;
|
|
748
|
+
const cache = this.readCache();
|
|
749
|
+
if (cache === null) return false;
|
|
750
|
+
try {
|
|
751
|
+
const restored = this.coordinator.undoOptimization(cache);
|
|
752
|
+
if (restored) this.setView("optimize", null);
|
|
753
|
+
return restored;
|
|
754
|
+
} catch (error) {
|
|
755
|
+
this.handleError(error);
|
|
756
|
+
return false;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
setEnabled(enabled) {
|
|
760
|
+
if (this.disposed || this.enabled === enabled) return;
|
|
761
|
+
this.enabled = enabled;
|
|
762
|
+
if (!enabled) {
|
|
763
|
+
this.cancel();
|
|
764
|
+
this.invalidate();
|
|
765
|
+
this.setView("optimize", null);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
dispose() {
|
|
769
|
+
if (this.disposed) return;
|
|
770
|
+
this.disposed = true;
|
|
771
|
+
this.cancel();
|
|
772
|
+
this.invalidate();
|
|
773
|
+
this.setView("optimize", null);
|
|
774
|
+
this.listeners.clear();
|
|
775
|
+
}
|
|
776
|
+
readCache() {
|
|
777
|
+
if (this.cache === null) return null;
|
|
778
|
+
const cached = this.store.read(this.cache.source);
|
|
779
|
+
if (cached === null) this.cache = null;
|
|
780
|
+
return cached;
|
|
781
|
+
}
|
|
782
|
+
invalidate() {
|
|
783
|
+
this.cache = null;
|
|
784
|
+
this.cacheSourceDraft = null;
|
|
785
|
+
this.cacheOptimizedDraft = null;
|
|
786
|
+
this.store.invalidate();
|
|
787
|
+
}
|
|
788
|
+
cancel() {
|
|
789
|
+
const pending = this.pending;
|
|
790
|
+
this.pending = null;
|
|
791
|
+
pending?.abort.abort();
|
|
792
|
+
}
|
|
793
|
+
setView(status, error) {
|
|
794
|
+
if (this.view.status === status && this.view.error === error) return;
|
|
795
|
+
this.view = { status, error };
|
|
796
|
+
for (const listener of this.listeners) listener();
|
|
797
|
+
}
|
|
798
|
+
};
|
|
799
|
+
|
|
800
|
+
// src/client/prompt/predict.ts
|
|
801
|
+
var PredictionGate = class {
|
|
802
|
+
requested = /* @__PURE__ */ new Set();
|
|
803
|
+
shouldStart(request, running, draft) {
|
|
804
|
+
const key = `${String(request.sessionId)}:${request.turn}`;
|
|
805
|
+
return !running && draft === "" && request.turn > 0 && !this.requested.has(key);
|
|
806
|
+
}
|
|
807
|
+
mark(request) {
|
|
808
|
+
this.requested.add(`${String(request.sessionId)}:${request.turn}`);
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
var requestSequence2 = 0;
|
|
812
|
+
var PredictionController = class {
|
|
813
|
+
constructor(coordinator, generate) {
|
|
814
|
+
this.coordinator = coordinator;
|
|
815
|
+
this.generate = generate;
|
|
816
|
+
}
|
|
817
|
+
coordinator;
|
|
818
|
+
generate;
|
|
819
|
+
gate = new PredictionGate();
|
|
820
|
+
current = null;
|
|
821
|
+
pending = null;
|
|
822
|
+
enabled = true;
|
|
823
|
+
disposed = false;
|
|
824
|
+
sync(input, context) {
|
|
825
|
+
if (this.disposed) return;
|
|
826
|
+
const previous = this.current;
|
|
827
|
+
const turn = context.at(-1)?.turn ?? 0;
|
|
828
|
+
this.current = { input: { ...input, selection: { ...input.selection } }, turn };
|
|
829
|
+
if (previous !== null && previous.turn !== turn) this.coordinator.dismissPrediction();
|
|
830
|
+
if (this.pending !== null && !this.matches(this.pending)) this.cancel();
|
|
831
|
+
if (!this.enabled || String(input.sessionId).trim() === "") return;
|
|
832
|
+
const request = { sessionId: input.sessionId, turn, draftRev: input.draftRev, context };
|
|
833
|
+
if (!this.gate.shouldStart(request, input.running, input.draft)) return;
|
|
834
|
+
this.gate.mark(request);
|
|
835
|
+
const pending = {
|
|
836
|
+
requestId: `predict-${++requestSequence2}`,
|
|
837
|
+
sessionId: input.sessionId,
|
|
838
|
+
turn,
|
|
839
|
+
draftRev: input.draftRev,
|
|
840
|
+
abort: new AbortController()
|
|
841
|
+
};
|
|
842
|
+
this.pending = pending;
|
|
843
|
+
void this.start(pending, context);
|
|
844
|
+
}
|
|
845
|
+
setEnabled(enabled) {
|
|
846
|
+
if (this.disposed || this.enabled === enabled) return;
|
|
847
|
+
this.enabled = enabled;
|
|
848
|
+
if (!enabled) this.cancel();
|
|
849
|
+
}
|
|
850
|
+
cancel() {
|
|
851
|
+
const pending = this.pending;
|
|
852
|
+
this.pending = null;
|
|
853
|
+
pending?.abort.abort();
|
|
854
|
+
this.coordinator.dismissPrediction();
|
|
855
|
+
}
|
|
856
|
+
dispose() {
|
|
857
|
+
if (this.disposed) return;
|
|
858
|
+
this.disposed = true;
|
|
859
|
+
this.cancel();
|
|
860
|
+
}
|
|
861
|
+
matches(pending) {
|
|
862
|
+
return this.current !== null && this.current.input.sessionId === pending.sessionId && this.current.turn === pending.turn && this.current.input.draftRev === pending.draftRev && this.current.input.draft === "" && !this.current.input.running;
|
|
863
|
+
}
|
|
864
|
+
async start(pending, context) {
|
|
865
|
+
try {
|
|
866
|
+
const result = await this.generate({
|
|
867
|
+
operation: "predict",
|
|
868
|
+
requestId: pending.requestId,
|
|
869
|
+
sessionId: pending.sessionId,
|
|
870
|
+
context
|
|
871
|
+
}, pending.abort.signal);
|
|
872
|
+
if (this.pending !== pending || this.disposed) return;
|
|
873
|
+
this.pending = null;
|
|
874
|
+
if (!this.enabled || !this.matches(pending) || result === null || result.requestId !== pending.requestId) return;
|
|
875
|
+
const text2 = result.text.trim();
|
|
876
|
+
if (text2 === "") return;
|
|
877
|
+
this.coordinator.showPrediction({
|
|
878
|
+
text: text2,
|
|
879
|
+
guard: { sessionId: pending.sessionId, draftRev: pending.draftRev }
|
|
880
|
+
});
|
|
881
|
+
} catch {
|
|
882
|
+
if (this.pending === pending) this.pending = null;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
};
|
|
886
|
+
|
|
887
|
+
// src/client/prompt/session.ts
|
|
888
|
+
var PromptSession = class {
|
|
889
|
+
constructor(switches, generateOptimization, generatePrediction) {
|
|
890
|
+
this.switches = switches;
|
|
891
|
+
const writer = {
|
|
892
|
+
replace: (text2, selection, segments, source) => this.writer?.replace(text2, selection, segments, source) ?? false,
|
|
893
|
+
setDraft: (text2, caret) => {
|
|
894
|
+
this.writer?.setDraft(text2, caret);
|
|
895
|
+
}
|
|
896
|
+
};
|
|
897
|
+
this.coordinator = new Coordinator(writer, switches);
|
|
898
|
+
this.optimization = new OptimizationController(this.coordinator, generateOptimization);
|
|
899
|
+
this.prediction = new PredictionController(this.coordinator, generatePrediction);
|
|
900
|
+
const state = this.optimization.getSnapshot();
|
|
901
|
+
this.controls = {
|
|
902
|
+
...state,
|
|
903
|
+
enabled: switches.optimize(),
|
|
904
|
+
canOptimize: false,
|
|
905
|
+
hasChips: false,
|
|
906
|
+
chipSelection: false
|
|
907
|
+
};
|
|
908
|
+
this.optimization.subscribe(() => {
|
|
909
|
+
this.refreshControls();
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
switches;
|
|
913
|
+
coordinator;
|
|
914
|
+
optimization;
|
|
915
|
+
prediction;
|
|
916
|
+
writer = null;
|
|
917
|
+
input = null;
|
|
918
|
+
context = [];
|
|
919
|
+
hasChips = false;
|
|
920
|
+
controls;
|
|
921
|
+
disposed = false;
|
|
922
|
+
listeners = /* @__PURE__ */ new Set();
|
|
923
|
+
subscribe(listener) {
|
|
924
|
+
if (this.disposed) return () => {
|
|
925
|
+
};
|
|
926
|
+
this.listeners.add(listener);
|
|
927
|
+
return () => {
|
|
928
|
+
this.listeners.delete(listener);
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
controlsSnapshot() {
|
|
932
|
+
return this.controls;
|
|
933
|
+
}
|
|
934
|
+
attach(writer) {
|
|
935
|
+
if (this.disposed) return () => {
|
|
936
|
+
};
|
|
937
|
+
this.writer = writer;
|
|
938
|
+
this.optimization.setEnabled(this.switches.optimize());
|
|
939
|
+
this.prediction.setEnabled(this.switches.predict());
|
|
940
|
+
this.refreshControls();
|
|
941
|
+
return () => {
|
|
942
|
+
if (this.writer !== writer) return;
|
|
943
|
+
this.writer = null;
|
|
944
|
+
this.optimization.setEnabled(false);
|
|
945
|
+
this.prediction.setEnabled(false);
|
|
946
|
+
this.refreshControls();
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
refreshSettings() {
|
|
950
|
+
if (this.disposed) return;
|
|
951
|
+
this.coordinator.refreshSettings();
|
|
952
|
+
this.optimization.setEnabled(this.writer !== null && this.switches.optimize());
|
|
953
|
+
this.prediction.setEnabled(this.writer !== null && this.switches.predict());
|
|
954
|
+
this.refreshControls();
|
|
955
|
+
}
|
|
956
|
+
sync(input, context, hasChips) {
|
|
957
|
+
if (this.disposed) return;
|
|
958
|
+
this.input = { ...input, selection: { ...input.selection } };
|
|
959
|
+
this.context = context;
|
|
960
|
+
this.hasChips = hasChips;
|
|
961
|
+
this.coordinator.sync(input);
|
|
962
|
+
this.optimization.setEnabled(this.writer !== null && this.switches.optimize());
|
|
963
|
+
this.prediction.setEnabled(this.writer !== null && this.switches.predict());
|
|
964
|
+
if (this.writer !== null) {
|
|
965
|
+
this.optimization.sync(this.snapshot(input));
|
|
966
|
+
this.prediction.sync(input, context);
|
|
967
|
+
}
|
|
968
|
+
this.refreshControls();
|
|
969
|
+
}
|
|
970
|
+
optimize() {
|
|
971
|
+
if (this.disposed || this.input === null || !this.controls.canOptimize) return Promise.resolve();
|
|
972
|
+
return this.optimization.start(this.snapshot(this.input), this.context);
|
|
973
|
+
}
|
|
974
|
+
undo() {
|
|
975
|
+
return !this.disposed && this.optimization.undo();
|
|
976
|
+
}
|
|
977
|
+
handleKey(key, context) {
|
|
978
|
+
if (this.disposed) return false;
|
|
979
|
+
try {
|
|
980
|
+
return this.coordinator.handleKey(key, context);
|
|
981
|
+
} catch (error) {
|
|
982
|
+
this.optimization.handleError(error);
|
|
983
|
+
return true;
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
cancelPrediction() {
|
|
987
|
+
if (!this.disposed) this.prediction.cancel();
|
|
988
|
+
}
|
|
989
|
+
dispose() {
|
|
990
|
+
if (this.disposed) return;
|
|
991
|
+
this.disposed = true;
|
|
992
|
+
this.writer = null;
|
|
993
|
+
this.prediction.dispose();
|
|
994
|
+
this.coordinator.dispose();
|
|
995
|
+
this.optimization.dispose();
|
|
996
|
+
this.listeners.clear();
|
|
997
|
+
}
|
|
998
|
+
snapshot(input) {
|
|
999
|
+
return {
|
|
1000
|
+
sessionId: input.sessionId,
|
|
1001
|
+
draftRev: input.draftRev,
|
|
1002
|
+
start: input.selection.start,
|
|
1003
|
+
end: input.selection.end,
|
|
1004
|
+
text: input.draft,
|
|
1005
|
+
...input.occurrences.length > 0 ? { occurrences: input.occurrences } : {},
|
|
1006
|
+
...input.selection.start === input.selection.end && input.occurrences.length > 0 ? { structured: true } : {}
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
1009
|
+
refreshControls() {
|
|
1010
|
+
if (this.disposed) return;
|
|
1011
|
+
const state = this.optimization.getSnapshot();
|
|
1012
|
+
const enabled = this.switches.optimize();
|
|
1013
|
+
const input = this.input;
|
|
1014
|
+
const selected = input !== null && input.selection.start !== input.selection.end;
|
|
1015
|
+
const chipSelection = input !== null && selected && input.occurrences.some((occurrence) => input.selection.start < occurrence.offset + occurrence.length && input.selection.end > occurrence.offset);
|
|
1016
|
+
const source = input === null ? "" : selected ? input.draft.slice(input.selection.start, input.selection.end) : input.draft;
|
|
1017
|
+
const next = {
|
|
1018
|
+
...state,
|
|
1019
|
+
enabled,
|
|
1020
|
+
canOptimize: this.writer !== null && enabled && !chipSelection && source.trim() !== "",
|
|
1021
|
+
hasChips: this.hasChips,
|
|
1022
|
+
chipSelection
|
|
1023
|
+
};
|
|
1024
|
+
if (this.controls.status === next.status && this.controls.error === next.error && this.controls.enabled === next.enabled && this.controls.canOptimize === next.canOptimize && this.controls.hasChips === next.hasChips && this.controls.chipSelection === next.chipSelection) return;
|
|
1025
|
+
this.controls = next;
|
|
1026
|
+
for (const listener of this.listeners) listener();
|
|
1027
|
+
}
|
|
1028
|
+
};
|
|
1029
|
+
|
|
1030
|
+
// src/client/dsh/controls.tsx
|
|
1031
|
+
var import_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
1032
|
+
var import_react = require("react");
|
|
1033
|
+
|
|
1034
|
+
// src/client/styles.module.css
|
|
1035
|
+
var styles_default = {
|
|
1036
|
+
root: "styles_root",
|
|
1037
|
+
toolbarIcon: "styles_toolbarIcon",
|
|
1038
|
+
settings: "styles_settings",
|
|
1039
|
+
settingsHeader: "styles_settingsHeader",
|
|
1040
|
+
settingDescription: "styles_settingDescription",
|
|
1041
|
+
privacy: "styles_privacy",
|
|
1042
|
+
settingRow: "styles_settingRow",
|
|
1043
|
+
settingText: "styles_settingText",
|
|
1044
|
+
settingControls: "styles_settingControls",
|
|
1045
|
+
modelPill: "styles_modelPill",
|
|
1046
|
+
modelPillLabel: "styles_modelPillLabel",
|
|
1047
|
+
prediction: "styles_prediction",
|
|
1048
|
+
historyDialog: "styles_historyDialog",
|
|
1049
|
+
historyHeader: "styles_historyHeader",
|
|
1050
|
+
historyResults: "styles_historyResults",
|
|
1051
|
+
historyResult: "styles_historyResult",
|
|
1052
|
+
hints: "styles_hints",
|
|
1053
|
+
hint: "styles_hint",
|
|
1054
|
+
rollbackDialog: "styles_rollbackDialog",
|
|
1055
|
+
rollbackContent: "styles_rollbackContent",
|
|
1056
|
+
rollbackPreview: "styles_rollbackPreview",
|
|
1057
|
+
rollbackSection: "styles_rollbackSection",
|
|
1058
|
+
rollbackList: "styles_rollbackList",
|
|
1059
|
+
rollbackMessage: "styles_rollbackMessage",
|
|
1060
|
+
rollbackFile: "styles_rollbackFile",
|
|
1061
|
+
rollbackMeta: "styles_rollbackMeta",
|
|
1062
|
+
rollbackConflict: "styles_rollbackConflict",
|
|
1063
|
+
userMessageRow: "styles_userMessageRow",
|
|
1064
|
+
userMessageActions: "styles_userMessageActions",
|
|
1065
|
+
userMessageAction: "styles_userMessageAction"
|
|
1066
|
+
};
|
|
1067
|
+
var css_module_default = styles_default;
|
|
1068
|
+
var cssText = "/* src/client/styles.module.css */\n.styles_root {\n position: relative;\n}\n.styles_toolbarIcon {\n width: 28px;\n padding: 0;\n}\n.styles_settings {\n display: grid;\n gap: 16px;\n max-width: 640px;\n color: var(--dsw-alias-label-primary);\n font: var(--dsw-font-sm-14);\n}\n.styles_settings h2,\n.styles_settings h3,\n.styles_settings p {\n margin: 0;\n}\n.styles_settingsHeader {\n display: grid;\n gap: 4px;\n}\n.styles_settingsHeader p,\n.styles_settingDescription,\n.styles_privacy p {\n color: var(--dsw-alias-label-secondary);\n}\n.styles_settingRow {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 16px;\n}\n.styles_settingText {\n display: grid;\n gap: 4px;\n min-width: 0;\n}\n.styles_settingText h3,\n.styles_privacy h3 {\n font: inherit;\n font-weight: 600;\n}\n.styles_settingControls {\n display: flex;\n align-items: center;\n gap: 8px;\n flex-shrink: 0;\n}\n.styles_modelPill {\n max-width: 168px;\n}\n.styles_modelPillLabel {\n display: block;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.styles_privacy {\n display: grid;\n gap: 8px;\n padding: 12px;\n background: var(--dsw-alias-bg-layer-2);\n border-radius: var(--dsw-radius-sm);\n}\n.styles_prediction {\n position: absolute;\n left: 0;\n right: 0;\n bottom: calc(100% + 8px);\n box-sizing: border-box;\n width: auto;\n max-width: none;\n padding: 8px 12px;\n color: var(--dsw-alias-label-secondary);\n font: var(--dsw-font-sm-14);\n white-space: pre-wrap;\n pointer-events: none;\n user-select: none;\n background: var(--dsw-alias-bg-layer-2);\n border-radius: var(--dsw-radius-sm);\n}\n.styles_prediction kbd {\n margin-left: 8px;\n}\n.styles_historyDialog {\n position: absolute;\n z-index: 20;\n left: 0;\n right: 0;\n bottom: calc(100% + 8px);\n display: grid;\n gap: 8px;\n box-sizing: border-box;\n width: auto;\n max-width: none;\n padding: 12px;\n color: var(--dsw-alias-label-primary);\n}\n.styles_historyHeader {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 8px;\n font: var(--dsw-font-sm-14);\n}\n.styles_historyResults {\n max-height: 240px;\n margin: 0;\n padding: 0;\n overflow-y: auto;\n list-style: none;\n}\n.styles_historyResult {\n padding: 8px;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n cursor: pointer;\n border-radius: var(--dsw-radius-sm);\n}\n.styles_historyResult[aria-selected=true] {\n background: var(--dsw-alias-bg-layer-2);\n}\n.styles_hints {\n position: absolute;\n z-index: 21;\n left: 0;\n right: 0;\n bottom: calc(100% + 8px);\n display: grid;\n gap: 8px;\n box-sizing: border-box;\n width: auto;\n max-width: none;\n}\n.styles_hint {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 12px;\n padding: 8px 12px;\n color: var(--dsw-alias-label-primary);\n font: var(--dsw-font-sm-14);\n background: var(--dsw-alias-bg-layer-2);\n border-radius: var(--dsw-radius-sm);\n}\n.styles_rollbackDialog {\n width: min(680px, 100%);\n max-height: 100%;\n min-height: 0;\n}\n.styles_rollbackContent {\n flex: 1 1 auto;\n min-height: 0;\n overflow-y: auto;\n}\n.styles_rollbackPreview {\n display: grid;\n gap: 20px;\n box-sizing: border-box;\n max-width: 72ch;\n padding: 16px;\n color: var(--dsw-alias-label-primary);\n font: var(--dsw-font-sm-14);\n}\n.styles_rollbackSection {\n display: grid;\n gap: 8px;\n min-width: 0;\n}\n.styles_rollbackSection h3,\n.styles_rollbackSection p {\n margin: 0;\n}\n.styles_rollbackSection h3 {\n font: inherit;\n font-weight: 600;\n}\n.styles_rollbackList {\n display: grid;\n gap: 8px;\n margin: 0;\n padding: 0;\n list-style: none;\n}\n.styles_rollbackList li {\n min-width: 0;\n overflow-wrap: anywhere;\n}\n.styles_rollbackMessage,\n.styles_rollbackFile {\n display: grid;\n gap: 4px;\n}\n.styles_rollbackFile {\n grid-template-columns: minmax(0, 1fr) auto;\n align-items: baseline;\n gap: 12px;\n}\n.styles_rollbackMeta {\n color: var(--dsw-alias-label-secondary);\n font-size: 0.92em;\n}\n.styles_rollbackConflict {\n display: block;\n color: var(--dsw-alias-label-secondary);\n}\n.styles_userMessageRow {\n display: flex;\n flex-direction: column;\n align-items: flex-end;\n gap: 6px;\n min-width: 0;\n}\n.styles_userMessageActions {\n display: inline-flex;\n align-items: center;\n justify-content: flex-end;\n gap: 4px;\n}\n.styles_userMessageAction {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: calc(28px + var(--dsh-content-font-delta, 0px));\n height: calc(28px + var(--dsh-content-font-delta, 0px));\n padding: 6px;\n color: var(--dsw-alias-label-tertiary);\n background: transparent;\n border: 0;\n border-radius: var(--dsw-radius-sm);\n cursor: pointer;\n}\n.styles_userMessageAction svg {\n width: calc(15px + var(--dsh-content-font-delta, 0px));\n height: calc(15px + var(--dsh-content-font-delta, 0px));\n}\n.styles_userMessageAction:hover {\n color: var(--dsw-alias-label-secondary);\n background: var(--dsw-alias-interactive-bg-hover);\n}\n.styles_userMessageAction:disabled,\n.styles_userMessageAction[data-unavailable] {\n cursor: default;\n opacity: 0.4;\n}\n.styles_userMessageAction:disabled:hover,\n.styles_userMessageAction[data-unavailable]:hover {\n color: var(--dsw-alias-label-tertiary);\n background: transparent;\n}\n";
|
|
1069
|
+
function installCss() {
|
|
1070
|
+
const style = document.createElement("style");
|
|
1071
|
+
style.setAttribute("data-dsh-agent-enhancer", "");
|
|
1072
|
+
style.textContent = cssText;
|
|
1073
|
+
document.head.append(style);
|
|
1074
|
+
return () => style.remove();
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
// src/client/dsh/icons.tsx
|
|
1078
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1079
|
+
function OptimizeIcon() {
|
|
1080
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1081
|
+
"svg",
|
|
1082
|
+
{
|
|
1083
|
+
width: "16",
|
|
1084
|
+
height: "16",
|
|
1085
|
+
viewBox: "0 0 16 16",
|
|
1086
|
+
fill: "none",
|
|
1087
|
+
stroke: "currentColor",
|
|
1088
|
+
strokeWidth: "1.5",
|
|
1089
|
+
strokeLinecap: "round",
|
|
1090
|
+
strokeLinejoin: "round",
|
|
1091
|
+
"aria-hidden": "true",
|
|
1092
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M8 2.5 9.8 6.2 13.5 8 9.8 9.8 8 13.5 6.2 9.8 2.5 8 6.2 6.2 8 2.5Z" })
|
|
1093
|
+
}
|
|
1094
|
+
);
|
|
1095
|
+
}
|
|
1096
|
+
function UndoIcon() {
|
|
1097
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
1098
|
+
"svg",
|
|
1099
|
+
{
|
|
1100
|
+
width: "16",
|
|
1101
|
+
height: "16",
|
|
1102
|
+
viewBox: "0 0 16 16",
|
|
1103
|
+
fill: "none",
|
|
1104
|
+
stroke: "currentColor",
|
|
1105
|
+
strokeWidth: "1.5",
|
|
1106
|
+
strokeLinecap: "round",
|
|
1107
|
+
strokeLinejoin: "round",
|
|
1108
|
+
"aria-hidden": "true",
|
|
1109
|
+
children: [
|
|
1110
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M6 3 2 7l4 4" }),
|
|
1111
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M2 7h7a4 4 0 0 1 0 8H7" })
|
|
1112
|
+
]
|
|
1113
|
+
}
|
|
1114
|
+
);
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
// src/client/dsh/controls.tsx
|
|
1118
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1119
|
+
var OPTIMIZATION_ERROR_LOCALES = {
|
|
1120
|
+
MODEL_UNAVAILABLE: "optimizeModelUnavailable",
|
|
1121
|
+
MODEL_FAILED: "optimizeRequestFailed",
|
|
1122
|
+
INVALID_OUTPUT: "optimizeInvalidOutput",
|
|
1123
|
+
ROLLBACK_FAILED: "optimizeRollbackFailed",
|
|
1124
|
+
SESSION_CHANGED: "optimizeSessionChanged"
|
|
1125
|
+
};
|
|
1126
|
+
function AgentControls({ session, t }) {
|
|
1127
|
+
const state = (0, import_react.useSyncExternalStore)(
|
|
1128
|
+
(listener) => session.subscribe(listener),
|
|
1129
|
+
() => session.controlsSnapshot()
|
|
1130
|
+
);
|
|
1131
|
+
if (!state.enabled) return null;
|
|
1132
|
+
const label = t(state.status === "pending" ? "optimizePending" : state.status === "undo" ? "optimizeUndo" : "optimize");
|
|
1133
|
+
const errorLocale = OPTIMIZATION_ERROR_LOCALES[state.error ?? "MODEL_FAILED"];
|
|
1134
|
+
const tooltip = state.chipSelection ? t("optimizeChipSelection") : state.error !== null ? t(errorLocale) : state.hasChips ? t("optimizeChips") : label;
|
|
1135
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1136
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives.Tooltip, { label: tooltip, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1137
|
+
import_dsh_client_ui_primitives.Button,
|
|
1138
|
+
{
|
|
1139
|
+
type: "button",
|
|
1140
|
+
variant: "ghost",
|
|
1141
|
+
size: "sm",
|
|
1142
|
+
className: css_module_default.toolbarIcon,
|
|
1143
|
+
"data-agent-enhancer-icon": state.status,
|
|
1144
|
+
disabled: state.error === "ROLLBACK_FAILED" || state.status === "pending" || state.status === "optimize" && !state.canOptimize,
|
|
1145
|
+
"aria-label": label,
|
|
1146
|
+
title: tooltip,
|
|
1147
|
+
onClick: () => {
|
|
1148
|
+
if (state.status === "undo") session.undo();
|
|
1149
|
+
else void session.optimize();
|
|
1150
|
+
},
|
|
1151
|
+
children: state.status === "pending" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives.StateDot, { state: "ongoing" }) : state.status === "undo" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(UndoIcon, {}) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(OptimizeIcon, {})
|
|
1152
|
+
}
|
|
1153
|
+
) }),
|
|
1154
|
+
state.error !== null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { role: "status", children: t(errorLocale) })
|
|
1155
|
+
] });
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
// src/client/dsh/overlay.tsx
|
|
1159
|
+
var import_dsh_client_ui_primitives3 = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
1160
|
+
var import_react3 = require("react");
|
|
1161
|
+
|
|
1162
|
+
// src/client/dsh/conversation.ts
|
|
1163
|
+
function textOf(node) {
|
|
1164
|
+
return node.content.flatMap((block2) => block2.type === "text" ? [block2.text] : []).join("");
|
|
1165
|
+
}
|
|
1166
|
+
function turnOf(node) {
|
|
1167
|
+
return node.location.kind === "turn" || node.location.kind === "step" ? node.location.turn.turn : void 0;
|
|
1168
|
+
}
|
|
1169
|
+
function sentPrompts(chat) {
|
|
1170
|
+
if (chat === void 0) return [];
|
|
1171
|
+
return chat.order.flatMap((key) => {
|
|
1172
|
+
const node = chat.nodes.get(key);
|
|
1173
|
+
if (node?.kind !== "user") return [];
|
|
1174
|
+
const text2 = textOf(node.data);
|
|
1175
|
+
return text2.trim() === "" ? [] : [{ seq: node.data.seq, text: text2 }];
|
|
1176
|
+
});
|
|
1177
|
+
}
|
|
1178
|
+
function latestCompletedTurn(chat, session) {
|
|
1179
|
+
if (chat === void 0 || session.running) return null;
|
|
1180
|
+
let tailNode;
|
|
1181
|
+
for (let index = chat.order.length - 1; index >= 0; index -= 1) {
|
|
1182
|
+
const candidate = chat.nodes.get(chat.order[index]);
|
|
1183
|
+
if (candidate?.kind === "turn-tail") {
|
|
1184
|
+
tailNode = candidate;
|
|
1185
|
+
break;
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
if (tailNode === void 0) return null;
|
|
1189
|
+
const tail = tailNode.data;
|
|
1190
|
+
const closing = tail.closing;
|
|
1191
|
+
if (closing?.status !== "settled") return null;
|
|
1192
|
+
const prompt = chat.order.flatMap((key) => {
|
|
1193
|
+
const node = chat.nodes.get(key);
|
|
1194
|
+
if (node?.kind !== "user" || turnOf(node) !== tail.turn) return [];
|
|
1195
|
+
return [textOf(node.data)];
|
|
1196
|
+
}).join("");
|
|
1197
|
+
const response = closing.blocks.flatMap((block2) => block2.kind === "text" ? [block2.text] : []).join("");
|
|
1198
|
+
return { turn: tail.turn, prompt, response };
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
// src/client/dsh/editor.ts
|
|
1202
|
+
var BLOCK_ELEMENTS = /* @__PURE__ */ new Set(["ADDRESS", "ARTICLE", "ASIDE", "BLOCKQUOTE", "DIV", "DL", "FIELDSET", "FIGURE", "FOOTER", "FORM", "H1", "H2", "H3", "H4", "H5", "H6", "HEADER", "HR", "LI", "MAIN", "NAV", "OL", "P", "PRE", "SECTION", "TABLE", "UL"]);
|
|
1203
|
+
function block(node) {
|
|
1204
|
+
return node.nodeType === Node.ELEMENT_NODE && BLOCK_ELEMENTS.has(node.tagName);
|
|
1205
|
+
}
|
|
1206
|
+
function projectedText(node) {
|
|
1207
|
+
if (node.nodeType === Node.TEXT_NODE) return node.textContent ?? "";
|
|
1208
|
+
if (node.nodeType === Node.ELEMENT_NODE && node.tagName === "BR") return "\n";
|
|
1209
|
+
let text2 = "";
|
|
1210
|
+
let previous;
|
|
1211
|
+
for (const child of node.childNodes) {
|
|
1212
|
+
if (previous !== void 0 && block(previous) && block(child)) text2 += "\n";
|
|
1213
|
+
text2 += projectedText(child);
|
|
1214
|
+
previous = child;
|
|
1215
|
+
}
|
|
1216
|
+
return text2;
|
|
1217
|
+
}
|
|
1218
|
+
function pointAt(node, offset) {
|
|
1219
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
1220
|
+
return { node, offset: Math.max(0, Math.min(offset, node.textContent?.length ?? 0)) };
|
|
1221
|
+
}
|
|
1222
|
+
if (node.nodeType === Node.ELEMENT_NODE && node.tagName === "BR") {
|
|
1223
|
+
const parent = node.parentNode;
|
|
1224
|
+
return { node: parent, offset: Array.prototype.indexOf.call(parent.childNodes, node) + (offset > 0 ? 1 : 0) };
|
|
1225
|
+
}
|
|
1226
|
+
if (node.childNodes.length === 0) return { node, offset: 0 };
|
|
1227
|
+
let remaining = Math.max(0, offset);
|
|
1228
|
+
let previous;
|
|
1229
|
+
for (const child of node.childNodes) {
|
|
1230
|
+
if (previous !== void 0 && block(previous) && block(child)) {
|
|
1231
|
+
if (remaining === 0) return pointAt(previous, projectedText(previous).length);
|
|
1232
|
+
remaining -= 1;
|
|
1233
|
+
if (remaining === 0) return pointAt(child, 0);
|
|
1234
|
+
}
|
|
1235
|
+
const length = projectedText(child).length;
|
|
1236
|
+
if (remaining <= length) return pointAt(child, remaining);
|
|
1237
|
+
remaining -= length;
|
|
1238
|
+
previous = child;
|
|
1239
|
+
}
|
|
1240
|
+
return { node, offset: node.childNodes.length };
|
|
1241
|
+
}
|
|
1242
|
+
function offsetOf(root, node, offset) {
|
|
1243
|
+
const range = root.ownerDocument.createRange();
|
|
1244
|
+
range.selectNodeContents(root);
|
|
1245
|
+
range.setEnd(node, offset);
|
|
1246
|
+
return projectedText(range.cloneContents()).length;
|
|
1247
|
+
}
|
|
1248
|
+
function readSelection(root) {
|
|
1249
|
+
const selection = root.ownerDocument.getSelection();
|
|
1250
|
+
const anchor = selection?.anchorNode;
|
|
1251
|
+
const focus = selection?.focusNode;
|
|
1252
|
+
if (selection?.rangeCount !== 1 || anchor == null || focus == null || !root.contains(anchor) || !root.contains(focus)) return null;
|
|
1253
|
+
const anchorOffset = offsetOf(root, anchor, selection.anchorOffset);
|
|
1254
|
+
const focusOffset = offsetOf(root, focus, selection.focusOffset);
|
|
1255
|
+
return { start: Math.min(anchorOffset, focusOffset), end: Math.max(anchorOffset, focusOffset) };
|
|
1256
|
+
}
|
|
1257
|
+
function restoreSelection(root, selection) {
|
|
1258
|
+
root.focus({ preventScroll: true });
|
|
1259
|
+
const start = pointAt(root, selection.start);
|
|
1260
|
+
const end = pointAt(root, selection.end);
|
|
1261
|
+
const range = root.ownerDocument.createRange();
|
|
1262
|
+
range.setStart(start.node, start.offset);
|
|
1263
|
+
range.setEnd(end.node, end.offset);
|
|
1264
|
+
const native = root.ownerDocument.getSelection();
|
|
1265
|
+
native?.removeAllRanges();
|
|
1266
|
+
native?.addRange(range);
|
|
1267
|
+
}
|
|
1268
|
+
function lineBoundary(text2, caret) {
|
|
1269
|
+
return {
|
|
1270
|
+
first: text2.lastIndexOf("\n", Math.max(0, caret - 1)) < 0,
|
|
1271
|
+
last: text2.indexOf("\n", caret) < 0
|
|
1272
|
+
};
|
|
1273
|
+
}
|
|
1274
|
+
function isComposing(event, root) {
|
|
1275
|
+
return event.isComposing || event.keyCode === 229 || root.hasAttribute("data-composer-composing");
|
|
1276
|
+
}
|
|
1277
|
+
function officialMenuOpen(document2) {
|
|
1278
|
+
return document2.querySelector('[role="menu"], [role="listbox"]') !== null;
|
|
1279
|
+
}
|
|
1280
|
+
function publicWriter(root, actions) {
|
|
1281
|
+
return {
|
|
1282
|
+
replace(text2, selection, segments, source) {
|
|
1283
|
+
if (selection.draftRev !== actions.captureInsertion().draftRev) return false;
|
|
1284
|
+
if (selection.structured === true) {
|
|
1285
|
+
return segments !== void 0 && selection.occurrences !== void 0 && source !== void 0 && replaceAroundOccurrences(actions, source, selection.occurrences, segments);
|
|
1286
|
+
}
|
|
1287
|
+
const occurrences = selection.occurrences ?? [];
|
|
1288
|
+
return actions.insertText(text2, {
|
|
1289
|
+
...selection,
|
|
1290
|
+
start: detectOffset(selection.start, occurrences),
|
|
1291
|
+
end: detectOffset(selection.end, occurrences)
|
|
1292
|
+
});
|
|
1293
|
+
},
|
|
1294
|
+
setDraft(text2, caret) {
|
|
1295
|
+
actions.setDraft(text2);
|
|
1296
|
+
actions.persistDraft();
|
|
1297
|
+
root.focus({ preventScroll: true });
|
|
1298
|
+
restoreSelection(root, { start: caret, end: caret });
|
|
1299
|
+
}
|
|
1300
|
+
};
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
// src/client/dsh/hints.tsx
|
|
1304
|
+
var import_dsh_client_ui_primitives2 = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
1305
|
+
var import_react2 = require("react");
|
|
1306
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1307
|
+
var HINT_KEYS = {
|
|
1308
|
+
history: "overlapHistory",
|
|
1309
|
+
optimize: "overlapOptimize",
|
|
1310
|
+
predict: "overlapPredict"
|
|
1311
|
+
};
|
|
1312
|
+
function CoexistenceHints({ store, t }) {
|
|
1313
|
+
const hints = (0, import_react2.useSyncExternalStore)(
|
|
1314
|
+
(listener) => store.subscribe(listener),
|
|
1315
|
+
() => store.getSnapshot()
|
|
1316
|
+
);
|
|
1317
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: css_module_default.hints, children: hints.map((module2) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1318
|
+
"div",
|
|
1319
|
+
{
|
|
1320
|
+
role: "status",
|
|
1321
|
+
className: css_module_default.hint,
|
|
1322
|
+
"data-agent-enhancer-hint": module2,
|
|
1323
|
+
children: [
|
|
1324
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: t(HINT_KEYS[module2]) }),
|
|
1325
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1326
|
+
import_dsh_client_ui_primitives2.Button,
|
|
1327
|
+
{
|
|
1328
|
+
type: "button",
|
|
1329
|
+
variant: "toolbar",
|
|
1330
|
+
size: "sm",
|
|
1331
|
+
"aria-label": t("dismissHint"),
|
|
1332
|
+
title: t("dismissHint"),
|
|
1333
|
+
onClick: () => {
|
|
1334
|
+
store.dismiss(module2);
|
|
1335
|
+
},
|
|
1336
|
+
children: "\xD7"
|
|
1337
|
+
}
|
|
1338
|
+
)
|
|
1339
|
+
]
|
|
1340
|
+
},
|
|
1341
|
+
module2
|
|
1342
|
+
)) });
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
// src/client/dsh/overlay.tsx
|
|
1346
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1347
|
+
function keyOf(event) {
|
|
1348
|
+
if (event.altKey && !event.ctrlKey && !event.metaKey && !event.shiftKey && event.code === "KeyR") return "search";
|
|
1349
|
+
if ((event.ctrlKey || event.metaKey) && !event.altKey && event.code === "KeyR") return "search";
|
|
1350
|
+
if (event.altKey || event.ctrlKey || event.metaKey) return null;
|
|
1351
|
+
switch (event.key) {
|
|
1352
|
+
case "ArrowUp":
|
|
1353
|
+
return "up";
|
|
1354
|
+
case "ArrowDown":
|
|
1355
|
+
return "down";
|
|
1356
|
+
case "Tab":
|
|
1357
|
+
return event.shiftKey ? null : "tab";
|
|
1358
|
+
case "Enter":
|
|
1359
|
+
return event.shiftKey ? null : "enter";
|
|
1360
|
+
case "Escape":
|
|
1361
|
+
return "escape";
|
|
1362
|
+
default:
|
|
1363
|
+
return null;
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
var dialogKeyContext = {
|
|
1367
|
+
composing: false,
|
|
1368
|
+
systemLayerOpen: false,
|
|
1369
|
+
officialMenuOpen: false,
|
|
1370
|
+
atFirstLine: true,
|
|
1371
|
+
atLastLine: true
|
|
1372
|
+
};
|
|
1373
|
+
function AgentOverlay(props) {
|
|
1374
|
+
const containerRef = (0, import_react3.useRef)(null);
|
|
1375
|
+
const activeRef = (0, import_react3.useRef)(null);
|
|
1376
|
+
const coordinatorRef = (0, import_react3.useRef)(null);
|
|
1377
|
+
const [search, setSearch] = (0, import_react3.useState)(null);
|
|
1378
|
+
const [prediction, setPrediction] = (0, import_react3.useState)(null);
|
|
1379
|
+
const input = props.useInput((state) => state);
|
|
1380
|
+
const session = props.useSession((state) => state);
|
|
1381
|
+
const chat = props.useConversation((snapshot) => snapshot.views.get("chat"));
|
|
1382
|
+
const latestRef = (0, import_react3.useRef)({ input, session, chat });
|
|
1383
|
+
latestRef.current = { input, session, chat };
|
|
1384
|
+
(0, import_react3.useEffect)(() => {
|
|
1385
|
+
const container = containerRef.current;
|
|
1386
|
+
const root = container?.closest("[data-composer-card]")?.querySelector("[data-composer-input]");
|
|
1387
|
+
if (container == null || root == null) return;
|
|
1388
|
+
const coordinator = props.session.coordinator;
|
|
1389
|
+
const detach = props.session.attach(publicWriter(root, props.inputActions));
|
|
1390
|
+
coordinatorRef.current = coordinator;
|
|
1391
|
+
const unsubscribe = coordinator.subscribe(() => {
|
|
1392
|
+
setSearch(coordinator.searchSnapshot());
|
|
1393
|
+
setPrediction(coordinator.predictionSnapshot());
|
|
1394
|
+
});
|
|
1395
|
+
let unregisterHistory = () => {
|
|
1396
|
+
};
|
|
1397
|
+
const refreshHistory = () => {
|
|
1398
|
+
unregisterHistory();
|
|
1399
|
+
unregisterHistory = coordinator.registerHistory({
|
|
1400
|
+
load: (requested) => requested === props.sessionId ? sentPrompts(latestRef.current.chat) : []
|
|
1401
|
+
});
|
|
1402
|
+
};
|
|
1403
|
+
let selection = { start: latestRef.current.input.draft.length, end: latestRef.current.input.draft.length };
|
|
1404
|
+
const sync = () => {
|
|
1405
|
+
selection = readSelection(root) ?? selection;
|
|
1406
|
+
const current = latestRef.current;
|
|
1407
|
+
const facts = {
|
|
1408
|
+
sessionId: props.sessionId,
|
|
1409
|
+
draft: current.input.draft,
|
|
1410
|
+
draftRev: current.input.draftRev,
|
|
1411
|
+
selection,
|
|
1412
|
+
occurrences: current.input.occurrences,
|
|
1413
|
+
running: current.session.running
|
|
1414
|
+
};
|
|
1415
|
+
const latest = latestCompletedTurn(current.chat, current.session);
|
|
1416
|
+
props.session.sync(facts, latest === null ? [] : [latest], current.input.occurrences.length > 0);
|
|
1417
|
+
};
|
|
1418
|
+
const externalMenuOpen = () => Array.from(root.ownerDocument.querySelectorAll('[role="menu"], [role="listbox"]')).some((menu) => !container.contains(menu));
|
|
1419
|
+
const cancelPredictionOnOfficialMenu = () => {
|
|
1420
|
+
if (externalMenuOpen()) props.session.cancelPrediction();
|
|
1421
|
+
};
|
|
1422
|
+
const onKeyDown = (event) => {
|
|
1423
|
+
queueMicrotask(cancelPredictionOnOfficialMenu);
|
|
1424
|
+
if (event.defaultPrevented) return;
|
|
1425
|
+
const key = keyOf(event);
|
|
1426
|
+
if (key === null) return;
|
|
1427
|
+
sync();
|
|
1428
|
+
if (latestRef.current.input.occurrences.length > 0 && (key === "up" || key === "down" || key === "search")) return;
|
|
1429
|
+
const context = {
|
|
1430
|
+
composing: isComposing(event, root),
|
|
1431
|
+
systemLayerOpen: root.ownerDocument.querySelector('[role="dialog"], [role="alertdialog"]') !== null,
|
|
1432
|
+
officialMenuOpen: officialMenuOpen(root.ownerDocument),
|
|
1433
|
+
atFirstLine: lineBoundary(latestRef.current.input.draft, selection.start).first,
|
|
1434
|
+
atLastLine: lineBoundary(latestRef.current.input.draft, selection.end).last
|
|
1435
|
+
};
|
|
1436
|
+
if (context.officialMenuOpen) props.session.cancelPrediction();
|
|
1437
|
+
const handled = props.session.handleKey(key, context);
|
|
1438
|
+
if (handled) {
|
|
1439
|
+
event.preventDefault();
|
|
1440
|
+
event.stopPropagation();
|
|
1441
|
+
}
|
|
1442
|
+
};
|
|
1443
|
+
const onInput = () => {
|
|
1444
|
+
props.session.cancelPrediction();
|
|
1445
|
+
sync();
|
|
1446
|
+
};
|
|
1447
|
+
const onOfficialMenuPointer = (event) => {
|
|
1448
|
+
if (container.contains(event.target)) return;
|
|
1449
|
+
if (!externalMenuOpen()) return;
|
|
1450
|
+
props.session.cancelPrediction();
|
|
1451
|
+
props.session.handleKey("escape", { ...dialogKeyContext, officialMenuOpen: true });
|
|
1452
|
+
};
|
|
1453
|
+
root.addEventListener("keydown", onKeyDown);
|
|
1454
|
+
root.addEventListener("input", onInput);
|
|
1455
|
+
root.addEventListener("compositionstart", sync);
|
|
1456
|
+
root.addEventListener("compositionend", sync);
|
|
1457
|
+
root.ownerDocument.addEventListener("selectionchange", sync);
|
|
1458
|
+
root.ownerDocument.addEventListener("pointerdown", onOfficialMenuPointer);
|
|
1459
|
+
root.ownerDocument.addEventListener("click", onOfficialMenuPointer);
|
|
1460
|
+
const active = {
|
|
1461
|
+
sync,
|
|
1462
|
+
refreshHistory,
|
|
1463
|
+
dispose() {
|
|
1464
|
+
root.removeEventListener("keydown", onKeyDown);
|
|
1465
|
+
root.removeEventListener("input", onInput);
|
|
1466
|
+
root.removeEventListener("compositionstart", sync);
|
|
1467
|
+
root.removeEventListener("compositionend", sync);
|
|
1468
|
+
root.ownerDocument.removeEventListener("selectionchange", sync);
|
|
1469
|
+
root.ownerDocument.removeEventListener("pointerdown", onOfficialMenuPointer);
|
|
1470
|
+
root.ownerDocument.removeEventListener("click", onOfficialMenuPointer);
|
|
1471
|
+
unregisterHistory();
|
|
1472
|
+
unsubscribe();
|
|
1473
|
+
detach();
|
|
1474
|
+
}
|
|
1475
|
+
};
|
|
1476
|
+
activeRef.current = active;
|
|
1477
|
+
sync();
|
|
1478
|
+
return () => {
|
|
1479
|
+
active.dispose();
|
|
1480
|
+
if (activeRef.current === active) activeRef.current = null;
|
|
1481
|
+
if (coordinatorRef.current === coordinator) coordinatorRef.current = null;
|
|
1482
|
+
};
|
|
1483
|
+
}, [props.inputActions, props.sessionId, props.session]);
|
|
1484
|
+
(0, import_react3.useEffect)(() => {
|
|
1485
|
+
activeRef.current?.refreshHistory();
|
|
1486
|
+
}, [chat, props.sessionId]);
|
|
1487
|
+
(0, import_react3.useEffect)(() => {
|
|
1488
|
+
activeRef.current?.sync();
|
|
1489
|
+
});
|
|
1490
|
+
const searchOpen = search !== null;
|
|
1491
|
+
(0, import_react3.useEffect)(() => {
|
|
1492
|
+
if (!searchOpen) return;
|
|
1493
|
+
const container = containerRef.current;
|
|
1494
|
+
const document2 = container?.ownerDocument;
|
|
1495
|
+
if (container == null || document2 == null) return;
|
|
1496
|
+
const onPointerDown = (event) => {
|
|
1497
|
+
if (container.contains(event.target)) return;
|
|
1498
|
+
props.session.handleKey("escape", dialogKeyContext);
|
|
1499
|
+
};
|
|
1500
|
+
document2.addEventListener("pointerdown", onPointerDown);
|
|
1501
|
+
return () => {
|
|
1502
|
+
document2.removeEventListener("pointerdown", onPointerDown);
|
|
1503
|
+
};
|
|
1504
|
+
}, [searchOpen]);
|
|
1505
|
+
const onSearchKeyDown = (event) => {
|
|
1506
|
+
if (event.defaultPrevented || event.nativeEvent.isComposing || event.nativeEvent.keyCode === 229) return;
|
|
1507
|
+
const key = keyOf(event.nativeEvent);
|
|
1508
|
+
if (key !== "up" && key !== "down" && key !== "enter" && key !== "escape") return;
|
|
1509
|
+
if (key === "enter" && event.target.closest("button") !== null) return;
|
|
1510
|
+
const handled = props.session.handleKey(key, dialogKeyContext) ?? false;
|
|
1511
|
+
if (handled) {
|
|
1512
|
+
event.preventDefault();
|
|
1513
|
+
event.stopPropagation();
|
|
1514
|
+
}
|
|
1515
|
+
};
|
|
1516
|
+
const acceptHistory = (entry) => {
|
|
1517
|
+
if (search !== null) coordinatorRef.current?.acceptHistory(entry, search.original);
|
|
1518
|
+
};
|
|
1519
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { ref: containerRef, "data-agent-enhancer-overlay": "", children: [
|
|
1520
|
+
props.hints === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CoexistenceHints, { store: props.hints, t: props.t }),
|
|
1521
|
+
prediction === null ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: css_module_default.prediction, "data-agent-enhancer-prediction": true, "aria-live": "polite", children: [
|
|
1522
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: prediction }),
|
|
1523
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("kbd", { children: "Tab" })
|
|
1524
|
+
] }),
|
|
1525
|
+
search !== null && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
1526
|
+
import_dsh_client_ui_primitives3.MenuSurface,
|
|
1527
|
+
{
|
|
1528
|
+
className: css_module_default.historyDialog,
|
|
1529
|
+
role: "dialog",
|
|
1530
|
+
"aria-label": props.t("historyTitle"),
|
|
1531
|
+
onKeyDown: onSearchKeyDown,
|
|
1532
|
+
children: [
|
|
1533
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: css_module_default.historyHeader, children: [
|
|
1534
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: props.t("historyTitle") }),
|
|
1535
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_dsh_client_ui_primitives3.Button, { type: "button", size: "sm", onClick: () => {
|
|
1536
|
+
props.session.handleKey("escape", dialogKeyContext);
|
|
1537
|
+
}, children: props.t("historyClose") })
|
|
1538
|
+
] }),
|
|
1539
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1540
|
+
import_dsh_client_ui_primitives3.Input,
|
|
1541
|
+
{
|
|
1542
|
+
autoFocus: true,
|
|
1543
|
+
"aria-label": props.t("historySearch"),
|
|
1544
|
+
value: search.query,
|
|
1545
|
+
onChange: (event) => coordinatorRef.current?.updateSearch(event.target.value)
|
|
1546
|
+
}
|
|
1547
|
+
),
|
|
1548
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { className: css_module_default.historyResults, role: "listbox", "aria-label": props.t("historyResults"), children: search.entries.map((entry) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1549
|
+
"li",
|
|
1550
|
+
{
|
|
1551
|
+
className: css_module_default.historyResult,
|
|
1552
|
+
role: "option",
|
|
1553
|
+
"aria-selected": entry.seq === search.selectedSeq,
|
|
1554
|
+
onMouseDown: (event) => {
|
|
1555
|
+
event.preventDefault();
|
|
1556
|
+
},
|
|
1557
|
+
onClick: () => {
|
|
1558
|
+
acceptHistory(entry);
|
|
1559
|
+
},
|
|
1560
|
+
children: entry.text
|
|
1561
|
+
},
|
|
1562
|
+
entry.seq
|
|
1563
|
+
)) })
|
|
1564
|
+
]
|
|
1565
|
+
}
|
|
1566
|
+
)
|
|
1567
|
+
] });
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
// src/client/dsh/plugin-hints.ts
|
|
1571
|
+
var KNOWN_OVERLAPS = {
|
|
1572
|
+
history: ["dsh-composer-history", "dsh-prompt-history", "dsh-input-assistant"],
|
|
1573
|
+
optimize: ["dsh-input-assistant"],
|
|
1574
|
+
predict: ["dsh-reply-suggestions", "dsh-prompt-history", "dsh-input-assistant"]
|
|
1575
|
+
};
|
|
1576
|
+
var OVERLAP_MODULES = Object.keys(KNOWN_OVERLAPS);
|
|
1577
|
+
function overlapHints(entries) {
|
|
1578
|
+
return OVERLAP_MODULES.filter((module2) => KNOWN_OVERLAPS[module2].some((name) => entries.some((entry) => entry.enabled && entry.moduleName === name)));
|
|
1579
|
+
}
|
|
1580
|
+
function browserStorage() {
|
|
1581
|
+
try {
|
|
1582
|
+
return globalThis.localStorage;
|
|
1583
|
+
} catch {
|
|
1584
|
+
return void 0;
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
var OverlapHintStore = class {
|
|
1588
|
+
constructor(storage = browserStorage(), version = "0.1.0") {
|
|
1589
|
+
this.storage = storage;
|
|
1590
|
+
this.version = version;
|
|
1591
|
+
}
|
|
1592
|
+
storage;
|
|
1593
|
+
version;
|
|
1594
|
+
hints = [];
|
|
1595
|
+
active = true;
|
|
1596
|
+
listeners = /* @__PURE__ */ new Set();
|
|
1597
|
+
getSnapshot() {
|
|
1598
|
+
return this.hints;
|
|
1599
|
+
}
|
|
1600
|
+
subscribe(listener) {
|
|
1601
|
+
if (!this.active) return () => {
|
|
1602
|
+
};
|
|
1603
|
+
this.listeners.add(listener);
|
|
1604
|
+
return () => {
|
|
1605
|
+
this.listeners.delete(listener);
|
|
1606
|
+
};
|
|
1607
|
+
}
|
|
1608
|
+
accept(entries) {
|
|
1609
|
+
if (!this.active) return;
|
|
1610
|
+
const arrived = overlapHints(entries).filter((module2) => !this.hints.includes(module2) && !this.dismissed(module2));
|
|
1611
|
+
if (arrived.length === 0) return;
|
|
1612
|
+
for (const module2 of arrived) this.remember(module2);
|
|
1613
|
+
this.hints = [...this.hints, ...arrived];
|
|
1614
|
+
this.emit();
|
|
1615
|
+
}
|
|
1616
|
+
dismiss(module2) {
|
|
1617
|
+
if (!this.active) return;
|
|
1618
|
+
this.remember(module2);
|
|
1619
|
+
if (!this.hints.includes(module2)) return;
|
|
1620
|
+
this.hints = this.hints.filter((candidate) => candidate !== module2);
|
|
1621
|
+
this.emit();
|
|
1622
|
+
}
|
|
1623
|
+
dispose() {
|
|
1624
|
+
this.active = false;
|
|
1625
|
+
this.listeners.clear();
|
|
1626
|
+
}
|
|
1627
|
+
key(module2) {
|
|
1628
|
+
return `dsh-agent-enhancer:overlap-hint:${this.version}:${module2}`;
|
|
1629
|
+
}
|
|
1630
|
+
dismissed(module2) {
|
|
1631
|
+
try {
|
|
1632
|
+
return this.storage?.getItem(this.key(module2)) === "1";
|
|
1633
|
+
} catch {
|
|
1634
|
+
return false;
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
remember(module2) {
|
|
1638
|
+
try {
|
|
1639
|
+
this.storage?.setItem(this.key(module2), "1");
|
|
1640
|
+
} catch {
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
emit() {
|
|
1644
|
+
for (const listener of this.listeners) listener();
|
|
1645
|
+
}
|
|
1646
|
+
};
|
|
1647
|
+
|
|
1648
|
+
// src/client/dsh/model-catalog.ts
|
|
1649
|
+
function asCatalogFn(face, method) {
|
|
1650
|
+
if (face === void 0 || face === null || typeof face !== "object") return void 0;
|
|
1651
|
+
const fn = face[method];
|
|
1652
|
+
if (typeof fn !== "function") return void 0;
|
|
1653
|
+
return () => fn.call(face);
|
|
1654
|
+
}
|
|
1655
|
+
function probeRemoteFace(remote, name) {
|
|
1656
|
+
try {
|
|
1657
|
+
return remote[name];
|
|
1658
|
+
} catch {
|
|
1659
|
+
return void 0;
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
function catalogLoadersFromRemote(remote) {
|
|
1663
|
+
if (remote === void 0 || remote === null || typeof remote !== "object") return {};
|
|
1664
|
+
return {
|
|
1665
|
+
sessionModelCatalog: asCatalogFn(probeRemoteFace(remote, "session"), "modelCatalog"),
|
|
1666
|
+
hostListCatalog: asCatalogFn(probeRemoteFace(remote, "agentEnhancer"), "listCatalog")
|
|
1667
|
+
};
|
|
1668
|
+
}
|
|
1669
|
+
async function loadDesktopModelCatalog(remoteOrLoaders) {
|
|
1670
|
+
const loaders = remoteOrLoaders !== null && typeof remoteOrLoaders === "object" && ("sessionModelCatalog" in remoteOrLoaders || "hostListCatalog" in remoteOrLoaders) ? remoteOrLoaders : catalogLoadersFromRemote(remoteOrLoaders);
|
|
1671
|
+
const attempts = [];
|
|
1672
|
+
if (loaders.sessionModelCatalog) {
|
|
1673
|
+
attempts.push({ name: "session.modelCatalog", load: loaders.sessionModelCatalog });
|
|
1674
|
+
}
|
|
1675
|
+
if (loaders.hostListCatalog) {
|
|
1676
|
+
attempts.push({ name: "agentEnhancer.listCatalog", load: loaders.hostListCatalog });
|
|
1677
|
+
}
|
|
1678
|
+
if (attempts.length === 0) {
|
|
1679
|
+
throw new Error("no catalog RPC on remote (session/agentEnhancer missing)");
|
|
1680
|
+
}
|
|
1681
|
+
const errors = [];
|
|
1682
|
+
for (const attempt of attempts) {
|
|
1683
|
+
try {
|
|
1684
|
+
const result = await attempt.load();
|
|
1685
|
+
if (result.ok) return result.value;
|
|
1686
|
+
errors.push(`${attempt.name}: ${result.error.code}`);
|
|
1687
|
+
} catch (error) {
|
|
1688
|
+
if (error instanceof Error && error.name === "AbortError") throw error;
|
|
1689
|
+
errors.push(`${attempt.name}: ${error instanceof Error ? error.message : String(error)}`);
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
throw new Error(errors.join(" | "));
|
|
1693
|
+
}
|
|
1694
|
+
var SEP = "|";
|
|
1695
|
+
function encodeFollowSelection() {
|
|
1696
|
+
return "follow";
|
|
1697
|
+
}
|
|
1698
|
+
function encodeModelSelection(provider, model) {
|
|
1699
|
+
return `m${SEP}${provider}${SEP}${model}`;
|
|
1700
|
+
}
|
|
1701
|
+
function encodeEffortSelection(provider, model, effort) {
|
|
1702
|
+
return `e${SEP}${provider}${SEP}${model}${SEP}${effort}`;
|
|
1703
|
+
}
|
|
1704
|
+
function decodeModelSelection(id) {
|
|
1705
|
+
if (id === "follow") return { kind: "follow" };
|
|
1706
|
+
if (id.startsWith(`m${SEP}`)) {
|
|
1707
|
+
const parts = id.slice(2).split(SEP);
|
|
1708
|
+
if (parts.length !== 2 || parts[0] === "" || parts[1] === "") return null;
|
|
1709
|
+
return {
|
|
1710
|
+
kind: "model",
|
|
1711
|
+
provider: parts[0],
|
|
1712
|
+
model: parts[1],
|
|
1713
|
+
reasoningEffort: ""
|
|
1714
|
+
};
|
|
1715
|
+
}
|
|
1716
|
+
if (id.startsWith(`e${SEP}`)) {
|
|
1717
|
+
const parts = id.slice(2).split(SEP);
|
|
1718
|
+
if (parts.length !== 3 || parts[0] === "" || parts[1] === "") return null;
|
|
1719
|
+
return {
|
|
1720
|
+
kind: "model",
|
|
1721
|
+
provider: parts[0],
|
|
1722
|
+
model: parts[1],
|
|
1723
|
+
reasoningEffort: parts[2]
|
|
1724
|
+
};
|
|
1725
|
+
}
|
|
1726
|
+
if (id.startsWith("m\0")) {
|
|
1727
|
+
const rest = id.slice(2);
|
|
1728
|
+
const separator = rest.indexOf("\0");
|
|
1729
|
+
if (separator <= 0 || separator === rest.length - 1) return null;
|
|
1730
|
+
return {
|
|
1731
|
+
kind: "model",
|
|
1732
|
+
provider: rest.slice(0, separator),
|
|
1733
|
+
model: rest.slice(separator + 1),
|
|
1734
|
+
reasoningEffort: ""
|
|
1735
|
+
};
|
|
1736
|
+
}
|
|
1737
|
+
if (id.startsWith("e\0")) {
|
|
1738
|
+
const parts = id.slice(2).split("\0");
|
|
1739
|
+
if (parts.length !== 3 || parts[0] === "" || parts[1] === "") return null;
|
|
1740
|
+
return {
|
|
1741
|
+
kind: "model",
|
|
1742
|
+
provider: parts[0],
|
|
1743
|
+
model: parts[1],
|
|
1744
|
+
reasoningEffort: parts[2]
|
|
1745
|
+
};
|
|
1746
|
+
}
|
|
1747
|
+
return null;
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
// src/client/dsh/settings-form.ts
|
|
1751
|
+
var AcceptedSettingsForm = class {
|
|
1752
|
+
constructor(form) {
|
|
1753
|
+
this.form = form;
|
|
1754
|
+
this.snapshot = form.getSnapshot();
|
|
1755
|
+
}
|
|
1756
|
+
form;
|
|
1757
|
+
listeners = /* @__PURE__ */ new Set();
|
|
1758
|
+
accepted = /* @__PURE__ */ new Map();
|
|
1759
|
+
snapshot;
|
|
1760
|
+
getSnapshot() {
|
|
1761
|
+
return this.snapshot;
|
|
1762
|
+
}
|
|
1763
|
+
subscribe(listener) {
|
|
1764
|
+
this.listeners.add(listener);
|
|
1765
|
+
const unsubscribe = this.form.subscribe(() => {
|
|
1766
|
+
this.refresh();
|
|
1767
|
+
listener();
|
|
1768
|
+
});
|
|
1769
|
+
return () => {
|
|
1770
|
+
this.listeners.delete(listener);
|
|
1771
|
+
unsubscribe();
|
|
1772
|
+
};
|
|
1773
|
+
}
|
|
1774
|
+
async set(field, value) {
|
|
1775
|
+
const key = field;
|
|
1776
|
+
const revision = this.form.getSnapshot().revision;
|
|
1777
|
+
const accepted = await this.form.set(key, value);
|
|
1778
|
+
if (accepted) {
|
|
1779
|
+
this.accepted.set(key, { value, revision });
|
|
1780
|
+
this.refresh();
|
|
1781
|
+
for (const listener of this.listeners) listener();
|
|
1782
|
+
}
|
|
1783
|
+
return accepted;
|
|
1784
|
+
}
|
|
1785
|
+
refresh() {
|
|
1786
|
+
const current = this.form.getSnapshot();
|
|
1787
|
+
const value = { ...current.value };
|
|
1788
|
+
let overridden = false;
|
|
1789
|
+
for (const [field, accepted] of this.accepted) {
|
|
1790
|
+
if (current.value?.[field] === accepted.value || current.revision !== void 0 && (accepted.revision === void 0 || current.revision > accepted.revision)) {
|
|
1791
|
+
this.accepted.delete(field);
|
|
1792
|
+
} else {
|
|
1793
|
+
value[field] = accepted.value;
|
|
1794
|
+
overridden = true;
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
this.snapshot = overridden ? { ...current, value } : current;
|
|
1798
|
+
}
|
|
1799
|
+
};
|
|
1800
|
+
|
|
1801
|
+
// src/client/dsh/settings.tsx
|
|
1802
|
+
var import_dsh_client_ui_primitives4 = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
1803
|
+
var import_react4 = require("react");
|
|
1804
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1805
|
+
var LABELS = {
|
|
1806
|
+
history: "history",
|
|
1807
|
+
optimize: "optimize",
|
|
1808
|
+
predict: "predict",
|
|
1809
|
+
rollback: "rollback"
|
|
1810
|
+
};
|
|
1811
|
+
var DESCRIPTIONS = {
|
|
1812
|
+
history: "historyDescription",
|
|
1813
|
+
optimize: "optimizeDescription",
|
|
1814
|
+
predict: "predictDescription",
|
|
1815
|
+
rollback: "rollbackDescription"
|
|
1816
|
+
};
|
|
1817
|
+
var MODEL_FEATURES = /* @__PURE__ */ new Set(["optimize", "predict"]);
|
|
1818
|
+
function findModel(groups, provider, model) {
|
|
1819
|
+
return groups.find((group) => group.id === provider)?.models.find((entry) => entry.id === model);
|
|
1820
|
+
}
|
|
1821
|
+
function pillLabel(selection, groups, followLabel) {
|
|
1822
|
+
if (isFollowSessionModel(selection)) return followLabel;
|
|
1823
|
+
const model = findModel(groups, selection.provider, selection.model);
|
|
1824
|
+
const name = model?.name ?? selection.model;
|
|
1825
|
+
if (selection.reasoningEffort === "") return name;
|
|
1826
|
+
const effort = model?.reasoning?.efforts.find((entry) => entry.id === selection.reasoningEffort);
|
|
1827
|
+
return `${name} \xB7 ${effort?.name ?? selection.reasoningEffort}`;
|
|
1828
|
+
}
|
|
1829
|
+
function catalogMenuItems(groups, followLabel, defaultEffortLabel) {
|
|
1830
|
+
const items = [{ id: encodeFollowSelection(), label: followLabel }];
|
|
1831
|
+
for (const group of groups) {
|
|
1832
|
+
items.push({ type: "separator", id: `sep:${group.id}` });
|
|
1833
|
+
items.push({ type: "label", id: `label:${group.id}`, text: group.name });
|
|
1834
|
+
for (const model of group.models) {
|
|
1835
|
+
const efforts = model.reasoning?.efforts ?? [];
|
|
1836
|
+
if (efforts.length === 0) {
|
|
1837
|
+
items.push({
|
|
1838
|
+
id: encodeModelSelection(group.id, model.id),
|
|
1839
|
+
label: model.name
|
|
1840
|
+
});
|
|
1841
|
+
continue;
|
|
1842
|
+
}
|
|
1843
|
+
items.push({
|
|
1844
|
+
id: encodeEffortSelection(group.id, model.id, ""),
|
|
1845
|
+
label: `${model.name} \xB7 ${defaultEffortLabel}`
|
|
1846
|
+
});
|
|
1847
|
+
for (const effort of efforts) {
|
|
1848
|
+
items.push({
|
|
1849
|
+
id: encodeEffortSelection(group.id, model.id, effort.id),
|
|
1850
|
+
label: `${model.name} \xB7 ${effort.name}`
|
|
1851
|
+
});
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
return items;
|
|
1856
|
+
}
|
|
1857
|
+
function selectedMenuId(selection, groups) {
|
|
1858
|
+
if (isFollowSessionModel(selection)) return encodeFollowSelection();
|
|
1859
|
+
const model = findModel(groups, selection.provider, selection.model);
|
|
1860
|
+
if ((model?.reasoning?.efforts.length ?? 0) > 0) {
|
|
1861
|
+
return encodeEffortSelection(selection.provider, selection.model, selection.reasoningEffort);
|
|
1862
|
+
}
|
|
1863
|
+
return encodeModelSelection(selection.provider, selection.model);
|
|
1864
|
+
}
|
|
1865
|
+
function ModelPill({
|
|
1866
|
+
feature,
|
|
1867
|
+
selection,
|
|
1868
|
+
groups,
|
|
1869
|
+
catalogStatus,
|
|
1870
|
+
disabled,
|
|
1871
|
+
t,
|
|
1872
|
+
onOpen,
|
|
1873
|
+
onSelect
|
|
1874
|
+
}) {
|
|
1875
|
+
const [open, setOpen] = (0, import_react4.useState)(false);
|
|
1876
|
+
const followLabel = t("modelFollowSession");
|
|
1877
|
+
const label = catalogStatus === "loading" ? t("modelCatalogLoading") : catalogStatus === "error" ? t("modelCatalogError") : pillLabel(selection, groups, followLabel);
|
|
1878
|
+
const items = catalogMenuItems(groups, followLabel, t("reasoningDefault"));
|
|
1879
|
+
const active = !isFollowSessionModel(selection);
|
|
1880
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1881
|
+
import_dsh_client_ui_primitives4.Menu,
|
|
1882
|
+
{
|
|
1883
|
+
open,
|
|
1884
|
+
onClose: () => {
|
|
1885
|
+
setOpen(false);
|
|
1886
|
+
},
|
|
1887
|
+
align: "end",
|
|
1888
|
+
side: "bottom",
|
|
1889
|
+
portal: true,
|
|
1890
|
+
compact: true,
|
|
1891
|
+
dense: true,
|
|
1892
|
+
selectedId: selectedMenuId(selection, groups),
|
|
1893
|
+
items: catalogStatus === "ready" ? items : [{ id: encodeFollowSelection(), label: followLabel }],
|
|
1894
|
+
onSelect: (id) => {
|
|
1895
|
+
setOpen(false);
|
|
1896
|
+
onSelect(feature, id);
|
|
1897
|
+
},
|
|
1898
|
+
anchor: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1899
|
+
import_dsh_client_ui_primitives4.Pill,
|
|
1900
|
+
{
|
|
1901
|
+
active: active || open,
|
|
1902
|
+
disabled,
|
|
1903
|
+
className: css_module_default.modelPill,
|
|
1904
|
+
"aria-label": `${t(LABELS[feature])} ${t("modelLabel")}`,
|
|
1905
|
+
title: label,
|
|
1906
|
+
onClick: () => {
|
|
1907
|
+
if (disabled) return;
|
|
1908
|
+
onOpen();
|
|
1909
|
+
setOpen((current) => !current);
|
|
1910
|
+
},
|
|
1911
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: css_module_default.modelPillLabel, children: label })
|
|
1912
|
+
}
|
|
1913
|
+
)
|
|
1914
|
+
}
|
|
1915
|
+
);
|
|
1916
|
+
}
|
|
1917
|
+
var SettingsErrorBoundary = class extends import_react4.Component {
|
|
1918
|
+
state = { error: null };
|
|
1919
|
+
static getDerivedStateFromError(error) {
|
|
1920
|
+
return { error };
|
|
1921
|
+
}
|
|
1922
|
+
componentDidCatch(error, info) {
|
|
1923
|
+
console.error("agent-enhancer settings render failed", error, info.componentStack);
|
|
1924
|
+
}
|
|
1925
|
+
render() {
|
|
1926
|
+
if (this.state.error !== null) return this.props.fallback(this.state.error);
|
|
1927
|
+
return this.props.children;
|
|
1928
|
+
}
|
|
1929
|
+
};
|
|
1930
|
+
function PluginSettingsBody({ form, t, loadCatalog }) {
|
|
1931
|
+
const formState = (0, import_react4.useSyncExternalStore)(
|
|
1932
|
+
(listener) => form.subscribe(listener),
|
|
1933
|
+
() => form.getSnapshot(),
|
|
1934
|
+
() => form.getSnapshot()
|
|
1935
|
+
);
|
|
1936
|
+
const settings = resolveSettings(formState?.value);
|
|
1937
|
+
const writable = formState?.writable !== false;
|
|
1938
|
+
const [saving, setSaving] = (0, import_react4.useState)(null);
|
|
1939
|
+
const [error, setError] = (0, import_react4.useState)(false);
|
|
1940
|
+
const [catalog, setCatalog] = (0, import_react4.useState)(null);
|
|
1941
|
+
const [catalogStatus, setCatalogStatus] = (0, import_react4.useState)(
|
|
1942
|
+
loadCatalog === void 0 ? "idle" : "loading"
|
|
1943
|
+
);
|
|
1944
|
+
const [catalogError, setCatalogError] = (0, import_react4.useState)(null);
|
|
1945
|
+
const refreshCatalog = () => {
|
|
1946
|
+
if (loadCatalog === void 0) return;
|
|
1947
|
+
setCatalogStatus((current) => current === "ready" ? current : "loading");
|
|
1948
|
+
setCatalogError(null);
|
|
1949
|
+
void loadCatalog().then(
|
|
1950
|
+
(value) => {
|
|
1951
|
+
setCatalog(value);
|
|
1952
|
+
setCatalogStatus("ready");
|
|
1953
|
+
setCatalogError(null);
|
|
1954
|
+
},
|
|
1955
|
+
(cause) => {
|
|
1956
|
+
setCatalog(null);
|
|
1957
|
+
setCatalogStatus("error");
|
|
1958
|
+
setCatalogError(cause instanceof Error ? cause.message : String(cause));
|
|
1959
|
+
}
|
|
1960
|
+
);
|
|
1961
|
+
};
|
|
1962
|
+
(0, import_react4.useEffect)(() => {
|
|
1963
|
+
if (loadCatalog === void 0) return;
|
|
1964
|
+
let active = true;
|
|
1965
|
+
setCatalogStatus("loading");
|
|
1966
|
+
setCatalogError(null);
|
|
1967
|
+
void loadCatalog().then(
|
|
1968
|
+
(value) => {
|
|
1969
|
+
if (!active) return;
|
|
1970
|
+
setCatalog(value);
|
|
1971
|
+
setCatalogStatus("ready");
|
|
1972
|
+
setCatalogError(null);
|
|
1973
|
+
},
|
|
1974
|
+
(cause) => {
|
|
1975
|
+
if (!active) return;
|
|
1976
|
+
setCatalog(null);
|
|
1977
|
+
setCatalogStatus("error");
|
|
1978
|
+
setCatalogError(cause instanceof Error ? cause.message : String(cause));
|
|
1979
|
+
}
|
|
1980
|
+
);
|
|
1981
|
+
return () => {
|
|
1982
|
+
active = false;
|
|
1983
|
+
};
|
|
1984
|
+
}, [loadCatalog]);
|
|
1985
|
+
const onToggle = async (module2, checked) => {
|
|
1986
|
+
setSaving(`${module2}Enabled`);
|
|
1987
|
+
setError(false);
|
|
1988
|
+
try {
|
|
1989
|
+
const accepted = await form.set(`${module2}Enabled`, checked);
|
|
1990
|
+
if (!accepted) setError(true);
|
|
1991
|
+
} catch {
|
|
1992
|
+
setError(true);
|
|
1993
|
+
} finally {
|
|
1994
|
+
setSaving(null);
|
|
1995
|
+
}
|
|
1996
|
+
};
|
|
1997
|
+
const saveFields = async (fields) => {
|
|
1998
|
+
setSaving(fields.map(([field]) => field).join(","));
|
|
1999
|
+
setError(false);
|
|
2000
|
+
try {
|
|
2001
|
+
for (const [field, value] of fields) {
|
|
2002
|
+
const accepted = await form.set(field, value);
|
|
2003
|
+
if (!accepted) {
|
|
2004
|
+
setError(true);
|
|
2005
|
+
return;
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
} catch {
|
|
2009
|
+
setError(true);
|
|
2010
|
+
} finally {
|
|
2011
|
+
setSaving(null);
|
|
2012
|
+
}
|
|
2013
|
+
};
|
|
2014
|
+
const onModelMenuSelect = async (feature, id) => {
|
|
2015
|
+
const decoded = decodeModelSelection(id);
|
|
2016
|
+
if (decoded === null) return;
|
|
2017
|
+
if (decoded.kind === "follow") {
|
|
2018
|
+
await saveFields([
|
|
2019
|
+
[`${feature}Provider`, ""],
|
|
2020
|
+
[`${feature}Model`, ""],
|
|
2021
|
+
[`${feature}ReasoningEffort`, ""]
|
|
2022
|
+
]);
|
|
2023
|
+
return;
|
|
2024
|
+
}
|
|
2025
|
+
await saveFields([
|
|
2026
|
+
[`${feature}Provider`, decoded.provider],
|
|
2027
|
+
[`${feature}Model`, decoded.model],
|
|
2028
|
+
[`${feature}ReasoningEffort`, decoded.reasoningEffort]
|
|
2029
|
+
]);
|
|
2030
|
+
};
|
|
2031
|
+
const busy = !writable || saving !== null;
|
|
2032
|
+
const groups = catalog?.groups ?? [];
|
|
2033
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { "aria-label": t("settingsTitle"), className: css_module_default.settings, children: [
|
|
2034
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("header", { className: css_module_default.settingsHeader, children: [
|
|
2035
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h2", { children: t("settingsTitle") }),
|
|
2036
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: t("settingsSubtitle") })
|
|
2037
|
+
] }),
|
|
2038
|
+
MODULES.map((module2) => {
|
|
2039
|
+
const modelFeature = MODEL_FEATURES.has(module2) ? module2 : null;
|
|
2040
|
+
const selection = modelFeature === null ? null : auxiliaryModelOf(settings, modelFeature);
|
|
2041
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: css_module_default.settingRow, children: [
|
|
2042
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: css_module_default.settingText, children: [
|
|
2043
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h3", { children: t(LABELS[module2]) }),
|
|
2044
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: css_module_default.settingDescription, children: t(DESCRIPTIONS[module2]) })
|
|
2045
|
+
] }),
|
|
2046
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: css_module_default.settingControls, children: [
|
|
2047
|
+
modelFeature !== null && selection !== null && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2048
|
+
ModelPill,
|
|
2049
|
+
{
|
|
2050
|
+
feature: modelFeature,
|
|
2051
|
+
selection,
|
|
2052
|
+
groups,
|
|
2053
|
+
catalogStatus,
|
|
2054
|
+
disabled: busy,
|
|
2055
|
+
t,
|
|
2056
|
+
onOpen: refreshCatalog,
|
|
2057
|
+
onSelect: (feature, id) => {
|
|
2058
|
+
void onModelMenuSelect(feature, id);
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
),
|
|
2062
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2063
|
+
import_dsh_client_ui_primitives4.Switch,
|
|
2064
|
+
{
|
|
2065
|
+
label: t(LABELS[module2]),
|
|
2066
|
+
checked: settings[`${module2}Enabled`],
|
|
2067
|
+
disabled: busy,
|
|
2068
|
+
onChange: (checked) => {
|
|
2069
|
+
void onToggle(module2, checked);
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
)
|
|
2073
|
+
] })
|
|
2074
|
+
] }, module2);
|
|
2075
|
+
}),
|
|
2076
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { role: "status", children: t("settingsError") }),
|
|
2077
|
+
catalogStatus === "error" && catalogError !== null && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("p", { role: "status", className: css_module_default.settingDescription, title: catalogError, children: [
|
|
2078
|
+
t("modelCatalogError"),
|
|
2079
|
+
": ",
|
|
2080
|
+
catalogError
|
|
2081
|
+
] }),
|
|
2082
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("aside", { "aria-label": t("privacyTitle"), className: css_module_default.privacy, children: [
|
|
2083
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h3", { children: t("privacyTitle") }),
|
|
2084
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: t("privacy") }),
|
|
2085
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: t("rollbackBoundary") }),
|
|
2086
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: t("coexistence") })
|
|
2087
|
+
] })
|
|
2088
|
+
] });
|
|
2089
|
+
}
|
|
2090
|
+
function PluginSettings(props) {
|
|
2091
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SettingsErrorBoundary, { fallback: (error) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { className: css_module_default.settings, role: "alert", children: [
|
|
2092
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h2", { children: props.t("settingsTitle") }),
|
|
2093
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: css_module_default.settingDescription, children: props.t("settingsError") }),
|
|
2094
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("pre", { className: css_module_default.settingDescription, children: error.message })
|
|
2095
|
+
] }), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PluginSettingsBody, { ...props }) });
|
|
2096
|
+
}
|
|
2097
|
+
|
|
2098
|
+
// src/client/locales.ts
|
|
2099
|
+
var agentLocales = {
|
|
2100
|
+
zh: {
|
|
2101
|
+
historyTitle: "\u5386\u53F2\u63D0\u793A\u8BCD",
|
|
2102
|
+
historySearch: "\u641C\u7D22\u5386\u53F2\u63D0\u793A\u8BCD",
|
|
2103
|
+
historyResults: "\u5386\u53F2\u63D0\u793A\u8BCD\u7ED3\u679C",
|
|
2104
|
+
historyClose: "\u5173\u95ED\u5386\u53F2\u63D0\u793A\u8BCD",
|
|
2105
|
+
optimize: "\u4F18\u5316\u63D0\u793A\u8BCD",
|
|
2106
|
+
optimizePending: "\u6B63\u5728\u4F18\u5316\u63D0\u793A\u8BCD",
|
|
2107
|
+
optimizeUndo: "\u64A4\u9500\u4F18\u5316",
|
|
2108
|
+
optimizeError: "\u4F18\u5316\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5",
|
|
2109
|
+
optimizeModelUnavailable: "\u5F53\u524D\u6A21\u578B\u4E0D\u53EF\u7528\uFF0C\u8BF7\u68C0\u67E5\u6A21\u578B\u9009\u62E9",
|
|
2110
|
+
optimizeRequestFailed: "\u4F18\u5316\u8BF7\u6C42\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5",
|
|
2111
|
+
optimizeInvalidOutput: "\u6A21\u578B\u8FD4\u56DE\u5185\u5BB9\u65E0\u6CD5\u5B89\u5168\u5E94\u7528\uFF0C\u8BF7\u91CD\u8BD5",
|
|
2112
|
+
optimizeRollbackFailed: "\u8349\u7A3F\u6062\u590D\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u8349\u7A3F\u5E76\u624B\u52A8\u6062\u590D",
|
|
2113
|
+
optimizeSessionChanged: "\u4F1A\u8BDD\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u4F18\u5316",
|
|
2114
|
+
optimizeChips: "\u4FDD\u7559\u5F15\u7528\uFF0C\u4EC5\u4F18\u5316\u5176\u4ED6\u6587\u5B57",
|
|
2115
|
+
optimizeChipSelection: "\u9009\u533A\u5305\u542B\u5F15\u7528\uFF0C\u8BF7\u4F18\u5316\u6574\u7A3F\u6216\u8C03\u6574\u9009\u533A",
|
|
2116
|
+
settingsTitle: "\u667A\u80FD\u4F53\u589E\u5F3A",
|
|
2117
|
+
settingsSubtitle: "\u4E00\u4E2A\u63D2\u4EF6\u8865\u9F50\u5E38\u7528 Agent \u4F53\u9A8C\uFF0C\u6309\u9700\u5F00\u5173",
|
|
2118
|
+
history: "\u5386\u53F2\u63D0\u793A\u8BCD",
|
|
2119
|
+
historyDescription: "\u2191\u2193 \u56DE\u987E\u5DF2\u53D1\u9001\u63D0\u793A\u8BCD\uFF1BAlt+R \u641C\u7D22\uFF08\u53EF\u7528\u73AF\u5883\u517C\u5BB9 Ctrl+R\uFF09",
|
|
2120
|
+
optimizeDescription: "\u4F18\u5316\u8349\u7A3F\u6216\u6240\u9009\u5185\u5BB9\uFF0C\u652F\u6301\u4E00\u952E\u64A4\u9500",
|
|
2121
|
+
predict: "\u4E0B\u4E00\u6761\u63D0\u793A\u8BCD\u9884\u6D4B",
|
|
2122
|
+
predictDescription: "\u56DE\u590D\u540E\u7ED9\u51FA\u4E00\u6761\u5EFA\u8BAE\uFF0C\u6309 Tab \u91C7\u7EB3",
|
|
2123
|
+
modelCatalogLoading: "\u52A0\u8F7D\u4E2D\u2026",
|
|
2124
|
+
modelCatalogError: "\u6A21\u578B\u4E0D\u53EF\u7528",
|
|
2125
|
+
modelLabel: "\u6A21\u578B",
|
|
2126
|
+
modelFollowSession: "\u8DDF\u968F\u4F1A\u8BDD",
|
|
2127
|
+
reasoningDefault: "\u9ED8\u8BA4",
|
|
2128
|
+
privacyTitle: "\u6570\u636E\u4E0E\u9690\u79C1",
|
|
2129
|
+
privacy: "\u4F18\u5316\u548C\u9884\u6D4B\u4F1A\u628A\u6240\u9009\u5185\u5BB9\u6216\u8FD1\u671F\u5BF9\u8BDD\u53D1\u9001\u7ED9\u6240\u9009\u6A21\u578B\u63D0\u4F9B\u5546\uFF08\u9ED8\u8BA4\u8DDF\u968F\u5F53\u524D\u4F1A\u8BDD\u6A21\u578B\uFF09\uFF1B\u5386\u53F2\u4E0D\u8BF7\u6C42\u6A21\u578B\uFF1B\u4E0D\u91C7\u96C6\u63D0\u793A\u8BCD\u5185\u5BB9\u6216\u91C7\u7EB3\u7387\u9065\u6D4B\u3002",
|
|
2130
|
+
coexistence: "\u68C0\u6D4B\u5230\u5B98\u65B9\u6216\u7B2C\u4E09\u65B9\u540C\u7C7B\u80FD\u529B\u65F6\u4EC5\u63D0\u793A\uFF0C\u4E0D\u4F1A\u81EA\u52A8\u505C\u7528\u3002",
|
|
2131
|
+
settingsError: "\u8BBE\u7F6E\u672A\u4FDD\u5B58\uFF0C\u8BF7\u91CD\u8BD5\u3002",
|
|
2132
|
+
overlapHistory: "\u68C0\u6D4B\u5230\u53E6\u4E00\u4E2A\u5386\u53F2\u63D0\u793A\u8BCD\u529F\u80FD\u3002\u667A\u80FD\u4F53\u589E\u5F3A\u7684\u5386\u53F2\u4ECD\u4FDD\u6301\u5F00\u542F\u3002",
|
|
2133
|
+
overlapOptimize: "\u68C0\u6D4B\u5230\u53E6\u4E00\u4E2A\u63D0\u793A\u8BCD\u4F18\u5316\u529F\u80FD\u3002\u667A\u80FD\u4F53\u589E\u5F3A\u7684\u4F18\u5316\u4ECD\u4FDD\u6301\u5F00\u542F\u3002",
|
|
2134
|
+
overlapPredict: "\u68C0\u6D4B\u5230\u53E6\u4E00\u4E2A\u56DE\u590D\u5EFA\u8BAE\u529F\u80FD\u3002\u667A\u80FD\u4F53\u589E\u5F3A\u7684\u9884\u6D4B\u4ECD\u4FDD\u6301\u5F00\u542F\u3002",
|
|
2135
|
+
dismissHint: "\u5173\u95ED\u5171\u5B58\u63D0\u793A",
|
|
2136
|
+
rollback: "\u5BF9\u8BDD\u4E0E\u6587\u4EF6\u6062\u590D",
|
|
2137
|
+
rollbackDescription: "\u5728\u5408\u89C4\u7528\u6237\u6D88\u606F\u65C1\u9884\u89C8\u5E76\u6062\u590D\u5BF9\u8BDD\u4E0E\u5DF2\u8DDF\u8E2A\u6587\u4EF6",
|
|
2138
|
+
rollbackBoundary: "\u4E0D\u6062\u590D\u8FDB\u7A0B\u3001\u7EC8\u7AEF\u3001\u540E\u53F0\u4EFB\u52A1\u3001\u6570\u636E\u5E93\u3001\u7F51\u7EDC\u3001\u90E8\u7F72\u3001\u7B2C\u4E09\u65B9\u670D\u52A1\u6216\u672A\u8DDF\u8E2A\u6587\u4EF6\uFF1B\u5173\u95ED\u540E\u4FDD\u7559\u5DF2\u6709\u65E5\u5FD7\u548C\u68C0\u67E5\u70B9\u3002",
|
|
2139
|
+
rollbackAction: "\u6062\u590D\u5230\u8FD9\u91CC",
|
|
2140
|
+
rollbackUndoAction: "\u64A4\u9500\u6062\u590D",
|
|
2141
|
+
rollbackUndoCommandDescription: "\u64A4\u56DE\u6700\u8FD1\u4E00\u6B21\u6062\u590D\u6807\u8BB0\uFF0C\u5E76\u8FD8\u539F\u6062\u590D\u524D\u7684\u9884\u89C8\u5185\u5BB9",
|
|
2142
|
+
rollbackTitle: "\u6062\u590D\u5230\u7B2C {turn} \u8F6E\u4E4B\u524D",
|
|
2143
|
+
rollbackUndoTitle: "\u64A4\u9500\u7B2C {turn} \u8F6E\u6062\u590D",
|
|
2144
|
+
rollbackScope: "\u53EF\u9009\u62E9\u4EC5\u6062\u590D\u5BF9\u8BDD\uFF0C\u6216\u540C\u65F6\u6062\u590D\u5DF2\u8DDF\u8E2A\u6587\u4EF6\u3002\u8FDB\u7A0B\u3001\u7EC8\u7AEF\u3001\u540E\u53F0\u4EFB\u52A1\u3001\u6570\u636E\u5E93\u3001\u7F51\u7EDC\u3001\u90E8\u7F72\u3001\u7B2C\u4E09\u65B9\u670D\u52A1\u548C\u672A\u8DDF\u8E2A\u6587\u4EF6\u4E0D\u4F1A\u6062\u590D\u3002\u65E0\u6587\u4EF6\u53D8\u66F4\u6216\u4EC5\u6709\u6355\u83B7\u7F3A\u53E3\u65F6\u4ECD\u53EF\u786E\u8BA4\uFF1B\u6709\u6587\u4EF6\u51B2\u7A81\u65F6\u4ECD\u53EF\u4EC5\u6062\u590D\u5BF9\u8BDD\u3002",
|
|
2145
|
+
rollbackUndoScope: "\u5C06\u64A4\u56DE\u672C\u6B21\u6062\u590D\u6807\u8BB0\uFF0C\u5E76\u8FD8\u539F\u6062\u590D\u524D\u7684\u5BF9\u8BDD\u4E0E\u5DF2\u8DDF\u8E2A\u6587\u4EF6\u9884\u89C8\u3002\u8FDB\u7A0B\u3001\u7EC8\u7AEF\u3001\u540E\u53F0\u4EFB\u52A1\u3001\u6570\u636E\u5E93\u3001\u7F51\u7EDC\u3001\u90E8\u7F72\u3001\u7B2C\u4E09\u65B9\u670D\u52A1\u548C\u672A\u8DDF\u8E2A\u6587\u4EF6\u4E0D\u4F1A\u6062\u590D\u3002",
|
|
2146
|
+
rollbackUndoScopeConversation: "\u5C06\u64A4\u56DE\u672C\u6B21\u4EC5\u5BF9\u8BDD\u6062\u590D\u6807\u8BB0\uFF0C\u5E76\u8FD8\u539F\u6062\u590D\u524D\u7684\u5BF9\u8BDD\u9884\u89C8\u3002\u5DF2\u8DDF\u8E2A\u6587\u4EF6\u4FDD\u6301\u5F53\u524D\u72B6\u6001\u3002",
|
|
2147
|
+
rollbackClose: "\u5173\u95ED\u6062\u590D\u9884\u89C8",
|
|
2148
|
+
rollbackConfirm: "\u6062\u590D\u5BF9\u8BDD\u4E0E\u5DF2\u8DDF\u8E2A\u6587\u4EF6",
|
|
2149
|
+
rollbackConfirmConversation: "\u4EC5\u6062\u590D\u5BF9\u8BDD",
|
|
2150
|
+
rollbackUndoConfirm: "\u64A4\u9500\u6062\u590D\u5E76\u8FD8\u539F\u9884\u89C8\u5185\u5BB9",
|
|
2151
|
+
rollbackUndoConfirmConversation: "\u64A4\u9500\u6062\u590D\u5E76\u8FD8\u539F\u5BF9\u8BDD",
|
|
2152
|
+
rollbackCancel: "\u53D6\u6D88",
|
|
2153
|
+
rollbackLoading: "\u6B63\u5728\u91CD\u65B0\u68C0\u67E5\u5BF9\u8BDD\u548C\u6587\u4EF6\u72B6\u6001\u2026",
|
|
2154
|
+
rollbackRestoring: "\u6B63\u5728\u6062\u590D\u5BF9\u8BDD\u4E0E\u5DF2\u8DDF\u8E2A\u6587\u4EF6\u2026",
|
|
2155
|
+
rollbackRestoringConversation: "\u6B63\u5728\u6062\u590D\u5BF9\u8BDD\u2026",
|
|
2156
|
+
rollbackUndoRestoring: "\u6B63\u5728\u64A4\u9500\u6062\u590D\u5E76\u8FD8\u539F\u5BF9\u8BDD\u4E0E\u5DF2\u8DDF\u8E2A\u6587\u4EF6\u2026",
|
|
2157
|
+
rollbackUndoRestoringConversation: "\u6B63\u5728\u64A4\u9500\u6062\u590D\u5E76\u8FD8\u539F\u5BF9\u8BDD\u2026",
|
|
2158
|
+
rollbackFailed: "\u6062\u590D\u672A\u5B8C\u6210\uFF0C\u8BF7\u5173\u95ED\u9884\u89C8\u540E\u91CD\u8BD5\u3002",
|
|
2159
|
+
rollbackTurnOpen: "\u672C\u8F6E\u5C1A\u672A\u7ED3\u675F",
|
|
2160
|
+
rollbackTurnStartMissing: "\u672C\u8F6E\u5F00\u59CB\u4E8B\u4EF6\u5C1A\u672A\u52A0\u8F7D",
|
|
2161
|
+
rollbackMessages: "\u5C06\u64A4\u56DE\u7684\u5BF9\u8BDD",
|
|
2162
|
+
rollbackFiles: "\u5C06\u6062\u590D\u7684\u5DF2\u8DDF\u8E2A\u6587\u4EF6",
|
|
2163
|
+
rollbackGaps: "\u65E0\u6CD5\u6062\u590D\u7684\u539F\u56E0",
|
|
2164
|
+
rollbackFilesLimited: "\u5B8C\u6574\u6062\u590D\u53D7\u9650",
|
|
2165
|
+
rollbackFilesLimitedHint: "\u4ECD\u53EF\u53EA\u6062\u590D\u5BF9\u8BDD\uFF1B\u5DE5\u4F5C\u533A\u6355\u83B7\u4E0D\u5B8C\u6574\u6216\u6587\u4EF6\u6709\u51B2\u7A81\u65F6\uFF0C\u4E0D\u5EFA\u8BAE\u6062\u590D\u6587\u4EF6\u3002",
|
|
2166
|
+
rollbackConflicts: "\u6587\u4EF6\u51B2\u7A81",
|
|
2167
|
+
rollbackNoMessages: "\u6CA1\u6709\u53EF\u9884\u89C8\u7684\u5BF9\u8BDD\u6D88\u606F\u3002",
|
|
2168
|
+
rollbackNoFiles: "\u6B64\u68C0\u67E5\u70B9\u6CA1\u6709\u5DF2\u8DDF\u8E2A\u6587\u4EF6\u3002",
|
|
2169
|
+
rollbackFile_create: "\u5220\u9664\u672C\u8F6E\u521B\u5EFA\u7684\u6587\u4EF6",
|
|
2170
|
+
rollbackFile_modify: "\u6062\u590D\u4FEE\u6539\u524D\u5185\u5BB9",
|
|
2171
|
+
rollbackFile_delete: "\u6062\u590D\u5DF2\u5220\u9664\u6587\u4EF6",
|
|
2172
|
+
rollbackGapWorkspace: "\u5DE5\u4F5C\u533A\u6355\u83B7\u4E0D\u5B8C\u6574",
|
|
2173
|
+
rollbackGapPrompt: "\u539F\u63D0\u793A\u8BCD\u4E0D\u662F\u7EAF\u6587\u672C",
|
|
2174
|
+
rollbackUnavailableCheckpoint: "\u627E\u4E0D\u5230\u6B64\u8F6E\u68C0\u67E5\u70B9",
|
|
2175
|
+
rollbackUnavailableIncomplete: "\u68C0\u67E5\u70B9\u4E0D\u5B8C\u6574\uFF1B\u4ECD\u53EF\u53EA\u6062\u590D\u5BF9\u8BDD",
|
|
2176
|
+
rollbackUnavailableSessionChanged: "\u4F1A\u8BDD\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u9884\u89C8",
|
|
2177
|
+
rollbackUnavailableRunning: "\u4F1A\u8BDD\u4ECD\u5728\u8FD0\u884C",
|
|
2178
|
+
rollbackUnavailablePermission: "\u5F53\u524D\u6CA1\u6709\u6062\u590D\u6743\u9650",
|
|
2179
|
+
rollbackUnavailableDisabled: "\u56DE\u6EDA\u529F\u80FD\u5DF2\u5173\u95ED",
|
|
2180
|
+
rollbackUnavailableFirstTurn: "\u9996\u8F6E\u8FB9\u754C\u8F83\u7279\u6B8A\uFF1B\u4ECD\u53EF\u5C1D\u8BD5\u53EA\u6062\u590D\u5BF9\u8BDD",
|
|
2181
|
+
rollbackUnavailableIncompatible: "\u68C0\u67E5\u70B9\u4E0E\u5F53\u524D\u4F1A\u8BDD\u6216\u63D2\u4EF6\u7248\u672C\u4E0D\u517C\u5BB9",
|
|
2182
|
+
rollbackUnavailableCompacted: "\u5BF9\u8BDD\u66FE\u88AB\u538B\u7F29\uFF1B\u5B8C\u6574\u6587\u4EF6\u6062\u590D\u53EF\u80FD\u4E0D\u53EF\u7528\uFF0C\u4ECD\u53EF\u53EA\u6062\u590D\u5BF9\u8BDD",
|
|
2183
|
+
rollbackUnavailableSubagent: "\u5B50 Agent \u4F1A\u8BDD\u4E0D\u652F\u6301\u56DE\u6EDA",
|
|
2184
|
+
rollbackUnavailableUnknown: "\u5BF9\u8BDD\u7ED3\u6784\u65E0\u6CD5\u5B89\u5168\u8BC6\u522B",
|
|
2185
|
+
rollbackConflictUnsafe: "\u6587\u4EF6\u8DEF\u5F84\u4E0D\u5B89\u5168",
|
|
2186
|
+
rollbackConflictSymlink: "\u6587\u4EF6\u8DEF\u5F84\u5305\u542B\u7B26\u53F7\u94FE\u63A5",
|
|
2187
|
+
rollbackConflictRegular: "\u5F53\u524D\u8DEF\u5F84\u4E0D\u662F\u666E\u901A\u6587\u4EF6",
|
|
2188
|
+
rollbackConflictBinary: "\u4E8C\u8FDB\u5236\u6587\u4EF6\u4E0D\u652F\u6301\u6062\u590D",
|
|
2189
|
+
rollbackConflictLarge: "\u6587\u4EF6\u8D85\u8FC7\u6062\u590D\u5927\u5C0F\u9650\u5236",
|
|
2190
|
+
rollbackConflictBefore: "\u68C0\u67E5\u70B9\u6587\u4EF6\u5185\u5BB9\u65E0\u6548",
|
|
2191
|
+
rollbackConflictHash: "\u6587\u4EF6\u5728\u68C0\u67E5\u70B9\u540E\u53D1\u751F\u4E86\u53D8\u5316"
|
|
2192
|
+
},
|
|
2193
|
+
en: {
|
|
2194
|
+
historyTitle: "Prompt history",
|
|
2195
|
+
historySearch: "Search prompt history",
|
|
2196
|
+
historyResults: "Prompt history results",
|
|
2197
|
+
historyClose: "Close prompt history",
|
|
2198
|
+
optimize: "Optimize prompt",
|
|
2199
|
+
optimizePending: "Optimizing prompt",
|
|
2200
|
+
optimizeUndo: "Undo optimization",
|
|
2201
|
+
optimizeError: "Optimization failed. Try again.",
|
|
2202
|
+
optimizeModelUnavailable: "Model unavailable. Check the model selection.",
|
|
2203
|
+
optimizeRequestFailed: "Optimization failed. Try again.",
|
|
2204
|
+
optimizeInvalidOutput: "The model response cannot be applied safely. Try again.",
|
|
2205
|
+
optimizeRollbackFailed: "Draft recovery failed. Check the draft and restore it manually.",
|
|
2206
|
+
optimizeSessionChanged: "Session changed. Optimize again.",
|
|
2207
|
+
optimizeChips: "References stay unchanged; only surrounding text is optimized",
|
|
2208
|
+
optimizeChipSelection: "Selection includes references. Optimize the full draft or adjust the selection.",
|
|
2209
|
+
settingsTitle: "Agent Enhance",
|
|
2210
|
+
settingsSubtitle: "One plugin for common agent UX \u2014 toggle features as needed",
|
|
2211
|
+
history: "Prompt history",
|
|
2212
|
+
historyDescription: "\u2191\u2193 revisit sent prompts; Alt+R to search (Ctrl+R in compatible environments)",
|
|
2213
|
+
optimizeDescription: "Optimize the draft or selection, with one-click undo",
|
|
2214
|
+
predict: "Next-prompt prediction",
|
|
2215
|
+
predictDescription: "One suggestion after a reply; Tab to accept",
|
|
2216
|
+
modelCatalogLoading: "Loading\u2026",
|
|
2217
|
+
modelCatalogError: "Unavailable",
|
|
2218
|
+
modelLabel: "Model",
|
|
2219
|
+
modelFollowSession: "Follow session",
|
|
2220
|
+
reasoningDefault: "Default",
|
|
2221
|
+
privacyTitle: "Data and privacy",
|
|
2222
|
+
privacy: "Optimization and prediction send selected text or recent conversation to the selected model provider (defaults to the current session model). History never requests a model. No prompt content or acceptance-rate telemetry is collected.",
|
|
2223
|
+
coexistence: "Similar official or third-party features are only reported; they are never disabled automatically.",
|
|
2224
|
+
settingsError: "Setting was not saved. Try again.",
|
|
2225
|
+
overlapHistory: "Another prompt-history feature is enabled. Agent Enhance history remains enabled.",
|
|
2226
|
+
overlapOptimize: "Another prompt-optimization feature is enabled. Agent Enhance optimization remains enabled.",
|
|
2227
|
+
overlapPredict: "Another reply-suggestion feature is enabled. Agent Enhance prediction remains enabled.",
|
|
2228
|
+
dismissHint: "Dismiss coexistence notice",
|
|
2229
|
+
rollback: "Conversation and file restore",
|
|
2230
|
+
rollbackDescription: "Preview and restore conversation and tracked files from eligible user messages",
|
|
2231
|
+
rollbackBoundary: "Processes, terminals, background jobs, databases, network activity, deployments, third-party state, and untracked files are not restored. Existing logs and checkpoints remain after disable.",
|
|
2232
|
+
rollbackAction: "Restore to here",
|
|
2233
|
+
rollbackUndoAction: "Undo restore",
|
|
2234
|
+
rollbackUndoCommandDescription: "Withdraw the latest restore marker and bring back the preview",
|
|
2235
|
+
rollbackTitle: "Restore before turn {turn}",
|
|
2236
|
+
rollbackUndoTitle: "Undo restore before turn {turn}",
|
|
2237
|
+
rollbackScope: "Choose conversation-only restore, or restore conversation and tracked files. Processes, terminals, background jobs, databases, network activity, deployments, third-party state, and untracked files are not restored. Soft capture gaps do not block restore when there are no tracked files; conversation-only remains available when files conflict.",
|
|
2238
|
+
rollbackUndoScope: "Withdraw the restore marker and bring back the conversation and tracked files shown in preview. Processes, terminals, background jobs, databases, network activity, deployments, third-party state, and untracked files are not restored.",
|
|
2239
|
+
rollbackUndoScopeConversation: "Withdraw the conversation-only restore marker and bring back the conversation shown in preview. Tracked files stay as they are.",
|
|
2240
|
+
rollbackClose: "Close restore preview",
|
|
2241
|
+
rollbackConfirm: "Restore conversation and tracked files",
|
|
2242
|
+
rollbackConfirmConversation: "Restore conversation only",
|
|
2243
|
+
rollbackUndoConfirm: "Undo restore and bring back preview",
|
|
2244
|
+
rollbackUndoConfirmConversation: "Undo restore and bring back conversation",
|
|
2245
|
+
rollbackCancel: "Cancel",
|
|
2246
|
+
rollbackLoading: "Rechecking conversation and file state\u2026",
|
|
2247
|
+
rollbackRestoring: "Restoring conversation and tracked files\u2026",
|
|
2248
|
+
rollbackRestoringConversation: "Restoring conversation\u2026",
|
|
2249
|
+
rollbackUndoRestoring: "Undoing restore and bringing back conversation and tracked files\u2026",
|
|
2250
|
+
rollbackUndoRestoringConversation: "Undoing restore and bringing back conversation\u2026",
|
|
2251
|
+
rollbackFailed: "Restore did not complete. Close the preview and try again.",
|
|
2252
|
+
rollbackTurnOpen: "The turn is not closed",
|
|
2253
|
+
rollbackTurnStartMissing: "The turn start is not loaded",
|
|
2254
|
+
rollbackMessages: "Conversation to withdraw",
|
|
2255
|
+
rollbackFiles: "Tracked files to restore",
|
|
2256
|
+
rollbackGaps: "Why restore is unavailable",
|
|
2257
|
+
rollbackFilesLimited: "Full restore is limited",
|
|
2258
|
+
rollbackFilesLimitedHint: "Conversation-only restore is still available. Skip file restore when workspace capture is incomplete or files conflict.",
|
|
2259
|
+
rollbackConflicts: "File conflicts",
|
|
2260
|
+
rollbackNoMessages: "No conversation messages are available for preview.",
|
|
2261
|
+
rollbackNoFiles: "This checkpoint has no tracked files.",
|
|
2262
|
+
rollbackFile_create: "Remove file created in this turn",
|
|
2263
|
+
rollbackFile_modify: "Restore previous content",
|
|
2264
|
+
rollbackFile_delete: "Restore deleted file",
|
|
2265
|
+
rollbackGapWorkspace: "Workspace capture is incomplete",
|
|
2266
|
+
rollbackGapPrompt: "The original prompt was not plain text",
|
|
2267
|
+
rollbackUnavailableCheckpoint: "No checkpoint was found for this turn",
|
|
2268
|
+
rollbackUnavailableIncomplete: "The checkpoint is incomplete; conversation-only restore is still available",
|
|
2269
|
+
rollbackUnavailableSessionChanged: "The session changed. Preview again.",
|
|
2270
|
+
rollbackUnavailableRunning: "The session is still running",
|
|
2271
|
+
rollbackUnavailablePermission: "Restore permission is unavailable",
|
|
2272
|
+
rollbackUnavailableDisabled: "Rollback is disabled",
|
|
2273
|
+
rollbackUnavailableFirstTurn: "The first-turn boundary is unusual; conversation-only restore may still work",
|
|
2274
|
+
rollbackUnavailableIncompatible: "The checkpoint is incompatible with this session or plugin version",
|
|
2275
|
+
rollbackUnavailableCompacted: "The conversation was compacted; full file restore may be unavailable, conversation-only restore still works",
|
|
2276
|
+
rollbackUnavailableSubagent: "Subagent sessions do not support rollback",
|
|
2277
|
+
rollbackUnavailableUnknown: "The conversation structure cannot be verified safely",
|
|
2278
|
+
rollbackConflictUnsafe: "The file path is unsafe",
|
|
2279
|
+
rollbackConflictSymlink: "The file path contains a symbolic link",
|
|
2280
|
+
rollbackConflictRegular: "The current path is not a regular file",
|
|
2281
|
+
rollbackConflictBinary: "Binary files cannot be restored",
|
|
2282
|
+
rollbackConflictLarge: "The file exceeds the restore size limit",
|
|
2283
|
+
rollbackConflictBefore: "The checkpoint file content is invalid",
|
|
2284
|
+
rollbackConflictHash: "File changed after this checkpoint"
|
|
2285
|
+
}
|
|
2286
|
+
};
|
|
2287
|
+
|
|
2288
|
+
// src/client/rollback/remote.ts
|
|
2289
|
+
function codec(typeSymbol) {
|
|
2290
|
+
return {
|
|
2291
|
+
mode: "strict",
|
|
2292
|
+
typeSymbol,
|
|
2293
|
+
create: () => {
|
|
2294
|
+
throw new Error("Client Remote schemas are only available on the Host");
|
|
2295
|
+
}
|
|
2296
|
+
};
|
|
2297
|
+
}
|
|
2298
|
+
var requestCodec = codec("dsh-agent-enhancer#CheckpointRollbackRequest");
|
|
2299
|
+
var checkpointClientRemoteInfo = {
|
|
2300
|
+
package: "dsh-agent-enhancer",
|
|
2301
|
+
descriptors: [{
|
|
2302
|
+
id: "dsh-agent-enhancer#checkpointRollback/preview",
|
|
2303
|
+
service: "checkpointRollback",
|
|
2304
|
+
namespace: "checkpointRollback",
|
|
2305
|
+
method: "preview",
|
|
2306
|
+
implementation: "preview",
|
|
2307
|
+
invocation: { kind: "direct" },
|
|
2308
|
+
parameters: [{ name: "request", wire: "request", source: "json", codec: requestCodec }],
|
|
2309
|
+
cancellation: { parameter: "signal" },
|
|
2310
|
+
result: codec("dsh-agent-enhancer#CheckpointRollbackPreview")
|
|
2311
|
+
}, {
|
|
2312
|
+
id: "dsh-agent-enhancer#checkpointRollback/execute",
|
|
2313
|
+
service: "checkpointRollback",
|
|
2314
|
+
namespace: "checkpointRollback",
|
|
2315
|
+
method: "execute",
|
|
2316
|
+
implementation: "execute",
|
|
2317
|
+
invocation: { kind: "direct" },
|
|
2318
|
+
parameters: [{ name: "request", wire: "request", source: "json", codec: requestCodec }],
|
|
2319
|
+
cancellation: { parameter: "signal" },
|
|
2320
|
+
result: codec("dsh-agent-enhancer#CheckpointRollbackResult")
|
|
2321
|
+
}]
|
|
2322
|
+
};
|
|
2323
|
+
var CheckpointRollbackClientError = class extends Error {
|
|
2324
|
+
constructor(code) {
|
|
2325
|
+
super(code);
|
|
2326
|
+
this.code = code;
|
|
2327
|
+
this.name = "CheckpointRollbackClientError";
|
|
2328
|
+
}
|
|
2329
|
+
code;
|
|
2330
|
+
};
|
|
2331
|
+
async function invoke(remote, method, request, signal) {
|
|
2332
|
+
const namespace = Reflect.get(remote, "checkpointRollback");
|
|
2333
|
+
const call = Reflect.get(namespace, method);
|
|
2334
|
+
let result;
|
|
2335
|
+
try {
|
|
2336
|
+
result = await call.apply(namespace, [request, signal]);
|
|
2337
|
+
} catch (error) {
|
|
2338
|
+
if (signal?.aborted || error instanceof Error && error.name === "AbortError") throw error;
|
|
2339
|
+
throw new CheckpointRollbackClientError("ROLLBACK_FAILED");
|
|
2340
|
+
}
|
|
2341
|
+
if (!result.ok) {
|
|
2342
|
+
const code = result.error.code === "agent-enhancer/rollback-failed" ? result.error.details.code : "ROLLBACK_FAILED";
|
|
2343
|
+
throw new CheckpointRollbackClientError(code);
|
|
2344
|
+
}
|
|
2345
|
+
return result.value;
|
|
2346
|
+
}
|
|
2347
|
+
var checkpointRollbackRemote = {
|
|
2348
|
+
preview(remote, request, signal) {
|
|
2349
|
+
return invoke(remote, "preview", request, signal);
|
|
2350
|
+
},
|
|
2351
|
+
execute(remote, request, signal) {
|
|
2352
|
+
return invoke(remote, "execute", request, signal);
|
|
2353
|
+
}
|
|
2354
|
+
};
|
|
2355
|
+
|
|
2356
|
+
// src/client/remote.ts
|
|
2357
|
+
function codec2(typeSymbol) {
|
|
2358
|
+
return {
|
|
2359
|
+
mode: "strict",
|
|
2360
|
+
typeSymbol,
|
|
2361
|
+
create: () => {
|
|
2362
|
+
throw new Error("Client Remote schemas are only available on the Host");
|
|
2363
|
+
}
|
|
2364
|
+
};
|
|
2365
|
+
}
|
|
2366
|
+
var payloadCodec = codec2("dsh-agent-enhancer#RpcPayload");
|
|
2367
|
+
var clientRemoteInfo = {
|
|
2368
|
+
package: "dsh-agent-enhancer",
|
|
2369
|
+
descriptors: [{
|
|
2370
|
+
id: "dsh-agent-enhancer#agentEnhancer/call",
|
|
2371
|
+
service: "agentEnhancer",
|
|
2372
|
+
namespace: "agentEnhancer",
|
|
2373
|
+
method: "call",
|
|
2374
|
+
implementation: "call",
|
|
2375
|
+
invocation: { kind: "direct" },
|
|
2376
|
+
parameters: [{
|
|
2377
|
+
name: "payload",
|
|
2378
|
+
wire: "payload",
|
|
2379
|
+
source: "json",
|
|
2380
|
+
codec: payloadCodec
|
|
2381
|
+
}],
|
|
2382
|
+
cancellation: { parameter: "signal" },
|
|
2383
|
+
result: codec2("dsh-agent-enhancer#AuxiliaryResult|null")
|
|
2384
|
+
}, {
|
|
2385
|
+
id: "dsh-agent-enhancer#agentEnhancer/listCatalog",
|
|
2386
|
+
service: "agentEnhancer",
|
|
2387
|
+
namespace: "agentEnhancer",
|
|
2388
|
+
method: "listCatalog",
|
|
2389
|
+
implementation: "listCatalog",
|
|
2390
|
+
invocation: { kind: "direct" },
|
|
2391
|
+
parameters: [],
|
|
2392
|
+
result: codec2("dsh-agent-enhancer#ModelCatalog")
|
|
2393
|
+
}, ...checkpointClientRemoteInfo.descriptors]
|
|
2394
|
+
};
|
|
2395
|
+
var agentEnhancerCall = {
|
|
2396
|
+
async invoke(remote, input, signal) {
|
|
2397
|
+
const namespace = Reflect.get(remote, "agentEnhancer");
|
|
2398
|
+
const call = Reflect.get(namespace, "call");
|
|
2399
|
+
let result;
|
|
2400
|
+
try {
|
|
2401
|
+
result = await call.apply(namespace, [input.payload, signal]);
|
|
2402
|
+
} catch (error) {
|
|
2403
|
+
if (signal?.aborted || error instanceof Error && error.name === "AbortError") throw error;
|
|
2404
|
+
throw new AuxiliaryError("MODEL_FAILED");
|
|
2405
|
+
}
|
|
2406
|
+
if (!result.ok) {
|
|
2407
|
+
const code = result.error.code === "agent-enhancer/failed" ? result.error.details.code : "MODEL_FAILED";
|
|
2408
|
+
throw new AuxiliaryError(code);
|
|
2409
|
+
}
|
|
2410
|
+
return result.value;
|
|
2411
|
+
}
|
|
2412
|
+
};
|
|
2413
|
+
|
|
2414
|
+
// src/host/checkpoint/availability.ts
|
|
2415
|
+
var CONVERSATION_SOFT = /* @__PURE__ */ new Set([
|
|
2416
|
+
"incomplete-checkpoint",
|
|
2417
|
+
"workspace-capture-failed",
|
|
2418
|
+
"prompt-non-text-content",
|
|
2419
|
+
// Official compaction / foreign replaces in the rolled-back region should not
|
|
2420
|
+
// block restoring the conversation draft and surface tip.
|
|
2421
|
+
"compacted-surface",
|
|
2422
|
+
// Conversation restore does not need a workspace cwd.
|
|
2423
|
+
"permission-denied",
|
|
2424
|
+
// Turn 1 is restorable; keep this soft for older previews that still emit it.
|
|
2425
|
+
"first-turn"
|
|
2426
|
+
// Non-contiguous logs are unusual but still restorable when a surface was built.
|
|
2427
|
+
// Only emit unknown-surface when surface is missing — that case stays hard.
|
|
2428
|
+
]);
|
|
2429
|
+
var EMPTY_FILES_SOFT = /* @__PURE__ */ new Set([
|
|
2430
|
+
"incomplete-checkpoint",
|
|
2431
|
+
"workspace-capture-failed",
|
|
2432
|
+
"prompt-non-text-content",
|
|
2433
|
+
"compacted-surface"
|
|
2434
|
+
]);
|
|
2435
|
+
function blockingUnavailable(unavailable, scope, options = {}) {
|
|
2436
|
+
const trackedFiles = options.trackedFiles;
|
|
2437
|
+
const soft = scope === "conversation" || trackedFiles === 0 ? scope === "conversation" ? CONVERSATION_SOFT : EMPTY_FILES_SOFT : null;
|
|
2438
|
+
if (soft === null) return unavailable;
|
|
2439
|
+
return unavailable.filter((reason) => !soft.has(reason));
|
|
2440
|
+
}
|
|
2441
|
+
|
|
2442
|
+
// src/client/rollback/scope.ts
|
|
2443
|
+
function confirmBlocked(unavailable, conflicts, scope, trackedFiles = 0) {
|
|
2444
|
+
if (blockingUnavailable(unavailable, scope, { trackedFiles }).length > 0) return true;
|
|
2445
|
+
return scope === "conversation-and-files" && conflicts.length > 0;
|
|
2446
|
+
}
|
|
2447
|
+
function scopeLabel(scope) {
|
|
2448
|
+
return scope ?? "conversation-and-files";
|
|
2449
|
+
}
|
|
2450
|
+
|
|
2451
|
+
// src/client/rollback/controller.ts
|
|
2452
|
+
var RollbackController = class {
|
|
2453
|
+
constructor(options) {
|
|
2454
|
+
this.options = options;
|
|
2455
|
+
this.snapshot = { enabled: options.enabled(), active: null };
|
|
2456
|
+
}
|
|
2457
|
+
options;
|
|
2458
|
+
listeners = /* @__PURE__ */ new Set();
|
|
2459
|
+
operation = null;
|
|
2460
|
+
snapshot;
|
|
2461
|
+
version = 0;
|
|
2462
|
+
disposed = false;
|
|
2463
|
+
subscribe = (listener) => {
|
|
2464
|
+
if (this.disposed) return () => {
|
|
2465
|
+
};
|
|
2466
|
+
this.listeners.add(listener);
|
|
2467
|
+
return () => {
|
|
2468
|
+
this.listeners.delete(listener);
|
|
2469
|
+
};
|
|
2470
|
+
};
|
|
2471
|
+
getSnapshot = () => this.snapshot;
|
|
2472
|
+
refreshSettings() {
|
|
2473
|
+
if (this.disposed) return;
|
|
2474
|
+
const enabled = this.options.enabled();
|
|
2475
|
+
if (!enabled) {
|
|
2476
|
+
this.cancelOperation();
|
|
2477
|
+
this.publish();
|
|
2478
|
+
return;
|
|
2479
|
+
}
|
|
2480
|
+
if (this.snapshot.enabled) return;
|
|
2481
|
+
this.publish();
|
|
2482
|
+
}
|
|
2483
|
+
open(turn, operation = "rollback") {
|
|
2484
|
+
if (this.disposed || !this.options.enabled() || this.operation?.status === "executing") return;
|
|
2485
|
+
this.cancelOperation();
|
|
2486
|
+
const version = ++this.version;
|
|
2487
|
+
const controller = new AbortController();
|
|
2488
|
+
this.operation = { turn, operation, status: "loading", version, controller };
|
|
2489
|
+
this.publish();
|
|
2490
|
+
const request = { sessionId: this.options.sessionId, turn, operation };
|
|
2491
|
+
void this.options.remote.preview(request, controller.signal).then((result) => {
|
|
2492
|
+
if (!this.current(version, request, result)) return;
|
|
2493
|
+
this.operation = { ...this.operation, status: "ready", preview: result };
|
|
2494
|
+
this.publish();
|
|
2495
|
+
}).catch(() => {
|
|
2496
|
+
if (!this.current(version, request)) return;
|
|
2497
|
+
this.operation = { ...this.operation, status: "error", error: "preview" };
|
|
2498
|
+
this.publish();
|
|
2499
|
+
});
|
|
2500
|
+
}
|
|
2501
|
+
close(turn) {
|
|
2502
|
+
if (this.disposed || turn !== void 0 && this.operation?.turn !== turn) return;
|
|
2503
|
+
if (this.operation?.status === "executing") return;
|
|
2504
|
+
this.cancelOperation();
|
|
2505
|
+
this.publish();
|
|
2506
|
+
}
|
|
2507
|
+
async confirm(actions, scope = "conversation-and-files") {
|
|
2508
|
+
const active = this.operation;
|
|
2509
|
+
if (this.disposed || active?.status !== "ready" || active.preview === void 0) return;
|
|
2510
|
+
const effectiveScope = active.operation === "undo" ? scopeLabel(active.preview.scope) : scope;
|
|
2511
|
+
if (confirmBlocked(
|
|
2512
|
+
active.preview.unavailable,
|
|
2513
|
+
active.preview.conflicts,
|
|
2514
|
+
effectiveScope,
|
|
2515
|
+
active.preview.files.length
|
|
2516
|
+
)) return;
|
|
2517
|
+
const { turn, operation } = active;
|
|
2518
|
+
const preview = active.preview;
|
|
2519
|
+
const request = {
|
|
2520
|
+
sessionId: this.options.sessionId,
|
|
2521
|
+
turn,
|
|
2522
|
+
operation,
|
|
2523
|
+
scope: effectiveScope
|
|
2524
|
+
};
|
|
2525
|
+
const controller = new AbortController();
|
|
2526
|
+
this.operation = { ...active, status: "executing", scope: effectiveScope, controller };
|
|
2527
|
+
this.publish();
|
|
2528
|
+
let result;
|
|
2529
|
+
try {
|
|
2530
|
+
result = await this.options.remote.execute(request, controller.signal);
|
|
2531
|
+
} catch (error) {
|
|
2532
|
+
if (this.disposed || !this.options.enabled()) return;
|
|
2533
|
+
if ((controller.signal.aborted || error instanceof Error && error.name === "AbortError") && !this.options.enabled()) return;
|
|
2534
|
+
this.operation = {
|
|
2535
|
+
turn,
|
|
2536
|
+
operation,
|
|
2537
|
+
status: "error",
|
|
2538
|
+
error: "execute",
|
|
2539
|
+
version: this.version,
|
|
2540
|
+
controller: new AbortController(),
|
|
2541
|
+
preview,
|
|
2542
|
+
scope: effectiveScope
|
|
2543
|
+
};
|
|
2544
|
+
this.publish();
|
|
2545
|
+
return;
|
|
2546
|
+
}
|
|
2547
|
+
if (this.disposed || !this.options.enabled()) return;
|
|
2548
|
+
if (result === null || typeof result !== "object" || result.sessionId !== request.sessionId || result.turn !== request.turn || typeof result.draft !== "string") {
|
|
2549
|
+
this.operation = {
|
|
2550
|
+
turn,
|
|
2551
|
+
operation,
|
|
2552
|
+
status: "error",
|
|
2553
|
+
error: "execute",
|
|
2554
|
+
version: this.version,
|
|
2555
|
+
controller: new AbortController(),
|
|
2556
|
+
preview,
|
|
2557
|
+
scope: effectiveScope
|
|
2558
|
+
};
|
|
2559
|
+
this.publish();
|
|
2560
|
+
return;
|
|
2561
|
+
}
|
|
2562
|
+
try {
|
|
2563
|
+
actions.setDraft(result.draft);
|
|
2564
|
+
actions.persistDraft();
|
|
2565
|
+
} catch {
|
|
2566
|
+
this.operation = {
|
|
2567
|
+
turn,
|
|
2568
|
+
operation,
|
|
2569
|
+
status: "error",
|
|
2570
|
+
error: "execute",
|
|
2571
|
+
version: this.version,
|
|
2572
|
+
controller: new AbortController(),
|
|
2573
|
+
preview,
|
|
2574
|
+
scope: effectiveScope
|
|
2575
|
+
};
|
|
2576
|
+
this.publish();
|
|
2577
|
+
return;
|
|
2578
|
+
}
|
|
2579
|
+
this.operation = null;
|
|
2580
|
+
this.publish();
|
|
2581
|
+
}
|
|
2582
|
+
dispose() {
|
|
2583
|
+
if (this.disposed) return;
|
|
2584
|
+
this.disposed = true;
|
|
2585
|
+
this.cancelOperation();
|
|
2586
|
+
this.listeners.clear();
|
|
2587
|
+
}
|
|
2588
|
+
current(version, request, response) {
|
|
2589
|
+
const operation = request.operation ?? "rollback";
|
|
2590
|
+
return !this.disposed && this.options.enabled() && this.version === version && this.operation?.version === version && this.operation.turn === request.turn && this.operation.operation === operation && (response === void 0 || response.sessionId === request.sessionId && response.turn === request.turn);
|
|
2591
|
+
}
|
|
2592
|
+
cancelOperation() {
|
|
2593
|
+
this.version += 1;
|
|
2594
|
+
this.operation?.controller.abort();
|
|
2595
|
+
this.operation = null;
|
|
2596
|
+
}
|
|
2597
|
+
publish() {
|
|
2598
|
+
this.snapshot = {
|
|
2599
|
+
enabled: !this.disposed && this.options.enabled(),
|
|
2600
|
+
active: this.operation === null ? null : {
|
|
2601
|
+
turn: this.operation.turn,
|
|
2602
|
+
operation: this.operation.operation,
|
|
2603
|
+
status: this.operation.status,
|
|
2604
|
+
version: this.operation.version,
|
|
2605
|
+
...this.operation.preview === void 0 ? {} : { preview: this.operation.preview },
|
|
2606
|
+
...this.operation.scope === void 0 ? {} : { scope: this.operation.scope },
|
|
2607
|
+
...this.operation.error === void 0 ? {} : { error: this.operation.error }
|
|
2608
|
+
}
|
|
2609
|
+
};
|
|
2610
|
+
for (const listener of this.listeners) listener();
|
|
2611
|
+
}
|
|
2612
|
+
};
|
|
2613
|
+
|
|
2614
|
+
// src/client/rollback/modal-host.tsx
|
|
2615
|
+
var import_dsh_client_ui_primitives6 = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
2616
|
+
var import_react5 = require("react");
|
|
2617
|
+
|
|
2618
|
+
// src/client/rollback/preview.tsx
|
|
2619
|
+
var import_dsh_client_ui_primitives5 = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
2620
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
2621
|
+
var UNAVAILABLE_KEYS = {
|
|
2622
|
+
"checkpoint-not-found": "rollbackUnavailableCheckpoint",
|
|
2623
|
+
"incomplete-checkpoint": "rollbackUnavailableIncomplete",
|
|
2624
|
+
"prompt-non-text-content": "rollbackGapPrompt",
|
|
2625
|
+
"workspace-capture-failed": "rollbackGapWorkspace",
|
|
2626
|
+
"session-changed": "rollbackUnavailableSessionChanged",
|
|
2627
|
+
"session-running": "rollbackUnavailableRunning",
|
|
2628
|
+
"permission-denied": "rollbackUnavailablePermission",
|
|
2629
|
+
"rollback-disabled": "rollbackUnavailableDisabled",
|
|
2630
|
+
"first-turn": "rollbackUnavailableFirstTurn",
|
|
2631
|
+
"incompatible-session": "rollbackUnavailableIncompatible",
|
|
2632
|
+
"compacted-surface": "rollbackUnavailableCompacted",
|
|
2633
|
+
"subagent-session": "rollbackUnavailableSubagent",
|
|
2634
|
+
"unknown-surface": "rollbackUnavailableUnknown"
|
|
2635
|
+
};
|
|
2636
|
+
var CONFLICT_KEYS = {
|
|
2637
|
+
"unsafe-path": "rollbackConflictUnsafe",
|
|
2638
|
+
"symlink": "rollbackConflictSymlink",
|
|
2639
|
+
"not-regular-file": "rollbackConflictRegular",
|
|
2640
|
+
"binary": "rollbackConflictBinary",
|
|
2641
|
+
"too-large": "rollbackConflictLarge",
|
|
2642
|
+
"invalid-before-image": "rollbackConflictBefore",
|
|
2643
|
+
"invalid-after-image": "rollbackConflictBefore",
|
|
2644
|
+
"hash-mismatch": "rollbackConflictHash"
|
|
2645
|
+
};
|
|
2646
|
+
function RollbackPreview({ active, t }) {
|
|
2647
|
+
if (active.status === "loading" || active.status === "executing") {
|
|
2648
|
+
const loadingKey = active.status === "loading" ? "rollbackLoading" : active.operation === "undo" ? "rollbackUndoRestoring" : "rollbackRestoring";
|
|
2649
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { role: "status", children: t(loadingKey) });
|
|
2650
|
+
}
|
|
2651
|
+
if (active.status === "error") return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { role: "alert", children: t("rollbackFailed") });
|
|
2652
|
+
const preview = active.preview;
|
|
2653
|
+
if (preview === void 0) return null;
|
|
2654
|
+
const hardUnavailable = blockingUnavailable(preview.unavailable, "conversation", {
|
|
2655
|
+
trackedFiles: preview.files.length
|
|
2656
|
+
});
|
|
2657
|
+
const filesLimited = active.operation !== "undo" && blockingUnavailable(preview.unavailable, "conversation-and-files", {
|
|
2658
|
+
trackedFiles: preview.files.length
|
|
2659
|
+
}).length > hardUnavailable.length;
|
|
2660
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_dsh_client_ui_primitives5.MenuSurface, { className: css_module_default.rollbackPreview, children: [
|
|
2661
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("section", { className: css_module_default.rollbackSection, "aria-label": t("rollbackMessages"), children: [
|
|
2662
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("h3", { children: t("rollbackMessages") }),
|
|
2663
|
+
preview.messages.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { children: t("rollbackNoMessages") }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("ul", { className: css_module_default.rollbackList, children: preview.messages.map((message) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("li", { className: css_module_default.rollbackMessage, children: [
|
|
2664
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: css_module_default.rollbackMeta, children: [
|
|
2665
|
+
message.type,
|
|
2666
|
+
" \xB7 ",
|
|
2667
|
+
message.seq
|
|
2668
|
+
] }),
|
|
2669
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: message.text })
|
|
2670
|
+
] }, message.seq)) })
|
|
2671
|
+
] }),
|
|
2672
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("section", { className: css_module_default.rollbackSection, "aria-label": t("rollbackFiles"), children: [
|
|
2673
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("h3", { children: t("rollbackFiles") }),
|
|
2674
|
+
preview.files.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { children: t("rollbackNoFiles") }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("ul", { className: css_module_default.rollbackList, children: preview.files.map((file) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("li", { className: css_module_default.rollbackFile, children: [
|
|
2675
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: file.path }),
|
|
2676
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: css_module_default.rollbackMeta, children: t(`rollbackFile_${file.change}`) })
|
|
2677
|
+
] }, file.path)) })
|
|
2678
|
+
] }),
|
|
2679
|
+
hardUnavailable.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("section", { className: css_module_default.rollbackSection, "aria-label": t("rollbackGaps"), children: [
|
|
2680
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("h3", { children: t("rollbackGaps") }),
|
|
2681
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("ul", { className: css_module_default.rollbackList, children: hardUnavailable.map((reason) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("li", { children: t(UNAVAILABLE_KEYS[reason]) }, reason)) })
|
|
2682
|
+
] }),
|
|
2683
|
+
!filesLimited ? null : /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("section", { className: css_module_default.rollbackSection, "aria-label": t("rollbackFilesLimited"), children: [
|
|
2684
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("h3", { children: t("rollbackFilesLimited") }),
|
|
2685
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { children: t("rollbackFilesLimitedHint") })
|
|
2686
|
+
] }),
|
|
2687
|
+
preview.conflicts.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("section", { className: css_module_default.rollbackSection, "aria-label": t("rollbackConflicts"), children: [
|
|
2688
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("h3", { children: t("rollbackConflicts") }),
|
|
2689
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("ul", { className: css_module_default.rollbackList, children: preview.conflicts.map((conflict) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("li", { children: [
|
|
2690
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: conflict.path }),
|
|
2691
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: css_module_default.rollbackConflict, children: t(CONFLICT_KEYS[conflict.reason]) })
|
|
2692
|
+
] }, `${conflict.path}:${conflict.reason}`)) })
|
|
2693
|
+
] })
|
|
2694
|
+
] });
|
|
2695
|
+
}
|
|
2696
|
+
function rollbackModalCopy(operation, t, turn, scope) {
|
|
2697
|
+
if (operation === "undo") {
|
|
2698
|
+
const conversationOnly = scope === "conversation";
|
|
2699
|
+
return {
|
|
2700
|
+
title: t("rollbackUndoTitle", { turn }),
|
|
2701
|
+
description: t(conversationOnly ? "rollbackUndoScopeConversation" : "rollbackUndoScope"),
|
|
2702
|
+
confirm: t(conversationOnly ? "rollbackUndoConfirmConversation" : "rollbackUndoConfirm"),
|
|
2703
|
+
confirmConversation: t("rollbackUndoConfirmConversation"),
|
|
2704
|
+
executing: t(conversationOnly ? "rollbackUndoRestoringConversation" : "rollbackUndoRestoring"),
|
|
2705
|
+
executingConversation: t("rollbackUndoRestoringConversation")
|
|
2706
|
+
};
|
|
2707
|
+
}
|
|
2708
|
+
return {
|
|
2709
|
+
title: t("rollbackTitle", { turn }),
|
|
2710
|
+
description: t("rollbackScope"),
|
|
2711
|
+
confirm: t("rollbackConfirm"),
|
|
2712
|
+
confirmConversation: t("rollbackConfirmConversation"),
|
|
2713
|
+
executing: t("rollbackRestoring"),
|
|
2714
|
+
executingConversation: t("rollbackRestoringConversation")
|
|
2715
|
+
};
|
|
2716
|
+
}
|
|
2717
|
+
|
|
2718
|
+
// src/client/rollback/modal-host.tsx
|
|
2719
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
2720
|
+
function RollbackModalHost(props) {
|
|
2721
|
+
const snapshot = (0, import_react5.useSyncExternalStore)(props.rollback.subscribe, props.rollback.getSnapshot);
|
|
2722
|
+
const active = snapshot.active;
|
|
2723
|
+
const trackedFiles = active?.preview?.files.length ?? 0;
|
|
2724
|
+
const undoScope = scopeLabel(active?.scope ?? active?.preview?.scope);
|
|
2725
|
+
const conversationBlocked = active?.preview === void 0 || confirmBlocked(active.preview.unavailable, active.preview.conflicts, "conversation", trackedFiles);
|
|
2726
|
+
const filesBlocked = active?.preview === void 0 || confirmBlocked(active.preview.unavailable, active.preview.conflicts, "conversation-and-files", trackedFiles);
|
|
2727
|
+
const undoBlocked = active?.preview === void 0 || confirmBlocked(active.preview.unavailable, active.preview.conflicts, undoScope, trackedFiles);
|
|
2728
|
+
const modal = active === null ? null : rollbackModalCopy(
|
|
2729
|
+
active.operation,
|
|
2730
|
+
props.t,
|
|
2731
|
+
active.turn,
|
|
2732
|
+
active.operation === "undo" ? undoScope : void 0
|
|
2733
|
+
);
|
|
2734
|
+
const ready = active?.status === "ready";
|
|
2735
|
+
const executing = active?.status === "executing";
|
|
2736
|
+
(0, import_react5.useEffect)(() => {
|
|
2737
|
+
if (active === null) return;
|
|
2738
|
+
const dialog = document.querySelector(`.${css_module_default.rollbackDialog}`);
|
|
2739
|
+
const parent = dialog?.parentElement;
|
|
2740
|
+
const byAria = parent?.querySelector('[aria-hidden="true"]');
|
|
2741
|
+
const first = parent?.firstElementChild;
|
|
2742
|
+
const mask = byAria instanceof HTMLElement ? byAria : first instanceof HTMLElement && first !== dialog ? first : null;
|
|
2743
|
+
if (mask === null) return;
|
|
2744
|
+
const stop = (event) => {
|
|
2745
|
+
event.preventDefault();
|
|
2746
|
+
event.stopImmediatePropagation();
|
|
2747
|
+
};
|
|
2748
|
+
for (const type of ["pointerdown", "mousedown", "mouseup", "click"]) {
|
|
2749
|
+
mask.addEventListener(type, stop, true);
|
|
2750
|
+
}
|
|
2751
|
+
return () => {
|
|
2752
|
+
for (const type of ["pointerdown", "mousedown", "mouseup", "click"]) {
|
|
2753
|
+
mask.removeEventListener(type, stop, true);
|
|
2754
|
+
}
|
|
2755
|
+
};
|
|
2756
|
+
}, [active]);
|
|
2757
|
+
if (!snapshot.enabled || active === null || modal === null) return null;
|
|
2758
|
+
const requestClose = () => {
|
|
2759
|
+
if (active.status === "executing") return;
|
|
2760
|
+
props.rollback.close(active.turn);
|
|
2761
|
+
};
|
|
2762
|
+
const runConfirm = (scope) => {
|
|
2763
|
+
if (active.status !== "ready" || executing) return;
|
|
2764
|
+
void props.rollback.confirm(props.inputActions, scope);
|
|
2765
|
+
};
|
|
2766
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
2767
|
+
import_dsh_client_ui_primitives6.Modal,
|
|
2768
|
+
{
|
|
2769
|
+
open: true,
|
|
2770
|
+
title: modal.title,
|
|
2771
|
+
description: modal.description,
|
|
2772
|
+
closeLabel: props.t("rollbackClose"),
|
|
2773
|
+
className: css_module_default.rollbackDialog,
|
|
2774
|
+
contentClassName: css_module_default.rollbackContent,
|
|
2775
|
+
onClose: requestClose,
|
|
2776
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
|
|
2777
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
2778
|
+
import_dsh_client_ui_primitives6.Button,
|
|
2779
|
+
{
|
|
2780
|
+
type: "button",
|
|
2781
|
+
disabled: executing,
|
|
2782
|
+
onClick: requestClose,
|
|
2783
|
+
children: props.t("rollbackCancel")
|
|
2784
|
+
}
|
|
2785
|
+
),
|
|
2786
|
+
active.operation === "undo" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
2787
|
+
import_dsh_client_ui_primitives6.Button,
|
|
2788
|
+
{
|
|
2789
|
+
type: "button",
|
|
2790
|
+
"data-modal-autofocus": true,
|
|
2791
|
+
disabled: !ready || undoBlocked || executing,
|
|
2792
|
+
onClick: () => {
|
|
2793
|
+
runConfirm(undoScope);
|
|
2794
|
+
},
|
|
2795
|
+
children: executing ? modal.executing : modal.confirm
|
|
2796
|
+
}
|
|
2797
|
+
) : executing ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_dsh_client_ui_primitives6.Button, { type: "button", disabled: true, children: active.scope === "conversation" ? modal.executingConversation : modal.executing }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
|
|
2798
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
2799
|
+
import_dsh_client_ui_primitives6.Button,
|
|
2800
|
+
{
|
|
2801
|
+
type: "button",
|
|
2802
|
+
"data-modal-autofocus": true,
|
|
2803
|
+
disabled: !ready || conversationBlocked,
|
|
2804
|
+
onClick: () => {
|
|
2805
|
+
runConfirm("conversation");
|
|
2806
|
+
},
|
|
2807
|
+
children: modal.confirmConversation
|
|
2808
|
+
}
|
|
2809
|
+
),
|
|
2810
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
2811
|
+
import_dsh_client_ui_primitives6.Button,
|
|
2812
|
+
{
|
|
2813
|
+
type: "button",
|
|
2814
|
+
disabled: !ready || filesBlocked,
|
|
2815
|
+
onClick: () => {
|
|
2816
|
+
runConfirm("conversation-and-files");
|
|
2817
|
+
},
|
|
2818
|
+
children: modal.confirm
|
|
2819
|
+
}
|
|
2820
|
+
)
|
|
2821
|
+
] })
|
|
2822
|
+
] }),
|
|
2823
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(RollbackPreview, { active, t: props.t })
|
|
2824
|
+
}
|
|
2825
|
+
);
|
|
2826
|
+
}
|
|
2827
|
+
|
|
2828
|
+
// src/client/rollback/command-ui.ts
|
|
2829
|
+
var import_dsh_client_ui_primitives7 = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
2830
|
+
function installRollbackUndoCommand(options) {
|
|
2831
|
+
const fiber = options.ctx.inject(["commandUi"], (scope) => {
|
|
2832
|
+
const commandUi = scope.get("commandUi");
|
|
2833
|
+
if (commandUi === void 0 || typeof commandUi.register !== "function") return;
|
|
2834
|
+
return scope.effect(() => commandUi.register({
|
|
2835
|
+
name: "undo-restore",
|
|
2836
|
+
label: () => options.t("rollbackUndoAction"),
|
|
2837
|
+
description: () => options.t("rollbackUndoCommandDescription"),
|
|
2838
|
+
icon: import_dsh_client_ui_primitives7.IconRefreshOutlineRegular,
|
|
2839
|
+
available: (session) => {
|
|
2840
|
+
if (!options.enabled()) return false;
|
|
2841
|
+
return options.tips.get(session.sessionId) !== void 0;
|
|
2842
|
+
},
|
|
2843
|
+
ui: {
|
|
2844
|
+
kind: "action",
|
|
2845
|
+
run: (session) => {
|
|
2846
|
+
const turn = options.tips.get(session.sessionId);
|
|
2847
|
+
if (turn === void 0 || !options.enabled()) return;
|
|
2848
|
+
options.rollbackFor(session.sessionId).open(turn, "undo");
|
|
2849
|
+
}
|
|
2850
|
+
}
|
|
2851
|
+
}), "agent-enhancer: undo-restore command");
|
|
2852
|
+
});
|
|
2853
|
+
return () => {
|
|
2854
|
+
void fiber.dispose();
|
|
2855
|
+
};
|
|
2856
|
+
}
|
|
2857
|
+
|
|
2858
|
+
// src/identity.ts
|
|
2859
|
+
var PACKAGE_NAME = "dsh-agent-enhancer";
|
|
2860
|
+
var LEGACY_PACKAGE_NAME = "dsh-composer-enhancer";
|
|
2861
|
+
var ROLLBACK_PREFIX = `${PACKAGE_NAME}:rollback:`;
|
|
2862
|
+
var UNDO_PREFIX = `${PACKAGE_NAME}:undo:`;
|
|
2863
|
+
var LEGACY_ROLLBACK_PREFIX = `${LEGACY_PACKAGE_NAME}:rollback:`;
|
|
2864
|
+
var LEGACY_UNDO_PREFIX = `${LEGACY_PACKAGE_NAME}:undo:`;
|
|
2865
|
+
function isRollbackId(id) {
|
|
2866
|
+
return id.startsWith(ROLLBACK_PREFIX) || id.startsWith(LEGACY_ROLLBACK_PREFIX);
|
|
2867
|
+
}
|
|
2868
|
+
function isUndoId(id) {
|
|
2869
|
+
return id.startsWith(UNDO_PREFIX) || id.startsWith(LEGACY_UNDO_PREFIX);
|
|
2870
|
+
}
|
|
2871
|
+
function turnFromRollbackId(id) {
|
|
2872
|
+
for (const prefix of [ROLLBACK_PREFIX, LEGACY_ROLLBACK_PREFIX]) {
|
|
2873
|
+
if (!id.startsWith(prefix)) continue;
|
|
2874
|
+
const match = new RegExp(`^${escapeRegExp(prefix)}(\\d+):`).exec(id);
|
|
2875
|
+
if (match !== null) return Number(match[1]);
|
|
2876
|
+
}
|
|
2877
|
+
return void 0;
|
|
2878
|
+
}
|
|
2879
|
+
function escapeRegExp(value) {
|
|
2880
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2881
|
+
}
|
|
2882
|
+
|
|
2883
|
+
// src/client/rollback/marker.ts
|
|
2884
|
+
function isRollbackMarkerSource(source) {
|
|
2885
|
+
return source?.kind === "checkpoint-rollback";
|
|
2886
|
+
}
|
|
2887
|
+
function isRollbackMarkerMessage(source, id) {
|
|
2888
|
+
return isRollbackMarkerSource(source) || id !== void 0 && isRollbackId(id);
|
|
2889
|
+
}
|
|
2890
|
+
function turnFromRollbackMarkerId(id) {
|
|
2891
|
+
if (id === void 0) return void 0;
|
|
2892
|
+
return turnFromRollbackId(id);
|
|
2893
|
+
}
|
|
2894
|
+
|
|
2895
|
+
// src/client/rollback/transcript.ts
|
|
2896
|
+
function isRecord(value) {
|
|
2897
|
+
return typeof value === "object" && value !== null;
|
|
2898
|
+
}
|
|
2899
|
+
function surfaceOpOf(event) {
|
|
2900
|
+
const op = event.surfaceOp;
|
|
2901
|
+
if (op === "append") return "append";
|
|
2902
|
+
if (!isRecord(op) || op.op !== "replace") return void 0;
|
|
2903
|
+
if (typeof op.startSeq !== "number" || typeof op.endSeq !== "number") return void 0;
|
|
2904
|
+
return { op: "replace", startSeq: op.startSeq, endSeq: op.endSeq };
|
|
2905
|
+
}
|
|
2906
|
+
function isRollbackMarkerEvent(event) {
|
|
2907
|
+
if (event.type !== "user/message") return false;
|
|
2908
|
+
return isRollbackMarkerMessage(event.data.source, event.data.id);
|
|
2909
|
+
}
|
|
2910
|
+
function isUndoCopyEvent(event) {
|
|
2911
|
+
switch (event.type) {
|
|
2912
|
+
case "user/message":
|
|
2913
|
+
return isUndoId(event.data.id);
|
|
2914
|
+
case "system/message":
|
|
2915
|
+
case "developer/message":
|
|
2916
|
+
case "assistant/message":
|
|
2917
|
+
case "tool/result":
|
|
2918
|
+
return isUndoId(event.data.message.id);
|
|
2919
|
+
default:
|
|
2920
|
+
return false;
|
|
2921
|
+
}
|
|
2922
|
+
}
|
|
2923
|
+
function markerStillActive(marker, events) {
|
|
2924
|
+
return !events.some((event) => {
|
|
2925
|
+
if (event.seq <= marker.seq) return false;
|
|
2926
|
+
const op = surfaceOpOf(event);
|
|
2927
|
+
return op !== void 0 && op !== "append" && op.startSeq <= marker.seq && op.endSeq >= marker.seq;
|
|
2928
|
+
});
|
|
2929
|
+
}
|
|
2930
|
+
function asAppend(event) {
|
|
2931
|
+
return { ...event, surfaceOp: "append" };
|
|
2932
|
+
}
|
|
2933
|
+
function turnOfEvent(event) {
|
|
2934
|
+
if (event.type === "turn/start" || event.type === "turn/end" || event.type === "step/start" || event.type === "step/end") {
|
|
2935
|
+
return event.data.turn;
|
|
2936
|
+
}
|
|
2937
|
+
const data = event.data;
|
|
2938
|
+
return typeof data.turn === "number" ? data.turn : void 0;
|
|
2939
|
+
}
|
|
2940
|
+
function activeMarkersOf(events) {
|
|
2941
|
+
return events.filter((event) => isRollbackMarkerEvent(event) && markerStillActive(event, events));
|
|
2942
|
+
}
|
|
2943
|
+
function activeRollbackHideTurnsFrom(entries) {
|
|
2944
|
+
const events = entries.flatMap((entry) => entry.type === "event" ? [entry.event] : []);
|
|
2945
|
+
let hideTurnsFrom;
|
|
2946
|
+
for (const event of activeMarkersOf(events)) {
|
|
2947
|
+
const turn = event.type === "user/message" ? turnFromRollbackMarkerId(event.data.id) : void 0;
|
|
2948
|
+
if (turn !== void 0) {
|
|
2949
|
+
hideTurnsFrom = hideTurnsFrom === void 0 ? turn : Math.min(hideTurnsFrom, turn);
|
|
2950
|
+
}
|
|
2951
|
+
}
|
|
2952
|
+
return hideTurnsFrom;
|
|
2953
|
+
}
|
|
2954
|
+
function activeRollbackContinueAfterSeq(entries) {
|
|
2955
|
+
const markers = activeMarkersOf(entries.flatMap((entry) => entry.type === "event" ? [entry.event] : []));
|
|
2956
|
+
if (markers.length === 0) return void 0;
|
|
2957
|
+
return Math.max(...markers.map((event) => Number(event.seq)));
|
|
2958
|
+
}
|
|
2959
|
+
function activeRollbackUndoTip(entries) {
|
|
2960
|
+
const events = entries.flatMap((entry) => entry.type === "event" ? [entry.event] : []);
|
|
2961
|
+
let tip;
|
|
2962
|
+
for (const event of events) {
|
|
2963
|
+
if (!isRollbackMarkerEvent(event) || !markerStillActive(event, events)) continue;
|
|
2964
|
+
if (event.type !== "user/message") continue;
|
|
2965
|
+
const turn = turnFromRollbackMarkerId(event.data.id);
|
|
2966
|
+
if (turn === void 0) continue;
|
|
2967
|
+
if (tip === void 0 || Number(event.seq) >= tip.seq) tip = { turn, seq: Number(event.seq) };
|
|
2968
|
+
}
|
|
2969
|
+
if (tip === void 0) return void 0;
|
|
2970
|
+
const later = events.some((event) => Number(event.seq) > tip.seq && !isRollbackMarkerEvent(event) && !isUndoCopyEvent(event));
|
|
2971
|
+
return later ? void 0 : { turn: tip.turn };
|
|
2972
|
+
}
|
|
2973
|
+
function filterTurnOutline(outline, hideTurnsFrom, continueAfterSeq) {
|
|
2974
|
+
if (hideTurnsFrom === void 0 || !Array.isArray(outline)) return outline;
|
|
2975
|
+
const next = outline.filter((entry) => {
|
|
2976
|
+
if (!isRecord(entry) || typeof entry.turn !== "number") return true;
|
|
2977
|
+
if (entry.turn < hideTurnsFrom) return true;
|
|
2978
|
+
return continueAfterSeq !== void 0 && typeof entry.seq === "number" && entry.seq > continueAfterSeq;
|
|
2979
|
+
});
|
|
2980
|
+
return next.length === outline.length ? outline : next;
|
|
2981
|
+
}
|
|
2982
|
+
function renumberCollidingTurns(entries) {
|
|
2983
|
+
const starts = [];
|
|
2984
|
+
const seen = /* @__PURE__ */ new Map();
|
|
2985
|
+
let collided = false;
|
|
2986
|
+
for (const entry of entries) {
|
|
2987
|
+
if (entry.type !== "event" || entry.event.type !== "turn/start") continue;
|
|
2988
|
+
const turn = entry.event.data.turn;
|
|
2989
|
+
const seq = Number(entry.event.seq);
|
|
2990
|
+
if (seen.has(turn)) collided = true;
|
|
2991
|
+
seen.set(turn, (seen.get(turn) ?? 0) + 1);
|
|
2992
|
+
starts.push({ seq, turn });
|
|
2993
|
+
}
|
|
2994
|
+
if (!collided || starts.length === 0) return entries;
|
|
2995
|
+
const shells = starts.map((start, index) => ({
|
|
2996
|
+
startSeq: start.seq,
|
|
2997
|
+
endSeq: index + 1 < starts.length ? starts[index + 1].seq - 1 : Number.POSITIVE_INFINITY,
|
|
2998
|
+
from: start.turn,
|
|
2999
|
+
to: index + 1
|
|
3000
|
+
}));
|
|
3001
|
+
let changed = false;
|
|
3002
|
+
const next = entries.map((entry) => {
|
|
3003
|
+
if (entry.type !== "event") return entry;
|
|
3004
|
+
const event = entry.event;
|
|
3005
|
+
const seq = Number(event.seq);
|
|
3006
|
+
const shell = shells.find((item) => seq >= item.startSeq && seq <= item.endSeq);
|
|
3007
|
+
if (shell === void 0 || shell.from === shell.to) return entry;
|
|
3008
|
+
if (event.type === "turn/start" || event.type === "turn/end") {
|
|
3009
|
+
changed = true;
|
|
3010
|
+
return {
|
|
3011
|
+
type: "event",
|
|
3012
|
+
event: { ...event, data: { ...event.data, turn: shell.to } }
|
|
3013
|
+
};
|
|
3014
|
+
}
|
|
3015
|
+
if (event.type === "step/start" || event.type === "step/end") {
|
|
3016
|
+
changed = true;
|
|
3017
|
+
return {
|
|
3018
|
+
type: "event",
|
|
3019
|
+
event: { ...event, data: { ...event.data, turn: shell.to } }
|
|
3020
|
+
};
|
|
3021
|
+
}
|
|
3022
|
+
const data = event.data;
|
|
3023
|
+
if (typeof data.turn === "number" && data.turn === shell.from) {
|
|
3024
|
+
changed = true;
|
|
3025
|
+
return {
|
|
3026
|
+
type: "event",
|
|
3027
|
+
event: { ...event, data: { ...event.data, turn: shell.to } }
|
|
3028
|
+
};
|
|
3029
|
+
}
|
|
3030
|
+
return entry;
|
|
3031
|
+
});
|
|
3032
|
+
return changed ? next : entries;
|
|
3033
|
+
}
|
|
3034
|
+
function presentRollbackTranscript(entries) {
|
|
3035
|
+
const events = entries.flatMap((entry) => entry.type === "event" ? [entry.event] : []);
|
|
3036
|
+
const everShadowed = /* @__PURE__ */ new Set();
|
|
3037
|
+
const activeMarkers = /* @__PURE__ */ new Set();
|
|
3038
|
+
const hideTurnsFrom = activeRollbackHideTurnsFrom(entries);
|
|
3039
|
+
const continueAfterSeq = activeRollbackContinueAfterSeq(entries);
|
|
3040
|
+
const undoneTurnCuts = /* @__PURE__ */ new Map();
|
|
3041
|
+
for (const event of events) {
|
|
3042
|
+
if (!isRollbackMarkerEvent(event)) continue;
|
|
3043
|
+
for (const seq of event.sourceEventSeqs ?? []) everShadowed.add(Number(seq));
|
|
3044
|
+
if (markerStillActive(event, events)) {
|
|
3045
|
+
activeMarkers.add(Number(event.seq));
|
|
3046
|
+
continue;
|
|
3047
|
+
}
|
|
3048
|
+
const replaced = events.some((candidate) => {
|
|
3049
|
+
if (candidate.seq <= event.seq || !isUndoCopyEvent(candidate)) return false;
|
|
3050
|
+
const op = surfaceOpOf(candidate);
|
|
3051
|
+
return op !== void 0 && op !== "append" && op.startSeq <= Number(event.seq) && op.endSeq >= Number(event.seq);
|
|
3052
|
+
});
|
|
3053
|
+
if (!replaced || event.type !== "user/message") continue;
|
|
3054
|
+
const turn = turnFromRollbackMarkerId(event.data.id);
|
|
3055
|
+
if (turn === void 0) continue;
|
|
3056
|
+
const prior = undoneTurnCuts.get(turn);
|
|
3057
|
+
undoneTurnCuts.set(turn, prior === void 0 ? Number(event.seq) : Math.min(prior, Number(event.seq)));
|
|
3058
|
+
}
|
|
3059
|
+
if (everShadowed.size === 0 && activeMarkers.size === 0 && !events.some(isUndoCopyEvent)) return renumberCollidingTurns(entries);
|
|
3060
|
+
let changed = false;
|
|
3061
|
+
const next = [];
|
|
3062
|
+
for (const entry of entries) {
|
|
3063
|
+
if (entry.type !== "event") {
|
|
3064
|
+
next.push(entry);
|
|
3065
|
+
continue;
|
|
3066
|
+
}
|
|
3067
|
+
const event = entry.event;
|
|
3068
|
+
if (everShadowed.has(Number(event.seq))) {
|
|
3069
|
+
changed = true;
|
|
3070
|
+
continue;
|
|
3071
|
+
}
|
|
3072
|
+
const ownedTurn = turnOfEvent(event);
|
|
3073
|
+
const undoneCut = ownedTurn === void 0 ? void 0 : undoneTurnCuts.get(ownedTurn);
|
|
3074
|
+
if (undoneCut !== void 0 && (event.type === "turn/start" || event.type === "turn/end" || event.type === "step/start" || event.type === "step/end") && Number(event.seq) < undoneCut) {
|
|
3075
|
+
changed = true;
|
|
3076
|
+
continue;
|
|
3077
|
+
}
|
|
3078
|
+
const beforeTip = continueAfterSeq === void 0 || Number(event.seq) <= continueAfterSeq;
|
|
3079
|
+
if (hideTurnsFrom !== void 0 && ownedTurn !== void 0 && ownedTurn >= hideTurnsFrom && beforeTip && !isRollbackMarkerEvent(event) && !isUndoCopyEvent(event)) {
|
|
3080
|
+
changed = true;
|
|
3081
|
+
continue;
|
|
3082
|
+
}
|
|
3083
|
+
if (isRollbackMarkerEvent(event)) {
|
|
3084
|
+
if (!activeMarkers.has(Number(event.seq))) {
|
|
3085
|
+
changed = true;
|
|
3086
|
+
continue;
|
|
3087
|
+
}
|
|
3088
|
+
if (surfaceOpOf(event) === "append") {
|
|
3089
|
+
next.push(entry);
|
|
3090
|
+
continue;
|
|
3091
|
+
}
|
|
3092
|
+
next.push({ type: "event", event: asAppend(event) });
|
|
3093
|
+
changed = true;
|
|
3094
|
+
continue;
|
|
3095
|
+
}
|
|
3096
|
+
if (isUndoCopyEvent(event) && surfaceOpOf(event) !== "append") {
|
|
3097
|
+
next.push({ type: "event", event: asAppend(event) });
|
|
3098
|
+
changed = true;
|
|
3099
|
+
continue;
|
|
3100
|
+
}
|
|
3101
|
+
next.push(entry);
|
|
3102
|
+
}
|
|
3103
|
+
return renumberCollidingTurns(changed ? next : entries);
|
|
3104
|
+
}
|
|
3105
|
+
|
|
3106
|
+
// src/client/rollback/transcript-filter.ts
|
|
3107
|
+
function installRollbackTranscriptFilter(ctx, tips) {
|
|
3108
|
+
const sessions = ctx.get("sessions");
|
|
3109
|
+
if (sessions?.list === void 0 || typeof sessions.binding !== "function") return () => {
|
|
3110
|
+
};
|
|
3111
|
+
const watched = /* @__PURE__ */ new Map();
|
|
3112
|
+
const syncSession = (sessionId) => {
|
|
3113
|
+
const binding = sessions.binding(sessionId);
|
|
3114
|
+
const source = binding?.eventSource;
|
|
3115
|
+
if (source?.replace === void 0) {
|
|
3116
|
+
tips?.set(sessionId, void 0);
|
|
3117
|
+
return;
|
|
3118
|
+
}
|
|
3119
|
+
const window2 = source.getSnapshot();
|
|
3120
|
+
const presented = presentRollbackTranscript(window2.entries);
|
|
3121
|
+
tips?.set(sessionId, activeRollbackUndoTip(presented)?.turn);
|
|
3122
|
+
if (presented !== window2.entries) source.replace(presented, window2.hasMore);
|
|
3123
|
+
};
|
|
3124
|
+
const watch = (sessionId) => {
|
|
3125
|
+
if (watched.has(sessionId)) return;
|
|
3126
|
+
const binding = sessions.binding(sessionId);
|
|
3127
|
+
if (binding === void 0) return;
|
|
3128
|
+
const source = binding.eventSource;
|
|
3129
|
+
const retention = sessions.retainInfo?.(sessionId);
|
|
3130
|
+
const unsubSource = source.subscribe(() => {
|
|
3131
|
+
syncSession(sessionId);
|
|
3132
|
+
});
|
|
3133
|
+
const unsubRetention = retention?.subscribe(() => {
|
|
3134
|
+
if (sessions.binding(sessionId) === void 0) {
|
|
3135
|
+
watched.get(sessionId)?.();
|
|
3136
|
+
watched.delete(sessionId);
|
|
3137
|
+
tips?.set(sessionId, void 0);
|
|
3138
|
+
}
|
|
3139
|
+
}) ?? (() => {
|
|
3140
|
+
});
|
|
3141
|
+
watched.set(sessionId, () => {
|
|
3142
|
+
unsubSource();
|
|
3143
|
+
unsubRetention();
|
|
3144
|
+
tips?.set(sessionId, void 0);
|
|
3145
|
+
});
|
|
3146
|
+
syncSession(sessionId);
|
|
3147
|
+
};
|
|
3148
|
+
const syncList = () => {
|
|
3149
|
+
for (const id of sessions.list.getSnapshot().ids ?? []) watch(id);
|
|
3150
|
+
};
|
|
3151
|
+
const unsubList = sessions.list.subscribe(syncList);
|
|
3152
|
+
syncList();
|
|
3153
|
+
return () => {
|
|
3154
|
+
unsubList();
|
|
3155
|
+
for (const dispose of watched.values()) dispose();
|
|
3156
|
+
watched.clear();
|
|
3157
|
+
};
|
|
3158
|
+
}
|
|
3159
|
+
|
|
3160
|
+
// src/client/rollback/turn-outline-filter.ts
|
|
3161
|
+
function installRollbackTurnOutlineFilter(ctx) {
|
|
3162
|
+
const sessions = ctx.get("sessions");
|
|
3163
|
+
if (sessions?.list === void 0 || typeof sessions.binding !== "function") return () => {
|
|
3164
|
+
};
|
|
3165
|
+
const watched = /* @__PURE__ */ new Map();
|
|
3166
|
+
const hostOutlines = /* @__PURE__ */ new Map();
|
|
3167
|
+
const publish = (sessionId) => {
|
|
3168
|
+
const binding = sessions.binding(sessionId);
|
|
3169
|
+
const projections = binding?.session.projections;
|
|
3170
|
+
const source = binding?.eventSource;
|
|
3171
|
+
if (projections?.get === void 0 || projections.apply === void 0 || source === void 0) return;
|
|
3172
|
+
const entries = source.getSnapshot().entries;
|
|
3173
|
+
const hideTurnsFrom = activeRollbackHideTurnsFrom(entries);
|
|
3174
|
+
const continueAfterSeq = activeRollbackContinueAfterSeq(entries);
|
|
3175
|
+
const base = hostOutlines.has(sessionId) ? hostOutlines.get(sessionId) : projections.get("turnOutline");
|
|
3176
|
+
const filtered = filterTurnOutline(base, hideTurnsFrom, continueAfterSeq);
|
|
3177
|
+
if (Object.is(filtered, projections.get("turnOutline"))) return;
|
|
3178
|
+
const currentSeq = Number(projections.seqOf("turnOutline") ?? 0);
|
|
3179
|
+
const nextSeq = Number.isFinite(currentSeq) ? currentSeq + 1 : 1;
|
|
3180
|
+
projections.apply("turnOutline", filtered, nextSeq);
|
|
3181
|
+
};
|
|
3182
|
+
const watch = (sessionId) => {
|
|
3183
|
+
if (watched.has(sessionId)) return;
|
|
3184
|
+
const binding = sessions.binding(sessionId);
|
|
3185
|
+
if (binding === void 0) return;
|
|
3186
|
+
const projections = binding.session.projections;
|
|
3187
|
+
if (projections?.faceOf === void 0 || projections.get === void 0) return;
|
|
3188
|
+
let applying = false;
|
|
3189
|
+
const onOutline = () => {
|
|
3190
|
+
if (applying) return;
|
|
3191
|
+
hostOutlines.set(sessionId, projections.get("turnOutline"));
|
|
3192
|
+
applying = true;
|
|
3193
|
+
try {
|
|
3194
|
+
publish(sessionId);
|
|
3195
|
+
} finally {
|
|
3196
|
+
applying = false;
|
|
3197
|
+
}
|
|
3198
|
+
};
|
|
3199
|
+
const onEvents = () => {
|
|
3200
|
+
applying = true;
|
|
3201
|
+
try {
|
|
3202
|
+
publish(sessionId);
|
|
3203
|
+
} finally {
|
|
3204
|
+
applying = false;
|
|
3205
|
+
}
|
|
3206
|
+
};
|
|
3207
|
+
const unsubSource = binding.eventSource.subscribe(onEvents);
|
|
3208
|
+
const unsubOutline = projections.faceOf("turnOutline").subscribe(onOutline);
|
|
3209
|
+
const retention = sessions.retainInfo?.(sessionId);
|
|
3210
|
+
const unsubRetention = retention?.subscribe(() => {
|
|
3211
|
+
if (sessions.binding(sessionId) === void 0) {
|
|
3212
|
+
watched.get(sessionId)?.();
|
|
3213
|
+
watched.delete(sessionId);
|
|
3214
|
+
hostOutlines.delete(sessionId);
|
|
3215
|
+
}
|
|
3216
|
+
}) ?? (() => {
|
|
3217
|
+
});
|
|
3218
|
+
watched.set(sessionId, () => {
|
|
3219
|
+
unsubSource();
|
|
3220
|
+
unsubOutline();
|
|
3221
|
+
unsubRetention();
|
|
3222
|
+
hostOutlines.delete(sessionId);
|
|
3223
|
+
});
|
|
3224
|
+
hostOutlines.set(sessionId, projections.get("turnOutline"));
|
|
3225
|
+
onEvents();
|
|
3226
|
+
};
|
|
3227
|
+
const syncList = () => {
|
|
3228
|
+
for (const id of sessions.list.getSnapshot().ids ?? []) watch(id);
|
|
3229
|
+
};
|
|
3230
|
+
const unsubList = sessions.list.subscribe(syncList);
|
|
3231
|
+
syncList();
|
|
3232
|
+
return () => {
|
|
3233
|
+
unsubList();
|
|
3234
|
+
for (const dispose of watched.values()) dispose();
|
|
3235
|
+
watched.clear();
|
|
3236
|
+
hostOutlines.clear();
|
|
3237
|
+
};
|
|
3238
|
+
}
|
|
3239
|
+
|
|
3240
|
+
// src/client/rollback/undo-tip.ts
|
|
3241
|
+
var RollbackUndoTipStore = class {
|
|
3242
|
+
tips = /* @__PURE__ */ new Map();
|
|
3243
|
+
get(sessionId) {
|
|
3244
|
+
return this.tips.get(String(sessionId));
|
|
3245
|
+
}
|
|
3246
|
+
set(sessionId, turn) {
|
|
3247
|
+
const key = String(sessionId);
|
|
3248
|
+
if (turn === void 0) {
|
|
3249
|
+
this.tips.delete(key);
|
|
3250
|
+
return;
|
|
3251
|
+
}
|
|
3252
|
+
this.tips.set(key, turn);
|
|
3253
|
+
}
|
|
3254
|
+
clear(sessionId) {
|
|
3255
|
+
if (sessionId === void 0) {
|
|
3256
|
+
this.tips.clear();
|
|
3257
|
+
return;
|
|
3258
|
+
}
|
|
3259
|
+
this.tips.delete(String(sessionId));
|
|
3260
|
+
}
|
|
3261
|
+
};
|
|
3262
|
+
|
|
3263
|
+
// src/client/rollback/user-node.tsx
|
|
3264
|
+
var import_dsh_client_ui_primitives9 = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
3265
|
+
var import_react7 = require("react");
|
|
3266
|
+
|
|
3267
|
+
// src/client/rollback/actions.tsx
|
|
3268
|
+
var import_dsh_client_ui_primitives8 = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
3269
|
+
var import_react6 = require("react");
|
|
3270
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
3271
|
+
function RollbackMessageActions(props) {
|
|
3272
|
+
const snapshot = (0, import_react6.useSyncExternalStore)(props.rollback.subscribe, props.rollback.getSnapshot);
|
|
3273
|
+
const session = props.useSession((state) => state);
|
|
3274
|
+
const turn = props.turn;
|
|
3275
|
+
if (!snapshot.enabled) return null;
|
|
3276
|
+
const canExecute = props.useAccess("checkpointRollback/execute");
|
|
3277
|
+
const disabledReason = canExecute === false ? "rollbackUnavailablePermission" : session.running ? "rollbackUnavailableRunning" : turn.status !== "closed" ? "rollbackTurnOpen" : turn.start === void 0 ? "rollbackTurnStartMissing" : null;
|
|
3278
|
+
const entryLabel = props.t("rollbackAction");
|
|
3279
|
+
const entryTooltip = disabledReason === null ? entryLabel : props.t(disabledReason);
|
|
3280
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_dsh_client_ui_primitives8.Tooltip, { label: entryTooltip, side: "bottom", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
3281
|
+
"button",
|
|
3282
|
+
{
|
|
3283
|
+
type: "button",
|
|
3284
|
+
className: css_module_default.userMessageAction,
|
|
3285
|
+
"aria-label": entryLabel,
|
|
3286
|
+
title: entryTooltip,
|
|
3287
|
+
disabled: disabledReason !== null,
|
|
3288
|
+
"data-unavailable": disabledReason !== null || void 0,
|
|
3289
|
+
onClick: () => {
|
|
3290
|
+
if (disabledReason === null) props.rollback.open(turn.turn, "rollback");
|
|
3291
|
+
},
|
|
3292
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(UndoIcon, {})
|
|
3293
|
+
}
|
|
3294
|
+
) });
|
|
3295
|
+
}
|
|
3296
|
+
|
|
3297
|
+
// src/client/rollback/content-parts.ts
|
|
3298
|
+
function contentParts(content) {
|
|
3299
|
+
const texts = [];
|
|
3300
|
+
const attachments = [];
|
|
3301
|
+
const rest = [];
|
|
3302
|
+
for (const block2 of content) {
|
|
3303
|
+
if (block2.type === "text" && typeof block2.text === "string") texts.push(block2.text);
|
|
3304
|
+
else if (block2.type === "image" && "attachment" in block2 && block2.attachment !== void 0) {
|
|
3305
|
+
attachments.push({ type: "image", image: { attachment: block2.attachment } });
|
|
3306
|
+
} else if (block2.type === "file" && "attachment" in block2 && block2.attachment !== void 0) {
|
|
3307
|
+
attachments.push({ type: "file", file: block2.attachment });
|
|
3308
|
+
} else rest.push(block2);
|
|
3309
|
+
}
|
|
3310
|
+
return { text: texts.join(""), attachments, rest };
|
|
3311
|
+
}
|
|
3312
|
+
|
|
3313
|
+
// src/client/rollback/user-node.tsx
|
|
3314
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
3315
|
+
function turnOf2(location) {
|
|
3316
|
+
return location.kind === "turn" || location.kind === "step" ? location.turn : null;
|
|
3317
|
+
}
|
|
3318
|
+
function UserCopyAction({ text: text2, tChat }) {
|
|
3319
|
+
const [copied, setCopied] = (0, import_react7.useState)(false);
|
|
3320
|
+
const copyPending = (0, import_react7.useRef)(false);
|
|
3321
|
+
const copyTimer = (0, import_react7.useRef)(null);
|
|
3322
|
+
const copyEpoch = (0, import_react7.useRef)(0);
|
|
3323
|
+
(0, import_react7.useEffect)(() => () => {
|
|
3324
|
+
copyEpoch.current += 1;
|
|
3325
|
+
copyPending.current = false;
|
|
3326
|
+
if (copyTimer.current !== null) window.clearTimeout(copyTimer.current);
|
|
3327
|
+
}, []);
|
|
3328
|
+
const onCopy = (0, import_react7.useCallback)(() => {
|
|
3329
|
+
if (copied || copyPending.current) return;
|
|
3330
|
+
const epoch = copyEpoch.current;
|
|
3331
|
+
copyPending.current = true;
|
|
3332
|
+
void (0, import_dsh_client_ui_primitives9.writeClipboard)(text2).then((ok) => {
|
|
3333
|
+
if (epoch !== copyEpoch.current) return;
|
|
3334
|
+
copyPending.current = false;
|
|
3335
|
+
if (!ok) return;
|
|
3336
|
+
setCopied(true);
|
|
3337
|
+
copyTimer.current = window.setTimeout(() => {
|
|
3338
|
+
copyTimer.current = null;
|
|
3339
|
+
setCopied(false);
|
|
3340
|
+
}, 1e3);
|
|
3341
|
+
});
|
|
3342
|
+
}, [copied, text2]);
|
|
3343
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_dsh_client_ui_primitives9.Tooltip, { label: copied ? tChat("copied") : tChat("copy"), side: "bottom", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
3344
|
+
"button",
|
|
3345
|
+
{
|
|
3346
|
+
type: "button",
|
|
3347
|
+
className: css_module_default.userMessageAction,
|
|
3348
|
+
"aria-label": copied ? tChat("copied") : tChat("copy"),
|
|
3349
|
+
onClick: onCopy,
|
|
3350
|
+
children: copied ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_dsh_client_ui_primitives9.IconCheckOutlineRegular, {}) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_dsh_client_ui_primitives9.IconCopyOutlineRegular, {})
|
|
3351
|
+
}
|
|
3352
|
+
) });
|
|
3353
|
+
}
|
|
3354
|
+
function RollbackUserNode(props) {
|
|
3355
|
+
const data = props.node.data;
|
|
3356
|
+
const messageId = data.id;
|
|
3357
|
+
const parts = (0, import_react7.useMemo)(() => contentParts(data.content), [data.content]);
|
|
3358
|
+
const prepared = (0, import_react7.useMemo)(() => ({
|
|
3359
|
+
text: parts.text,
|
|
3360
|
+
attachments: parts.attachments,
|
|
3361
|
+
extraBlocks: parts.rest,
|
|
3362
|
+
...data.referenceLabels === void 0 ? {} : { referenceLabels: data.referenceLabels }
|
|
3363
|
+
}), [parts, data.referenceLabels]);
|
|
3364
|
+
const facts = (0, import_react7.useMemo)(() => ({
|
|
3365
|
+
...data.referenceLabels === void 0 ? {} : { sessionLabels: data.referenceLabels },
|
|
3366
|
+
...data.skillNames === void 0 ? {} : { skillNames: data.skillNames }
|
|
3367
|
+
}), [data.referenceLabels, data.skillNames]);
|
|
3368
|
+
const turn = turnOf2(props.node.location);
|
|
3369
|
+
const isMarker = isRollbackMarkerMessage(data.source, messageId);
|
|
3370
|
+
const rollbackTurn = turnFromRollbackMarkerId(messageId) ?? turn?.turn;
|
|
3371
|
+
const rollbackEnabled = (0, import_react7.useSyncExternalStore)(props.rollback.subscribe, props.rollback.getSnapshot).enabled;
|
|
3372
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: css_module_default.userMessageRow, children: [
|
|
3373
|
+
props.renderFactorySlot("conversation.chat.user.content", {
|
|
3374
|
+
content: prepared,
|
|
3375
|
+
loadImage: props.loadImage,
|
|
3376
|
+
facts,
|
|
3377
|
+
interactive: true
|
|
3378
|
+
}),
|
|
3379
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: css_module_default.userMessageActions, "data-clock": "start", children: [
|
|
3380
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(UserCopyAction, { text: prepared.text, tChat: props.tChat }),
|
|
3381
|
+
rollbackEnabled && turn !== null && rollbackTurn !== void 0 && !isMarker ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
3382
|
+
RollbackMessageActions,
|
|
3383
|
+
{
|
|
3384
|
+
rollback: props.rollback,
|
|
3385
|
+
t: props.tEnhancer,
|
|
3386
|
+
turn,
|
|
3387
|
+
useSession: props.useSession,
|
|
3388
|
+
useAccess: props.useAccess
|
|
3389
|
+
}
|
|
3390
|
+
) : null
|
|
3391
|
+
] })
|
|
3392
|
+
] });
|
|
3393
|
+
}
|
|
3394
|
+
|
|
3395
|
+
// src/client/index.ts
|
|
3396
|
+
var inject = ["remote", "remote.session", "remote.pluginInventory", "configForms", "locale", "slots"];
|
|
3397
|
+
function apply(ctx) {
|
|
3398
|
+
ctx.effect(installCss);
|
|
3399
|
+
ctx.effect(() => ctx.locale.register("agent-enhancer", agentLocales));
|
|
3400
|
+
const t = ctx.locale.bind("agent-enhancer");
|
|
3401
|
+
const form = new AcceptedSettingsForm(ctx.configForms.get("agent-enhancer"));
|
|
3402
|
+
const catalogLoaders = { ...catalogLoadersFromRemote(ctx.remote) };
|
|
3403
|
+
const adoptCatalogLoaders = (remote) => {
|
|
3404
|
+
const next = catalogLoadersFromRemote(remote);
|
|
3405
|
+
if (next.sessionModelCatalog) catalogLoaders.sessionModelCatalog = next.sessionModelCatalog;
|
|
3406
|
+
if (next.hostListCatalog) catalogLoaders.hostListCatalog = next.hostListCatalog;
|
|
3407
|
+
};
|
|
3408
|
+
const loadCatalog = () => Promise.resolve().then(
|
|
3409
|
+
() => loadDesktopModelCatalog(catalogLoaders)
|
|
3410
|
+
);
|
|
3411
|
+
const SettingsTab = (props) => (0, import_react8.createElement)(PluginSettings, { form: props.form, t: props.t, loadCatalog });
|
|
3412
|
+
ctx.effect(() => ctx.slots.inject("settings.plugins.tab", () => ctx.slots.register({
|
|
3413
|
+
name: "settings.plugins.tab",
|
|
3414
|
+
id: "agent-enhancer",
|
|
3415
|
+
order: 120,
|
|
3416
|
+
label: () => t("settingsTitle"),
|
|
3417
|
+
locale: "agent-enhancer",
|
|
3418
|
+
inject: () => ({ form })
|
|
3419
|
+
}, SettingsTab)));
|
|
3420
|
+
const hints = new OverlapHintStore();
|
|
3421
|
+
ctx.effect(() => {
|
|
3422
|
+
let active = true;
|
|
3423
|
+
const load = async () => {
|
|
3424
|
+
try {
|
|
3425
|
+
const result = await ctx.remote.pluginInventory.list();
|
|
3426
|
+
if (active && result.ok) hints.accept(result.value.entries);
|
|
3427
|
+
} catch {
|
|
3428
|
+
}
|
|
3429
|
+
};
|
|
3430
|
+
void load();
|
|
3431
|
+
return () => {
|
|
3432
|
+
active = false;
|
|
3433
|
+
hints.dispose();
|
|
3434
|
+
};
|
|
3435
|
+
});
|
|
3436
|
+
const applyAgentMounted = (mountedCtx) => {
|
|
3437
|
+
const switches = {
|
|
3438
|
+
history: () => resolveSettings(form.getSnapshot().value).historyEnabled,
|
|
3439
|
+
optimize: () => resolveSettings(form.getSnapshot().value).optimizeEnabled,
|
|
3440
|
+
predict: () => resolveSettings(form.getSnapshot().value).predictEnabled
|
|
3441
|
+
};
|
|
3442
|
+
const desktopUiLocale = () => {
|
|
3443
|
+
try {
|
|
3444
|
+
return resolveUiLocale(mountedCtx.locale.getLocale().active);
|
|
3445
|
+
} catch {
|
|
3446
|
+
return "zh";
|
|
3447
|
+
}
|
|
3448
|
+
};
|
|
3449
|
+
const generate = async (request, signal) => {
|
|
3450
|
+
const uiLocale = request.uiLocale ?? desktopUiLocale();
|
|
3451
|
+
const data = request.operation === "optimize" ? { ...request, references: [...request.references], context: [...request.context], uiLocale } : { ...request, context: [...request.context], uiLocale };
|
|
3452
|
+
return agentEnhancerCall.invoke(mountedCtx.remote, {
|
|
3453
|
+
payload: { method: "generate", data }
|
|
3454
|
+
}, signal);
|
|
3455
|
+
};
|
|
3456
|
+
const sessions = /* @__PURE__ */ new Map();
|
|
3457
|
+
mountedCtx.effect(() => form.subscribe(() => {
|
|
3458
|
+
for (const session of sessions.values()) session.refreshSettings();
|
|
3459
|
+
}));
|
|
3460
|
+
mountedCtx.effect(() => () => {
|
|
3461
|
+
for (const session of sessions.values()) session.dispose();
|
|
3462
|
+
sessions.clear();
|
|
3463
|
+
});
|
|
3464
|
+
const sessionFor = (sessionId) => {
|
|
3465
|
+
let session = sessions.get(sessionId);
|
|
3466
|
+
if (session === void 0) {
|
|
3467
|
+
session = new PromptSession(switches, generate, generate);
|
|
3468
|
+
sessions.set(sessionId, session);
|
|
3469
|
+
}
|
|
3470
|
+
return session;
|
|
3471
|
+
};
|
|
3472
|
+
mountedCtx.slots.inject("conversation.input.right", () => mountedCtx.slots.register({
|
|
3473
|
+
name: "conversation.input.right",
|
|
3474
|
+
id: "agent-enhancer",
|
|
3475
|
+
order: 120,
|
|
3476
|
+
locale: "agent-enhancer",
|
|
3477
|
+
inject: (sessionId) => ({ session: sessionFor(sessionId) })
|
|
3478
|
+
}, AgentControls));
|
|
3479
|
+
mountedCtx.slots.inject("conversation.input.overlay", () => mountedCtx.slots.register({
|
|
3480
|
+
name: "conversation.input.overlay",
|
|
3481
|
+
id: "agent-enhancer",
|
|
3482
|
+
order: 120,
|
|
3483
|
+
locale: "agent-enhancer",
|
|
3484
|
+
inject: (sessionId) => ({ session: sessionFor(sessionId), hints })
|
|
3485
|
+
}, AgentOverlay));
|
|
3486
|
+
};
|
|
3487
|
+
const applyRollbackMounted = (mountedCtx) => {
|
|
3488
|
+
const rollbackRemote = {
|
|
3489
|
+
preview: (request, signal) => checkpointRollbackRemote.preview(mountedCtx.remote, request, signal),
|
|
3490
|
+
execute: (request, signal) => checkpointRollbackRemote.execute(mountedCtx.remote, request, signal)
|
|
3491
|
+
};
|
|
3492
|
+
const rollbackSessions = /* @__PURE__ */ new Map();
|
|
3493
|
+
const rollbackRetentions = /* @__PURE__ */ new Map();
|
|
3494
|
+
const undoTips = new RollbackUndoTipStore();
|
|
3495
|
+
const tEnhancer = mountedCtx.locale.bind("agent-enhancer");
|
|
3496
|
+
const tChat = mountedCtx.locale.bind("chat");
|
|
3497
|
+
const rollbackEnabled = () => resolveSettings(form.getSnapshot().value).rollbackEnabled;
|
|
3498
|
+
const rollbackFor = (sessionId) => {
|
|
3499
|
+
let rollback = rollbackSessions.get(sessionId);
|
|
3500
|
+
if (rollback === void 0) {
|
|
3501
|
+
rollback = new RollbackController({
|
|
3502
|
+
sessionId,
|
|
3503
|
+
enabled: rollbackEnabled,
|
|
3504
|
+
remote: rollbackRemote
|
|
3505
|
+
});
|
|
3506
|
+
rollbackSessions.set(sessionId, rollback);
|
|
3507
|
+
const sessions = mountedCtx.get("sessions");
|
|
3508
|
+
if (sessions !== void 0) {
|
|
3509
|
+
const retention = sessions.retainInfo(sessionId);
|
|
3510
|
+
rollbackRetentions.set(sessionId, retention.subscribe(() => {
|
|
3511
|
+
if ((retention.getSnapshot().retainedBy.mainView ?? 0) === 0) {
|
|
3512
|
+
rollbackSessions.get(sessionId)?.close();
|
|
3513
|
+
}
|
|
3514
|
+
}));
|
|
3515
|
+
}
|
|
3516
|
+
}
|
|
3517
|
+
return rollback;
|
|
3518
|
+
};
|
|
3519
|
+
const rollbackUserNode = (props) => (0, import_react8.createElement)(
|
|
3520
|
+
RollbackUserNode,
|
|
3521
|
+
{ ...props, rollback: rollbackFor(props.sessionId), tEnhancer, tChat }
|
|
3522
|
+
);
|
|
3523
|
+
const rollbackOverlay = (props) => (0, import_react8.createElement)(
|
|
3524
|
+
RollbackModalHost,
|
|
3525
|
+
{ rollback: rollbackFor(props.sessionId), t: tEnhancer, inputActions: props.inputActions }
|
|
3526
|
+
);
|
|
3527
|
+
const disposers = [];
|
|
3528
|
+
const disableRollback = () => {
|
|
3529
|
+
while (disposers.length > 0) disposers.pop()?.();
|
|
3530
|
+
for (const rollback of rollbackSessions.values()) rollback.dispose();
|
|
3531
|
+
for (const unsubscribe of rollbackRetentions.values()) unsubscribe();
|
|
3532
|
+
rollbackSessions.clear();
|
|
3533
|
+
rollbackRetentions.clear();
|
|
3534
|
+
undoTips.clear();
|
|
3535
|
+
};
|
|
3536
|
+
mountedCtx.effect(() => {
|
|
3537
|
+
const synchronize = () => {
|
|
3538
|
+
const enabled = rollbackEnabled();
|
|
3539
|
+
if (!enabled) {
|
|
3540
|
+
disableRollback();
|
|
3541
|
+
} else if (disposers.length === 0) {
|
|
3542
|
+
disposers.push(mountedCtx.slots.inject("conversation.chat.node", () => mountedCtx.slots.register({
|
|
3543
|
+
name: "conversation.chat.node",
|
|
3544
|
+
key: "user",
|
|
3545
|
+
priority: -120,
|
|
3546
|
+
registrant: "agent-enhancer-rollback-user"
|
|
3547
|
+
}, rollbackUserNode)));
|
|
3548
|
+
disposers.push(mountedCtx.slots.inject("conversation.input.overlay", () => mountedCtx.slots.register({
|
|
3549
|
+
name: "conversation.input.overlay",
|
|
3550
|
+
id: "agent-enhancer-rollback",
|
|
3551
|
+
order: 121,
|
|
3552
|
+
locale: "agent-enhancer"
|
|
3553
|
+
}, rollbackOverlay)));
|
|
3554
|
+
disposers.push(installRollbackTranscriptFilter(mountedCtx, undoTips));
|
|
3555
|
+
disposers.push(installRollbackTurnOutlineFilter(mountedCtx));
|
|
3556
|
+
disposers.push(installRollbackUndoCommand({
|
|
3557
|
+
ctx: mountedCtx,
|
|
3558
|
+
tips: undoTips,
|
|
3559
|
+
rollbackFor,
|
|
3560
|
+
enabled: rollbackEnabled,
|
|
3561
|
+
t: tEnhancer
|
|
3562
|
+
}));
|
|
3563
|
+
}
|
|
3564
|
+
};
|
|
3565
|
+
const unsubscribe = form.subscribe(synchronize);
|
|
3566
|
+
synchronize();
|
|
3567
|
+
return () => {
|
|
3568
|
+
unsubscribe();
|
|
3569
|
+
disableRollback();
|
|
3570
|
+
};
|
|
3571
|
+
});
|
|
3572
|
+
};
|
|
3573
|
+
ctx.effect(async () => {
|
|
3574
|
+
const unmount = await ctx.remote.$mount(clientRemoteInfo);
|
|
3575
|
+
const agentFiber = await ctx.plugin({
|
|
3576
|
+
name: "agent-enhancer-mounted",
|
|
3577
|
+
inject: ["remote.agentEnhancer"],
|
|
3578
|
+
apply: (mountedCtx) => {
|
|
3579
|
+
adoptCatalogLoaders(mountedCtx.remote);
|
|
3580
|
+
applyAgentMounted(mountedCtx);
|
|
3581
|
+
}
|
|
3582
|
+
});
|
|
3583
|
+
const rollbackFiber = await ctx.plugin({
|
|
3584
|
+
name: "agent-enhancer-rollback-mounted",
|
|
3585
|
+
inject: ["remote.checkpointRollback"],
|
|
3586
|
+
apply: applyRollbackMounted
|
|
3587
|
+
});
|
|
3588
|
+
return async () => {
|
|
3589
|
+
await rollbackFiber.dispose();
|
|
3590
|
+
await agentFiber.dispose();
|
|
3591
|
+
await unmount();
|
|
3592
|
+
};
|
|
3593
|
+
});
|
|
3594
|
+
}
|
|
3595
|
+
|
|
3596
|
+
return module.exports;
|
|
3597
|
+
}});
|