@kitionstage/dsh-kits 0.0.0-stage → 0.1.1-stage.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +405 -2
- package/bin/kits-mcp.mjs +70 -0
- package/cordis.patch.yml +27 -0
- package/lib/client.js +2252 -0
- package/lib/forward.mjs +81 -0
- package/lib/freshness.mjs +79 -0
- package/lib/gateways.mjs +208 -0
- package/lib/host.mjs +170 -0
- package/lib/kition.mjs +222 -0
- package/lib/live.mjs +127 -0
- package/lib/mcp.mjs +151 -0
- package/lib/reviews.mjs +49 -0
- package/lib/routes.mjs +152 -0
- package/lib/tools.mjs +364 -0
- package/lib/workspaces.mjs +66 -0
- package/package.json +66 -4
- package/skills/board-editing/SKILL.md +683 -0
- package/skills/cad-editing/SKILL.md +463 -0
- package/skills/design-editing/SKILL.md +356 -0
- package/skills/doc-editing/SKILL.md +312 -0
- package/skills/drafts-compare/SKILL.md +16 -0
- package/skills/drafts-discard/SKILL.md +15 -0
- package/skills/drafts-list/SKILL.md +16 -0
- package/skills/drafts-merge/SKILL.md +16 -0
- package/skills/film-editing/SKILL.md +541 -0
- package/skills/html-editing/SKILL.md +149 -0
- package/skills/layout-editing/SKILL.md +322 -0
- package/skills/motion-editing/SKILL.md +682 -0
- package/skills/note-editing/SKILL.md +256 -0
- package/skills/pdf-editing/SKILL.md +265 -0
- package/skills/photo-editing/SKILL.md +316 -0
- package/skills/scene-editing/SKILL.md +722 -0
- package/skills/sheet-editing/SKILL.md +364 -0
- package/skills/slide-editing/SKILL.md +447 -0
- package/skills/table-editing/SKILL.md +402 -0
- package/skills/vector-editing/SKILL.md +255 -0
package/lib/client.js
ADDED
|
@@ -0,0 +1,2252 @@
|
|
|
1
|
+
// @kitionstage/dsh-kits: the Kition kits in DeepSeek Harness, the browser module. Built by build-client.mjs
|
|
2
|
+
// from src/client/; do not edit.
|
|
3
|
+
window.__ModuleLoader__.load({
|
|
4
|
+
id: "@kitionstage/dsh-kits",
|
|
5
|
+
factory: (require) => {
|
|
6
|
+
var module = { exports: {} };
|
|
7
|
+
var exports = module.exports;
|
|
8
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
9
|
+
// \0rolldown/runtime.js
|
|
10
|
+
var __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
19
|
+
desc = __getOwnPropDesc(from, key);
|
|
20
|
+
__defProp(to, key, {
|
|
21
|
+
get: desc && desc.get && !desc.configurable ? desc.get : () => from[key],
|
|
22
|
+
enumerable: !desc || desc.enumerable
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
29
|
+
value: mod,
|
|
30
|
+
enumerable: true
|
|
31
|
+
}) : target, mod));
|
|
32
|
+
let react = require("react");
|
|
33
|
+
react = __toESM(react);
|
|
34
|
+
// plugins/deepseek-harness/kition-kits/src/client/address.ts
|
|
35
|
+
/**
|
|
36
|
+
* DeepSeek Harness's file addresses, as its right sidebar names a file (the tab's content id):
|
|
37
|
+
* `dsh-resource://file/session/<session id>/<path>` (a path relative to the session's workspace
|
|
38
|
+
* folder, or absolute) and `dsh-resource://file/absolute/<path>` (no session; the leading `/`
|
|
39
|
+
* dropped). Every segment is component-encoded. Only reading is needed here.
|
|
40
|
+
*/
|
|
41
|
+
var PREFIX = "dsh-resource://file/";
|
|
42
|
+
function parseFileAddress(address) {
|
|
43
|
+
if (typeof address !== "string" || !address.startsWith(PREFIX)) return null;
|
|
44
|
+
const end = address.search(/[?#]/);
|
|
45
|
+
const [scope, ...rest] = address.slice(20, end === -1 ? void 0 : end).split("/");
|
|
46
|
+
try {
|
|
47
|
+
if (scope === "session") {
|
|
48
|
+
const [id, ...segments] = rest;
|
|
49
|
+
if (!id || segments.length === 0) return null;
|
|
50
|
+
const path = segments.map(decodeURIComponent).join("/");
|
|
51
|
+
return path ? {
|
|
52
|
+
scope: "session",
|
|
53
|
+
sessionId: decodeURIComponent(id),
|
|
54
|
+
path
|
|
55
|
+
} : null;
|
|
56
|
+
}
|
|
57
|
+
if (scope === "absolute" && rest.length > 0) {
|
|
58
|
+
const path = rest.map(decodeURIComponent).join("/");
|
|
59
|
+
return {
|
|
60
|
+
scope: "absolute",
|
|
61
|
+
path: /^[A-Za-z]:/.test(path) ? path : `/${path}`
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
} catch {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
/** The file's name: the last segment of its path. */
|
|
70
|
+
var baseName = (path) => path.slice(path.replace(/\\/g, "/").lastIndexOf("/") + 1);
|
|
71
|
+
/** The file's extension, lower case, without the dot; `''` when it has none. */
|
|
72
|
+
function extensionOf(path) {
|
|
73
|
+
const name = baseName(path);
|
|
74
|
+
const dot = name.lastIndexOf(".");
|
|
75
|
+
return dot > 0 ? name.slice(dot + 1).toLowerCase() : "";
|
|
76
|
+
}
|
|
77
|
+
/** Whether `data` is a message of this protocol (either way). */
|
|
78
|
+
function isGatewayPageMessage(data) {
|
|
79
|
+
return typeof data === "object" && data !== null && data.kitionGatewayPage === 1 && typeof data.type === "string";
|
|
80
|
+
}
|
|
81
|
+
// plugins/deepseek-harness/kition-kits/src/client/frame.ts
|
|
82
|
+
/**
|
|
83
|
+
* The editor page's frame in a DeepSeek Harness tab and the host's side of its `postMessage`
|
|
84
|
+
* protocol (kition-sdk docs/sdk/gateway-page.md): it tells the page the theme and the language,
|
|
85
|
+
* and hears its state (title, dirty mark, draft), its shortcuts and its requests to close.
|
|
86
|
+
*/
|
|
87
|
+
/**
|
|
88
|
+
* The name DeepSeek Harness gives the frame of a sidebar tab's HTML preview. Its keyboard
|
|
89
|
+
* shortcuts reach a frame only when the frame carries this name and a `data-html-preview`
|
|
90
|
+
* attribute from the moment it is made (setting them later has no effect).
|
|
91
|
+
*/
|
|
92
|
+
var frameName = (tabId) => `dsh-sidebar-html-${tabId}`;
|
|
93
|
+
/** Makes the page's frame for the tab `tabId` at `src`. */
|
|
94
|
+
function makeFrame(tabId, src, title) {
|
|
95
|
+
const frame = document.createElement("iframe");
|
|
96
|
+
frame.name = frameName(tabId);
|
|
97
|
+
frame.setAttribute("data-html-preview", "");
|
|
98
|
+
frame.setAttribute("data-kition-page", "");
|
|
99
|
+
frame.title = title;
|
|
100
|
+
frame.allow = "clipboard-read; clipboard-write; fullscreen";
|
|
101
|
+
frame.style.cssText = "flex: 1 1 auto; width: 100%; height: 100%; min-height: 0; border: 0; display: block; -webkit-app-region: no-drag";
|
|
102
|
+
frame.src = src;
|
|
103
|
+
return frame;
|
|
104
|
+
}
|
|
105
|
+
/** The host's side of the protocol with one page frame. */
|
|
106
|
+
var PageFrame = class {
|
|
107
|
+
frame;
|
|
108
|
+
events;
|
|
109
|
+
scheme;
|
|
110
|
+
language;
|
|
111
|
+
state = {
|
|
112
|
+
ready: false,
|
|
113
|
+
title: null,
|
|
114
|
+
kit: null,
|
|
115
|
+
status: null,
|
|
116
|
+
dirty: false,
|
|
117
|
+
readOnly: false,
|
|
118
|
+
draft: null
|
|
119
|
+
};
|
|
120
|
+
listener;
|
|
121
|
+
constructor(frame, events, scheme, language) {
|
|
122
|
+
this.frame = frame;
|
|
123
|
+
this.events = events;
|
|
124
|
+
this.scheme = scheme;
|
|
125
|
+
this.language = language;
|
|
126
|
+
this.listener = (event) => this.receive(event);
|
|
127
|
+
window.addEventListener("message", this.listener);
|
|
128
|
+
}
|
|
129
|
+
/** The page's origin is the host's (a same-origin proxy): its messages come from there. */
|
|
130
|
+
receive(event) {
|
|
131
|
+
if (event.source !== this.frame.contentWindow) return;
|
|
132
|
+
if (event.origin !== location.origin && !(event.origin === "null" || location.origin === "null")) return;
|
|
133
|
+
if (!isGatewayPageMessage(event.data)) return;
|
|
134
|
+
const message = event.data;
|
|
135
|
+
switch (message.type) {
|
|
136
|
+
case "ready":
|
|
137
|
+
this.state.ready = true;
|
|
138
|
+
this.send({
|
|
139
|
+
kitionGatewayPage: 1,
|
|
140
|
+
type: "theme",
|
|
141
|
+
theme: this.scheme
|
|
142
|
+
});
|
|
143
|
+
this.send({
|
|
144
|
+
kitionGatewayPage: 1,
|
|
145
|
+
type: "locale",
|
|
146
|
+
locale: this.language
|
|
147
|
+
});
|
|
148
|
+
break;
|
|
149
|
+
case "state":
|
|
150
|
+
Object.assign(this.state, {
|
|
151
|
+
title: message.title,
|
|
152
|
+
kit: message.kit,
|
|
153
|
+
status: message.status,
|
|
154
|
+
dirty: message.dirty,
|
|
155
|
+
readOnly: message.readOnly === true,
|
|
156
|
+
progress: message.progress,
|
|
157
|
+
detail: message.detail
|
|
158
|
+
});
|
|
159
|
+
break;
|
|
160
|
+
case "draft":
|
|
161
|
+
this.state.draft = message.draft;
|
|
162
|
+
break;
|
|
163
|
+
case "reviewed":
|
|
164
|
+
this.state.draft = null;
|
|
165
|
+
this.events.reviewed?.(message.outcome);
|
|
166
|
+
break;
|
|
167
|
+
case "shortcut":
|
|
168
|
+
if (!(message.key.code === "KeyW" && (message.key.meta || message.key.ctrl))) this.events.shortcut?.(message.key);
|
|
169
|
+
return;
|
|
170
|
+
case "request-close":
|
|
171
|
+
this.events.requestClose?.(message.dirty);
|
|
172
|
+
return;
|
|
173
|
+
case "saved":
|
|
174
|
+
this.events.saved?.(message.saved, message.error);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
this.events.change?.({ ...this.state });
|
|
178
|
+
}
|
|
179
|
+
send(command) {
|
|
180
|
+
const target = location.origin && location.origin !== "null" ? location.origin : "*";
|
|
181
|
+
this.frame.contentWindow?.postMessage(command, target);
|
|
182
|
+
}
|
|
183
|
+
setTheme(scheme) {
|
|
184
|
+
if (scheme === this.scheme) return;
|
|
185
|
+
this.scheme = scheme;
|
|
186
|
+
if (this.state.ready) this.send({
|
|
187
|
+
kitionGatewayPage: 1,
|
|
188
|
+
type: "theme",
|
|
189
|
+
theme: scheme
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
setLanguage(language) {
|
|
193
|
+
if (language === this.language) return;
|
|
194
|
+
this.language = language;
|
|
195
|
+
if (this.state.ready) this.send({
|
|
196
|
+
kitionGatewayPage: 1,
|
|
197
|
+
type: "locale",
|
|
198
|
+
locale: language
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
save() {
|
|
202
|
+
this.send({
|
|
203
|
+
kitionGatewayPage: 1,
|
|
204
|
+
type: "save"
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
focus() {
|
|
208
|
+
this.send({
|
|
209
|
+
kitionGatewayPage: 1,
|
|
210
|
+
type: "focus"
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
/** Opens the review of the agent's draft in the page. */
|
|
214
|
+
review() {
|
|
215
|
+
this.send({
|
|
216
|
+
kitionGatewayPage: 1,
|
|
217
|
+
type: "review"
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
dispose() {
|
|
221
|
+
window.removeEventListener("message", this.listener);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
// plugins/deepseek-harness/kition-kits/src/client/gateway.ts
|
|
225
|
+
/** The host module's route `path`, relative to where DeepSeek Harness is served. */
|
|
226
|
+
var route = (path) => new URL(path, document.baseURI).href;
|
|
227
|
+
/** Asks the host module to open a session's file: its gateway started, the page's address. */
|
|
228
|
+
async function openFile(sessionId, path) {
|
|
229
|
+
try {
|
|
230
|
+
const response = await fetch(route(`kition/api/open?${new URLSearchParams({
|
|
231
|
+
session: sessionId,
|
|
232
|
+
path
|
|
233
|
+
})}`), {
|
|
234
|
+
credentials: "same-origin",
|
|
235
|
+
cache: "no-store"
|
|
236
|
+
});
|
|
237
|
+
const answer = await response.json().catch(() => ({}));
|
|
238
|
+
if (response.ok && typeof answer.page === "string") return {
|
|
239
|
+
phase: "open",
|
|
240
|
+
page: answer.page,
|
|
241
|
+
key: answer.key,
|
|
242
|
+
path: answer.path
|
|
243
|
+
};
|
|
244
|
+
return {
|
|
245
|
+
phase: "failed",
|
|
246
|
+
error: String(answer.error ?? `http-${response.status}`),
|
|
247
|
+
message: String(answer.message ?? response.statusText),
|
|
248
|
+
...typeof answer.reason === "string" ? { reason: answer.reason } : {},
|
|
249
|
+
...typeof answer.platform === "string" ? { platform: answer.platform } : {}
|
|
250
|
+
};
|
|
251
|
+
} catch (error) {
|
|
252
|
+
return {
|
|
253
|
+
phase: "failed",
|
|
254
|
+
error: "unreachable",
|
|
255
|
+
message: error.message
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
var GatewayError = class extends Error {
|
|
260
|
+
status;
|
|
261
|
+
reason;
|
|
262
|
+
constructor(message, status, reason) {
|
|
263
|
+
super(message);
|
|
264
|
+
this.status = status;
|
|
265
|
+
this.reason = reason;
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
/** A JSON call to the gateway of workspace `key`: its envelope's `data`, or its refusal thrown. */
|
|
269
|
+
async function gatewayJson(key, path, init = {}) {
|
|
270
|
+
let response;
|
|
271
|
+
try {
|
|
272
|
+
response = await fetch(route(`kition/w/${key}/${path}`), {
|
|
273
|
+
credentials: "same-origin",
|
|
274
|
+
cache: "no-store",
|
|
275
|
+
...init
|
|
276
|
+
});
|
|
277
|
+
} catch (error) {
|
|
278
|
+
throw new GatewayError(error.message, 0, "unreachable");
|
|
279
|
+
}
|
|
280
|
+
const envelope = await response.json().catch(() => null);
|
|
281
|
+
if (!response.ok) throw new GatewayError(envelope?.message ?? `the gateway answered ${response.status}`, response.status, envelope?.data?.reason ?? envelope?.error ?? null);
|
|
282
|
+
return envelope?.data ?? null;
|
|
283
|
+
}
|
|
284
|
+
var post = (key, path, body, origin) => gatewayJson(key, path, {
|
|
285
|
+
method: "POST",
|
|
286
|
+
headers: {
|
|
287
|
+
"Content-Type": "application/json",
|
|
288
|
+
...origin ? {
|
|
289
|
+
"Kition-Dsh-Session": origin.session,
|
|
290
|
+
"Kition-Dsh-Turn": String(origin.turn)
|
|
291
|
+
} : {}
|
|
292
|
+
},
|
|
293
|
+
body: JSON.stringify(body)
|
|
294
|
+
});
|
|
295
|
+
var compare = (key, path) => gatewayJson(key, `api/v1/kits/drafts/compare?${new URLSearchParams({
|
|
296
|
+
path,
|
|
297
|
+
previews: "true"
|
|
298
|
+
})}`);
|
|
299
|
+
/** The person's Merge (with `overwrite`, over a file that changed since the draft began). */
|
|
300
|
+
var merge = (key, path, overwrite = false, origin) => post(key, "api/v1/kits/drafts/merge", {
|
|
301
|
+
path,
|
|
302
|
+
overwrite
|
|
303
|
+
}, origin);
|
|
304
|
+
/** The person's Discard. */
|
|
305
|
+
var discard = (key, path, origin) => post(key, "api/v1/kits/drafts/discard", { path }, origin);
|
|
306
|
+
/** Whether the workspace file is still there. */
|
|
307
|
+
async function exists(key, path) {
|
|
308
|
+
const response = await fetch(route(`kition/w/${key}/kit-files/${path.split("/").map(encodeURIComponent).join("/")}`), {
|
|
309
|
+
method: "HEAD",
|
|
310
|
+
credentials: "same-origin",
|
|
311
|
+
cache: "no-store"
|
|
312
|
+
}).catch(() => null);
|
|
313
|
+
return response ? response.status !== 404 : true;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* The drafts of one workspace, followed: listed again when the gateway's bridge says they changed
|
|
317
|
+
* (`kit/draftsChanged`), when a page or a card says so, and every 10 s while anyone listens.
|
|
318
|
+
*/
|
|
319
|
+
var DraftsWatch = class {
|
|
320
|
+
key;
|
|
321
|
+
drafts = null;
|
|
322
|
+
failed = null;
|
|
323
|
+
listeners = /* @__PURE__ */ new Set();
|
|
324
|
+
stream = null;
|
|
325
|
+
timer = null;
|
|
326
|
+
constructor(key) {
|
|
327
|
+
this.key = key;
|
|
328
|
+
}
|
|
329
|
+
subscribe(listener) {
|
|
330
|
+
this.listeners.add(listener);
|
|
331
|
+
if (this.listeners.size === 1) this.start();
|
|
332
|
+
return () => {
|
|
333
|
+
this.listeners.delete(listener);
|
|
334
|
+
if (this.listeners.size === 0) this.stop();
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
async refresh() {
|
|
338
|
+
try {
|
|
339
|
+
const listed = await gatewayJson(this.key, "api/v1/kits/drafts");
|
|
340
|
+
this.drafts = new Map(listed.drafts.map((draft) => [draft.path, draft]));
|
|
341
|
+
this.failed = null;
|
|
342
|
+
} catch (error) {
|
|
343
|
+
this.failed = error.message;
|
|
344
|
+
}
|
|
345
|
+
for (const listener of [...this.listeners]) listener();
|
|
346
|
+
}
|
|
347
|
+
start() {
|
|
348
|
+
this.refresh();
|
|
349
|
+
this.timer = setInterval(() => void this.refresh(), 1e4);
|
|
350
|
+
this.stream = new AbortController();
|
|
351
|
+
this.listen(this.stream.signal);
|
|
352
|
+
}
|
|
353
|
+
stop() {
|
|
354
|
+
if (this.timer) clearInterval(this.timer);
|
|
355
|
+
this.timer = null;
|
|
356
|
+
this.stream?.abort();
|
|
357
|
+
this.stream = null;
|
|
358
|
+
}
|
|
359
|
+
/** The gateway's bridge stream, as a window with no editor: it hears the drafts change. */
|
|
360
|
+
async listen(signal) {
|
|
361
|
+
for (let attempt = 0; !signal.aborted; attempt++) {
|
|
362
|
+
try {
|
|
363
|
+
const response = await fetch(route(`kition/w/${this.key}/api/v1/kits/bridge`), {
|
|
364
|
+
credentials: "same-origin",
|
|
365
|
+
headers: { Accept: "text/event-stream" },
|
|
366
|
+
signal
|
|
367
|
+
});
|
|
368
|
+
if (!response.ok || !response.body) throw new Error(String(response.status));
|
|
369
|
+
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
370
|
+
let buffer = "";
|
|
371
|
+
let session = null;
|
|
372
|
+
for (;;) {
|
|
373
|
+
const { value, done } = await reader.read();
|
|
374
|
+
if (done) break;
|
|
375
|
+
buffer += value.replace(/\r\n/g, "\n");
|
|
376
|
+
for (let end = buffer.indexOf("\n\n"); end >= 0; end = buffer.indexOf("\n\n")) {
|
|
377
|
+
const frame = buffer.slice(0, end);
|
|
378
|
+
buffer = buffer.slice(end + 2);
|
|
379
|
+
const data = frame.split("\n").filter((line) => line.startsWith("data:")).map((line) => line.slice(5).trim()).join("\n");
|
|
380
|
+
if (!data) continue;
|
|
381
|
+
let message;
|
|
382
|
+
try {
|
|
383
|
+
message = JSON.parse(data);
|
|
384
|
+
} catch {
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
attempt = 0;
|
|
388
|
+
if (message.method === "bridge.ready") session = Number(message.params?.session);
|
|
389
|
+
else if (message.id != null && session != null) {
|
|
390
|
+
const answer = message.method === "kit/documents" ? { result: { documents: [] } } : { error: {
|
|
391
|
+
code: -32e3,
|
|
392
|
+
message: "no editor is open here"
|
|
393
|
+
} };
|
|
394
|
+
fetch(route(`kition/w/${this.key}/api/v1/kits/bridge?session=${session}`), {
|
|
395
|
+
method: "POST",
|
|
396
|
+
credentials: "same-origin",
|
|
397
|
+
headers: { "Content-Type": "application/json" },
|
|
398
|
+
body: JSON.stringify({
|
|
399
|
+
jsonrpc: "2.0",
|
|
400
|
+
id: message.id,
|
|
401
|
+
...answer
|
|
402
|
+
})
|
|
403
|
+
}).catch(() => void 0);
|
|
404
|
+
} else if (message.method === "kit/draftsChanged") this.refresh();
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
} catch {
|
|
408
|
+
if (signal.aborted) return;
|
|
409
|
+
}
|
|
410
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(1e4, 500 * 2 ** attempt)));
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
var watches = /* @__PURE__ */ new Map();
|
|
415
|
+
function draftsOf(key) {
|
|
416
|
+
let watch = watches.get(key);
|
|
417
|
+
if (!watch) watches.set(key, watch = new DraftsWatch(key));
|
|
418
|
+
return watch;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* The person's reviews of the session's workspace's drafts, as the host module records them (every
|
|
422
|
+
* Merge and Discard through it, from a card or the editor's own review), followed: asked again when
|
|
423
|
+
* a draft changes or the person reviews one.
|
|
424
|
+
*/
|
|
425
|
+
var ReviewsWatch = class {
|
|
426
|
+
sessionId;
|
|
427
|
+
reviews = [];
|
|
428
|
+
listeners = /* @__PURE__ */ new Set();
|
|
429
|
+
asked = false;
|
|
430
|
+
constructor(sessionId) {
|
|
431
|
+
this.sessionId = sessionId;
|
|
432
|
+
}
|
|
433
|
+
subscribe(listener) {
|
|
434
|
+
this.listeners.add(listener);
|
|
435
|
+
if (!this.asked) this.refresh();
|
|
436
|
+
return () => this.listeners.delete(listener);
|
|
437
|
+
}
|
|
438
|
+
async refresh() {
|
|
439
|
+
this.asked = true;
|
|
440
|
+
try {
|
|
441
|
+
const response = await fetch(route(`kition/api/reviews?${new URLSearchParams({ session: this.sessionId })}`), {
|
|
442
|
+
credentials: "same-origin",
|
|
443
|
+
cache: "no-store"
|
|
444
|
+
});
|
|
445
|
+
const answer = await response.json();
|
|
446
|
+
if (response.ok && Array.isArray(answer.reviews)) this.reviews = answer.reviews;
|
|
447
|
+
} catch {}
|
|
448
|
+
for (const listener of [...this.listeners]) listener();
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
var reviewWatches = /* @__PURE__ */ new Map();
|
|
452
|
+
function reviewsOf(sessionId) {
|
|
453
|
+
let watch = reviewWatches.get(sessionId);
|
|
454
|
+
if (!watch) reviewWatches.set(sessionId, watch = new ReviewsWatch(sessionId));
|
|
455
|
+
return watch;
|
|
456
|
+
}
|
|
457
|
+
/** Every turn shown that drafted each session's file, and when: what a review without a turn is matched against. */
|
|
458
|
+
var draftingTurns = /* @__PURE__ */ new Map();
|
|
459
|
+
var draftingListeners = /* @__PURE__ */ new Set();
|
|
460
|
+
var draftingVersion = 0;
|
|
461
|
+
function noteDraftingTurn(sessionId, path, turn, at) {
|
|
462
|
+
const key = `${sessionId}:${path}`;
|
|
463
|
+
let turns = draftingTurns.get(key);
|
|
464
|
+
if (!turns) draftingTurns.set(key, turns = /* @__PURE__ */ new Map());
|
|
465
|
+
if (turns.get(turn) === at) return;
|
|
466
|
+
turns.set(turn, at);
|
|
467
|
+
draftingVersion++;
|
|
468
|
+
queueMicrotask(() => {
|
|
469
|
+
for (const listener of [...draftingListeners]) listener();
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
function subscribeDraftingTurns(listener) {
|
|
473
|
+
draftingListeners.add(listener);
|
|
474
|
+
return () => draftingListeners.delete(listener);
|
|
475
|
+
}
|
|
476
|
+
var draftingVersionNow = () => draftingVersion;
|
|
477
|
+
var draftingTurnsOf = (sessionId, path) => [...(draftingTurns.get(`${sessionId}:${path}`) ?? /* @__PURE__ */ new Map()).entries()];
|
|
478
|
+
/** The latest turn shown that drafted the file. */
|
|
479
|
+
var draftingTurnOf = (sessionId, path) => {
|
|
480
|
+
const turns = draftingTurnsOf(sessionId, path).map(([turn]) => turn);
|
|
481
|
+
return turns.length ? Math.max(...turns) : null;
|
|
482
|
+
};
|
|
483
|
+
// plugins/deepseek-harness/kition-kits/src/client/i18n.ts
|
|
484
|
+
/** The browser module's words, in English and Chinese, as DeepSeek Harness's locale service takes them. */
|
|
485
|
+
var NAMESPACE = "kitionKits";
|
|
486
|
+
var en = {
|
|
487
|
+
openWith: "Kition {kit}",
|
|
488
|
+
starting: "Starting Kition…",
|
|
489
|
+
startingDetail: "Kition is starting for this folder.",
|
|
490
|
+
missingTitle: "Kition cannot run here",
|
|
491
|
+
missingUnsupported: "The Kition program that comes with the plugin has no build for this computer ({platform}). Set KITION_BIN to a kition built for it, and restart DeepSeek Harness.",
|
|
492
|
+
missingOmitted: "The plugin was installed without its optional dependencies, which bring the Kition program for this computer ({platform}). Add the plugin again without leaving them out.",
|
|
493
|
+
missingCli: "The package that brings the Kition program (@kitionstage/cli) is not installed beside the plugin. Add the plugin again.",
|
|
494
|
+
missingFolder: "The plugin was added from a folder, which is linked without its dependencies, so the Kition program is not there. Run npm install --omit=dev in that folder, or add the plugin by name or from its .tgz.",
|
|
495
|
+
missingOption: "An option names a Kition program that cannot be used:",
|
|
496
|
+
unreachableTitle: "Kition does not answer",
|
|
497
|
+
unreachableDetail: "Kition could not open this file.",
|
|
498
|
+
retry: "Try again",
|
|
499
|
+
outsideTitle: "This file is outside the session’s folder",
|
|
500
|
+
outsideDetail: "Kition opens files inside the folder this session works in.",
|
|
501
|
+
noSession: "Open a session to edit this file with Kition.",
|
|
502
|
+
closeDirty: "{name} has unsaved changes in Kition.",
|
|
503
|
+
closeSave: "Save and close",
|
|
504
|
+
closeDiscard: "Close without saving",
|
|
505
|
+
closeKeep: "Keep editing",
|
|
506
|
+
keepDraft: "Keep the draft",
|
|
507
|
+
draft: "Draft",
|
|
508
|
+
draftTitle: "An agent drafted changes to this file",
|
|
509
|
+
readOnly: "Read-only",
|
|
510
|
+
unsaved: "Unsaved changes",
|
|
511
|
+
cardsLabel: "Kition files this turn",
|
|
512
|
+
statePending: "The agent is editing…",
|
|
513
|
+
stateFailed: "The agent’s edit failed",
|
|
514
|
+
stateLive: "Edited live in the open editor",
|
|
515
|
+
stateSaved: "Edited",
|
|
516
|
+
stateCreated: "Created",
|
|
517
|
+
stateDraftOpen: "Draft, for your review",
|
|
518
|
+
stateDraftReady: "Draft ready for your review",
|
|
519
|
+
stateStale: "Draft — the file changed since it began",
|
|
520
|
+
stateMerged: "Merged",
|
|
521
|
+
stateDiscarded: "Discarded",
|
|
522
|
+
stateDraftGone: "The draft is no longer there",
|
|
523
|
+
stateMissing: "The file was deleted",
|
|
524
|
+
stateKitionMissing: "Kition cannot run here; open the file for why",
|
|
525
|
+
stateGatewayDown: "Kition does not answer",
|
|
526
|
+
actionOpen: "Open",
|
|
527
|
+
actionReview: "Review",
|
|
528
|
+
actionMerge: "Merge",
|
|
529
|
+
actionDiscard: "Discard",
|
|
530
|
+
actionOverwrite: "Merge and overwrite",
|
|
531
|
+
confirmDiscard: "Discard the agent’s draft of {name}? The file stays as it is.",
|
|
532
|
+
changes: "{created} created, {changed} changed, {deleted} deleted",
|
|
533
|
+
failedAction: "Kition could not do that: {message}",
|
|
534
|
+
liveWatching: "Live: the agent edits this file",
|
|
535
|
+
liveOpenEditor: "Open in editor",
|
|
536
|
+
settingsTitle: "Kition",
|
|
537
|
+
settingLiveFloat: "Show an agent’s edit of a file that is not open in a floating window, as it happens",
|
|
538
|
+
settingAutoOpen: "Open a file in the right sidebar after an agent’s first edit of it in a turn",
|
|
539
|
+
settingOpenWith: "Open Markdown, HTML, PDF, Word, Excel, PowerPoint, CSV and SVG files first in",
|
|
540
|
+
settingOpenWithDsh: "DeepSeek Harness’s preview",
|
|
541
|
+
settingOpenWithKition: "the Kition editor",
|
|
542
|
+
settingsUnavailable: "These settings need DeepSeek Harness’s settings service."
|
|
543
|
+
};
|
|
544
|
+
var zh = {
|
|
545
|
+
openWith: "Kition {kit}",
|
|
546
|
+
starting: "正在启动 Kition…",
|
|
547
|
+
startingDetail: "Kition 正在为这个文件夹启动。",
|
|
548
|
+
missingTitle: "Kition 无法在这里运行",
|
|
549
|
+
missingUnsupported: "插件自带的 Kition 程序没有这台电脑({platform})的版本。请把 KITION_BIN 设为为它构建的 kition,然后重启 DeepSeek Harness。",
|
|
550
|
+
missingOmitted: "安装插件时没有安装它的可选依赖,而这台电脑({platform})的 Kition 程序正是由可选依赖带来的。请重新添加插件,不要省略可选依赖。",
|
|
551
|
+
missingCli: "带来 Kition 程序的包(@kitionstage/cli)没有和插件一起安装。请重新添加插件。",
|
|
552
|
+
missingFolder: "插件是从文件夹添加的,文件夹会被直接链接而不安装依赖,所以没有 Kition 程序。请在该文件夹里运行 npm install --omit=dev,或者按包名或 .tgz 添加插件。",
|
|
553
|
+
missingOption: "一个选项指定的 Kition 程序无法使用:",
|
|
554
|
+
unreachableTitle: "Kition 没有响应",
|
|
555
|
+
unreachableDetail: "Kition 无法打开这个文件。",
|
|
556
|
+
retry: "重试",
|
|
557
|
+
outsideTitle: "这个文件不在会话的文件夹里",
|
|
558
|
+
outsideDetail: "Kition 只打开这个会话所在文件夹里的文件。",
|
|
559
|
+
noSession: "打开一个会话,才能用 Kition 编辑这个文件。",
|
|
560
|
+
closeDirty: "{name} 在 Kition 里有未保存的修改。",
|
|
561
|
+
closeSave: "保存并关闭",
|
|
562
|
+
closeDiscard: "不保存,关闭",
|
|
563
|
+
closeKeep: "继续编辑",
|
|
564
|
+
keepDraft: "保留草稿",
|
|
565
|
+
draft: "草稿",
|
|
566
|
+
draftTitle: "Agent 起草了对这个文件的修改",
|
|
567
|
+
readOnly: "只读",
|
|
568
|
+
unsaved: "有未保存的修改",
|
|
569
|
+
cardsLabel: "本轮的 Kition 文件",
|
|
570
|
+
statePending: "Agent 正在编辑…",
|
|
571
|
+
stateFailed: "Agent 的修改失败了",
|
|
572
|
+
stateLive: "已在打开的编辑器里实时修改",
|
|
573
|
+
stateSaved: "已修改",
|
|
574
|
+
stateCreated: "已创建",
|
|
575
|
+
stateDraftOpen: "草稿,等你审阅",
|
|
576
|
+
stateDraftReady: "草稿已就绪,等你审阅",
|
|
577
|
+
stateStale: "草稿:文件在起草之后又改过",
|
|
578
|
+
stateMerged: "已合入",
|
|
579
|
+
stateDiscarded: "已丢弃",
|
|
580
|
+
stateDraftGone: "草稿已经不在了",
|
|
581
|
+
stateMissing: "文件已被删除",
|
|
582
|
+
stateKitionMissing: "Kition 无法在这里运行;打开文件查看原因",
|
|
583
|
+
stateGatewayDown: "Kition 没有响应",
|
|
584
|
+
actionOpen: "打开",
|
|
585
|
+
actionReview: "审阅",
|
|
586
|
+
actionMerge: "合入",
|
|
587
|
+
actionDiscard: "丢弃",
|
|
588
|
+
actionOverwrite: "合入并覆盖",
|
|
589
|
+
confirmDiscard: "丢弃 Agent 对 {name} 的草稿吗?文件保持不变。",
|
|
590
|
+
changes: "新增 {created},修改 {changed},删除 {deleted}",
|
|
591
|
+
failedAction: "Kition 没能完成:{message}",
|
|
592
|
+
liveWatching: "实时:Agent 正在编辑这个文件",
|
|
593
|
+
liveOpenEditor: "在编辑器中打开",
|
|
594
|
+
settingsTitle: "Kition",
|
|
595
|
+
settingLiveFloat: "Agent 编辑一个没有打开的文件时,在浮动窗口里实时显示",
|
|
596
|
+
settingAutoOpen: "Agent 在一轮里第一次编辑一个文件后,在右侧栏打开它",
|
|
597
|
+
settingOpenWith: "Markdown、HTML、PDF、Word、Excel、PowerPoint、CSV 和 SVG 文件先用",
|
|
598
|
+
settingOpenWithDsh: "DeepSeek Harness 的预览",
|
|
599
|
+
settingOpenWithKition: "Kition 编辑器",
|
|
600
|
+
settingsUnavailable: "这些设置需要 DeepSeek Harness 的设置服务。"
|
|
601
|
+
};
|
|
602
|
+
/** `text` with `{name}` placeholders filled from `params`. */
|
|
603
|
+
var fill = (text, params = {}) => text.replace(/\{(\w+)\}/g, (whole, name) => params[name] ?? whole);
|
|
604
|
+
// \0kit-extensions
|
|
605
|
+
var _kit_extensions_default = {
|
|
606
|
+
"ai": {
|
|
607
|
+
"kit": "vector",
|
|
608
|
+
"view": true
|
|
609
|
+
},
|
|
610
|
+
"csv": {
|
|
611
|
+
"kit": "sheet",
|
|
612
|
+
"view": true
|
|
613
|
+
},
|
|
614
|
+
"docx": {
|
|
615
|
+
"kit": "doc",
|
|
616
|
+
"view": false
|
|
617
|
+
},
|
|
618
|
+
"dxf": {
|
|
619
|
+
"kit": "cad",
|
|
620
|
+
"view": false
|
|
621
|
+
},
|
|
622
|
+
"eps": {
|
|
623
|
+
"kit": "vector",
|
|
624
|
+
"view": true
|
|
625
|
+
},
|
|
626
|
+
"et": {
|
|
627
|
+
"kit": "sheet",
|
|
628
|
+
"view": true
|
|
629
|
+
},
|
|
630
|
+
"ett": {
|
|
631
|
+
"kit": "sheet",
|
|
632
|
+
"view": true
|
|
633
|
+
},
|
|
634
|
+
"fig": {
|
|
635
|
+
"kit": "design",
|
|
636
|
+
"view": true
|
|
637
|
+
},
|
|
638
|
+
"htm": {
|
|
639
|
+
"kit": "html",
|
|
640
|
+
"view": false
|
|
641
|
+
},
|
|
642
|
+
"html": {
|
|
643
|
+
"kit": "html",
|
|
644
|
+
"view": false
|
|
645
|
+
},
|
|
646
|
+
"idml": {
|
|
647
|
+
"kit": "layout",
|
|
648
|
+
"view": true
|
|
649
|
+
},
|
|
650
|
+
"kboard": {
|
|
651
|
+
"kit": "board",
|
|
652
|
+
"view": false
|
|
653
|
+
},
|
|
654
|
+
"kdesign": {
|
|
655
|
+
"kit": "design",
|
|
656
|
+
"view": false
|
|
657
|
+
},
|
|
658
|
+
"kfilm": {
|
|
659
|
+
"kit": "film",
|
|
660
|
+
"view": false
|
|
661
|
+
},
|
|
662
|
+
"klayout": {
|
|
663
|
+
"kit": "layout",
|
|
664
|
+
"view": false
|
|
665
|
+
},
|
|
666
|
+
"kmotion": {
|
|
667
|
+
"kit": "motion",
|
|
668
|
+
"view": false
|
|
669
|
+
},
|
|
670
|
+
"kphoto": {
|
|
671
|
+
"kit": "photo",
|
|
672
|
+
"view": false
|
|
673
|
+
},
|
|
674
|
+
"kscene": {
|
|
675
|
+
"kit": "scene",
|
|
676
|
+
"view": false
|
|
677
|
+
},
|
|
678
|
+
"kslide": {
|
|
679
|
+
"kit": "slide",
|
|
680
|
+
"view": false
|
|
681
|
+
},
|
|
682
|
+
"ktable": {
|
|
683
|
+
"kit": "table",
|
|
684
|
+
"view": false
|
|
685
|
+
},
|
|
686
|
+
"kvector": {
|
|
687
|
+
"kit": "vector",
|
|
688
|
+
"view": false
|
|
689
|
+
},
|
|
690
|
+
"markdown": {
|
|
691
|
+
"kit": "note",
|
|
692
|
+
"view": false
|
|
693
|
+
},
|
|
694
|
+
"md": {
|
|
695
|
+
"kit": "note",
|
|
696
|
+
"view": false
|
|
697
|
+
},
|
|
698
|
+
"ods": {
|
|
699
|
+
"kit": "sheet",
|
|
700
|
+
"view": true
|
|
701
|
+
},
|
|
702
|
+
"pdf": {
|
|
703
|
+
"kit": "pdf",
|
|
704
|
+
"view": false
|
|
705
|
+
},
|
|
706
|
+
"pptx": {
|
|
707
|
+
"kit": "slide",
|
|
708
|
+
"view": false
|
|
709
|
+
},
|
|
710
|
+
"psb": {
|
|
711
|
+
"kit": "photo",
|
|
712
|
+
"view": false
|
|
713
|
+
},
|
|
714
|
+
"psd": {
|
|
715
|
+
"kit": "photo",
|
|
716
|
+
"view": false
|
|
717
|
+
},
|
|
718
|
+
"sketch": {
|
|
719
|
+
"kit": "design",
|
|
720
|
+
"view": true
|
|
721
|
+
},
|
|
722
|
+
"svg": {
|
|
723
|
+
"kit": "vector",
|
|
724
|
+
"view": true
|
|
725
|
+
},
|
|
726
|
+
"xls": {
|
|
727
|
+
"kit": "sheet",
|
|
728
|
+
"view": true
|
|
729
|
+
},
|
|
730
|
+
"xlsb": {
|
|
731
|
+
"kit": "sheet",
|
|
732
|
+
"view": true
|
|
733
|
+
},
|
|
734
|
+
"xlsm": {
|
|
735
|
+
"kit": "sheet",
|
|
736
|
+
"view": false
|
|
737
|
+
},
|
|
738
|
+
"xlsx": {
|
|
739
|
+
"kit": "sheet",
|
|
740
|
+
"view": false
|
|
741
|
+
},
|
|
742
|
+
"xlt": {
|
|
743
|
+
"kit": "sheet",
|
|
744
|
+
"view": true
|
|
745
|
+
},
|
|
746
|
+
"xltm": {
|
|
747
|
+
"kit": "sheet",
|
|
748
|
+
"view": true
|
|
749
|
+
},
|
|
750
|
+
"xltx": {
|
|
751
|
+
"kit": "sheet",
|
|
752
|
+
"view": true
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
// plugins/deepseek-harness/kition-kits/src/client/kits.ts
|
|
756
|
+
/**
|
|
757
|
+
* Which kit opens which file, and how DeepSeek Harness is told. The table of the extensions each
|
|
758
|
+
* published kit opens is generated at build time (build-client.mjs) from the kits' manifests: those
|
|
759
|
+
* it edits, and those it only views (opened read-only).
|
|
760
|
+
*
|
|
761
|
+
* DeepSeek Harness previews some of these types itself (its document previews, the same in
|
|
762
|
+
* 0.2.2-rc.2 and rc.5: Markdown md, markdown; HTML html, htm; PDF pdf; Office doc, docx, ppt,
|
|
763
|
+
* pptx; Excel xlsx, xls, csv, tsv; images png, jpg, jpeg, gif, webp, bmp, ico, svg; and source code
|
|
764
|
+
* by extension). For those the kit is one more preview under "Open with", and DeepSeek Harness's own
|
|
765
|
+
* stays the default. Every other kit extension is a right sidebar tab type of its own, so a click
|
|
766
|
+
* in the file tree opens the Kition editor.
|
|
767
|
+
*/
|
|
768
|
+
/** Each extension a published kit opens, the kit, and whether it only views it. */
|
|
769
|
+
var KIT_FORMATS = _kit_extensions_default;
|
|
770
|
+
/** Each extension a published kit opens, and the kit. */
|
|
771
|
+
var KIT_EXTENSIONS = Object.fromEntries(Object.entries(_kit_extensions_default).map(([extension, entry]) => [extension, entry.kit]));
|
|
772
|
+
/** The extensions DeepSeek Harness 0.2.2-rc.2 and rc.5 preview themselves (dsh-client-ui-sidebar-documentpreview, dsh-util-code-language). */
|
|
773
|
+
var DSH_PREVIEWS = /* @__PURE__ */ new Set([
|
|
774
|
+
...[
|
|
775
|
+
"md",
|
|
776
|
+
"markdown",
|
|
777
|
+
"html",
|
|
778
|
+
"htm",
|
|
779
|
+
"pdf",
|
|
780
|
+
"doc",
|
|
781
|
+
"docx",
|
|
782
|
+
"ppt",
|
|
783
|
+
"pptx",
|
|
784
|
+
"xlsx",
|
|
785
|
+
"xls",
|
|
786
|
+
"csv",
|
|
787
|
+
"tsv"
|
|
788
|
+
],
|
|
789
|
+
...[
|
|
790
|
+
"png",
|
|
791
|
+
"jpg",
|
|
792
|
+
"jpeg",
|
|
793
|
+
"gif",
|
|
794
|
+
"webp",
|
|
795
|
+
"bmp",
|
|
796
|
+
"ico",
|
|
797
|
+
"svg"
|
|
798
|
+
],
|
|
799
|
+
..."ts tsx mts cts js jsx mjs cjs sh bash zsh fish json jsonc jsonl ndjson ipynb py pyw pyi rb rake gemspec go rs java c h cc cpp cxx hh hpp hxx cs kt kts swift php yaml yml toml ini conf cfg properties env log diff patch http mdx rst tex sty cls bib adoc xhtml css scss less sql xml xsd xsl xslt plist lua bat cmd ps1 psm1 psd1 r jl dart scala clj cljs edn erl hrl ex exs hs fs fsi fsx vb pl pm v sv svh graphql gql proto tf tfvars hcl nix vue svelte makefile mk cmake gradle groovy".split(" ")
|
|
800
|
+
]);
|
|
801
|
+
/** The extensions that open in a Kition tab when clicked: no DeepSeek Harness preview takes them. */
|
|
802
|
+
var TAB_EXTENSIONS = Object.keys(KIT_EXTENSIONS).filter((extension) => !DSH_PREVIEWS.has(extension));
|
|
803
|
+
/** Per kit, the extensions it is offered for under "Open with" beside DeepSeek Harness's own preview. */
|
|
804
|
+
var PREVIEW_EXTENSIONS = Object.entries(KIT_EXTENSIONS).filter(([extension]) => DSH_PREVIEWS.has(extension)).reduce((byKit, [extension, kit]) => {
|
|
805
|
+
(byKit[kit] ??= []).push(extension);
|
|
806
|
+
return byKit;
|
|
807
|
+
}, {});
|
|
808
|
+
/** The kit's name as people read it. */
|
|
809
|
+
var kitName = (kit) => kit === "html" || kit === "pdf" || kit === "cad" ? kit.toUpperCase() : kit.charAt(0).toUpperCase() + kit.slice(1);
|
|
810
|
+
/** The kit tool actions that change a file (or its draft). */
|
|
811
|
+
var WRITES = /* @__PURE__ */ new Set([
|
|
812
|
+
"run",
|
|
813
|
+
"batch",
|
|
814
|
+
"create",
|
|
815
|
+
"draft_ready",
|
|
816
|
+
"draft_reopen"
|
|
817
|
+
]);
|
|
818
|
+
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
819
|
+
/** The action of a kit tool name (`mcp__kition__kit_draft_ready` → `draft_ready`); null for any other tool. */
|
|
820
|
+
function actionOf(name) {
|
|
821
|
+
if (typeof name !== "string" || !name.startsWith("mcp__kition__")) return null;
|
|
822
|
+
const raw = name.slice(13);
|
|
823
|
+
const at = raw.indexOf("_");
|
|
824
|
+
return at > 0 ? raw.slice(at + 1) : null;
|
|
825
|
+
}
|
|
826
|
+
function argumentsOf(data) {
|
|
827
|
+
const value = data.arguments;
|
|
828
|
+
if (isRecord(value)) return value;
|
|
829
|
+
if (typeof value !== "string") return {};
|
|
830
|
+
try {
|
|
831
|
+
const parsed = JSON.parse(value);
|
|
832
|
+
return isRecord(parsed) ? parsed : {};
|
|
833
|
+
} catch {
|
|
834
|
+
return {};
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
/** A workspace path as files are named here: `/`-separated, without a leading `./`. */
|
|
838
|
+
var normalPath = (path) => path.replace(/\\/g, "/").replace(/^(\.\/)+/, "");
|
|
839
|
+
function withOperation(files, path, kit, operation) {
|
|
840
|
+
const next = files.map((file) => ({
|
|
841
|
+
...file,
|
|
842
|
+
operations: file.operations.filter((entry) => entry.callId !== operation.callId)
|
|
843
|
+
}));
|
|
844
|
+
const at = next.findIndex((file) => file.path === path);
|
|
845
|
+
if (at < 0) next.push({
|
|
846
|
+
path,
|
|
847
|
+
kit,
|
|
848
|
+
operations: [operation]
|
|
849
|
+
});
|
|
850
|
+
else next[at] = {
|
|
851
|
+
path,
|
|
852
|
+
kit: kit ?? next[at].kit,
|
|
853
|
+
operations: [...next[at].operations, operation]
|
|
854
|
+
};
|
|
855
|
+
return next.filter((file) => file.operations.length > 0);
|
|
856
|
+
}
|
|
857
|
+
/** A `tool/call` of a kit tool: the file and a pending operation. */
|
|
858
|
+
function addCall(state, data) {
|
|
859
|
+
const action = actionOf(data.name);
|
|
860
|
+
const args = argumentsOf(data);
|
|
861
|
+
if (!action || typeof args.path !== "string" || !args.path || typeof data.callId !== "string") return state;
|
|
862
|
+
const operation = {
|
|
863
|
+
callId: data.callId,
|
|
864
|
+
action,
|
|
865
|
+
phase: "pending",
|
|
866
|
+
writes: WRITES.has(action),
|
|
867
|
+
live: false,
|
|
868
|
+
draft: args.draft === true,
|
|
869
|
+
created: action === "create"
|
|
870
|
+
};
|
|
871
|
+
return {
|
|
872
|
+
...state,
|
|
873
|
+
files: withOperation(state.files, normalPath(args.path), null, operation)
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
/** What a result says of its call: from the kept presentation, else from its text. */
|
|
877
|
+
function outcome(data) {
|
|
878
|
+
const meta = [
|
|
879
|
+
data.meta,
|
|
880
|
+
isRecord(data.message) ? data.message.meta : void 0,
|
|
881
|
+
isRecord(data.result) ? data.result.meta : void 0
|
|
882
|
+
].find((value) => isRecord(value) && value.kition === 1);
|
|
883
|
+
if (isRecord(meta)) return {
|
|
884
|
+
live: meta.live === true,
|
|
885
|
+
draft: meta.draft === true,
|
|
886
|
+
kit: typeof meta.kit === "string" ? meta.kit : null,
|
|
887
|
+
path: typeof meta.path === "string" ? meta.path : null
|
|
888
|
+
};
|
|
889
|
+
const message = isRecord(data.message) ? data.message : {};
|
|
890
|
+
const text = (Array.isArray(message.content) ? message.content : []).map((block) => isRecord(block) && typeof block.text === "string" ? block.text : "").join("\n");
|
|
891
|
+
if (!text) return null;
|
|
892
|
+
return {
|
|
893
|
+
live: /"live":true/.test(text),
|
|
894
|
+
draft: /"draft":true/.test(text),
|
|
895
|
+
kit: /"kit":"(kit\.[a-z0-9-]+)"/.exec(text)?.[1] ?? null,
|
|
896
|
+
path: null
|
|
897
|
+
};
|
|
898
|
+
}
|
|
899
|
+
/** A `tool/result` (at `time`): its call's operation done or failed, with what it did. */
|
|
900
|
+
function applyResult(state, data, time) {
|
|
901
|
+
const message = isRecord(data.message) ? data.message : {};
|
|
902
|
+
const callId = typeof message.toolCallId === "string" ? message.toolCallId : typeof data.callId === "string" ? data.callId : null;
|
|
903
|
+
if (!callId) return state;
|
|
904
|
+
const file = state.files.find((entry) => entry.operations.some((operation) => operation.callId === callId));
|
|
905
|
+
if (!file) return state;
|
|
906
|
+
const before = file.operations.find((operation) => operation.callId === callId);
|
|
907
|
+
const failed = message.isError === true || data.error !== void 0;
|
|
908
|
+
const said = failed ? null : outcome(data);
|
|
909
|
+
const operation = {
|
|
910
|
+
...before,
|
|
911
|
+
phase: failed ? "failed" : "done",
|
|
912
|
+
live: said?.live ?? false,
|
|
913
|
+
draft: said?.draft ?? before.draft,
|
|
914
|
+
...typeof time === "number" ? { time } : {}
|
|
915
|
+
};
|
|
916
|
+
return {
|
|
917
|
+
...state,
|
|
918
|
+
files: withOperation(state.files, file.path, said?.kit ?? file.kit, operation)
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
/** The projection's definition for DeepSeek Harness's conversation engine (`uiConversation.events.register`). */
|
|
922
|
+
var kitTurnDefinition = {
|
|
923
|
+
kind: "kitionTurn",
|
|
924
|
+
match(event) {
|
|
925
|
+
const turn = event.data?.turn;
|
|
926
|
+
if (typeof turn !== "number") return null;
|
|
927
|
+
if (event.type === "turn/start") return {
|
|
928
|
+
id: String(turn),
|
|
929
|
+
role: "start"
|
|
930
|
+
};
|
|
931
|
+
if (event.type === "tool/call" || event.type === "tool/result") return {
|
|
932
|
+
id: String(turn),
|
|
933
|
+
role: "update"
|
|
934
|
+
};
|
|
935
|
+
return null;
|
|
936
|
+
},
|
|
937
|
+
start(_context, match) {
|
|
938
|
+
return {
|
|
939
|
+
turn: Number(match.event.data?.turn),
|
|
940
|
+
files: []
|
|
941
|
+
};
|
|
942
|
+
},
|
|
943
|
+
update(context, match) {
|
|
944
|
+
const data = match.event.data ?? {};
|
|
945
|
+
if (match.event.type === "tool/call") return addCall(context.state, data);
|
|
946
|
+
if (match.event.type === "tool/result") return applyResult(context.state, data, match.event.time);
|
|
947
|
+
return context.state;
|
|
948
|
+
},
|
|
949
|
+
buildLocationData(context, scope, previous) {
|
|
950
|
+
const state = context.state;
|
|
951
|
+
if (scope !== "turn" || !state || state.files.length === 0) return null;
|
|
952
|
+
if (previous?.value && previous.value.files === state.files) return previous;
|
|
953
|
+
return {
|
|
954
|
+
kind: "turn",
|
|
955
|
+
turn: state.turn,
|
|
956
|
+
key: "kitionTurn",
|
|
957
|
+
value: { files: state.files }
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
};
|
|
961
|
+
/**
|
|
962
|
+
* Whether the live window shows a file the running turn edits: once something is written into it.
|
|
963
|
+
* A file only created shows nothing yet (a new presentation's empty title page): the window opens
|
|
964
|
+
* with its first content.
|
|
965
|
+
*/
|
|
966
|
+
var hasLiveContent = (file) => file.operations.some((operation) => operation.writes && operation.action !== "create" && operation.phase !== "failed");
|
|
967
|
+
/** When the turn last drafted the file (its last draft write's result), or null. */
|
|
968
|
+
function draftedAt(file) {
|
|
969
|
+
const times = file.operations.filter((operation) => operation.writes && operation.draft && operation.phase === "done" && typeof operation.time === "number").map((operation) => operation.time);
|
|
970
|
+
return times.length ? Math.max(...times) : null;
|
|
971
|
+
}
|
|
972
|
+
/**
|
|
973
|
+
* What the person did to the draft one turn made of `path`: the review recorded for that session
|
|
974
|
+
* and turn (a card's), else the first review recorded after the turn drafted it and before any
|
|
975
|
+
* later turn drafted it again (the editor's own review, or a card's from before turns were kept).
|
|
976
|
+
* `drafts` are every turn of the session that drafted `path`: `[turn, draftedAt]`.
|
|
977
|
+
*/
|
|
978
|
+
function outcomeFor(reviews, sessionId, path, turn, drafts) {
|
|
979
|
+
const own = reviews.filter((review) => review.path === path);
|
|
980
|
+
const exact = own.find((review) => review.session === sessionId && review.turn === turn);
|
|
981
|
+
if (exact) return exact;
|
|
982
|
+
const at = drafts.find(([candidate]) => candidate === turn)?.[1];
|
|
983
|
+
if (at == null) return null;
|
|
984
|
+
const next = drafts.map(([, time]) => time).filter((time) => time != null && time > at).sort((a, b) => a - b)[0] ?? 1e400;
|
|
985
|
+
return own.find((review) => review.turn === null && review.at >= at && review.at < next) ?? null;
|
|
986
|
+
}
|
|
987
|
+
/**
|
|
988
|
+
* The card of `file`: `null` when the turn only read it. `draft` is the gateway's current draft of
|
|
989
|
+
* the file (`undefined` while unknown), `outcome` what the person did to it here, `exists` whether
|
|
990
|
+
* the file is still there.
|
|
991
|
+
*/
|
|
992
|
+
function cardState(file, now) {
|
|
993
|
+
const writes = file.operations.filter((operation) => operation.writes);
|
|
994
|
+
if (writes.length === 0) return null;
|
|
995
|
+
if (writes.some((operation) => operation.phase === "pending")) return "pending";
|
|
996
|
+
const done = writes.filter((operation) => operation.phase === "done");
|
|
997
|
+
if (done.length === 0) return "failed";
|
|
998
|
+
if (done.some((operation) => operation.draft)) {
|
|
999
|
+
if (now.draft) return now.draft.stale ? "stale" : now.draft.state === "ready" ? "draft-ready" : "draft-open";
|
|
1000
|
+
if (now.draft === void 0) return "draft-open";
|
|
1001
|
+
if (now.outcome) return now.outcome;
|
|
1002
|
+
return now.exists === false ? "missing" : "draft-gone";
|
|
1003
|
+
}
|
|
1004
|
+
if (now.exists === false) return "missing";
|
|
1005
|
+
if (done.some((operation) => operation.created)) return "created";
|
|
1006
|
+
return done.some((operation) => operation.live) ? "live" : "saved";
|
|
1007
|
+
}
|
|
1008
|
+
/** The actions a card offers in `state`: the person's own, never the agent's. */
|
|
1009
|
+
function cardActions(state) {
|
|
1010
|
+
switch (state) {
|
|
1011
|
+
case "draft-open":
|
|
1012
|
+
case "draft-ready": return [
|
|
1013
|
+
"open",
|
|
1014
|
+
"review",
|
|
1015
|
+
"merge",
|
|
1016
|
+
"discard"
|
|
1017
|
+
];
|
|
1018
|
+
case "stale": return [
|
|
1019
|
+
"open",
|
|
1020
|
+
"review",
|
|
1021
|
+
"overwrite",
|
|
1022
|
+
"discard"
|
|
1023
|
+
];
|
|
1024
|
+
case "missing":
|
|
1025
|
+
case "pending": return [];
|
|
1026
|
+
default: return ["open"];
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
// plugins/deepseek-harness/kition-kits/src/client/dialog.ts
|
|
1030
|
+
var STYLE_ID = "kition-kits-dialog-style";
|
|
1031
|
+
var STYLE = `
|
|
1032
|
+
.kition-dialog-backdrop { position: fixed; inset: 0; z-index: 2147483000; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgb(0 0 0 / 0.35); }
|
|
1033
|
+
.kition-dialog { max-width: min(440px, 100%); padding: 18px 20px; border-radius: 12px; background: Canvas; color: CanvasText; box-shadow: 0 10px 40px rgb(0 0 0 / 0.25); font: 14px/1.5 system-ui, sans-serif; }
|
|
1034
|
+
.kition-dialog p { margin: 0 0 16px; }
|
|
1035
|
+
.kition-dialog__actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
|
|
1036
|
+
.kition-dialog button { padding: 6px 14px; border-radius: 8px; border: 1px solid rgb(127 127 127 / 0.4); background: transparent; color: inherit; font: inherit; cursor: pointer; }
|
|
1037
|
+
.kition-dialog button[data-primary] { background: #5645d4; border-color: #5645d4; color: #fff; }
|
|
1038
|
+
.kition-dialog button[data-danger] { color: #c0392b; border-color: rgb(192 57 43 / 0.5); }
|
|
1039
|
+
`;
|
|
1040
|
+
/** Asks `message`; answers the chosen choice's id, or the last one's (the safe one) on Escape. */
|
|
1041
|
+
function ask(message, choices) {
|
|
1042
|
+
if (!document.getElementById(STYLE_ID)) {
|
|
1043
|
+
const style = document.createElement("style");
|
|
1044
|
+
style.id = STYLE_ID;
|
|
1045
|
+
style.textContent = STYLE;
|
|
1046
|
+
document.head.append(style);
|
|
1047
|
+
}
|
|
1048
|
+
return new Promise((resolve) => {
|
|
1049
|
+
const previous = document.activeElement;
|
|
1050
|
+
const backdrop = document.createElement("div");
|
|
1051
|
+
backdrop.className = "kition-dialog-backdrop";
|
|
1052
|
+
const box = document.createElement("div");
|
|
1053
|
+
box.className = "kition-dialog";
|
|
1054
|
+
box.setAttribute("role", "alertdialog");
|
|
1055
|
+
box.setAttribute("aria-modal", "true");
|
|
1056
|
+
box.setAttribute("data-kition-dialog", "");
|
|
1057
|
+
const text = document.createElement("p");
|
|
1058
|
+
text.textContent = message;
|
|
1059
|
+
const actions = document.createElement("div");
|
|
1060
|
+
actions.className = "kition-dialog__actions";
|
|
1061
|
+
const fallback = choices[choices.length - 1]?.id ?? "";
|
|
1062
|
+
const finish = (id) => {
|
|
1063
|
+
document.removeEventListener("keydown", onKey, true);
|
|
1064
|
+
backdrop.remove();
|
|
1065
|
+
previous?.focus?.({ preventScroll: true });
|
|
1066
|
+
resolve(id);
|
|
1067
|
+
};
|
|
1068
|
+
const onKey = (event) => {
|
|
1069
|
+
if (event.key !== "Escape") return;
|
|
1070
|
+
event.preventDefault();
|
|
1071
|
+
event.stopPropagation();
|
|
1072
|
+
finish(fallback);
|
|
1073
|
+
};
|
|
1074
|
+
for (const choice of choices) {
|
|
1075
|
+
const button = document.createElement("button");
|
|
1076
|
+
button.type = "button";
|
|
1077
|
+
button.textContent = choice.label;
|
|
1078
|
+
button.dataset.kitionDialogChoice = choice.id;
|
|
1079
|
+
if (choice.primary) button.dataset.primary = "";
|
|
1080
|
+
if (choice.danger) button.dataset.danger = "";
|
|
1081
|
+
button.addEventListener("click", () => finish(choice.id));
|
|
1082
|
+
actions.append(button);
|
|
1083
|
+
}
|
|
1084
|
+
box.append(text, actions);
|
|
1085
|
+
backdrop.append(box);
|
|
1086
|
+
document.body.append(backdrop);
|
|
1087
|
+
document.addEventListener("keydown", onKey, true);
|
|
1088
|
+
actions.querySelector("button[data-primary]")?.focus() ?? actions.querySelector("button")?.focus();
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
/** The smallest live window the document still reads in, CSS pixels. */
|
|
1092
|
+
var LIVE_MIN = {
|
|
1093
|
+
width: 320,
|
|
1094
|
+
height: 240
|
|
1095
|
+
};
|
|
1096
|
+
/** The window's top: under DeepSeek Harness's title bar. */
|
|
1097
|
+
var TOP = 96;
|
|
1098
|
+
var MARGIN = 16;
|
|
1099
|
+
/**
|
|
1100
|
+
* Where the live window goes: a small floating window at the top right, beside the conversation's
|
|
1101
|
+
* column where there is room (the composer marks its right edge), else over the column's right
|
|
1102
|
+
* side; the conversation keeps its width (the sidebar does not open). Null when the window is too
|
|
1103
|
+
* small for one, and the file goes in the right sidebar instead.
|
|
1104
|
+
*/
|
|
1105
|
+
function liveWindowRect(viewport, conversation) {
|
|
1106
|
+
const beside = viewport.width - (conversation?.right ?? viewport.width) - 32;
|
|
1107
|
+
const width = Math.min(440, beside >= LIVE_MIN.width ? beside : viewport.width - 32);
|
|
1108
|
+
const height = Math.min(Math.round(width * .8), viewport.height - TOP - MARGIN);
|
|
1109
|
+
if (width < LIVE_MIN.width || height < LIVE_MIN.height) return null;
|
|
1110
|
+
return {
|
|
1111
|
+
x: Math.round(viewport.width - MARGIN - width),
|
|
1112
|
+
y: TOP,
|
|
1113
|
+
width: Math.round(width),
|
|
1114
|
+
height
|
|
1115
|
+
};
|
|
1116
|
+
}
|
|
1117
|
+
// plugins/deepseek-harness/kition-kits/src/client/index.ts
|
|
1118
|
+
/**
|
|
1119
|
+
* @kitionstage/dsh-kits, the browser module: a Kition kit's file opens in the kit's own editor in
|
|
1120
|
+
* DeepSeek Harness's right sidebar, and the person reviews what an agent did to kit files at the
|
|
1121
|
+
* end of its turn. The editor is kition gateway's editor page (kition-sdk docs/sdk/gateway-page.md),
|
|
1122
|
+
* framed same-origin from the host module's /kition/ routes, so an agent's kit tool calls on the
|
|
1123
|
+
* open file happen in it, live, and its draft shows there for review.
|
|
1124
|
+
*
|
|
1125
|
+
* - Extensions only Kition opens (`.ktable`, `.kboard`, ...) are a right sidebar tab type: a click
|
|
1126
|
+
* in the file tree opens the Kition editor.
|
|
1127
|
+
* - Extensions DeepSeek Harness previews itself (`.md`, `.docx`, `.xlsx`, `.pptx`, `.pdf`,
|
|
1128
|
+
* `.html`, `.csv`, `.svg`) get the kit as a document preview under "Open with"; DeepSeek
|
|
1129
|
+
* Harness's stays the default unless the person's setting says Kition.
|
|
1130
|
+
* - A kit's view-only formats (Vector's `.svg`, Sheet's `.csv`) open read-only.
|
|
1131
|
+
* - Each turn's kit tool calls are projected from the session's events (`kitionTurn`), and the
|
|
1132
|
+
* turn's tail shows a card per file it changed: what changed, its state, Open, Review, and the
|
|
1133
|
+
* person's own Merge and Discard. While an agent edits a file that is not open, a floating
|
|
1134
|
+
* window shows it (a setting).
|
|
1135
|
+
*
|
|
1136
|
+
* Every service it uses is the same in DeepSeek Harness 0.2.2-rc.2 and rc.5; each is looked up
|
|
1137
|
+
* and left out when a host lacks it.
|
|
1138
|
+
*/
|
|
1139
|
+
var h = react.createElement;
|
|
1140
|
+
var name = "@kitionstage/dsh-kits";
|
|
1141
|
+
var inject = ["slots"];
|
|
1142
|
+
/** The tab type's id and kind, and the slot key of its body and title. */
|
|
1143
|
+
var TAB_TYPE = "kition";
|
|
1144
|
+
/** DeepSeek Harness's own document preview tab type (its id and kind), where "Open with" lives. */
|
|
1145
|
+
var TEXT_TYPE = "@deepseek-ai/dsh-client-ui-sidebar-documentpreview";
|
|
1146
|
+
var TEXT_KIND = "text";
|
|
1147
|
+
/** The host module's row: its Config is the person's settings. */
|
|
1148
|
+
var HOST_ENTRY = "kition-kits-host";
|
|
1149
|
+
var previewId = (kit) => `kition/${kit}`;
|
|
1150
|
+
var DEFAULTS = {
|
|
1151
|
+
liveFloat: true,
|
|
1152
|
+
openWith: "dsh",
|
|
1153
|
+
autoOpen: false
|
|
1154
|
+
};
|
|
1155
|
+
var Environment = class {
|
|
1156
|
+
listeners = /* @__PURE__ */ new Set();
|
|
1157
|
+
scheme = "light";
|
|
1158
|
+
language = "en";
|
|
1159
|
+
settings = DEFAULTS;
|
|
1160
|
+
/** DeepSeek Harness's own shortcuts the editor hands back (the web UI's; Desktop routes them itself). */
|
|
1161
|
+
keys = [];
|
|
1162
|
+
translate = null;
|
|
1163
|
+
sidebar = null;
|
|
1164
|
+
version = 0;
|
|
1165
|
+
subscribe = (listener) => {
|
|
1166
|
+
this.listeners.add(listener);
|
|
1167
|
+
return () => this.listeners.delete(listener);
|
|
1168
|
+
};
|
|
1169
|
+
set(changes) {
|
|
1170
|
+
Object.assign(this, changes);
|
|
1171
|
+
this.version++;
|
|
1172
|
+
for (const listener of [...this.listeners]) listener();
|
|
1173
|
+
}
|
|
1174
|
+
t(key, params = {}) {
|
|
1175
|
+
const bound = this.translate?.(key, params);
|
|
1176
|
+
if (bound && bound !== key) return bound;
|
|
1177
|
+
return fill((this.language === "zh" ? zh : en)[key], params);
|
|
1178
|
+
}
|
|
1179
|
+
};
|
|
1180
|
+
var environment = new Environment();
|
|
1181
|
+
/** Each open Kition view, by tab id: its title and close guard read it, cards and the float too. */
|
|
1182
|
+
var pages = /* @__PURE__ */ new Map();
|
|
1183
|
+
var pageListeners = /* @__PURE__ */ new Set();
|
|
1184
|
+
function setPage(tabId, state) {
|
|
1185
|
+
if (state) pages.set(tabId, state);
|
|
1186
|
+
else pages.delete(tabId);
|
|
1187
|
+
for (const listener of [...pageListeners]) listener();
|
|
1188
|
+
}
|
|
1189
|
+
var subscribePages = (listener) => {
|
|
1190
|
+
pageListeners.add(listener);
|
|
1191
|
+
return () => pageListeners.delete(listener);
|
|
1192
|
+
};
|
|
1193
|
+
var openPage = (sessionId, path) => [...pages.values()].find((page) => page.path === path && (page.sessionId === null || page.sessionId === sessionId));
|
|
1194
|
+
/** Reviews asked for before their file's page is ready, by `<session>:<path>`. */
|
|
1195
|
+
var pendingReview = /* @__PURE__ */ new Set();
|
|
1196
|
+
var schemeOf = (snapshot) => snapshot?.active?.colorScheme === "dark" ? "dark" : "light";
|
|
1197
|
+
var languageOf = (active) => typeof active === "string" && active.toLowerCase().startsWith("zh") ? "zh" : "en";
|
|
1198
|
+
function useEnvironment() {
|
|
1199
|
+
react.useSyncExternalStore(environment.subscribe, () => environment.version);
|
|
1200
|
+
return environment;
|
|
1201
|
+
}
|
|
1202
|
+
/** A session's file as DeepSeek Harness addresses it. */
|
|
1203
|
+
function fileAddress(sessionId, path) {
|
|
1204
|
+
const segment = (text) => encodeURIComponent(text).replace(/%3A/gi, ":");
|
|
1205
|
+
return `dsh-resource://file/session/${segment(sessionId)}/${path.split("/").map(segment).join("/")}`;
|
|
1206
|
+
}
|
|
1207
|
+
/**
|
|
1208
|
+
* Opens a session's file in a Kition tab, in the sidebar (`sidebar`) or as a live window the
|
|
1209
|
+
* person watches (`live`): a small floating window at the top right where it fits, else in the
|
|
1210
|
+
* sidebar; the keyboard stays where the person had it. Opened in the sidebar, a file in a live
|
|
1211
|
+
* window leaves it for the full editor: the window's page shows the editor in Menus only.
|
|
1212
|
+
*/
|
|
1213
|
+
function openInSidebar(sessionId, path, destination = "sidebar") {
|
|
1214
|
+
const sidebar = environment.sidebar;
|
|
1215
|
+
if (typeof sidebar?.openResource !== "function") return false;
|
|
1216
|
+
const watched = destination === "sidebar" ? [...pages.values()].find((page) => page.floating && page.watching && page.path === path && page.sessionId === sessionId) : void 0;
|
|
1217
|
+
if (watched) try {
|
|
1218
|
+
sidebar.close?.(watched.tabId);
|
|
1219
|
+
} catch {
|
|
1220
|
+
return true;
|
|
1221
|
+
}
|
|
1222
|
+
const active = document.activeElement;
|
|
1223
|
+
const address = fileAddress(sessionId, path);
|
|
1224
|
+
const composer = document.querySelector("[data-composer-input]")?.closest("form, [class*=\"input\"], [class*=\"Input\"]") ?? document.querySelector("[data-composer-input]");
|
|
1225
|
+
const rect = destination === "live" ? liveWindowRect({
|
|
1226
|
+
width: innerWidth,
|
|
1227
|
+
height: innerHeight
|
|
1228
|
+
}, composer?.getBoundingClientRect() ?? null) : null;
|
|
1229
|
+
const collapsed = typeof sidebar.isExpanded === "function" ? !sidebar.isExpanded() : false;
|
|
1230
|
+
try {
|
|
1231
|
+
sidebar.openResource(address, {
|
|
1232
|
+
kind: TAB_TYPE,
|
|
1233
|
+
revealIfOpened: true,
|
|
1234
|
+
...destination === "live" ? { params: { live: true } } : {}
|
|
1235
|
+
});
|
|
1236
|
+
if (rect && typeof sidebar.float === "function" && typeof sidebar.tabsIn === "function") {
|
|
1237
|
+
const tab = sidebar.tabsIn(sessionId).find((record) => record.contentId === address && record.kind === "kition");
|
|
1238
|
+
if (tab) {
|
|
1239
|
+
sidebar.float(tab.id, rect);
|
|
1240
|
+
if (collapsed && sidebar.isExpanded?.()) sidebar.toggleExpanded?.();
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
} catch {
|
|
1244
|
+
return false;
|
|
1245
|
+
}
|
|
1246
|
+
if (destination === "live" && active && active !== document.body) requestAnimationFrame(() => active.focus({ preventScroll: true }));
|
|
1247
|
+
return true;
|
|
1248
|
+
}
|
|
1249
|
+
/** Gives DeepSeek Harness a shortcut pressed in the editor (in the web UI its keys are heard on the top window only). */
|
|
1250
|
+
function forwardShortcut(key) {
|
|
1251
|
+
const init = {
|
|
1252
|
+
key: key.key,
|
|
1253
|
+
code: key.code,
|
|
1254
|
+
metaKey: !!key.meta,
|
|
1255
|
+
ctrlKey: !!key.ctrl,
|
|
1256
|
+
shiftKey: !!key.shift,
|
|
1257
|
+
altKey: !!key.alt,
|
|
1258
|
+
bubbles: true,
|
|
1259
|
+
cancelable: true
|
|
1260
|
+
};
|
|
1261
|
+
document.body.dispatchEvent(new KeyboardEvent("keydown", init));
|
|
1262
|
+
document.body.dispatchEvent(new KeyboardEvent("keyup", init));
|
|
1263
|
+
}
|
|
1264
|
+
function Panel(props) {
|
|
1265
|
+
const env = useEnvironment();
|
|
1266
|
+
return h("div", {
|
|
1267
|
+
"data-kition-state": props.state,
|
|
1268
|
+
role: props.state === "starting" ? "status" : "alert",
|
|
1269
|
+
style: {
|
|
1270
|
+
padding: "24px",
|
|
1271
|
+
display: "flex",
|
|
1272
|
+
flexDirection: "column",
|
|
1273
|
+
gap: "10px",
|
|
1274
|
+
font: "inherit",
|
|
1275
|
+
color: "inherit",
|
|
1276
|
+
overflow: "auto"
|
|
1277
|
+
}
|
|
1278
|
+
}, h("strong", { style: { fontSize: "14px" } }, props.title), props.detail ? h("div", { style: { opacity: .8 } }, props.detail) : null, props.children, props.onRetry ? h("button", {
|
|
1279
|
+
type: "button",
|
|
1280
|
+
onClick: props.onRetry,
|
|
1281
|
+
"data-kition-retry": "",
|
|
1282
|
+
style: {
|
|
1283
|
+
alignSelf: "flex-start",
|
|
1284
|
+
padding: "4px 12px",
|
|
1285
|
+
cursor: "pointer"
|
|
1286
|
+
}
|
|
1287
|
+
}, env.t("retry")) : null);
|
|
1288
|
+
}
|
|
1289
|
+
function KitionView(props) {
|
|
1290
|
+
const env = useEnvironment();
|
|
1291
|
+
const parsed = parseFileAddress(props.address);
|
|
1292
|
+
const sessionId = parsed?.scope === "session" ? parsed.sessionId : props.sessionId;
|
|
1293
|
+
const path = parsed?.path ?? "";
|
|
1294
|
+
const fileName = baseName(path);
|
|
1295
|
+
const [attempt, setAttempt] = react.useState(0);
|
|
1296
|
+
const [opened, setOpened] = react.useState({ phase: "opening" });
|
|
1297
|
+
const host = react.useRef(null);
|
|
1298
|
+
const latest = react.useRef(props);
|
|
1299
|
+
latest.current = props;
|
|
1300
|
+
react.useEffect(() => {
|
|
1301
|
+
if (!sessionId || !path) return;
|
|
1302
|
+
let current = true;
|
|
1303
|
+
setOpened({ phase: "opening" });
|
|
1304
|
+
openFile(sessionId, path).then((result) => current && setOpened(result));
|
|
1305
|
+
return () => {
|
|
1306
|
+
current = false;
|
|
1307
|
+
};
|
|
1308
|
+
}, [
|
|
1309
|
+
sessionId,
|
|
1310
|
+
path,
|
|
1311
|
+
attempt
|
|
1312
|
+
]);
|
|
1313
|
+
react.useEffect(() => {
|
|
1314
|
+
if (opened.phase !== "open" || !host.current) return;
|
|
1315
|
+
const url = new URL(opened.page, document.baseURI);
|
|
1316
|
+
url.searchParams.set("theme", environment.scheme);
|
|
1317
|
+
url.searchParams.set("locale", environment.language);
|
|
1318
|
+
if (environment.keys.length) url.searchParams.set("keys", environment.keys.join(" "));
|
|
1319
|
+
if (props.watching) url.searchParams.set("focus", "no");
|
|
1320
|
+
url.searchParams.set("closing", "host");
|
|
1321
|
+
const frame = makeFrame(props.tabId, url.href, `Kition ${fileName}`);
|
|
1322
|
+
const reviewKey = `${sessionId}:${opened.path}`;
|
|
1323
|
+
const remember = (state) => setPage(props.tabId, {
|
|
1324
|
+
...state,
|
|
1325
|
+
name: fileName,
|
|
1326
|
+
path: opened.path,
|
|
1327
|
+
sessionId: sessionId ?? null,
|
|
1328
|
+
frame: page,
|
|
1329
|
+
tabId: props.tabId,
|
|
1330
|
+
floating: latest.current.floating === true,
|
|
1331
|
+
watching: latest.current.watching === true
|
|
1332
|
+
});
|
|
1333
|
+
const page = new PageFrame(frame, {
|
|
1334
|
+
change: (state) => {
|
|
1335
|
+
remember(state);
|
|
1336
|
+
if (state.status === "open") latest.current.onOpen?.();
|
|
1337
|
+
if (state.status === "open" && pendingReview.delete(reviewKey)) page.review();
|
|
1338
|
+
draftsOf(opened.key).refresh();
|
|
1339
|
+
},
|
|
1340
|
+
shortcut: forwardShortcut,
|
|
1341
|
+
requestClose: (dirty) => {
|
|
1342
|
+
if (latest.current.guardClose() && dirty) confirmClose(props.tabId, () => latest.current.close?.());
|
|
1343
|
+
else latest.current.close?.();
|
|
1344
|
+
},
|
|
1345
|
+
reviewed: () => {
|
|
1346
|
+
draftsOf(opened.key).refresh();
|
|
1347
|
+
if (sessionId) reviewsOf(sessionId).refresh();
|
|
1348
|
+
}
|
|
1349
|
+
}, environment.scheme, environment.language);
|
|
1350
|
+
remember(page.state);
|
|
1351
|
+
const stop = environment.subscribe(() => {
|
|
1352
|
+
page.setTheme(environment.scheme);
|
|
1353
|
+
page.setLanguage(environment.language);
|
|
1354
|
+
});
|
|
1355
|
+
host.current.replaceChildren(frame);
|
|
1356
|
+
return () => {
|
|
1357
|
+
stop();
|
|
1358
|
+
page.dispose();
|
|
1359
|
+
frame.remove();
|
|
1360
|
+
setPage(props.tabId, null);
|
|
1361
|
+
};
|
|
1362
|
+
}, [
|
|
1363
|
+
opened,
|
|
1364
|
+
props.tabId,
|
|
1365
|
+
fileName
|
|
1366
|
+
]);
|
|
1367
|
+
if (!sessionId || !path) return h(Panel, {
|
|
1368
|
+
state: "no-session",
|
|
1369
|
+
title: env.t("noSession")
|
|
1370
|
+
});
|
|
1371
|
+
if (opened.phase === "opening") return h(Panel, {
|
|
1372
|
+
state: "starting",
|
|
1373
|
+
title: env.t("starting"),
|
|
1374
|
+
detail: env.t("startingDetail")
|
|
1375
|
+
});
|
|
1376
|
+
if (opened.phase === "failed") {
|
|
1377
|
+
const retry = () => setAttempt((n) => n + 1);
|
|
1378
|
+
if (opened.error === "kition-missing" || opened.error === "kition-invalid") {
|
|
1379
|
+
const why = opened.error === "kition-invalid" ? "missingOption" : opened.reason === "unsupported" ? "missingUnsupported" : opened.reason === "omitted" ? "missingOmitted" : opened.reason === "folder" ? "missingFolder" : "missingCli";
|
|
1380
|
+
return h(Panel, {
|
|
1381
|
+
state: "kition-missing",
|
|
1382
|
+
title: env.t("missingTitle"),
|
|
1383
|
+
detail: env.t(why, { platform: opened.platform ?? "" }),
|
|
1384
|
+
onRetry: retry
|
|
1385
|
+
}, h("div", {
|
|
1386
|
+
"data-kition-missing-reason": opened.reason ?? opened.error,
|
|
1387
|
+
style: {
|
|
1388
|
+
opacity: .7,
|
|
1389
|
+
fontSize: "12px",
|
|
1390
|
+
overflowWrap: "anywhere"
|
|
1391
|
+
}
|
|
1392
|
+
}, opened.message));
|
|
1393
|
+
}
|
|
1394
|
+
if (opened.error === "outside-workspace") return h(Panel, {
|
|
1395
|
+
state: "outside-workspace",
|
|
1396
|
+
title: env.t("outsideTitle"),
|
|
1397
|
+
detail: env.t("outsideDetail")
|
|
1398
|
+
});
|
|
1399
|
+
return h(Panel, {
|
|
1400
|
+
state: "unreachable",
|
|
1401
|
+
title: env.t("unreachableTitle"),
|
|
1402
|
+
detail: env.t("unreachableDetail"),
|
|
1403
|
+
onRetry: retry
|
|
1404
|
+
}, h("div", { style: {
|
|
1405
|
+
opacity: .7,
|
|
1406
|
+
fontSize: "12px"
|
|
1407
|
+
} }, opened.message));
|
|
1408
|
+
}
|
|
1409
|
+
return h("div", {
|
|
1410
|
+
ref: host,
|
|
1411
|
+
"data-kition-view": "",
|
|
1412
|
+
style: {
|
|
1413
|
+
display: "flex",
|
|
1414
|
+
flexDirection: "column",
|
|
1415
|
+
width: "100%",
|
|
1416
|
+
height: "100%",
|
|
1417
|
+
minHeight: 0,
|
|
1418
|
+
WebkitAppRegion: "no-drag"
|
|
1419
|
+
}
|
|
1420
|
+
});
|
|
1421
|
+
}
|
|
1422
|
+
function TabBody(props) {
|
|
1423
|
+
const env = useEnvironment();
|
|
1424
|
+
const info = props.useTabInfo();
|
|
1425
|
+
const params = info.tab.navigation?.params ?? {};
|
|
1426
|
+
const watching = params.live === true || params.float === true;
|
|
1427
|
+
const floating = info.panel?.isFloating === true;
|
|
1428
|
+
const view = h(KitionView, {
|
|
1429
|
+
address: info.tab.contentId,
|
|
1430
|
+
sessionId: props.sessionId,
|
|
1431
|
+
tabId: info.tab.id,
|
|
1432
|
+
close: () => info.tab.actions?.close?.(),
|
|
1433
|
+
guardClose: () => !guards.kition,
|
|
1434
|
+
watching,
|
|
1435
|
+
floating
|
|
1436
|
+
});
|
|
1437
|
+
if (!(watching && floating)) return view;
|
|
1438
|
+
const parsed = parseFileAddress(info.tab.contentId);
|
|
1439
|
+
const sessionId = parsed?.scope === "session" ? parsed.sessionId : props.sessionId;
|
|
1440
|
+
const path = parsed?.path;
|
|
1441
|
+
return h("div", {
|
|
1442
|
+
"data-kition-live": "",
|
|
1443
|
+
style: {
|
|
1444
|
+
display: "flex",
|
|
1445
|
+
flexDirection: "column",
|
|
1446
|
+
width: "100%",
|
|
1447
|
+
height: "100%",
|
|
1448
|
+
minHeight: 0
|
|
1449
|
+
}
|
|
1450
|
+
}, h("div", { style: {
|
|
1451
|
+
display: "flex",
|
|
1452
|
+
alignItems: "center",
|
|
1453
|
+
gap: "8px",
|
|
1454
|
+
padding: "4px 8px",
|
|
1455
|
+
fontSize: "12px",
|
|
1456
|
+
borderBottom: "1px solid rgba(127,127,127,0.2)",
|
|
1457
|
+
flex: "none"
|
|
1458
|
+
} }, h("span", { style: {
|
|
1459
|
+
flex: 1,
|
|
1460
|
+
minWidth: 0,
|
|
1461
|
+
opacity: .75,
|
|
1462
|
+
overflow: "hidden",
|
|
1463
|
+
textOverflow: "ellipsis",
|
|
1464
|
+
whiteSpace: "nowrap"
|
|
1465
|
+
} }, env.t("liveWatching")), sessionId && path ? button(env.t("liveOpenEditor"), "open-editor", () => void openInSidebar(sessionId, path, "sidebar"), false) : null), h("div", { style: {
|
|
1466
|
+
flex: 1,
|
|
1467
|
+
minHeight: 0,
|
|
1468
|
+
display: "flex",
|
|
1469
|
+
flexDirection: "column"
|
|
1470
|
+
} }, view));
|
|
1471
|
+
}
|
|
1472
|
+
/**
|
|
1473
|
+
* A tab's title: its marks, then its name. The marks come first because DeepSeek Harness's tab is at
|
|
1474
|
+
* most 170 px wide and fades its title's last 30 px under the close button: a long name is cut, the
|
|
1475
|
+
* marks never are. `●` while it has unsaved edits, a Draft mark while an agent's draft waits, Read-only.
|
|
1476
|
+
*/
|
|
1477
|
+
function titled(name, page, env) {
|
|
1478
|
+
const mark = {
|
|
1479
|
+
flex: "none",
|
|
1480
|
+
fontSize: "10px",
|
|
1481
|
+
lineHeight: "14px",
|
|
1482
|
+
padding: "0 4px",
|
|
1483
|
+
borderRadius: "6px",
|
|
1484
|
+
whiteSpace: "nowrap"
|
|
1485
|
+
};
|
|
1486
|
+
return [
|
|
1487
|
+
page?.dirty ? h("span", {
|
|
1488
|
+
key: "dirty",
|
|
1489
|
+
"data-kition-dirty": "",
|
|
1490
|
+
"aria-label": env.t("unsaved"),
|
|
1491
|
+
title: env.t("unsaved"),
|
|
1492
|
+
style: { flex: "none" }
|
|
1493
|
+
}, "●") : null,
|
|
1494
|
+
page?.draft ? h("span", {
|
|
1495
|
+
key: "draft",
|
|
1496
|
+
"data-kition-draft": page.draft.state,
|
|
1497
|
+
title: env.t("draftTitle"),
|
|
1498
|
+
style: {
|
|
1499
|
+
...mark,
|
|
1500
|
+
background: "rgba(255,170,0,0.25)"
|
|
1501
|
+
}
|
|
1502
|
+
}, env.t("draft")) : null,
|
|
1503
|
+
page?.readOnly ? h("span", {
|
|
1504
|
+
key: "ro",
|
|
1505
|
+
"data-kition-readonly": "",
|
|
1506
|
+
style: {
|
|
1507
|
+
...mark,
|
|
1508
|
+
opacity: .75,
|
|
1509
|
+
border: "1px solid currentColor",
|
|
1510
|
+
lineHeight: "12px"
|
|
1511
|
+
}
|
|
1512
|
+
}, env.t("readOnly")) : null,
|
|
1513
|
+
h("span", {
|
|
1514
|
+
key: "name",
|
|
1515
|
+
style: {
|
|
1516
|
+
minWidth: 0,
|
|
1517
|
+
overflow: "hidden",
|
|
1518
|
+
textOverflow: "ellipsis",
|
|
1519
|
+
whiteSpace: "nowrap"
|
|
1520
|
+
}
|
|
1521
|
+
}, name)
|
|
1522
|
+
];
|
|
1523
|
+
}
|
|
1524
|
+
function TabTitle(props) {
|
|
1525
|
+
const env = useEnvironment();
|
|
1526
|
+
const info = props.useTabInfo();
|
|
1527
|
+
react.useSyncExternalStore(subscribePages, () => pages.get(info.tab.id));
|
|
1528
|
+
return h(react.Fragment, null, ...titled(info.tab.title, pages.get(info.tab.id), env));
|
|
1529
|
+
}
|
|
1530
|
+
/**
|
|
1531
|
+
* DeepSeek Harness's document preview title, with the marks of a Kition preview in it. It stands in
|
|
1532
|
+
* for DeepSeek Harness's own (a plugin's keyed entry shadows the product's), drawn the same way:
|
|
1533
|
+
* the file type's sheet, then the name.
|
|
1534
|
+
*/
|
|
1535
|
+
function textTitle(primitives) {
|
|
1536
|
+
return function TextTabTitle(props) {
|
|
1537
|
+
const env = useEnvironment();
|
|
1538
|
+
const info = props.useTabInfo();
|
|
1539
|
+
react.useSyncExternalStore(subscribePages, () => pages.get(info.tab.id));
|
|
1540
|
+
const icon = primitives?.FileTypeIcon && primitives.classifyFileType ? h(primitives.FileTypeIcon, {
|
|
1541
|
+
kind: primitives.classifyFileType(info.tab.title),
|
|
1542
|
+
size: 16,
|
|
1543
|
+
style: { flex: "none" }
|
|
1544
|
+
}) : null;
|
|
1545
|
+
return h(react.Fragment, null, icon, ...titled(info.tab.title, pages.get(info.tab.id), env));
|
|
1546
|
+
};
|
|
1547
|
+
}
|
|
1548
|
+
function PreviewBody(props) {
|
|
1549
|
+
const info = props.useTabInfo?.();
|
|
1550
|
+
const content = props.content;
|
|
1551
|
+
const loaded = react.useRef(false);
|
|
1552
|
+
react.useEffect(() => {
|
|
1553
|
+
loaded.current = false;
|
|
1554
|
+
}, [content?.revision]);
|
|
1555
|
+
return h(KitionView, {
|
|
1556
|
+
address: props.resourceAddress,
|
|
1557
|
+
sessionId: props.sessionId,
|
|
1558
|
+
tabId: info?.tab?.id ?? props.resourceAddress,
|
|
1559
|
+
close: () => info?.tab?.actions?.close?.(),
|
|
1560
|
+
guardClose: () => !guards.text,
|
|
1561
|
+
onOpen: () => {
|
|
1562
|
+
if (loaded.current || content?.kind !== "renderer") return;
|
|
1563
|
+
loaded.current = true;
|
|
1564
|
+
content.loaded(String(content.revision));
|
|
1565
|
+
}
|
|
1566
|
+
});
|
|
1567
|
+
}
|
|
1568
|
+
/** Which tab kinds have the plugin's close guard (it asks before a tab with unsaved edits closes). */
|
|
1569
|
+
var guards = {
|
|
1570
|
+
kition: false,
|
|
1571
|
+
text: false
|
|
1572
|
+
};
|
|
1573
|
+
/** Tabs the person chose to close with their unsaved edits: the guard lets them go. */
|
|
1574
|
+
var closing = /* @__PURE__ */ new Set();
|
|
1575
|
+
/**
|
|
1576
|
+
* Asks the person what becomes of a tab's unsaved edits: Save and close, Close without saving, or
|
|
1577
|
+
* Keep editing. An in-page dialog: a native one (the browser's confirm) would stop the whole page,
|
|
1578
|
+
* DeepSeek Harness Desktop's included, until answered.
|
|
1579
|
+
*/
|
|
1580
|
+
async function confirmClose(tabId, close) {
|
|
1581
|
+
const page = pages.get(tabId);
|
|
1582
|
+
if (!page) return close();
|
|
1583
|
+
const choice = await ask(environment.t("closeDirty", { name: page.name }), [
|
|
1584
|
+
{
|
|
1585
|
+
id: "save",
|
|
1586
|
+
label: environment.t("closeSave"),
|
|
1587
|
+
primary: true
|
|
1588
|
+
},
|
|
1589
|
+
{
|
|
1590
|
+
id: "discard",
|
|
1591
|
+
label: environment.t("closeDiscard"),
|
|
1592
|
+
danger: true
|
|
1593
|
+
},
|
|
1594
|
+
{
|
|
1595
|
+
id: "keep",
|
|
1596
|
+
label: environment.t("closeKeep")
|
|
1597
|
+
}
|
|
1598
|
+
]);
|
|
1599
|
+
if (choice === "save") {
|
|
1600
|
+
if (!await new Promise((resolve) => {
|
|
1601
|
+
const stop = subscribePages(() => {
|
|
1602
|
+
const now = pages.get(tabId);
|
|
1603
|
+
if (!now || !now.dirty) {
|
|
1604
|
+
stop();
|
|
1605
|
+
resolve(true);
|
|
1606
|
+
}
|
|
1607
|
+
});
|
|
1608
|
+
page.frame.save();
|
|
1609
|
+
setTimeout(() => {
|
|
1610
|
+
stop();
|
|
1611
|
+
resolve(!pages.get(tabId)?.dirty);
|
|
1612
|
+
}, 15e3);
|
|
1613
|
+
})) return;
|
|
1614
|
+
} else if (choice !== "discard") return;
|
|
1615
|
+
closing.add(tabId);
|
|
1616
|
+
close();
|
|
1617
|
+
setTimeout(() => closing.delete(tabId), 2e3);
|
|
1618
|
+
}
|
|
1619
|
+
function closeGuard(_session, tab) {
|
|
1620
|
+
if (!pages.get(tab.id)?.dirty || closing.has(tab.id)) return;
|
|
1621
|
+
confirmClose(tab.id, () => environment.sidebar?.close?.(tab.id));
|
|
1622
|
+
throw new Error("Kition: the tab has unsaved edits; the person is asked");
|
|
1623
|
+
}
|
|
1624
|
+
/** The workspace key of a session, from the host module (which starts its gateway). */
|
|
1625
|
+
var keys = /* @__PURE__ */ new Map();
|
|
1626
|
+
function workspaceOf(sessionId, path) {
|
|
1627
|
+
const cached = keys.get(sessionId);
|
|
1628
|
+
if (cached) return cached;
|
|
1629
|
+
const asked = openFile(sessionId, path);
|
|
1630
|
+
keys.set(sessionId, asked);
|
|
1631
|
+
asked.then((answer) => answer.phase !== "open" && keys.delete(sessionId));
|
|
1632
|
+
return asked;
|
|
1633
|
+
}
|
|
1634
|
+
function useWatch(subscribe, read) {
|
|
1635
|
+
const [, setTick] = react.useState(0);
|
|
1636
|
+
react.useEffect(() => subscribe ? subscribe(() => setTick((n) => n + 1)) : void 0, [subscribe]);
|
|
1637
|
+
return read();
|
|
1638
|
+
}
|
|
1639
|
+
var STATE_WORDS = {
|
|
1640
|
+
pending: "statePending",
|
|
1641
|
+
failed: "stateFailed",
|
|
1642
|
+
live: "stateLive",
|
|
1643
|
+
saved: "stateSaved",
|
|
1644
|
+
created: "stateCreated",
|
|
1645
|
+
"draft-open": "stateDraftOpen",
|
|
1646
|
+
"draft-ready": "stateDraftReady",
|
|
1647
|
+
stale: "stateStale",
|
|
1648
|
+
merged: "stateMerged",
|
|
1649
|
+
discarded: "stateDiscarded",
|
|
1650
|
+
"draft-gone": "stateDraftGone",
|
|
1651
|
+
missing: "stateMissing"
|
|
1652
|
+
};
|
|
1653
|
+
var button = (label, action, onClick, busy, primary = false) => h("button", {
|
|
1654
|
+
key: action,
|
|
1655
|
+
type: "button",
|
|
1656
|
+
"data-kition-card-action": action,
|
|
1657
|
+
disabled: busy,
|
|
1658
|
+
onClick,
|
|
1659
|
+
style: {
|
|
1660
|
+
padding: "2px 10px",
|
|
1661
|
+
borderRadius: "6px",
|
|
1662
|
+
border: "1px solid rgba(127,127,127,0.35)",
|
|
1663
|
+
background: primary ? "rgba(80,90,255,0.12)" : "transparent",
|
|
1664
|
+
color: "inherit",
|
|
1665
|
+
cursor: busy ? "default" : "pointer",
|
|
1666
|
+
font: "inherit",
|
|
1667
|
+
fontSize: "12px"
|
|
1668
|
+
}
|
|
1669
|
+
}, label);
|
|
1670
|
+
function FileCard(props) {
|
|
1671
|
+
const env = useEnvironment();
|
|
1672
|
+
const { sessionId, file, turn } = props;
|
|
1673
|
+
const [workspace, setWorkspace] = react.useState({ phase: "opening" });
|
|
1674
|
+
const [attempt, setAttempt] = react.useState(0);
|
|
1675
|
+
const [busy, setBusy] = react.useState(false);
|
|
1676
|
+
const [problem, setProblem] = react.useState(null);
|
|
1677
|
+
const [fileThere, setFileThere] = react.useState(void 0);
|
|
1678
|
+
const [comparison, setComparison] = react.useState(null);
|
|
1679
|
+
react.useEffect(() => {
|
|
1680
|
+
let current = true;
|
|
1681
|
+
workspaceOf(sessionId, file.path).then((answer) => current && setWorkspace(answer));
|
|
1682
|
+
return () => {
|
|
1683
|
+
current = false;
|
|
1684
|
+
};
|
|
1685
|
+
}, [
|
|
1686
|
+
sessionId,
|
|
1687
|
+
file.path,
|
|
1688
|
+
attempt
|
|
1689
|
+
]);
|
|
1690
|
+
const key = workspace.phase === "open" ? workspace.key : null;
|
|
1691
|
+
const watch = react.useMemo(() => key ? draftsOf(key) : null, [key]);
|
|
1692
|
+
const listed = useWatch(react.useMemo(() => watch ? (listener) => watch.subscribe(listener) : null, [watch]), () => watch?.drafts ? watch.drafts.get(file.path) ?? null : void 0);
|
|
1693
|
+
react.useSyncExternalStore(subscribePages, () => pages.size);
|
|
1694
|
+
const drafted = file.operations.some((operation) => operation.writes && operation.draft && operation.phase === "done");
|
|
1695
|
+
if (drafted) noteDraftingTurn(sessionId, file.path, turn, draftedAt(file));
|
|
1696
|
+
const reviews = react.useMemo(() => reviewsOf(sessionId), [sessionId]);
|
|
1697
|
+
useWatch(react.useMemo(() => (listener) => reviews.subscribe(listener), [reviews]), () => reviews.reviews);
|
|
1698
|
+
react.useEffect(() => watch ? watch.subscribe(() => void reviews.refresh()) : void 0, [watch, reviews]);
|
|
1699
|
+
const listedKey = listed ? `${listed.state}:${listed.stale}:${listed.updated ?? ""}` : String(listed);
|
|
1700
|
+
react.useEffect(() => {
|
|
1701
|
+
if (!key) return;
|
|
1702
|
+
let current = true;
|
|
1703
|
+
exists(key, file.path).then((there) => current && setFileThere(there));
|
|
1704
|
+
if (listed && drafted) compare(key, file.path).then((answer) => current && setComparison(answer), () => current && setComparison(null));
|
|
1705
|
+
else setComparison(null);
|
|
1706
|
+
return () => {
|
|
1707
|
+
current = false;
|
|
1708
|
+
};
|
|
1709
|
+
}, [
|
|
1710
|
+
key,
|
|
1711
|
+
file.path,
|
|
1712
|
+
listedKey,
|
|
1713
|
+
drafted
|
|
1714
|
+
]);
|
|
1715
|
+
react.useSyncExternalStore(subscribeDraftingTurns, draftingVersionNow);
|
|
1716
|
+
const latest = draftingTurnOf(sessionId, file.path) === turn;
|
|
1717
|
+
const kept = (drafted ? outcomeFor(reviews.reviews, sessionId, file.path, turn, draftingTurnsOf(sessionId, file.path)) : null)?.outcome ?? null;
|
|
1718
|
+
const state = cardState(file, {
|
|
1719
|
+
draft: kept ? null : watch?.drafts ? latest ? listed : null : void 0,
|
|
1720
|
+
outcome: kept,
|
|
1721
|
+
exists: fileThere
|
|
1722
|
+
});
|
|
1723
|
+
if (state === null) return null;
|
|
1724
|
+
const kit = file.kit?.replace(/^kit\./, "") ?? KIT_EXTENSIONS[extensionOf(file.path)] ?? null;
|
|
1725
|
+
let words = env.t(STATE_WORDS[state]);
|
|
1726
|
+
let shown = state;
|
|
1727
|
+
if (workspace.phase === "failed") {
|
|
1728
|
+
shown = workspace.error === "kition-missing" || workspace.error === "kition-invalid" ? "kition-missing" : "gateway-down";
|
|
1729
|
+
words = env.t(shown === "kition-missing" ? "stateKitionMissing" : "stateGatewayDown");
|
|
1730
|
+
}
|
|
1731
|
+
const origin = {
|
|
1732
|
+
session: sessionId,
|
|
1733
|
+
turn
|
|
1734
|
+
};
|
|
1735
|
+
const act = (run) => async () => {
|
|
1736
|
+
if (!key) return;
|
|
1737
|
+
setBusy(true);
|
|
1738
|
+
setProblem(null);
|
|
1739
|
+
try {
|
|
1740
|
+
await run();
|
|
1741
|
+
} catch (error) {
|
|
1742
|
+
setProblem(env.t("failedAction", { message: error.message }));
|
|
1743
|
+
} finally {
|
|
1744
|
+
setBusy(false);
|
|
1745
|
+
watch?.refresh();
|
|
1746
|
+
reviews.refresh();
|
|
1747
|
+
}
|
|
1748
|
+
};
|
|
1749
|
+
const actions = workspace.phase === "failed" ? [] : cardActions(state);
|
|
1750
|
+
const counts = comparison?.diff ? {
|
|
1751
|
+
created: String(comparison.diff.created?.length ?? 0),
|
|
1752
|
+
changed: String(comparison.diff.changed?.length ?? 0),
|
|
1753
|
+
deleted: String(comparison.diff.deleted?.length ?? 0)
|
|
1754
|
+
} : null;
|
|
1755
|
+
const picture = comparison?.previews?.draft;
|
|
1756
|
+
return h("div", {
|
|
1757
|
+
"data-kition-card": file.path,
|
|
1758
|
+
"data-state": shown,
|
|
1759
|
+
style: {
|
|
1760
|
+
display: "flex",
|
|
1761
|
+
gap: "10px",
|
|
1762
|
+
alignItems: "flex-start",
|
|
1763
|
+
padding: "8px 10px",
|
|
1764
|
+
border: "1px solid rgba(127,127,127,0.25)",
|
|
1765
|
+
borderRadius: "8px",
|
|
1766
|
+
margin: "6px 0",
|
|
1767
|
+
fontSize: "13px"
|
|
1768
|
+
}
|
|
1769
|
+
}, picture ? h("img", {
|
|
1770
|
+
src: `data:image/png;base64,${picture}`,
|
|
1771
|
+
alt: "",
|
|
1772
|
+
"data-kition-card-picture": "",
|
|
1773
|
+
style: {
|
|
1774
|
+
width: "64px",
|
|
1775
|
+
height: "48px",
|
|
1776
|
+
objectFit: "contain",
|
|
1777
|
+
borderRadius: "4px",
|
|
1778
|
+
background: "rgba(127,127,127,0.1)",
|
|
1779
|
+
flex: "none"
|
|
1780
|
+
}
|
|
1781
|
+
}) : null, h("div", { style: {
|
|
1782
|
+
display: "flex",
|
|
1783
|
+
flexDirection: "column",
|
|
1784
|
+
gap: "4px",
|
|
1785
|
+
minWidth: 0,
|
|
1786
|
+
flex: 1
|
|
1787
|
+
} }, h("div", { style: {
|
|
1788
|
+
display: "flex",
|
|
1789
|
+
gap: "8px",
|
|
1790
|
+
alignItems: "baseline",
|
|
1791
|
+
flexWrap: "wrap"
|
|
1792
|
+
} }, h("strong", {
|
|
1793
|
+
style: {
|
|
1794
|
+
overflow: "hidden",
|
|
1795
|
+
textOverflow: "ellipsis",
|
|
1796
|
+
whiteSpace: "nowrap"
|
|
1797
|
+
},
|
|
1798
|
+
title: file.path
|
|
1799
|
+
}, baseName(file.path)), kit ? h("span", { style: {
|
|
1800
|
+
opacity: .7,
|
|
1801
|
+
fontSize: "12px"
|
|
1802
|
+
} }, `Kition ${kitName(kit)}`) : null, h("span", {
|
|
1803
|
+
"data-kition-card-state": shown,
|
|
1804
|
+
style: {
|
|
1805
|
+
fontSize: "12px",
|
|
1806
|
+
opacity: .85
|
|
1807
|
+
}
|
|
1808
|
+
}, words)), counts ? h("div", {
|
|
1809
|
+
"data-kition-card-changes": "",
|
|
1810
|
+
style: {
|
|
1811
|
+
fontSize: "12px",
|
|
1812
|
+
opacity: .75
|
|
1813
|
+
}
|
|
1814
|
+
}, env.t("changes", counts)) : comparison?.diffUnavailable ? h("div", { style: {
|
|
1815
|
+
fontSize: "12px",
|
|
1816
|
+
opacity: .75
|
|
1817
|
+
} }, comparison.diffUnavailable) : null, problem ? h("div", {
|
|
1818
|
+
role: "alert",
|
|
1819
|
+
style: {
|
|
1820
|
+
fontSize: "12px",
|
|
1821
|
+
color: "#c0392b"
|
|
1822
|
+
}
|
|
1823
|
+
}, problem) : null, workspace.phase === "failed" ? h("div", null, button(env.t("retry"), "retry", () => setAttempt((n) => n + 1), false)) : null, actions.length ? h("div", { style: {
|
|
1824
|
+
display: "flex",
|
|
1825
|
+
gap: "6px",
|
|
1826
|
+
flexWrap: "wrap"
|
|
1827
|
+
} }, ...actions.map((action) => {
|
|
1828
|
+
switch (action) {
|
|
1829
|
+
case "open": return button(env.t("actionOpen"), action, () => props.open(file.path), false);
|
|
1830
|
+
case "review": return button(env.t("actionReview"), action, () => reviewInSidebar(sessionId, file.path), false);
|
|
1831
|
+
case "merge": return button(env.t("actionMerge"), action, act(() => merge(key, file.path, false, origin)), busy, true);
|
|
1832
|
+
case "overwrite": return button(env.t("actionOverwrite"), action, act(() => merge(key, file.path, true, origin)), busy, true);
|
|
1833
|
+
case "discard": return button(env.t("actionDiscard"), action, () => {
|
|
1834
|
+
ask(env.t("confirmDiscard", { name: baseName(file.path) }), [{
|
|
1835
|
+
id: "discard",
|
|
1836
|
+
label: env.t("actionDiscard"),
|
|
1837
|
+
danger: true
|
|
1838
|
+
}, {
|
|
1839
|
+
id: "keep",
|
|
1840
|
+
label: env.t("keepDraft")
|
|
1841
|
+
}]).then((choice) => {
|
|
1842
|
+
if (choice === "discard") act(() => discard(key, file.path, origin))();
|
|
1843
|
+
});
|
|
1844
|
+
}, busy);
|
|
1845
|
+
}
|
|
1846
|
+
})) : null));
|
|
1847
|
+
}
|
|
1848
|
+
/** The turn tail: a card per kit file the turn changed. */
|
|
1849
|
+
function TurnCards(props) {
|
|
1850
|
+
const data = props.turn?.data?.get?.("kitionTurn");
|
|
1851
|
+
const sessionId = props.sessionId;
|
|
1852
|
+
if (!data || !sessionId) return null;
|
|
1853
|
+
const files = data.files.filter((file) => cardState(file, {}) !== null);
|
|
1854
|
+
if (files.length === 0) return null;
|
|
1855
|
+
const open = (path) => {
|
|
1856
|
+
if (!openInSidebar(sessionId, path)) props.openFile?.(path);
|
|
1857
|
+
};
|
|
1858
|
+
return h("div", {
|
|
1859
|
+
"data-kition-cards": props.turn.turn,
|
|
1860
|
+
"aria-label": environment.t("cardsLabel")
|
|
1861
|
+
}, ...files.map((file) => h(FileCard, {
|
|
1862
|
+
key: file.path,
|
|
1863
|
+
sessionId,
|
|
1864
|
+
turn: props.turn.turn,
|
|
1865
|
+
file,
|
|
1866
|
+
open
|
|
1867
|
+
})));
|
|
1868
|
+
}
|
|
1869
|
+
/**
|
|
1870
|
+
* Opens the review of a file's draft at a usable size: in the right sidebar (a live window the file
|
|
1871
|
+
* was in moves there), over its editor.
|
|
1872
|
+
*/
|
|
1873
|
+
function reviewInSidebar(sessionId, path) {
|
|
1874
|
+
const page = openPage(sessionId, path);
|
|
1875
|
+
if (page && page.status === "open" && !page.floating) return page.frame.review();
|
|
1876
|
+
const key = `${sessionId}:${path}`;
|
|
1877
|
+
pendingReview.add(key);
|
|
1878
|
+
openInSidebar(sessionId, path, "sidebar");
|
|
1879
|
+
setTimeout(() => {
|
|
1880
|
+
const now = openPage(sessionId, path);
|
|
1881
|
+
if (now && now.status === "open" && pendingReview.delete(key)) now.frame.review();
|
|
1882
|
+
}, 800);
|
|
1883
|
+
}
|
|
1884
|
+
/** Waits until the file's page is open (its editor attached to the gateway's bridge), at most `ms`. */
|
|
1885
|
+
function whenOpen(sessionId, path, ms) {
|
|
1886
|
+
return new Promise((resolve) => {
|
|
1887
|
+
const done = (value) => {
|
|
1888
|
+
stop();
|
|
1889
|
+
clearTimeout(timer);
|
|
1890
|
+
resolve(value);
|
|
1891
|
+
};
|
|
1892
|
+
const check = () => {
|
|
1893
|
+
if (openPage(sessionId, path)?.status === "open") done(true);
|
|
1894
|
+
};
|
|
1895
|
+
const stop = subscribePages(check);
|
|
1896
|
+
const timer = setTimeout(() => done(false), ms);
|
|
1897
|
+
check();
|
|
1898
|
+
});
|
|
1899
|
+
}
|
|
1900
|
+
/**
|
|
1901
|
+
* The live window: the host module announces an agent's edit of a file before it runs it (an event
|
|
1902
|
+
* stream, /kition/api/live); this opens the file, floating beside the conversation or in the
|
|
1903
|
+
* sidebar, and answers once its editor is attached, so the edit runs in it and the person watches.
|
|
1904
|
+
* Once per file and turn: a window the person closed stays closed for the turn. Edits the host
|
|
1905
|
+
* does not announce (drafts, new files) open the window once they show in the turn.
|
|
1906
|
+
*/
|
|
1907
|
+
function LiveWatcher(props) {
|
|
1908
|
+
const timeline = props.useChat?.((snapshot) => snapshot.timeline);
|
|
1909
|
+
useEnvironment();
|
|
1910
|
+
const seen = react.useRef(/* @__PURE__ */ new Set());
|
|
1911
|
+
const sessionId = props.sessionId;
|
|
1912
|
+
const current = react.useRef({ timeline });
|
|
1913
|
+
current.current.timeline = timeline;
|
|
1914
|
+
/** The turn now running, if any. */
|
|
1915
|
+
const runningTurn = () => {
|
|
1916
|
+
const now = current.current.timeline;
|
|
1917
|
+
for (const turnNumber of [...now?.turnOrder ?? []].reverse()) if (now.turns.get(turnNumber)?.status === "open") return turnNumber;
|
|
1918
|
+
return null;
|
|
1919
|
+
};
|
|
1920
|
+
const show = (path, turn) => {
|
|
1921
|
+
if (!sessionId) return false;
|
|
1922
|
+
const { liveFloat, autoOpen } = environment.settings;
|
|
1923
|
+
if (!(liveFloat || autoOpen) || !(extensionOf(path) in KIT_EXTENSIONS)) return false;
|
|
1924
|
+
const once = `${sessionId}:${turn ?? "now"}:${path}`;
|
|
1925
|
+
if (seen.current.has(once)) return false;
|
|
1926
|
+
seen.current.add(once);
|
|
1927
|
+
return openInSidebar(sessionId, path, autoOpen ? "sidebar" : "live");
|
|
1928
|
+
};
|
|
1929
|
+
react.useEffect(() => {
|
|
1930
|
+
if (!sessionId) return;
|
|
1931
|
+
const stop = new AbortController();
|
|
1932
|
+
const answerEditing = async (event) => {
|
|
1933
|
+
if (typeof event.id !== "string" || typeof event.path !== "string") return;
|
|
1934
|
+
const id = event.id;
|
|
1935
|
+
const answer = (state) => fetch(route("kition/api/live"), {
|
|
1936
|
+
method: "POST",
|
|
1937
|
+
credentials: "same-origin",
|
|
1938
|
+
headers: { "Content-Type": "application/json" },
|
|
1939
|
+
body: JSON.stringify({
|
|
1940
|
+
id,
|
|
1941
|
+
state
|
|
1942
|
+
})
|
|
1943
|
+
}).catch(() => void 0);
|
|
1944
|
+
const path = event.path.replace(/^(\.\/)+/, "");
|
|
1945
|
+
if (openPage(sessionId, path)?.status === "open") return void await answer("open");
|
|
1946
|
+
if (!show(path, runningTurn())) return void await answer("none");
|
|
1947
|
+
answer("opening");
|
|
1948
|
+
const within = typeof event.openingMs === "number" && event.openingMs > 0 ? event.openingMs - 300 : 2700;
|
|
1949
|
+
await answer(await whenOpen(sessionId, path, within) ? "attached" : "none");
|
|
1950
|
+
};
|
|
1951
|
+
(async () => {
|
|
1952
|
+
for (let attempt = 0; !stop.signal.aborted; attempt++) {
|
|
1953
|
+
try {
|
|
1954
|
+
const response = await fetch(route(`kition/api/live?${new URLSearchParams({ session: sessionId })}`), {
|
|
1955
|
+
credentials: "same-origin",
|
|
1956
|
+
headers: { Accept: "text/event-stream" },
|
|
1957
|
+
signal: stop.signal
|
|
1958
|
+
});
|
|
1959
|
+
if (!response.ok || !response.body) throw new Error(String(response.status));
|
|
1960
|
+
attempt = 0;
|
|
1961
|
+
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
1962
|
+
let buffer = "";
|
|
1963
|
+
for (;;) {
|
|
1964
|
+
const { value, done } = await reader.read();
|
|
1965
|
+
if (done) break;
|
|
1966
|
+
buffer += value;
|
|
1967
|
+
for (let end = buffer.indexOf("\n\n"); end >= 0; end = buffer.indexOf("\n\n")) {
|
|
1968
|
+
const frame = buffer.slice(0, end);
|
|
1969
|
+
buffer = buffer.slice(end + 2);
|
|
1970
|
+
const data = frame.split("\n").find((line) => line.startsWith("data:"))?.slice(5).trim();
|
|
1971
|
+
if (!data) continue;
|
|
1972
|
+
let event;
|
|
1973
|
+
try {
|
|
1974
|
+
event = JSON.parse(data);
|
|
1975
|
+
} catch {
|
|
1976
|
+
continue;
|
|
1977
|
+
}
|
|
1978
|
+
answerEditing(event);
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
} catch {
|
|
1982
|
+
if (stop.signal.aborted) return;
|
|
1983
|
+
}
|
|
1984
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(1e4, 500 * 2 ** attempt)));
|
|
1985
|
+
}
|
|
1986
|
+
})();
|
|
1987
|
+
return () => stop.abort();
|
|
1988
|
+
}, [sessionId]);
|
|
1989
|
+
react.useEffect(() => {
|
|
1990
|
+
if (!timeline || !sessionId) return;
|
|
1991
|
+
for (const turnNumber of timeline.turnOrder ?? []) {
|
|
1992
|
+
const turn = timeline.turns.get(turnNumber);
|
|
1993
|
+
if (!turn || turn.status !== "open") continue;
|
|
1994
|
+
const data = turn.data?.get?.("kitionTurn");
|
|
1995
|
+
for (const file of data?.files ?? []) {
|
|
1996
|
+
if (!hasLiveContent(file)) continue;
|
|
1997
|
+
if (openPage(sessionId, file.path)) {
|
|
1998
|
+
seen.current.add(`${sessionId}:${turnNumber}:${file.path}`);
|
|
1999
|
+
continue;
|
|
2000
|
+
}
|
|
2001
|
+
show(file.path, turnNumber);
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
}, [
|
|
2005
|
+
timeline,
|
|
2006
|
+
sessionId,
|
|
2007
|
+
environment.version
|
|
2008
|
+
]);
|
|
2009
|
+
return null;
|
|
2010
|
+
}
|
|
2011
|
+
var settingsForm = null;
|
|
2012
|
+
function SettingsCard() {
|
|
2013
|
+
const env = useEnvironment();
|
|
2014
|
+
const writable = settingsForm?.getSnapshot?.()?.writable === true;
|
|
2015
|
+
const set = (field, value) => void settingsForm?.set?.(field, value);
|
|
2016
|
+
const row = (children) => h("label", { style: {
|
|
2017
|
+
display: "flex",
|
|
2018
|
+
gap: "8px",
|
|
2019
|
+
alignItems: "center",
|
|
2020
|
+
fontSize: "13px"
|
|
2021
|
+
} }, ...children);
|
|
2022
|
+
if (!settingsForm) return h("div", { "data-kition-settings": "unavailable" }, env.t("settingsUnavailable"));
|
|
2023
|
+
return h("div", {
|
|
2024
|
+
"data-kition-settings": "",
|
|
2025
|
+
style: {
|
|
2026
|
+
display: "flex",
|
|
2027
|
+
flexDirection: "column",
|
|
2028
|
+
gap: "10px",
|
|
2029
|
+
padding: "8px 0"
|
|
2030
|
+
}
|
|
2031
|
+
}, h("strong", null, env.t("settingsTitle")), row([h("input", {
|
|
2032
|
+
type: "checkbox",
|
|
2033
|
+
"data-kition-setting": "liveFloat",
|
|
2034
|
+
checked: env.settings.liveFloat,
|
|
2035
|
+
disabled: !writable,
|
|
2036
|
+
onChange: (event) => set("liveFloat", event.target.checked)
|
|
2037
|
+
}), env.t("settingLiveFloat")]), row([h("input", {
|
|
2038
|
+
type: "checkbox",
|
|
2039
|
+
"data-kition-setting": "autoOpen",
|
|
2040
|
+
checked: env.settings.autoOpen,
|
|
2041
|
+
disabled: !writable,
|
|
2042
|
+
onChange: (event) => set("autoOpen", event.target.checked)
|
|
2043
|
+
}), env.t("settingAutoOpen")]), row([env.t("settingOpenWith"), h("select", {
|
|
2044
|
+
"data-kition-setting": "openWith",
|
|
2045
|
+
value: env.settings.openWith,
|
|
2046
|
+
disabled: !writable,
|
|
2047
|
+
onChange: (event) => set("openWith", event.target.value)
|
|
2048
|
+
}, h("option", { value: "dsh" }, env.t("settingOpenWithDsh")), h("option", { value: "kition" }, env.t("settingOpenWithKition")))]));
|
|
2049
|
+
}
|
|
2050
|
+
/** DeepSeek Harness's web shortcut bindings as the editor writes keys (`Cmd+Alt+,`); none in Desktop, which routes keys itself. */
|
|
2051
|
+
function webKeys(shortcuts, mac) {
|
|
2052
|
+
if (shortcuts?.runtime !== "web") return [];
|
|
2053
|
+
const names = {
|
|
2054
|
+
Comma: ",",
|
|
2055
|
+
Period: ".",
|
|
2056
|
+
Slash: "/",
|
|
2057
|
+
Backslash: "\\",
|
|
2058
|
+
BracketLeft: "[",
|
|
2059
|
+
BracketRight: "]",
|
|
2060
|
+
Minus: "-",
|
|
2061
|
+
Equal: "=",
|
|
2062
|
+
Semicolon: ";",
|
|
2063
|
+
Quote: "'",
|
|
2064
|
+
Backquote: "`",
|
|
2065
|
+
Enter: "Enter",
|
|
2066
|
+
Backspace: "Backspace",
|
|
2067
|
+
Delete: "Delete"
|
|
2068
|
+
};
|
|
2069
|
+
const out = [];
|
|
2070
|
+
for (const entry of shortcuts.catalog?.getSnapshot?.() ?? []) {
|
|
2071
|
+
const binding = entry?.binding;
|
|
2072
|
+
if (!binding || binding.secondCode) continue;
|
|
2073
|
+
const key = /^Key[A-Z]$/.test(binding.code) ? binding.code.slice(3) : /^Digit[0-9]$/.test(binding.code) ? binding.code.slice(5) : /^F[0-9]{1,2}$/.test(binding.code) ? binding.code : names[binding.code];
|
|
2074
|
+
if (!key) continue;
|
|
2075
|
+
const modifiers = [];
|
|
2076
|
+
for (const modifier of binding.modifiers) if (modifier === "meta") {
|
|
2077
|
+
if (!mac) modifiers.length = 0;
|
|
2078
|
+
modifiers.push("Cmd");
|
|
2079
|
+
} else if (modifier === "control") modifiers.push(mac ? "Ctrl" : "Cmd");
|
|
2080
|
+
else if (modifier === "alt") modifiers.push("Alt");
|
|
2081
|
+
else if (modifier === "shift") modifiers.push("Shift");
|
|
2082
|
+
if (modifiers.some((modifier) => modifier === "Cmd" || modifier === "Ctrl" || modifier === "Alt")) out.push([...modifiers, key].join("+"));
|
|
2083
|
+
}
|
|
2084
|
+
return [...new Set(out)].slice(0, 32);
|
|
2085
|
+
}
|
|
2086
|
+
function apply(ctx) {
|
|
2087
|
+
ctx.inject(["theme"], (inner) => {
|
|
2088
|
+
const read = () => environment.set({ scheme: schemeOf(inner.theme.getTheme()) });
|
|
2089
|
+
read();
|
|
2090
|
+
inner.on("theme/change", read);
|
|
2091
|
+
});
|
|
2092
|
+
ctx.inject(["locale"], (inner) => {
|
|
2093
|
+
inner.effect(() => inner.locale.register(NAMESPACE, {
|
|
2094
|
+
en,
|
|
2095
|
+
zh
|
|
2096
|
+
}), "kition: words");
|
|
2097
|
+
const t = inner.locale.bind(NAMESPACE);
|
|
2098
|
+
environment.translate = (key, params) => t(key, params);
|
|
2099
|
+
const read = () => environment.set({ language: languageOf(inner.locale.getSnapshot()?.active) });
|
|
2100
|
+
read();
|
|
2101
|
+
inner.on("locale/change", read);
|
|
2102
|
+
});
|
|
2103
|
+
ctx.inject(["configForms"], (inner) => {
|
|
2104
|
+
const form = inner.configForms.get(HOST_ENTRY);
|
|
2105
|
+
settingsForm = form;
|
|
2106
|
+
const read = () => {
|
|
2107
|
+
const value = form?.getSnapshot?.()?.value ?? {};
|
|
2108
|
+
environment.set({ settings: {
|
|
2109
|
+
liveFloat: typeof value.liveFloat === "boolean" ? value.liveFloat : DEFAULTS.liveFloat,
|
|
2110
|
+
openWith: value.openWith === "kition" ? "kition" : "dsh",
|
|
2111
|
+
autoOpen: typeof value.autoOpen === "boolean" ? value.autoOpen : DEFAULTS.autoOpen
|
|
2112
|
+
} });
|
|
2113
|
+
};
|
|
2114
|
+
read();
|
|
2115
|
+
if (typeof form?.subscribe === "function") inner.effect(() => form.subscribe(read), "kition: settings");
|
|
2116
|
+
inner.effect(() => inner.slots.inject("plugins.bundle.config", () => inner.slots.register({
|
|
2117
|
+
name: "plugins.bundle.config",
|
|
2118
|
+
key: name
|
|
2119
|
+
}, SettingsCard)), "kition: settings card");
|
|
2120
|
+
});
|
|
2121
|
+
ctx.inject(["shortcuts"], (inner) => {
|
|
2122
|
+
const mac = /Mac|iPhone|iPad/i.test(navigator.platform);
|
|
2123
|
+
const read = () => environment.set({ keys: webKeys(inner.shortcuts, mac) });
|
|
2124
|
+
read();
|
|
2125
|
+
if (typeof inner.shortcuts.catalog?.subscribe === "function") inner.effect(() => inner.shortcuts.catalog.subscribe(read), "kition: shortcuts");
|
|
2126
|
+
});
|
|
2127
|
+
ctx.inject(["sidebarRightTabs"], (inner) => {
|
|
2128
|
+
inner.effect(() => {
|
|
2129
|
+
const disposeBody = inner.slots.inject("sidebar.right.pane.tab", () => inner.slots.register({
|
|
2130
|
+
name: "sidebar.right.pane.tab",
|
|
2131
|
+
key: TAB_TYPE
|
|
2132
|
+
}, TabBody));
|
|
2133
|
+
const disposeTitle = inner.slots.inject("sidebar.right.pane.tab.title", () => inner.slots.register({
|
|
2134
|
+
name: "sidebar.right.pane.tab.title",
|
|
2135
|
+
key: TAB_TYPE
|
|
2136
|
+
}, TabTitle));
|
|
2137
|
+
const disposeType = inner.sidebarRightTabs.register({
|
|
2138
|
+
id: TAB_TYPE,
|
|
2139
|
+
kind: TAB_TYPE,
|
|
2140
|
+
patterns: TAB_EXTENSIONS.map((extension) => `*.${extension}`),
|
|
2141
|
+
priority: "extension",
|
|
2142
|
+
canOpen: (address) => {
|
|
2143
|
+
const parsed = parseFileAddress(address);
|
|
2144
|
+
return parsed !== null && extensionOf(parsed.path) in KIT_FORMATS;
|
|
2145
|
+
},
|
|
2146
|
+
title: (address) => baseName(parseFileAddress(address)?.path ?? address)
|
|
2147
|
+
});
|
|
2148
|
+
return () => {
|
|
2149
|
+
disposeType();
|
|
2150
|
+
disposeTitle();
|
|
2151
|
+
disposeBody();
|
|
2152
|
+
};
|
|
2153
|
+
}, "kition: sidebar tab type");
|
|
2154
|
+
inner.effect(() => inner.slots.inject("sidebar.right.pane.tab.title", () => inner.slots.register({
|
|
2155
|
+
name: "sidebar.right.pane.tab.title",
|
|
2156
|
+
key: TEXT_TYPE,
|
|
2157
|
+
priority: -10
|
|
2158
|
+
}, textTitle(primitives()))), "kition: preview title");
|
|
2159
|
+
});
|
|
2160
|
+
ctx.inject(["sidebarRight"], (inner) => {
|
|
2161
|
+
environment.sidebar = inner.sidebarRight;
|
|
2162
|
+
if (typeof inner.sidebarRight.registerCloseHandler !== "function") return;
|
|
2163
|
+
for (const kind of [TAB_TYPE, TEXT_KIND]) inner.effect(() => {
|
|
2164
|
+
try {
|
|
2165
|
+
const dispose = inner.sidebarRight.registerCloseHandler(kind, closeGuard);
|
|
2166
|
+
guards[kind === "kition" ? "kition" : "text"] = true;
|
|
2167
|
+
return () => {
|
|
2168
|
+
guards[kind === "kition" ? "kition" : "text"] = false;
|
|
2169
|
+
dispose();
|
|
2170
|
+
};
|
|
2171
|
+
} catch {
|
|
2172
|
+
return () => void 0;
|
|
2173
|
+
}
|
|
2174
|
+
}, `kition: close guard (${kind})`);
|
|
2175
|
+
});
|
|
2176
|
+
if (location.protocol !== "dsh-app:") {
|
|
2177
|
+
const unloadGuard = (event) => {
|
|
2178
|
+
if (![...pages.values()].some((page) => page.dirty)) return;
|
|
2179
|
+
event.preventDefault();
|
|
2180
|
+
event.returnValue = "";
|
|
2181
|
+
};
|
|
2182
|
+
ctx.effect(() => {
|
|
2183
|
+
window.addEventListener("beforeunload", unloadGuard);
|
|
2184
|
+
return () => window.removeEventListener("beforeunload", unloadGuard);
|
|
2185
|
+
}, "kition: unload guard");
|
|
2186
|
+
}
|
|
2187
|
+
ctx.inject(["documentPreviews"], (inner) => {
|
|
2188
|
+
for (const [kit, extensions] of Object.entries(PREVIEW_EXTENSIONS)) {
|
|
2189
|
+
const id = previewId(kit);
|
|
2190
|
+
inner.effect(() => inner.slots.inject("sidebar.right.tab.document", () => inner.slots.register({
|
|
2191
|
+
name: "sidebar.right.tab.document",
|
|
2192
|
+
key: id
|
|
2193
|
+
}, PreviewBody)), `kition: ${kit} preview body`);
|
|
2194
|
+
}
|
|
2195
|
+
let registered = [];
|
|
2196
|
+
let priority = null;
|
|
2197
|
+
const register = () => {
|
|
2198
|
+
const next = environment.settings.openWith === "kition" ? "extension" : "builtin";
|
|
2199
|
+
if (next === priority) return;
|
|
2200
|
+
priority = next;
|
|
2201
|
+
for (const dispose of registered) dispose();
|
|
2202
|
+
registered = Object.entries(PREVIEW_EXTENSIONS).map(([kit, extensions]) => inner.documentPreviews.register({
|
|
2203
|
+
id: previewId(kit),
|
|
2204
|
+
extensions,
|
|
2205
|
+
priority: next,
|
|
2206
|
+
loading: "renderer",
|
|
2207
|
+
title: () => environment.t("openWith", { kit: kitName(kit) })
|
|
2208
|
+
}));
|
|
2209
|
+
};
|
|
2210
|
+
register();
|
|
2211
|
+
inner.effect(() => {
|
|
2212
|
+
const stop = environment.subscribe(register);
|
|
2213
|
+
return () => {
|
|
2214
|
+
stop();
|
|
2215
|
+
for (const dispose of registered) dispose();
|
|
2216
|
+
registered = [];
|
|
2217
|
+
priority = null;
|
|
2218
|
+
};
|
|
2219
|
+
}, "kition: previews");
|
|
2220
|
+
});
|
|
2221
|
+
ctx.inject(["uiConversation"], (inner) => {
|
|
2222
|
+
try {
|
|
2223
|
+
inner.uiConversation.events.register(kitTurnDefinition);
|
|
2224
|
+
} catch (error) {
|
|
2225
|
+
if (!(error instanceof Error) || !/already registered/.test(error.message)) throw error;
|
|
2226
|
+
}
|
|
2227
|
+
inner.effect(() => inner.slots.inject("conversation.chat.turnTail", () => inner.slots.register({
|
|
2228
|
+
name: "conversation.chat.turnTail",
|
|
2229
|
+
id: "kition-cards"
|
|
2230
|
+
}, TurnCards)), "kition: review cards");
|
|
2231
|
+
inner.effect(() => inner.slots.inject("conversation.input.dock", () => inner.slots.register({
|
|
2232
|
+
name: "conversation.input.dock",
|
|
2233
|
+
id: "kition-live",
|
|
2234
|
+
order: 900
|
|
2235
|
+
}, LiveWatcher)), "kition: live window");
|
|
2236
|
+
});
|
|
2237
|
+
}
|
|
2238
|
+
/** DeepSeek Harness's UI primitives (the file type's sheet), from its module loader; null where it has none. */
|
|
2239
|
+
function primitives() {
|
|
2240
|
+
try {
|
|
2241
|
+
return require("@deepseek-ai/dsh-client-ui-primitives") ?? null;
|
|
2242
|
+
} catch {
|
|
2243
|
+
return null;
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
exports.TAB_TYPE = TAB_TYPE;
|
|
2247
|
+
exports.apply = apply;
|
|
2248
|
+
exports.inject = inject;
|
|
2249
|
+
exports.name = name;
|
|
2250
|
+
return module.exports;
|
|
2251
|
+
}
|
|
2252
|
+
});
|