@ceasarxuu/dsh-maid 0.0.0-stage → 0.1.16
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 +23 -2
- package/cordis.patch.yml +3 -0
- package/host/chrome.js +71 -0
- package/host/companion.js +27 -0
- package/host/memory.js +88 -0
- package/host/routes.js +79 -0
- package/host/runtime.js +491 -0
- package/host/schedules.js +130 -0
- package/host/store.js +84 -0
- package/host/tools.js +142 -0
- package/index.js +45 -0
- package/lib/client.js +867 -0
- package/package.json +61 -4
package/lib/client.js
ADDED
|
@@ -0,0 +1,867 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({id:"@ceasarxuu/dsh-maid",factory:(require)=>{const module={exports:{}};const exports=module.exports;
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// ui/client.jsx
|
|
31
|
+
var client_exports = {};
|
|
32
|
+
__export(client_exports, {
|
|
33
|
+
apply: () => apply,
|
|
34
|
+
inject: () => inject
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(client_exports);
|
|
37
|
+
var import_react6 = __toESM(require("react"), 1);
|
|
38
|
+
var import_dsh_client_ui_primitives4 = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
39
|
+
|
|
40
|
+
// ui/api.js
|
|
41
|
+
async function api(endpoint, options = {}) {
|
|
42
|
+
const { body, signal } = options;
|
|
43
|
+
const response = await fetch("/plugin/maid/" + endpoint, {
|
|
44
|
+
method: body === void 0 ? "GET" : "POST",
|
|
45
|
+
credentials: "same-origin",
|
|
46
|
+
headers: body === void 0 ? { Accept: "application/json" } : { "Content-Type": "application/json" },
|
|
47
|
+
body: body === void 0 ? void 0 : JSON.stringify(body),
|
|
48
|
+
cache: "no-store",
|
|
49
|
+
signal
|
|
50
|
+
});
|
|
51
|
+
const payload = await response.json().catch(() => null);
|
|
52
|
+
if (!response.ok || payload === null) throw new Error(payload?.error || "Maid \u6682\u65F6\u65E0\u6CD5\u8FDE\u63A5\u5230 DSH\u3002");
|
|
53
|
+
return payload;
|
|
54
|
+
}
|
|
55
|
+
function dateTime(value) {
|
|
56
|
+
if (!value) return "";
|
|
57
|
+
return new Intl.DateTimeFormat("zh-CN", { dateStyle: "medium", timeStyle: "short" }).format(new Date(value));
|
|
58
|
+
}
|
|
59
|
+
var statusLabel = {
|
|
60
|
+
queued: "\u6392\u961F\u4E2D",
|
|
61
|
+
running: "\u6B63\u5728\u6267\u884C",
|
|
62
|
+
waiting: "\u7B49\u4F60\u51B3\u5B9A",
|
|
63
|
+
blocked: "\u5F85\u63A5\u7EED",
|
|
64
|
+
completed: "\u5DF2\u5B8C\u6210",
|
|
65
|
+
cancelled: "\u5DF2\u505C\u6B62",
|
|
66
|
+
active: "\u5DF2\u542F\u7528",
|
|
67
|
+
paused: "\u5DF2\u6682\u505C",
|
|
68
|
+
ended: "\u5DF2\u7ED3\u675F"
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// ui/conversation-header.jsx
|
|
72
|
+
var import_react3 = __toESM(require("react"), 1);
|
|
73
|
+
|
|
74
|
+
// ui/settings.jsx
|
|
75
|
+
var import_react2 = __toESM(require("react"), 1);
|
|
76
|
+
var import_dsh_client_ui_primitives2 = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
77
|
+
|
|
78
|
+
// ui/fields.jsx
|
|
79
|
+
var import_react = __toESM(require("react"), 1);
|
|
80
|
+
var import_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
81
|
+
function TextField({ label, ...input }) {
|
|
82
|
+
return /* @__PURE__ */ import_react.default.createElement("label", { className: "maid-native-field" }, /* @__PURE__ */ import_react.default.createElement("span", null, label), /* @__PURE__ */ import_react.default.createElement(import_dsh_client_ui_primitives.Input, { ...input }));
|
|
83
|
+
}
|
|
84
|
+
function EditorField({ label, value, onChange, onSubmit, onCancel }) {
|
|
85
|
+
return /* @__PURE__ */ import_react.default.createElement("div", { className: "maid-native-field" }, /* @__PURE__ */ import_react.default.createElement("span", null, label), /* @__PURE__ */ import_react.default.createElement(import_dsh_client_ui_primitives.InlineEditor, { label, value, onChange, onSave: onSubmit, onCancel }));
|
|
86
|
+
}
|
|
87
|
+
function ChoiceField({ label, value, choices, onChange }) {
|
|
88
|
+
const [open, setOpen] = (0, import_react.useState)(false);
|
|
89
|
+
return /* @__PURE__ */ import_react.default.createElement("div", { className: "maid-native-field" }, /* @__PURE__ */ import_react.default.createElement("span", null, label), /* @__PURE__ */ import_react.default.createElement(
|
|
90
|
+
import_dsh_client_ui_primitives.Menu,
|
|
91
|
+
{
|
|
92
|
+
open,
|
|
93
|
+
onClose: () => setOpen(false),
|
|
94
|
+
selectedId: value,
|
|
95
|
+
items: choices,
|
|
96
|
+
onSelect: (id) => {
|
|
97
|
+
onChange(id);
|
|
98
|
+
setOpen(false);
|
|
99
|
+
},
|
|
100
|
+
portal: true,
|
|
101
|
+
autoFocus: true,
|
|
102
|
+
anchor: /* @__PURE__ */ import_react.default.createElement(
|
|
103
|
+
import_dsh_client_ui_primitives.Button,
|
|
104
|
+
{
|
|
105
|
+
variant: "outline",
|
|
106
|
+
"aria-label": label,
|
|
107
|
+
"aria-haspopup": "menu",
|
|
108
|
+
"aria-expanded": open,
|
|
109
|
+
onClick: () => setOpen((current) => !current)
|
|
110
|
+
},
|
|
111
|
+
choices.find((item) => item.id === value)?.label,
|
|
112
|
+
/* @__PURE__ */ import_react.default.createElement(import_dsh_client_ui_primitives.IconChevronDownOutlineRegular, { size: 14 })
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
));
|
|
116
|
+
}
|
|
117
|
+
function StateMessage({ error, loading, retry }) {
|
|
118
|
+
if (error) return /* @__PURE__ */ import_react.default.createElement("div", { className: "maid-native-actions" }, /* @__PURE__ */ import_react.default.createElement("p", { role: "alert" }, error), retry && /* @__PURE__ */ import_react.default.createElement(import_dsh_client_ui_primitives.Button, { size: "sm", onClick: retry }, "\u91CD\u8BD5"));
|
|
119
|
+
return loading ? /* @__PURE__ */ import_react.default.createElement("p", { role: "status" }, loading) : null;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// ui/settings.jsx
|
|
123
|
+
function Persona() {
|
|
124
|
+
const [text, setText] = (0, import_react2.useState)(null);
|
|
125
|
+
const [draft, setDraft] = (0, import_react2.useState)(null);
|
|
126
|
+
const [result, setResult] = (0, import_react2.useState)("");
|
|
127
|
+
const [error, setError] = (0, import_react2.useState)("");
|
|
128
|
+
const [busy, setBusy] = (0, import_react2.useState)(false);
|
|
129
|
+
(0, import_react2.useEffect)(() => {
|
|
130
|
+
const controller = new AbortController();
|
|
131
|
+
api("persona", { signal: controller.signal }).then((value) => setText(value.text)).catch((error2) => {
|
|
132
|
+
if (!controller.signal.aborted) setError(error2.message);
|
|
133
|
+
});
|
|
134
|
+
return () => controller.abort();
|
|
135
|
+
}, []);
|
|
136
|
+
async function save(value) {
|
|
137
|
+
if (busy || value !== "" && !value?.trim()) return;
|
|
138
|
+
setError("");
|
|
139
|
+
setResult("");
|
|
140
|
+
setBusy(true);
|
|
141
|
+
try {
|
|
142
|
+
setText(await api("persona", { body: { text: value } }));
|
|
143
|
+
setDraft(null);
|
|
144
|
+
setResult("\u6027\u683C\u8BBE\u7F6E\u5DF2\u4FDD\u5B58\u3002");
|
|
145
|
+
} catch (error2) {
|
|
146
|
+
setError(error2.message);
|
|
147
|
+
} finally {
|
|
148
|
+
setBusy(false);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return /* @__PURE__ */ import_react2.default.createElement("section", { className: "maid-native-settings" }, /* @__PURE__ */ import_react2.default.createElement("div", { className: "maid-native-heading" }, /* @__PURE__ */ import_react2.default.createElement("h2", null, "\u6027\u683C"), text !== null && /* @__PURE__ */ import_react2.default.createElement(import_dsh_client_ui_primitives2.Button, { onClick: () => {
|
|
152
|
+
setDraft(text);
|
|
153
|
+
setResult("");
|
|
154
|
+
} }, "\u7F16\u8F91")), /* @__PURE__ */ import_react2.default.createElement(StateMessage, { error: draft === null ? error : "", loading: text === null ? "\u6B63\u5728\u8BFB\u53D6\u6027\u683C\u8BBE\u7F6E\u2026" : void 0 }), text !== null && /* @__PURE__ */ import_react2.default.createElement("p", { className: "maid-native-note" }, text), /* @__PURE__ */ import_react2.default.createElement("p", { role: "status" }, result), draft !== null && /* @__PURE__ */ import_react2.default.createElement(
|
|
155
|
+
import_dsh_client_ui_primitives2.Modal,
|
|
156
|
+
{
|
|
157
|
+
open: true,
|
|
158
|
+
title: "\u7F16\u8F91 Maid \u6027\u683C",
|
|
159
|
+
closeLabel: "\u5173\u95ED",
|
|
160
|
+
onClose: () => setDraft(null),
|
|
161
|
+
footer: /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, /* @__PURE__ */ import_react2.default.createElement(import_dsh_client_ui_primitives2.Button, { variant: "outline", onClick: () => save(""), disabled: busy }, "\u6062\u590D\u9ED8\u8BA4"), /* @__PURE__ */ import_react2.default.createElement(import_dsh_client_ui_primitives2.Button, { variant: "primary", onClick: () => save(draft), disabled: busy || !draft.trim() }, "\u4FDD\u5B58\u6027\u683C"))
|
|
162
|
+
},
|
|
163
|
+
/* @__PURE__ */ import_react2.default.createElement("div", { className: "maid-native-form" }, /* @__PURE__ */ import_react2.default.createElement(
|
|
164
|
+
EditorField,
|
|
165
|
+
{
|
|
166
|
+
label: "\u8BF4\u8BDD\u548C\u505A\u4E8B\u7684\u98CE\u683C",
|
|
167
|
+
value: draft,
|
|
168
|
+
onChange: (value) => setDraft(value.slice(0, 4e3)),
|
|
169
|
+
onSubmit: () => save(draft),
|
|
170
|
+
onCancel: () => setDraft(null)
|
|
171
|
+
}
|
|
172
|
+
), /* @__PURE__ */ import_react2.default.createElement(StateMessage, { error }))
|
|
173
|
+
));
|
|
174
|
+
}
|
|
175
|
+
var empty = { topic: "", scope: "", fact: "" };
|
|
176
|
+
function Memory() {
|
|
177
|
+
const [list, setList] = (0, import_react2.useState)(null);
|
|
178
|
+
const [query, setQuery] = (0, import_react2.useState)("");
|
|
179
|
+
const [editing, setEditing] = (0, import_react2.useState)(null);
|
|
180
|
+
const [forgetting, setForgetting] = (0, import_react2.useState)(null);
|
|
181
|
+
const [source, setSource] = (0, import_react2.useState)(null);
|
|
182
|
+
const [error, setError] = (0, import_react2.useState)("");
|
|
183
|
+
const [busy, setBusy] = (0, import_react2.useState)(false);
|
|
184
|
+
async function find(text, signal) {
|
|
185
|
+
try {
|
|
186
|
+
const result = await api("memory?query=" + encodeURIComponent(text), { signal });
|
|
187
|
+
if (!signal?.aborted) setList(result);
|
|
188
|
+
} catch (error2) {
|
|
189
|
+
if (!signal?.aborted) setError(error2.message);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
(0, import_react2.useEffect)(() => {
|
|
193
|
+
const controller = new AbortController();
|
|
194
|
+
void find("", controller.signal);
|
|
195
|
+
return () => controller.abort();
|
|
196
|
+
}, []);
|
|
197
|
+
async function save() {
|
|
198
|
+
if (busy || !editing.topic.trim() || !editing.fact.trim()) return;
|
|
199
|
+
setError("");
|
|
200
|
+
setBusy(true);
|
|
201
|
+
try {
|
|
202
|
+
await api("memory", { body: editing });
|
|
203
|
+
setEditing(null);
|
|
204
|
+
await find(query);
|
|
205
|
+
} catch (error2) {
|
|
206
|
+
setError(error2.message);
|
|
207
|
+
} finally {
|
|
208
|
+
setBusy(false);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
async function forget() {
|
|
212
|
+
if (busy) return;
|
|
213
|
+
setError("");
|
|
214
|
+
setBusy(true);
|
|
215
|
+
try {
|
|
216
|
+
await api("memory/forget", { body: { id: forgetting.id } });
|
|
217
|
+
setForgetting(null);
|
|
218
|
+
if (source?.id === forgetting.id) setSource(null);
|
|
219
|
+
await find(query);
|
|
220
|
+
} catch (error2) {
|
|
221
|
+
setError(error2.message);
|
|
222
|
+
} finally {
|
|
223
|
+
setBusy(false);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
async function original(entry) {
|
|
227
|
+
if (source?.id === entry.id) {
|
|
228
|
+
setSource(null);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
setError("");
|
|
232
|
+
try {
|
|
233
|
+
const result = await api("memory/source?id=" + encodeURIComponent(entry.id));
|
|
234
|
+
setSource({ id: entry.id, text: result.text });
|
|
235
|
+
} catch (error2) {
|
|
236
|
+
setError(error2.message);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const edit = (entry) => {
|
|
240
|
+
setError("");
|
|
241
|
+
setEditing(entry);
|
|
242
|
+
};
|
|
243
|
+
const change = (key, value) => setEditing((current) => ({ ...current, [key]: value }));
|
|
244
|
+
return /* @__PURE__ */ import_react2.default.createElement("section", { className: "maid-native-settings" }, /* @__PURE__ */ import_react2.default.createElement("div", { className: "maid-native-heading" }, /* @__PURE__ */ import_react2.default.createElement("h2", null, "\u8BB0\u5FC6"), /* @__PURE__ */ import_react2.default.createElement(import_dsh_client_ui_primitives2.Button, { icon: /* @__PURE__ */ import_react2.default.createElement(import_dsh_client_ui_primitives2.IconPlusOutlineRegular, { size: 16 }), onClick: () => edit(empty) }, "\u8BB0\u5F55\u4E8B\u5B9E")), /* @__PURE__ */ import_react2.default.createElement("form", { className: "maid-native-actions", onSubmit: (event) => {
|
|
245
|
+
event.preventDefault();
|
|
246
|
+
setError("");
|
|
247
|
+
void find(query);
|
|
248
|
+
} }, /* @__PURE__ */ import_react2.default.createElement(
|
|
249
|
+
import_dsh_client_ui_primitives2.Input,
|
|
250
|
+
{
|
|
251
|
+
icon: /* @__PURE__ */ import_react2.default.createElement(import_dsh_client_ui_primitives2.IconSearchOutlineRegular, { size: 16 }),
|
|
252
|
+
type: "search",
|
|
253
|
+
"aria-label": "\u641C\u7D22\u8BB0\u5FC6",
|
|
254
|
+
placeholder: "\u641C\u7D22\u8BB0\u5FC6",
|
|
255
|
+
value: query,
|
|
256
|
+
maxLength: 500,
|
|
257
|
+
onChange: (event) => setQuery(event.target.value)
|
|
258
|
+
}
|
|
259
|
+
), /* @__PURE__ */ import_react2.default.createElement(import_dsh_client_ui_primitives2.Button, { type: "submit" }, "\u641C\u7D22")), /* @__PURE__ */ import_react2.default.createElement(StateMessage, { error: !editing && !forgetting ? error : "", loading: list === null ? "\u6B63\u5728\u8BFB\u53D6\u8BB0\u5FC6\u2026" : void 0 }), list?.length === 0 && /* @__PURE__ */ import_react2.default.createElement("p", { className: "maid-native-muted" }, query ? "\u6CA1\u6709\u627E\u5230\u76F8\u5173\u4E8B\u5B9E\u3002" : "\u8FD8\u6CA1\u6709\u8BB0\u5F55\u4E8B\u5B9E\u3002"), /* @__PURE__ */ import_react2.default.createElement("ul", { className: "maid-native-list" }, list?.map((entry) => /* @__PURE__ */ import_react2.default.createElement("li", { className: "maid-native-note", key: entry.id }, /* @__PURE__ */ import_react2.default.createElement("div", { className: "maid-native-heading" }, /* @__PURE__ */ import_react2.default.createElement("h3", null, entry.topic), /* @__PURE__ */ import_react2.default.createElement(import_dsh_client_ui_primitives2.Tag, { tone: "quiet" }, entry.scope)), /* @__PURE__ */ import_react2.default.createElement("p", null, entry.fact), /* @__PURE__ */ import_react2.default.createElement("small", null, entry.fromChat ? "\u6765\u81EA\u5BF9\u8BDD" : entry.source, " \xB7 ", dateTime(entry.updatedAt)), source?.id === entry.id && /* @__PURE__ */ import_react2.default.createElement("blockquote", null, source.text), /* @__PURE__ */ import_react2.default.createElement("div", { className: "maid-native-actions" }, entry.fromChat && /* @__PURE__ */ import_react2.default.createElement(import_dsh_client_ui_primitives2.Button, { size: "sm", onClick: () => original(entry), "aria-expanded": source?.id === entry.id }, source?.id === entry.id ? "\u6536\u8D77\u539F\u8BDD" : "\u67E5\u770B\u539F\u8BDD"), /* @__PURE__ */ import_react2.default.createElement(import_dsh_client_ui_primitives2.Button, { size: "sm", onClick: () => edit(entry) }, "\u7F16\u8F91"), /* @__PURE__ */ import_react2.default.createElement(import_dsh_client_ui_primitives2.Button, { size: "sm", onClick: () => {
|
|
260
|
+
setError("");
|
|
261
|
+
setForgetting(entry);
|
|
262
|
+
} }, "\u5FD8\u6389"))))), editing && /* @__PURE__ */ import_react2.default.createElement(
|
|
263
|
+
import_dsh_client_ui_primitives2.Modal,
|
|
264
|
+
{
|
|
265
|
+
open: true,
|
|
266
|
+
title: editing.id ? "\u7F16\u8F91\u4E8B\u5B9E" : "\u8BB0\u5F55\u4E8B\u5B9E",
|
|
267
|
+
closeLabel: "\u5173\u95ED",
|
|
268
|
+
onClose: () => setEditing(null),
|
|
269
|
+
footer: /* @__PURE__ */ import_react2.default.createElement(import_dsh_client_ui_primitives2.Button, { variant: "primary", onClick: save, disabled: busy || !editing.topic.trim() || !editing.fact.trim() }, "\u4FDD\u5B58\u4E8B\u5B9E")
|
|
270
|
+
},
|
|
271
|
+
/* @__PURE__ */ import_react2.default.createElement("div", { className: "maid-native-form" }, /* @__PURE__ */ import_react2.default.createElement(TextField, { label: "\u4E3B\u9898", value: editing.topic, onChange: (event) => change("topic", event.target.value), maxLength: 120 }), /* @__PURE__ */ import_react2.default.createElement(TextField, { label: "\u8303\u56F4", value: editing.scope, onChange: (event) => change("scope", event.target.value), placeholder: "\u5168\u5C40", maxLength: 120 }), /* @__PURE__ */ import_react2.default.createElement(
|
|
272
|
+
EditorField,
|
|
273
|
+
{
|
|
274
|
+
label: "\u4E8B\u5B9E",
|
|
275
|
+
value: editing.fact,
|
|
276
|
+
onChange: (value) => change("fact", value.slice(0, 4e3)),
|
|
277
|
+
onSubmit: save,
|
|
278
|
+
onCancel: () => setEditing(null)
|
|
279
|
+
}
|
|
280
|
+
), /* @__PURE__ */ import_react2.default.createElement(StateMessage, { error }))
|
|
281
|
+
), forgetting && /* @__PURE__ */ import_react2.default.createElement(
|
|
282
|
+
import_dsh_client_ui_primitives2.Modal,
|
|
283
|
+
{
|
|
284
|
+
open: true,
|
|
285
|
+
tone: "warning",
|
|
286
|
+
title: "\u5FD8\u8BB0\u4E8B\u5B9E",
|
|
287
|
+
closeLabel: "\u5173\u95ED",
|
|
288
|
+
onClose: () => setForgetting(null),
|
|
289
|
+
description: "\u5FD8\u6389\u300C" + forgetting.topic + "\u300D\u91CC\u7684\u8FD9\u6761\u4E8B\u5B9E\uFF1F",
|
|
290
|
+
footer: /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, /* @__PURE__ */ import_react2.default.createElement(import_dsh_client_ui_primitives2.Button, { variant: "outline", onClick: () => setForgetting(null) }, "\u53D6\u6D88"), /* @__PURE__ */ import_react2.default.createElement(import_dsh_client_ui_primitives2.Button, { variant: "primary", onClick: forget, disabled: busy }, "\u786E\u8BA4\u5FD8\u6389"))
|
|
291
|
+
},
|
|
292
|
+
/* @__PURE__ */ import_react2.default.createElement(StateMessage, { error })
|
|
293
|
+
));
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// ui/conversation-header.css
|
|
297
|
+
var conversation_header_default = '[data-slot="conversation.session.header"]:has([data-maid-header]) nav,\n[data-slot="conversation.session.header.actions"]:has(> [data-maid-header]) > span[title]:has(> svg),\n[data-slot="conversation.session.header"]:has([data-maid-header]) > :has(> [data-conversation-tabs]) > :not([data-conversation-tabs]) {\n display: none;\n}\n\nheader:has(> [data-slot="conversation.session.header"] [data-maid-header]) {\n grid-template-columns: auto minmax(0, 1fr) auto;\n min-block-size: 38px;\n}\n\n/* Keep the native header utilities beside the tabs on the same grid row. */\n[data-slot="conversation.session.header"] > :has([data-maid-header]) {\n grid-area: 1 / 3;\n align-self: center;\n min-block-size: 0;\n padding-inline-start: 0;\n container-type: normal;\n}\n\n/* The native row budgets 120px per tab and reserves 48px for its More menu. */\n[data-slot="conversation.session.header"]:has([data-maid-header]) > :has(> [data-conversation-tabs]) {\n grid-area: 1 / 2;\n align-self: end;\n margin-block-start: 0;\n min-inline-size: 288px;\n /* The header is inset 20px and the native tab hit target extends 10px left of its label. */\n padding-inline-start: max(8px, calc(var(--dsh-frame-leading-clearance, 0px) - 10px));\n pointer-events: none;\n}\n\n[data-slot="conversation.session.header"]:has([data-maid-header]) [data-conversation-tabs] > button {\n pointer-events: auto;\n}\n\n.maid-conversation-settings {\n display: grid;\n align-content: start;\n gap: 24px;\n inline-size: 100%;\n max-inline-size: var(--dsh-chat-content-width, 748px);\n box-sizing: border-box;\n margin-inline: auto;\n padding: 24px;\n}\n\n[data-conversation-scroll]:has(.maid-conversation-settings) > [data-composer-seat] {\n display: none;\n}\n';
|
|
298
|
+
|
|
299
|
+
// ui/conversation-header.jsx
|
|
300
|
+
var settingsView = "@ceasarxuu/dsh-maid/settings";
|
|
301
|
+
function registerMaidConversationHeader(ctx, useAttention, register) {
|
|
302
|
+
function Settings({ sessionId }) {
|
|
303
|
+
const { sessionId: maidSessionId } = useAttention();
|
|
304
|
+
if (sessionId !== maidSessionId) return null;
|
|
305
|
+
return /* @__PURE__ */ import_react3.default.createElement("div", { className: "maid-conversation-settings" }, /* @__PURE__ */ import_react3.default.createElement(Persona, null), /* @__PURE__ */ import_react3.default.createElement(Memory, null));
|
|
306
|
+
}
|
|
307
|
+
let headers = 0;
|
|
308
|
+
let disposeView;
|
|
309
|
+
function HeaderMarker({ sessionId }) {
|
|
310
|
+
const { sessionId: maidSessionId } = useAttention();
|
|
311
|
+
const isMaid = sessionId === maidSessionId;
|
|
312
|
+
(0, import_react3.useLayoutEffect)(() => {
|
|
313
|
+
if (!isMaid) return;
|
|
314
|
+
if (headers === 0) {
|
|
315
|
+
disposeView = ctx.slots.inject("conversation.view", () => ctx.slots.register({
|
|
316
|
+
name: "conversation.view",
|
|
317
|
+
id: settingsView,
|
|
318
|
+
order: Number.MIN_SAFE_INTEGER,
|
|
319
|
+
label: () => "\u8BBE\u7F6E"
|
|
320
|
+
}, Settings));
|
|
321
|
+
}
|
|
322
|
+
headers++;
|
|
323
|
+
return () => {
|
|
324
|
+
headers--;
|
|
325
|
+
if (headers === 0) {
|
|
326
|
+
disposeView?.();
|
|
327
|
+
disposeView = void 0;
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
}, [isMaid]);
|
|
331
|
+
return isMaid ? /* @__PURE__ */ import_react3.default.createElement("span", { "data-maid-header": "", hidden: true }) : null;
|
|
332
|
+
}
|
|
333
|
+
register("conversation.session.header.actions", { id: "maid-header" }, HeaderMarker);
|
|
334
|
+
ctx.effect(() => {
|
|
335
|
+
const tag = document.createElement("style");
|
|
336
|
+
tag.textContent = conversation_header_default;
|
|
337
|
+
document.head.append(tag);
|
|
338
|
+
return () => tag.remove();
|
|
339
|
+
}, "maid: conversation header styles");
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// ui/notebook.jsx
|
|
343
|
+
var import_react4 = __toESM(require("react"), 1);
|
|
344
|
+
var import_dsh_client_ui_primitives3 = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
345
|
+
var later = ["waiting", "blocked"];
|
|
346
|
+
var ended = ["completed", "cancelled"];
|
|
347
|
+
var scheduleFilters = [{ id: "current", label: "\u9690\u85CF\u5DF2\u7ED3\u675F" }, { id: "all", label: "\u5168\u90E8\u5B89\u6392" }];
|
|
348
|
+
var repeatOptions = [{ id: "once", label: "\u4EC5\u4E00\u6B21" }, { id: "daily", label: "\u6BCF\u5929" }, { id: "weekly", label: "\u6BCF\u5468" }];
|
|
349
|
+
var dayOptions = ["\u4E00", "\u4E8C", "\u4E09", "\u56DB", "\u4E94", "\u516D", "\u65E5"].map((day, index) => ({ id: String(index + 1), label: "\u5468" + day }));
|
|
350
|
+
var zone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
351
|
+
function useNotebook() {
|
|
352
|
+
const [model, setModel] = (0, import_react4.useState)(null);
|
|
353
|
+
const [error, setError] = (0, import_react4.useState)("");
|
|
354
|
+
const scope = (0, import_react4.useRef)(null);
|
|
355
|
+
const requests = (0, import_react4.useRef)(0);
|
|
356
|
+
const refresh = (0, import_react4.useCallback)(async () => {
|
|
357
|
+
const signal = scope.current?.signal;
|
|
358
|
+
const request = ++requests.current;
|
|
359
|
+
try {
|
|
360
|
+
const current = await api("notebook", { signal });
|
|
361
|
+
if (!signal?.aborted && request === requests.current) {
|
|
362
|
+
setModel(current);
|
|
363
|
+
setError("");
|
|
364
|
+
}
|
|
365
|
+
} catch (error2) {
|
|
366
|
+
if (!signal?.aborted && request === requests.current) setError(error2.message);
|
|
367
|
+
}
|
|
368
|
+
}, []);
|
|
369
|
+
(0, import_react4.useEffect)(() => {
|
|
370
|
+
const controller = new AbortController();
|
|
371
|
+
scope.current = controller;
|
|
372
|
+
let timer;
|
|
373
|
+
async function poll() {
|
|
374
|
+
await refresh();
|
|
375
|
+
if (!controller.signal.aborted) timer = setTimeout(poll, 2400);
|
|
376
|
+
}
|
|
377
|
+
void poll();
|
|
378
|
+
return () => {
|
|
379
|
+
controller.abort();
|
|
380
|
+
clearTimeout(timer);
|
|
381
|
+
};
|
|
382
|
+
}, [refresh]);
|
|
383
|
+
return { model, error, refresh };
|
|
384
|
+
}
|
|
385
|
+
function statusOf(task) {
|
|
386
|
+
if (task.kind === "watch" && task.status === "waiting") return "\u6B63\u5728\u76D1\u542C\u4F1A\u8BDD";
|
|
387
|
+
if (task.kind === "schedule" && task.status === "waiting") return "\u7B49\u5F85\u4E0B\u6B21\u8FD0\u884C";
|
|
388
|
+
return statusLabel[task.status] ?? task.status;
|
|
389
|
+
}
|
|
390
|
+
function statusIcon(task) {
|
|
391
|
+
if (task.status === "completed") return "done";
|
|
392
|
+
if (task.status === "blocked") return "error";
|
|
393
|
+
if (task.status === "waiting" && task.kind === "task") return "warning";
|
|
394
|
+
return task.status === "running" ? "ongoing" : "idle";
|
|
395
|
+
}
|
|
396
|
+
function TaskList({ title, items, open, empty: empty2 }) {
|
|
397
|
+
if (items.length === 0 && !empty2) return null;
|
|
398
|
+
return /* @__PURE__ */ import_react4.default.createElement("section", { className: "maid-native-section" }, /* @__PURE__ */ import_react4.default.createElement("h3", null, title), items.length === 0 ? /* @__PURE__ */ import_react4.default.createElement("p", { className: "maid-native-muted" }, empty2) : /* @__PURE__ */ import_react4.default.createElement("ul", { className: "maid-native-list" }, items.map((task) => /* @__PURE__ */ import_react4.default.createElement("li", { key: task.id }, /* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.Button, { className: "maid-native-row", icon: /* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.StateDot, { state: statusIcon(task) }), onClick: () => open(task.id) }, /* @__PURE__ */ import_react4.default.createElement("span", null, task.title), /* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.Tag, { tone: task.status === "waiting" && task.kind === "task" ? "warning" : "quiet" }, statusOf(task)))))));
|
|
399
|
+
}
|
|
400
|
+
function MaidDock({ openNotebook }) {
|
|
401
|
+
const { model, error, refresh } = useNotebook();
|
|
402
|
+
const [expanded, setExpanded] = (0, import_react4.useState)(null);
|
|
403
|
+
const [failure, setFailure] = (0, import_react4.useState)("");
|
|
404
|
+
const [busy, setBusy] = (0, import_react4.useState)(null);
|
|
405
|
+
const [taskId, setTaskId] = (0, import_react4.useState)(null);
|
|
406
|
+
if (!model && !error) return null;
|
|
407
|
+
const notices = model?.notices ?? [];
|
|
408
|
+
const interrupted = model?.interruptedInputs ?? [];
|
|
409
|
+
const decision = notices.find((notice) => notice.kind === "waiting" && model.tasks.some((task) => task.id === notice.taskId && later.includes(task.status)));
|
|
410
|
+
const latest = decision ?? notices[0];
|
|
411
|
+
const open = expanded ?? Boolean(decision || interrupted.length || error);
|
|
412
|
+
if (!latest && interrupted.length === 0 && !error) return null;
|
|
413
|
+
async function retry(input) {
|
|
414
|
+
setFailure("");
|
|
415
|
+
setBusy(input.id);
|
|
416
|
+
try {
|
|
417
|
+
await api("message", { body: { id: input.id, text: input.text, mode: input.mode } });
|
|
418
|
+
await refresh();
|
|
419
|
+
} catch (error2) {
|
|
420
|
+
setFailure(error2.message);
|
|
421
|
+
} finally {
|
|
422
|
+
setBusy(null);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return /* @__PURE__ */ import_react4.default.createElement("section", { className: "maid-native-dock", "aria-label": "Maid \u52A8\u6001" }, /* @__PURE__ */ import_react4.default.createElement(
|
|
426
|
+
import_dsh_client_ui_primitives3.DisclosureRow,
|
|
427
|
+
{
|
|
428
|
+
title: "Maid \u52A8\u6001",
|
|
429
|
+
icon: /* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.IconChecklistOutlineRegular, { size: 16 }),
|
|
430
|
+
open,
|
|
431
|
+
expandable: true,
|
|
432
|
+
expandOnRowClick: true,
|
|
433
|
+
onToggle: () => setExpanded(!open),
|
|
434
|
+
collapsedContent: decision && /* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.Tag, { tone: "warning" }, "\u5F85\u4F60\u5904\u7406")
|
|
435
|
+
},
|
|
436
|
+
/* @__PURE__ */ import_react4.default.createElement("div", { className: "maid-native-dock-body" }, /* @__PURE__ */ import_react4.default.createElement(StateMessage, { error: failure || error }), latest && /* @__PURE__ */ import_react4.default.createElement("div", { className: "maid-native-activity" }, /* @__PURE__ */ import_react4.default.createElement("p", null, latest.text), /* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.Button, { size: "sm", onClick: () => setTaskId(latest.taskId) }, "\u67E5\u770B\u4EFB\u52A1")), interrupted.map((input) => /* @__PURE__ */ import_react4.default.createElement("div", { className: "maid-native-activity", key: input.id }, /* @__PURE__ */ import_react4.default.createElement("p", null, /* @__PURE__ */ import_react4.default.createElement("strong", null, "\u5F85\u91CD\u65B0\u6295\u9012"), " \xB7 ", input.text), /* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.Button, { size: "sm", disabled: busy === input.id, onClick: () => retry(input) }, "\u91CD\u8BD5"))), notices.length > 1 && /* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.Button, { size: "sm", onClick: openNotebook }, "\u67E5\u770B\u5168\u90E8\u52A8\u6001"))
|
|
437
|
+
), taskId && /* @__PURE__ */ import_react4.default.createElement(TaskDialog, { model, id: taskId, onClose: () => setTaskId(null), refresh }));
|
|
438
|
+
}
|
|
439
|
+
function Notebook() {
|
|
440
|
+
const { model, error, refresh } = useNotebook();
|
|
441
|
+
const [dialog, setDialog] = (0, import_react4.useState)(null);
|
|
442
|
+
const [scheduleFilter, setScheduleFilter] = (0, import_react4.useState)("current");
|
|
443
|
+
const [filterOpen, setFilterOpen] = (0, import_react4.useState)(false);
|
|
444
|
+
const openTask = (id) => setDialog({ kind: "detail", id });
|
|
445
|
+
if (!model) return /* @__PURE__ */ import_react4.default.createElement("div", { className: "maid-native-sheet" }, /* @__PURE__ */ import_react4.default.createElement(StateMessage, { error, loading: "\u6B63\u5728\u8BFB\u53D6\u8BB0\u4E8B\u672C\u2026", retry: refresh }));
|
|
446
|
+
const tasks = model.tasks.filter((task) => task.kind !== "schedule");
|
|
447
|
+
const waiting = tasks.filter((task) => later.includes(task.status) && task.kind !== "watch");
|
|
448
|
+
const finished = tasks.filter((task) => ended.includes(task.status));
|
|
449
|
+
const working = tasks.filter((task) => !waiting.includes(task) && !finished.includes(task));
|
|
450
|
+
const selectedSchedule = model.schedules.find((item) => item.id === dialog?.id);
|
|
451
|
+
const visibleSchedules = scheduleFilter === "all" ? model.schedules : model.schedules.filter((item) => item.status !== "ended");
|
|
452
|
+
return /* @__PURE__ */ import_react4.default.createElement("div", { className: "maid-native-sheet" }, /* @__PURE__ */ import_react4.default.createElement("div", { className: "maid-native-actions" }, /* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.Button, { size: "sm", icon: /* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.IconEditOutlineRegular, { size: 16 }), onClick: () => setDialog({ kind: "note" }) }, "\u5199\u7B14\u8BB0"), /* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.Button, { size: "sm", icon: /* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.IconPlusOutlineRegular, { size: 16 }), onClick: () => setDialog({ kind: "task" }) }, "\u65B0\u5EFA\u4EFB\u52A1")), /* @__PURE__ */ import_react4.default.createElement(StateMessage, { error, retry: refresh }), /* @__PURE__ */ import_react4.default.createElement(TaskList, { title: "\u5F85\u4F60\u5904\u7406", items: waiting, open: openTask }), /* @__PURE__ */ import_react4.default.createElement(TaskList, { title: "\u6B63\u5728\u8DDF\u8FDB", items: working, open: openTask, empty: "\u5F53\u524D\u6CA1\u6709\u6B63\u5728\u8DDF\u8FDB\u7684\u4EFB\u52A1\u3002" }), model.scheduleAvailable && /* @__PURE__ */ import_react4.default.createElement("section", { className: "maid-native-section" }, /* @__PURE__ */ import_react4.default.createElement("div", { className: "maid-native-heading" }, /* @__PURE__ */ import_react4.default.createElement("h3", null, "\u5B9A\u65F6\u5B89\u6392"), /* @__PURE__ */ import_react4.default.createElement("div", { className: "maid-native-actions" }, /* @__PURE__ */ import_react4.default.createElement(
|
|
453
|
+
import_dsh_client_ui_primitives3.Menu,
|
|
454
|
+
{
|
|
455
|
+
open: filterOpen,
|
|
456
|
+
onClose: () => setFilterOpen(false),
|
|
457
|
+
selectedId: scheduleFilter,
|
|
458
|
+
items: scheduleFilters,
|
|
459
|
+
onSelect: (id) => {
|
|
460
|
+
setScheduleFilter(id);
|
|
461
|
+
setFilterOpen(false);
|
|
462
|
+
},
|
|
463
|
+
portal: true,
|
|
464
|
+
autoFocus: true,
|
|
465
|
+
anchor: /* @__PURE__ */ import_react4.default.createElement(
|
|
466
|
+
import_dsh_client_ui_primitives3.Button,
|
|
467
|
+
{
|
|
468
|
+
size: "sm",
|
|
469
|
+
icon: /* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.IconSlidersTwoOutlineRegular, { size: 16 }),
|
|
470
|
+
"aria-haspopup": "menu",
|
|
471
|
+
"aria-expanded": filterOpen,
|
|
472
|
+
onClick: () => setFilterOpen((current) => !current)
|
|
473
|
+
},
|
|
474
|
+
"\u7B5B\u9009"
|
|
475
|
+
)
|
|
476
|
+
}
|
|
477
|
+
), /* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.Button, { size: "sm", icon: /* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.IconPlusOutlineRegular, { size: 16 }), onClick: () => setDialog({ kind: "schedule" }) }, "\u65B0\u5EFA"))), visibleSchedules.length === 0 && /* @__PURE__ */ import_react4.default.createElement("p", { className: "maid-native-muted" }, model.schedules.length === 0 ? "\u8FD8\u6CA1\u6709\u5B9A\u65F6\u4EFB\u52A1\u3002" : "\u6CA1\u6709\u672A\u7ED3\u675F\u7684\u5B9A\u65F6\u4EFB\u52A1\u3002"), /* @__PURE__ */ import_react4.default.createElement("ul", { className: "maid-native-list" }, visibleSchedules.map((item) => /* @__PURE__ */ import_react4.default.createElement("li", { key: item.id }, /* @__PURE__ */ import_react4.default.createElement(
|
|
478
|
+
import_dsh_client_ui_primitives3.Button,
|
|
479
|
+
{
|
|
480
|
+
className: "maid-native-row",
|
|
481
|
+
icon: /* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.IconClockOutlineRegular, { size: 16 }),
|
|
482
|
+
onClick: () => setDialog({ kind: "schedule", id: item.id })
|
|
483
|
+
},
|
|
484
|
+
/* @__PURE__ */ import_react4.default.createElement("span", null, item.title),
|
|
485
|
+
/* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.Tag, { tone: "quiet" }, item.next ? "\u4E0B\u6B21 " + dateTime(item.next) : statusLabel[item.status])
|
|
486
|
+
), item.result && /* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.Button, { size: "sm", onClick: () => openTask(item.taskId) }, "\u67E5\u770B\u4E0A\u6B21\u7ED3\u679C"))))), model.notes.length > 0 && /* @__PURE__ */ import_react4.default.createElement("section", { className: "maid-native-section" }, /* @__PURE__ */ import_react4.default.createElement("h3", null, "\u7B14\u8BB0"), /* @__PURE__ */ import_react4.default.createElement("ul", { className: "maid-native-list" }, model.notes.map((note) => /* @__PURE__ */ import_react4.default.createElement("li", { className: "maid-native-note", key: note.id }, /* @__PURE__ */ import_react4.default.createElement("p", null, note.text), /* @__PURE__ */ import_react4.default.createElement("small", null, dateTime(note.at)))))), /* @__PURE__ */ import_react4.default.createElement(TaskList, { title: "\u5DF2\u7ED3\u675F", items: finished, open: openTask }), model.notices.length > 0 && /* @__PURE__ */ import_react4.default.createElement("section", { className: "maid-native-section" }, /* @__PURE__ */ import_react4.default.createElement("h3", null, "\u8FD1\u671F\u52A8\u6001"), /* @__PURE__ */ import_react4.default.createElement("ul", { className: "maid-native-list" }, model.notices.map((notice) => /* @__PURE__ */ import_react4.default.createElement("li", { className: "maid-native-note", key: notice.id }, /* @__PURE__ */ import_react4.default.createElement("p", null, notice.text), /* @__PURE__ */ import_react4.default.createElement("div", { className: "maid-native-heading" }, /* @__PURE__ */ import_react4.default.createElement("small", null, dateTime(notice.at)), /* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.Button, { size: "sm", onClick: () => openTask(notice.taskId) }, "\u67E5\u770B\u4EFB\u52A1")))))), dialog?.kind === "detail" && /* @__PURE__ */ import_react4.default.createElement(TaskDialog, { model, id: dialog.id, onClose: () => setDialog(null), refresh }), (dialog?.kind === "task" || dialog?.kind === "note") && /* @__PURE__ */ import_react4.default.createElement(
|
|
487
|
+
NewWork,
|
|
488
|
+
{
|
|
489
|
+
kind: dialog.kind,
|
|
490
|
+
workspaces: model.workspaces,
|
|
491
|
+
close: () => setDialog(null),
|
|
492
|
+
refresh
|
|
493
|
+
}
|
|
494
|
+
), dialog?.kind === "schedule" && (!dialog.id || selectedSchedule) && /* @__PURE__ */ import_react4.default.createElement(ScheduleEditor, { initial: selectedSchedule, close: () => setDialog(null), refresh }));
|
|
495
|
+
}
|
|
496
|
+
function NewWork({ kind, workspaces, close, refresh }) {
|
|
497
|
+
const [title, setTitle] = (0, import_react4.useState)("");
|
|
498
|
+
const [text, setText] = (0, import_react4.useState)("");
|
|
499
|
+
const [workspaceId, setWorkspace] = (0, import_react4.useState)("");
|
|
500
|
+
const [busy, setBusy] = (0, import_react4.useState)(false);
|
|
501
|
+
const [error, setError] = (0, import_react4.useState)("");
|
|
502
|
+
const request = (0, import_react4.useRef)(null);
|
|
503
|
+
const isTask = kind === "task";
|
|
504
|
+
const ready = Boolean(text.trim()) && (!isTask || Boolean(title.trim()));
|
|
505
|
+
async function save() {
|
|
506
|
+
if (!ready || busy) return;
|
|
507
|
+
setBusy(true);
|
|
508
|
+
setError("");
|
|
509
|
+
const body = isTask ? { title, goal: text, workspaceId } : { text };
|
|
510
|
+
const serialized = JSON.stringify(body);
|
|
511
|
+
if (request.current?.serialized !== serialized) request.current = { id: crypto.randomUUID(), serialized };
|
|
512
|
+
try {
|
|
513
|
+
await api(kind, { body: { ...body, id: request.current.id } });
|
|
514
|
+
await refresh();
|
|
515
|
+
close();
|
|
516
|
+
} catch (error2) {
|
|
517
|
+
setError(error2.message);
|
|
518
|
+
} finally {
|
|
519
|
+
setBusy(false);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
return /* @__PURE__ */ import_react4.default.createElement(
|
|
523
|
+
import_dsh_client_ui_primitives3.Modal,
|
|
524
|
+
{
|
|
525
|
+
open: true,
|
|
526
|
+
title: isTask ? "\u65B0\u5EFA\u4EFB\u52A1" : "\u5199\u7B14\u8BB0",
|
|
527
|
+
closeLabel: "\u5173\u95ED",
|
|
528
|
+
onClose: close,
|
|
529
|
+
footer: /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null, /* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.Button, { variant: "outline", onClick: close }, "\u53D6\u6D88"), /* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.Button, { variant: "primary", onClick: save, disabled: !ready || busy }, "\u4FDD\u5B58"))
|
|
530
|
+
},
|
|
531
|
+
/* @__PURE__ */ import_react4.default.createElement("div", { className: "maid-native-form" }, isTask && /* @__PURE__ */ import_react4.default.createElement(TextField, { label: "\u4EFB\u52A1\u540D\u79F0", value: title, maxLength: 120, onChange: (event) => setTitle(event.target.value) }), /* @__PURE__ */ import_react4.default.createElement(
|
|
532
|
+
EditorField,
|
|
533
|
+
{
|
|
534
|
+
label: isTask ? "\u76EE\u6807" : "\u7B14\u8BB0",
|
|
535
|
+
value: text,
|
|
536
|
+
onChange: (value) => setText(value.slice(0, 12e3)),
|
|
537
|
+
onSubmit: save,
|
|
538
|
+
onCancel: close
|
|
539
|
+
}
|
|
540
|
+
), isTask && workspaces.length > 0 && /* @__PURE__ */ import_react4.default.createElement(
|
|
541
|
+
ChoiceField,
|
|
542
|
+
{
|
|
543
|
+
label: "\u5DE5\u4F5C\u533A",
|
|
544
|
+
value: workspaceId,
|
|
545
|
+
onChange: setWorkspace,
|
|
546
|
+
choices: [{ id: "", label: "\u4E2A\u4EBA\u4E8B\u52A1" }, ...workspaces.map((item) => ({ id: item.id, label: item.title }))]
|
|
547
|
+
}
|
|
548
|
+
), /* @__PURE__ */ import_react4.default.createElement(StateMessage, { error }))
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
function TaskDialog({ id, model, onClose, refresh }) {
|
|
552
|
+
const [task, setTask] = (0, import_react4.useState)(null);
|
|
553
|
+
const [error, setError] = (0, import_react4.useState)("");
|
|
554
|
+
const [reply, setReply] = (0, import_react4.useState)("");
|
|
555
|
+
const [busy, setBusy] = (0, import_react4.useState)(false);
|
|
556
|
+
const item = model?.tasks.find((row) => row.id === id);
|
|
557
|
+
(0, import_react4.useEffect)(() => {
|
|
558
|
+
const controller = new AbortController();
|
|
559
|
+
api("task?id=" + encodeURIComponent(id), { signal: controller.signal }).then(setTask).catch((error2) => {
|
|
560
|
+
if (!controller.signal.aborted) setError(error2.message);
|
|
561
|
+
});
|
|
562
|
+
return () => controller.abort();
|
|
563
|
+
}, [id, item?.latest, item?.status]);
|
|
564
|
+
async function act(endpoint, body) {
|
|
565
|
+
if (busy) return;
|
|
566
|
+
setBusy(true);
|
|
567
|
+
setError("");
|
|
568
|
+
try {
|
|
569
|
+
await api(endpoint, { body: { id, ...body } });
|
|
570
|
+
setReply("");
|
|
571
|
+
await refresh();
|
|
572
|
+
} catch (error2) {
|
|
573
|
+
setError(error2.message);
|
|
574
|
+
} finally {
|
|
575
|
+
setBusy(false);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
const continueTask = () => act("task/reply", { text: reply.trim() || "\u8BF7\u63A5\u7740\u5B8C\u6210\u8FD9\u4EF6\u4E8B\u3002" });
|
|
579
|
+
const followUp = task?.kind === "task" && later.includes(task.status);
|
|
580
|
+
const stoppable = task && task.kind !== "schedule" && !ended.includes(task.status);
|
|
581
|
+
return /* @__PURE__ */ import_react4.default.createElement(
|
|
582
|
+
import_dsh_client_ui_primitives3.Modal,
|
|
583
|
+
{
|
|
584
|
+
open: true,
|
|
585
|
+
title: item?.title || "\u4EFB\u52A1\u8BE6\u60C5",
|
|
586
|
+
closeLabel: "\u5173\u95ED",
|
|
587
|
+
onClose,
|
|
588
|
+
footer: /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null, stoppable && /* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.Button, { variant: "outline", disabled: busy, onClick: () => act("task/cancel") }, "\u505C\u6B62\u8DDF\u8FDB"), followUp && /* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.Button, { variant: "primary", disabled: busy, onClick: continueTask }, "\u7EE7\u7EED\u4EFB\u52A1"))
|
|
589
|
+
},
|
|
590
|
+
/* @__PURE__ */ import_react4.default.createElement(StateMessage, { error, loading: !task ? "\u6B63\u5728\u8BFB\u53D6\u4EFB\u52A1\u2026" : void 0 }),
|
|
591
|
+
task && /* @__PURE__ */ import_react4.default.createElement("div", { className: "maid-native-form" }, /* @__PURE__ */ import_react4.default.createElement("div", null, /* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.Tag, { tone: "neutral" }, statusOf(task))), /* @__PURE__ */ import_react4.default.createElement("section", null, /* @__PURE__ */ import_react4.default.createElement("h3", null, "\u76EE\u6807"), /* @__PURE__ */ import_react4.default.createElement("p", null, task.goal)), task.result && /* @__PURE__ */ import_react4.default.createElement("section", null, /* @__PURE__ */ import_react4.default.createElement("h3", null, "\u7ED3\u679C"), /* @__PURE__ */ import_react4.default.createElement("p", null, task.result)), task.history.length > 0 && /* @__PURE__ */ import_react4.default.createElement("section", null, /* @__PURE__ */ import_react4.default.createElement("h3", null, "\u8FDB\u5C55"), /* @__PURE__ */ import_react4.default.createElement("ol", { className: "maid-native-list" }, task.history.map((entry) => /* @__PURE__ */ import_react4.default.createElement("li", { className: "maid-native-note", key: entry.id }, /* @__PURE__ */ import_react4.default.createElement("small", null, dateTime(entry.at)), /* @__PURE__ */ import_react4.default.createElement("p", null, entry.text))))), followUp && /* @__PURE__ */ import_react4.default.createElement(
|
|
592
|
+
EditorField,
|
|
593
|
+
{
|
|
594
|
+
label: "\u8865\u5145\u4FE1\u606F",
|
|
595
|
+
value: reply,
|
|
596
|
+
onChange: (value) => setReply(value.slice(0, 12e3)),
|
|
597
|
+
onSubmit: continueTask,
|
|
598
|
+
onCancel: onClose
|
|
599
|
+
}
|
|
600
|
+
))
|
|
601
|
+
);
|
|
602
|
+
}
|
|
603
|
+
function localScheduleFields(value) {
|
|
604
|
+
const local = new Date(value ?? Date.now());
|
|
605
|
+
const pad = (number) => String(number).padStart(2, "0");
|
|
606
|
+
return {
|
|
607
|
+
date: `${local.getFullYear()}-${pad(local.getMonth() + 1)}-${pad(local.getDate())}`,
|
|
608
|
+
time: `${pad(local.getHours())}:${pad(local.getMinutes())}`
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
function ScheduleEditor({ initial, close, refresh }) {
|
|
612
|
+
const nativeSchedule = initial?.native === true;
|
|
613
|
+
const [title, setTitle] = (0, import_react4.useState)("");
|
|
614
|
+
const [goal, setGoal] = (0, import_react4.useState)("");
|
|
615
|
+
const [repeat, setRepeat] = (0, import_react4.useState)(repeatOptions.some((option) => option.id === initial?.repeat) ? initial.repeat : "weekly");
|
|
616
|
+
const [weekday, selectDay] = (0, import_react4.useState)(String(initial?.weekday ?? 5));
|
|
617
|
+
const [date, setDate] = (0, import_react4.useState)(() => localScheduleFields(initial?.scheduledAt).date);
|
|
618
|
+
const [time, setTime] = (0, import_react4.useState)(() => initial?.repeat === "once" ? localScheduleFields(initial.scheduledAt).time : initial?.time || "09:00");
|
|
619
|
+
const [timeZone, setZone] = (0, import_react4.useState)(initial?.repeat === "once" ? zone : initial?.timeZone || zone);
|
|
620
|
+
const [busy, setBusy] = (0, import_react4.useState)(false);
|
|
621
|
+
const [error, setError] = (0, import_react4.useState)("");
|
|
622
|
+
const stableId = (0, import_react4.useRef)(null);
|
|
623
|
+
const ready = Boolean(time && timeZone.trim() && (repeat !== "once" || date) && (initial || title.trim() && goal.trim()));
|
|
624
|
+
async function save(active) {
|
|
625
|
+
if (busy || typeof active !== "boolean" && (nativeSchedule || !ready)) return;
|
|
626
|
+
setBusy(true);
|
|
627
|
+
setError("");
|
|
628
|
+
const base = { id: initial?.id ?? (stableId.current ??= crypto.randomUUID()), revision: initial?.revision };
|
|
629
|
+
const body = typeof active === "boolean" ? { ...base, active } : { ...base, title, goal, repeat, time, timeZone, ...repeat === "once" ? { date } : { weekday: Number(weekday) } };
|
|
630
|
+
try {
|
|
631
|
+
await api(initial ? "schedule/edit" : "schedule", { body });
|
|
632
|
+
await refresh();
|
|
633
|
+
close();
|
|
634
|
+
} catch (error2) {
|
|
635
|
+
setError(error2.message);
|
|
636
|
+
} finally {
|
|
637
|
+
setBusy(false);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
return /* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.Modal, { open: true, title: initial?.title || "\u65B0\u5EFA\u5B9A\u65F6\u4EFB\u52A1", closeLabel: "\u5173\u95ED", onClose: close, footer: /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null, initial && initial.status !== "ended" && /* @__PURE__ */ import_react4.default.createElement(
|
|
641
|
+
import_dsh_client_ui_primitives3.Button,
|
|
642
|
+
{
|
|
643
|
+
variant: "outline",
|
|
644
|
+
disabled: busy,
|
|
645
|
+
onClick: () => save(initial.status === "paused")
|
|
646
|
+
},
|
|
647
|
+
initial.status === "paused" ? "\u6062\u590D\u4EFB\u52A1" : "\u6682\u505C\u4EFB\u52A1"
|
|
648
|
+
), !nativeSchedule && /* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.Button, { variant: "primary", disabled: !ready || busy, onClick: () => save() }, "\u4FDD\u5B58\u5B89\u6392")) }, /* @__PURE__ */ import_react4.default.createElement("div", { className: "maid-native-form" }, initial ? /* @__PURE__ */ import_react4.default.createElement("p", null, initial.goal) : /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null, /* @__PURE__ */ import_react4.default.createElement(TextField, { label: "\u540D\u79F0", value: title, maxLength: 120, onChange: (event) => setTitle(event.target.value) }), /* @__PURE__ */ import_react4.default.createElement(
|
|
649
|
+
EditorField,
|
|
650
|
+
{
|
|
651
|
+
label: "\u6267\u884C\u5185\u5BB9",
|
|
652
|
+
value: goal,
|
|
653
|
+
onChange: (value) => setGoal(value.slice(0, 12e3)),
|
|
654
|
+
onSubmit: () => save(),
|
|
655
|
+
onCancel: close
|
|
656
|
+
}
|
|
657
|
+
)), nativeSchedule ? /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null, /* @__PURE__ */ import_react4.default.createElement("div", { className: "maid-native-heading" }, initial.scheduledAt && /* @__PURE__ */ import_react4.default.createElement("p", null, "\u8BA1\u5212\u65F6\u95F4 ", dateTime(initial.scheduledAt)), /* @__PURE__ */ import_react4.default.createElement(import_dsh_client_ui_primitives3.Tag, { tone: "quiet" }, statusLabel[initial.status])), /* @__PURE__ */ import_react4.default.createElement("p", { className: "maid-native-muted" }, "\u53EF\u5728 DSH \u7684\u300C\u81EA\u52A8\u5316\u4EFB\u52A1\u300D\u4E2D\u4FEE\u6539\u6267\u884C\u89C4\u5219\u3002")) : /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null, /* @__PURE__ */ import_react4.default.createElement(ChoiceField, { label: "\u91CD\u590D", value: repeat, choices: repeatOptions, onChange: setRepeat }), repeat === "once" && /* @__PURE__ */ import_react4.default.createElement(TextField, { label: "\u65E5\u671F", type: "date", value: date, onChange: (event) => setDate(event.target.value) }), repeat === "weekly" && /* @__PURE__ */ import_react4.default.createElement(ChoiceField, { label: "\u661F\u671F", value: weekday, choices: dayOptions, onChange: selectDay }), /* @__PURE__ */ import_react4.default.createElement(TextField, { label: "\u65F6\u95F4", type: "time", value: time, onChange: (event) => setTime(event.target.value) }), /* @__PURE__ */ import_react4.default.createElement(TextField, { label: "\u65F6\u533A", value: timeZone, onChange: (event) => setZone(event.target.value), maxLength: 100 })), /* @__PURE__ */ import_react4.default.createElement(StateMessage, { error })));
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
// ui/sidebar-notebook.jsx
|
|
661
|
+
var import_react5 = __toESM(require("react"), 1);
|
|
662
|
+
var notebookKind = "maidNotebook";
|
|
663
|
+
var notebookId = "@ceasarxuu/dsh-maid/notebook";
|
|
664
|
+
var panelSelector = (sessionId) => `[data-sidebar-right-panel][data-sidebar-right-session="${CSS.escape(sessionId)}"]`;
|
|
665
|
+
function notebookOnlyCss(panel, tabId) {
|
|
666
|
+
const other = tabId ? `:not([data-dockkit-tab="${CSS.escape(tabId)}"])` : "";
|
|
667
|
+
const hiddenHost = tabId ? `:not(:has(> [data-dockkit-content="${CSS.escape(tabId)}"]))` : "";
|
|
668
|
+
return `
|
|
669
|
+
${panel} :is([data-dockkit-host]${hiddenHost}, [data-dockkit-host="float"], [data-dockkit-divider],
|
|
670
|
+
[data-dockkit-empty], [data-dockkit-add-tab], [data-dockkit-split-control],
|
|
671
|
+
[data-dockkit-tab-close], [data-dockkit-tab]${other}) { display: none !important; }
|
|
672
|
+
${panel} [data-dockkit-split] { grid-template-columns: minmax(0, 1fr) !important; }
|
|
673
|
+
${panel} [data-dockkit-host="dock"] { grid-column: 1 !important; }
|
|
674
|
+
/* DockKit draws its outer border on logical column 0. The notebook can occupy column 1. */
|
|
675
|
+
${panel}[data-sidebar-right-panel="push"] [data-dockkit-host="dock"][data-dockkit-column="1"] > [data-dockkit-content] {
|
|
676
|
+
border-left: 0.5px solid var(--dsw-alias-border-l4);
|
|
677
|
+
}
|
|
678
|
+
`;
|
|
679
|
+
}
|
|
680
|
+
function keepNotebookVisible(sidebar, attention) {
|
|
681
|
+
const style = document.createElement("style");
|
|
682
|
+
document.head.append(style);
|
|
683
|
+
let panel;
|
|
684
|
+
let watching = false;
|
|
685
|
+
let queued = false;
|
|
686
|
+
let stopped = false;
|
|
687
|
+
function selectNotebook() {
|
|
688
|
+
const { sessionId } = attention.getSnapshot();
|
|
689
|
+
const selector = sessionId ? panelSelector(sessionId) : void 0;
|
|
690
|
+
const onMaid = selector && sidebar.mounted.getSnapshot() === sessionId;
|
|
691
|
+
const tabs = sessionId ? sidebar.openTabs.getSnapshot().filter((tab) => tab.sessionId === sessionId) : [];
|
|
692
|
+
const notebook = tabs.find((tab) => tab.kind === notebookKind);
|
|
693
|
+
const css = selector ? notebookOnlyCss(selector, notebook?.tabId) : "";
|
|
694
|
+
if (style.textContent !== css) style.textContent = css;
|
|
695
|
+
const nextPanel = onMaid ? document.querySelector(selector) : null;
|
|
696
|
+
if (panel !== nextPanel || Boolean(onMaid) !== watching) {
|
|
697
|
+
observer.disconnect();
|
|
698
|
+
panel = nextPanel;
|
|
699
|
+
watching = Boolean(onMaid);
|
|
700
|
+
if (watching) {
|
|
701
|
+
observer.observe(panel ?? document.body, {
|
|
702
|
+
childList: true,
|
|
703
|
+
subtree: true,
|
|
704
|
+
attributes: true,
|
|
705
|
+
attributeFilter: ["data-sidebar-right-open", "hidden", "aria-selected", "data-dockkit-float"]
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
if (!onMaid || !panel || !sidebar.isExpanded()) return;
|
|
710
|
+
const chromePane = panel.querySelector("[data-dockkit-strip-chrome]")?.closest("[data-dockkit-pane]");
|
|
711
|
+
const paneId = chromePane?.dataset.dockkitPane;
|
|
712
|
+
const guide = tabs.find((tab) => tab.kind === "guide" && tab.tabId === chromePane?.dataset.dockkitContent);
|
|
713
|
+
const open = () => sidebar.openTab(notebookKind, { paneId, replaceTab: guide?.tabId });
|
|
714
|
+
if (!notebook) {
|
|
715
|
+
open();
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
const content = panel.querySelector(`[data-dockkit-content="${CSS.escape(notebook.tabId)}"]`);
|
|
719
|
+
if (content?.dataset.dockkitFloat) {
|
|
720
|
+
sidebar.dock(content.dataset.dockkitFloat);
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
if (paneId && content?.dataset.dockkitPane && content.dataset.dockkitPane !== paneId) {
|
|
724
|
+
open();
|
|
725
|
+
sidebar.close(notebook.tabId);
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
728
|
+
if (sidebar.active()?.id !== notebook.tabId) sidebar.focus(notebook.tabId);
|
|
729
|
+
}
|
|
730
|
+
function schedule() {
|
|
731
|
+
if (queued || stopped) return;
|
|
732
|
+
queued = true;
|
|
733
|
+
queueMicrotask(() => {
|
|
734
|
+
queued = false;
|
|
735
|
+
if (!stopped) selectNotebook();
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
const observer = new MutationObserver(schedule);
|
|
739
|
+
const unsubscribe = [attention, sidebar.mounted, sidebar.openTabs].map((source) => source.subscribe(schedule));
|
|
740
|
+
schedule();
|
|
741
|
+
return () => {
|
|
742
|
+
stopped = true;
|
|
743
|
+
observer.disconnect();
|
|
744
|
+
for (const dispose of unsubscribe) dispose();
|
|
745
|
+
style.remove();
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
function registerMaidSidebar(ctx, register, useAttention, attention) {
|
|
749
|
+
ctx.effect(() => ctx.sidebarRightTabs.register({
|
|
750
|
+
id: notebookId,
|
|
751
|
+
kind: notebookKind,
|
|
752
|
+
title: () => "Maid \u8BB0\u4E8B\u672C"
|
|
753
|
+
}), "maid: notebook tab");
|
|
754
|
+
register("sidebar.right.pane.tab", { key: notebookId }, ({ sessionId }) => sessionId === useAttention().sessionId ? /* @__PURE__ */ import_react5.default.createElement(Notebook, null) : null);
|
|
755
|
+
ctx.effect(() => keepNotebookVisible(ctx.sidebarRight, attention), "maid: notebook sidebar");
|
|
756
|
+
return () => {
|
|
757
|
+
const sidebar = ctx.sidebarRight;
|
|
758
|
+
const { sessionId } = attention.getSnapshot();
|
|
759
|
+
if (!sessionId || sidebar.mounted.getSnapshot() !== sessionId) return;
|
|
760
|
+
if (!sidebar.isExpanded()) sidebar.toggleExpanded();
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
// ui/style.css
|
|
765
|
+
var style_default = ".maid-native-opening, .maid-native-sheet, .maid-native-settings, .maid-native-form {\n min-width: 0;\n color: var(--dsw-alias-label-primary);\n}\n.maid-native-opening {\n display: grid;\n justify-items: start;\n gap: 8px;\n padding: calc(24px + var(--dsh-frame-top-clearance, 0px)) 24px 24px;\n}\n.maid-native-entry { display: inline-flex; align-items: center; position: relative; }\n.maid-native-count { position: absolute; inset-inline-end: -7px; inset-block-start: -7px; }\n.maid-native-sheet {\n block-size: 100%;\n overflow: auto;\n display: grid;\n align-content: start;\n gap: 14px;\n padding: 12px;\n}\n.maid-native-settings, .maid-native-form, .maid-native-dock-body, .maid-native-section {\n display: grid;\n align-content: start;\n gap: 8px;\n}\n.maid-native-settings > p:empty { display: none; }\n.maid-native-dock { padding-block: 4px; }\n.maid-native-dock-body { padding-inline-start: 20px; }\n.maid-native-activity { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: start; }\n.maid-native-activity p { flex: 1 1 220px; white-space: pre-wrap; overflow-wrap: anywhere; }\n.maid-native-heading, .maid-native-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }\n.maid-native-heading { justify-content: space-between; }\n.maid-native-list { display: grid; list-style: none; margin: 0; padding: 0; }\n.maid-native-form p, .maid-native-note { white-space: pre-wrap; overflow-wrap: anywhere; }\n.maid-native-note { padding-block: 6px; }\n.maid-native-note blockquote { margin: 4px 0; padding-inline-start: 8px; color: var(--dsw-alias-label-secondary); }\n.maid-native-row {\n inline-size: 100%;\n justify-content: flex-start;\n min-width: 0;\n}\n.maid-native-row > span:not(:first-child):not(:last-child) {\n min-width: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.maid-native-row > span:last-child { margin-inline-start: auto; }\n.maid-native-field { display: grid; justify-items: start; gap: 4px; }\n.maid-native-field > textarea { inline-size: 100%; }\n.maid-native-muted, .maid-native-note small { color: var(--dsw-alias-label-tertiary); }\n";
|
|
766
|
+
|
|
767
|
+
// ui/client.jsx
|
|
768
|
+
var inject = ["slots", "sessions", "workspaces", "uiConversation", "uiWorkspace", "sidebarRight", "sidebarRightTabs"];
|
|
769
|
+
var activityView = "@ceasarxuu/dsh-maid/activity";
|
|
770
|
+
var emptyAttention = { count: 0, sessionId: void 0 };
|
|
771
|
+
function observeAttention(ctx) {
|
|
772
|
+
let current = emptyAttention;
|
|
773
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
774
|
+
ctx.effect(() => {
|
|
775
|
+
const controller = new AbortController();
|
|
776
|
+
let timer;
|
|
777
|
+
async function poll() {
|
|
778
|
+
try {
|
|
779
|
+
const next = await api("attention", { signal: controller.signal });
|
|
780
|
+
if (!controller.signal.aborted && (next.sessionId !== current.sessionId || next.count !== current.count)) {
|
|
781
|
+
current = next;
|
|
782
|
+
for (const listener of listeners) listener();
|
|
783
|
+
}
|
|
784
|
+
} catch {
|
|
785
|
+
}
|
|
786
|
+
if (!controller.signal.aborted) timer = setTimeout(poll, 4e3);
|
|
787
|
+
}
|
|
788
|
+
void poll();
|
|
789
|
+
return () => {
|
|
790
|
+
controller.abort();
|
|
791
|
+
clearTimeout(timer);
|
|
792
|
+
};
|
|
793
|
+
}, "maid: identity");
|
|
794
|
+
const subscribe = (listener) => {
|
|
795
|
+
listeners.add(listener);
|
|
796
|
+
return () => listeners.delete(listener);
|
|
797
|
+
};
|
|
798
|
+
return { subscribe, getSnapshot: () => current };
|
|
799
|
+
}
|
|
800
|
+
function OpenConversation({ open }) {
|
|
801
|
+
const [attempt, setAttempt] = (0, import_react6.useState)(0);
|
|
802
|
+
const [error, setError] = (0, import_react6.useState)("");
|
|
803
|
+
(0, import_react6.useEffect)(() => {
|
|
804
|
+
const controller = new AbortController();
|
|
805
|
+
setError("");
|
|
806
|
+
void open(controller.signal).catch((error2) => {
|
|
807
|
+
if (!controller.signal.aborted) setError(error2.message);
|
|
808
|
+
});
|
|
809
|
+
return () => controller.abort();
|
|
810
|
+
}, [open, attempt]);
|
|
811
|
+
return /* @__PURE__ */ import_react6.default.createElement("div", { className: "maid-native-opening" }, error ? /* @__PURE__ */ import_react6.default.createElement(import_react6.default.Fragment, null, /* @__PURE__ */ import_react6.default.createElement("p", { role: "alert" }, error), /* @__PURE__ */ import_react6.default.createElement(import_dsh_client_ui_primitives4.Button, { onClick: () => setAttempt((value) => value + 1) }, "\u91CD\u8BD5")) : /* @__PURE__ */ import_react6.default.createElement(import_dsh_client_ui_primitives4.TextShimmer, { active: true }, "\u6B63\u5728\u6253\u5F00 Maid\u2026"));
|
|
812
|
+
}
|
|
813
|
+
function apply(ctx) {
|
|
814
|
+
const attention = observeAttention(ctx);
|
|
815
|
+
const useAttention = () => (0, import_react6.useSyncExternalStore)(attention.subscribe, attention.getSnapshot);
|
|
816
|
+
const register = (name, options, component) => ctx.effect(() => ctx.slots.inject(name, () => ctx.slots.register({ name, ...options }, component)), "maid: " + name);
|
|
817
|
+
registerMaidConversationHeader(ctx, useAttention, register);
|
|
818
|
+
const openNotebook = registerMaidSidebar(ctx, register, useAttention, attention);
|
|
819
|
+
const open = async (signal) => {
|
|
820
|
+
const { sessionId } = await api("conversation", { body: {}, signal });
|
|
821
|
+
const isKnown = () => Object.hasOwn(ctx.sessions.list.getSnapshot().byId, sessionId);
|
|
822
|
+
for (let attempt = 0; attempt < 2 && !isKnown(); attempt++) {
|
|
823
|
+
signal.throwIfAborted();
|
|
824
|
+
await ctx.sessions.refresh();
|
|
825
|
+
}
|
|
826
|
+
signal.throwIfAborted();
|
|
827
|
+
if (!isKnown()) throw new Error("DSH \u5C1A\u672A\u8F7D\u5165 Maid \u4F1A\u8BDD\uFF0C\u8BF7\u91CD\u8BD5\u3002");
|
|
828
|
+
const workspaceState = ctx.workspaces.list.getSnapshot();
|
|
829
|
+
if (workspaceState.phase !== "ready" || workspaceState.archivedSessionIds.includes(sessionId)) {
|
|
830
|
+
await ctx.uiWorkspace.unarchiveSession(sessionId);
|
|
831
|
+
signal.throwIfAborted();
|
|
832
|
+
}
|
|
833
|
+
const removed = ctx.sessions.binding(sessionId)?.session.getSnapshot().removed;
|
|
834
|
+
ctx.uiWorkspace.openSession(sessionId);
|
|
835
|
+
if (removed) window.location.reload();
|
|
836
|
+
};
|
|
837
|
+
ctx.effect(() => {
|
|
838
|
+
const tag = document.createElement("style");
|
|
839
|
+
tag.textContent = style_default;
|
|
840
|
+
document.head.append(tag);
|
|
841
|
+
return () => tag.remove();
|
|
842
|
+
}, "maid: layout");
|
|
843
|
+
ctx.effect(() => ctx.uiConversation.views.register({
|
|
844
|
+
target: activityView,
|
|
845
|
+
create: () => ({ empty: true, replace: () => true, apply: () => true }),
|
|
846
|
+
isActive: (ready) => ready === true
|
|
847
|
+
}), "maid: conversation activity");
|
|
848
|
+
register("main", { key: "maid" }, () => /* @__PURE__ */ import_react6.default.createElement(OpenConversation, { open }));
|
|
849
|
+
register("sidebar.panellist", { id: "maid", order: -10, label: () => "Maid" }, () => {
|
|
850
|
+
const { count } = useAttention();
|
|
851
|
+
return /* @__PURE__ */ import_react6.default.createElement("span", { className: "maid-native-entry" }, /* @__PURE__ */ import_react6.default.createElement(import_dsh_client_ui_primitives4.IconNewChatOutlineRegular, { size: 18 }), count > 0 && /* @__PURE__ */ import_react6.default.createElement(import_dsh_client_ui_primitives4.Tag, { tone: "warning", className: "maid-native-count" }, /* @__PURE__ */ import_react6.default.createElement("span", { "aria-label": count + " \u4EF6\u4E8B\u5F85\u4F60\u5904\u7406" }, count > 9 ? "9+" : count)));
|
|
852
|
+
});
|
|
853
|
+
register("conversation.input.right", { id: "maid-notebook", order: 5 }, ({ sessionId }) => {
|
|
854
|
+
const attention2 = useAttention();
|
|
855
|
+
if (sessionId !== attention2.sessionId) return null;
|
|
856
|
+
return /* @__PURE__ */ import_react6.default.createElement(import_dsh_client_ui_primitives4.Button, { size: "sm", variant: "toolbar", icon: /* @__PURE__ */ import_react6.default.createElement(import_dsh_client_ui_primitives4.IconChecklistOutlineRegular, { size: 16 }), onClick: openNotebook }, "\u8BB0\u4E8B\u672C");
|
|
857
|
+
});
|
|
858
|
+
register("conversation.input.dock", { id: "maid-activity", order: 5 }, ({ sessionId }) => {
|
|
859
|
+
const isMaid = useAttention().sessionId === sessionId;
|
|
860
|
+
(0, import_react6.useLayoutEffect)(() => {
|
|
861
|
+
if (isMaid) ctx.uiConversation.binding(sessionId).activate(activityView);
|
|
862
|
+
}, [isMaid, sessionId]);
|
|
863
|
+
return isMaid ? /* @__PURE__ */ import_react6.default.createElement(MaidDock, { openNotebook }) : null;
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
return module.exports;}});
|