@klarkxy/dsh-memory 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1036 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let react = require("react");
3
+ let react_jsx_runtime = require("react/jsx-runtime");
4
+ //#region ../dsh-ai-services/src/client-utils.ts
5
+ /** The Editor retains its manuscript session separately; native DSH exposes the main-view binding. */
6
+ function selectedSessionId(client) {
7
+ return client.uiWorkspace.current ? client.uiWorkspace.current.getSnapshot()?.sessionId ?? "" : client.uiSession.adapter.current.getSnapshot().key ?? "";
8
+ }
9
+ /** Owner props win; native settings only supplies close, so resolve its selected session. */
10
+ function useNativeSeat(client, props) {
11
+ const current = (0, react.useSyncExternalStore)((0, react.useCallback)((fn) => (client.uiWorkspace.current ?? client.uiSession.adapter.current).subscribe(fn), [client]), (0, react.useCallback)(() => selectedSessionId(client), [client]), () => "");
12
+ const language = (0, react.useSyncExternalStore)((0, react.useCallback)((fn) => client.locale.subscribe(fn), [client]), (0, react.useCallback)(() => client.locale.getSnapshot().active, [client]), () => "en");
13
+ const row = props && typeof props === "object" ? props : {};
14
+ const owner = row.owner && typeof row.owner === "object" ? row.owner : {};
15
+ const sessionId = typeof row.sessionId === "string" ? row.sessionId : typeof owner.sessionId === "string" ? owner.sessionId : current;
16
+ const requestedLocale = row.locale ?? owner.locale ?? language;
17
+ return {
18
+ sessionId,
19
+ locale: String(requestedLocale).startsWith("zh") ? "zh" : "en",
20
+ hidden: row.hidden === true || owner.hidden === true
21
+ };
22
+ }
23
+ /** Refresh on native log boundaries/reconnect/focus. Read-only settling is bounded to an observed job. */
24
+ function useFeatureRefresh(client, sessionId, refresh, working = false, enabled = true) {
25
+ const refreshRef = (0, react.useRef)(refresh);
26
+ refreshRef.current = refresh;
27
+ (0, react.useEffect)(() => {
28
+ if (!enabled) return;
29
+ let timer;
30
+ const queue = () => {
31
+ if (typeof document !== "undefined" && document.visibilityState === "hidden") return;
32
+ clearTimeout(timer);
33
+ timer = setTimeout(() => refreshRef.current(), 150);
34
+ };
35
+ const stopEvents = (sessionId ? client.sessions.binding?.(sessionId)?.eventSource : void 0)?.subscribe(queue);
36
+ const stopConnection = client.connection?.generation?.subscribe(queue);
37
+ const visibility = () => {
38
+ if (document.visibilityState === "visible") queue();
39
+ };
40
+ window.addEventListener("focus", queue);
41
+ document.addEventListener("visibilitychange", visibility);
42
+ document.addEventListener("toggle", queue, true);
43
+ return () => {
44
+ clearTimeout(timer);
45
+ stopEvents?.();
46
+ stopConnection?.();
47
+ window.removeEventListener("focus", queue);
48
+ document.removeEventListener("visibilitychange", visibility);
49
+ document.removeEventListener("toggle", queue, true);
50
+ };
51
+ }, [
52
+ client,
53
+ sessionId,
54
+ enabled
55
+ ]);
56
+ (0, react.useEffect)(() => {
57
+ if (!enabled || !working) return;
58
+ let delay = 250;
59
+ const until = Date.now() + 3e5;
60
+ let timer;
61
+ const tick = () => {
62
+ if (Date.now() >= until) return;
63
+ if (document.visibilityState !== "hidden") refreshRef.current();
64
+ delay = Math.min(delay * 2, 2e3);
65
+ timer = setTimeout(tick, delay);
66
+ };
67
+ timer = setTimeout(tick, delay);
68
+ return () => clearTimeout(timer);
69
+ }, [
70
+ client,
71
+ sessionId,
72
+ working,
73
+ enabled
74
+ ]);
75
+ }
76
+ //#endregion
77
+ //#region src/contracts.ts
78
+ const MEMORY_RPC_CHANNEL = "/dsh-memory";
79
+ //#endregion
80
+ //#region src/view-lifetime.ts
81
+ function createMemoryGeneration(start = 0) {
82
+ let current = start;
83
+ return {
84
+ current: () => current,
85
+ next: () => {
86
+ current += 1;
87
+ return current;
88
+ },
89
+ isCurrent: (token) => token === current
90
+ };
91
+ }
92
+ function memoryRequestStillCurrent(input) {
93
+ return input.gate.isCurrent(input.token) && !input.signal.aborted && input.sessionId === input.viewSessionId;
94
+ }
95
+ /** Capture session, generation token, and abort lifetime before the first await. */
96
+ function beginMemoryRequest(gate, sessionId, previous) {
97
+ previous?.abort();
98
+ const controller = new AbortController();
99
+ return {
100
+ sessionId,
101
+ token: gate.next(),
102
+ signal: controller.signal,
103
+ controller
104
+ };
105
+ }
106
+ function disposeMemoryRequest(gate, controller) {
107
+ controller.abort();
108
+ gate.next();
109
+ }
110
+ function unwrapMemoryResult(result) {
111
+ if (!result.ok) throw new Error(result.error.message);
112
+ return result.value;
113
+ }
114
+ function shouldSkipMemoryRefresh(input) {
115
+ return input.busy || input.editing;
116
+ }
117
+ async function loadMemoryStatus(input) {
118
+ const captured = input.sessionId;
119
+ const raw = await input.rpc("status", captured ? { sessionId: captured } : {}, input.signal);
120
+ if (!memoryRequestStillCurrent({
121
+ token: input.token,
122
+ gate: input.gate,
123
+ signal: input.signal,
124
+ sessionId: captured,
125
+ viewSessionId: input.viewSessionId()
126
+ })) return void 0;
127
+ return unwrapMemoryResult(raw);
128
+ }
129
+ /** Read-only status peek; uses an independent signal so it cannot abort an in-flight write. */
130
+ async function peekMemoryStatus(input) {
131
+ if (shouldSkipMemoryRefresh({
132
+ busy: input.busy(),
133
+ editing: input.editing?.() === true
134
+ })) return void 0;
135
+ const token = input.token;
136
+ if (!input.gate.isCurrent(token) || token === 0) return void 0;
137
+ const next = await loadMemoryStatus({
138
+ rpc: input.rpc,
139
+ sessionId: input.sessionId,
140
+ token,
141
+ gate: input.gate,
142
+ signal: new AbortController().signal,
143
+ viewSessionId: input.viewSessionId
144
+ });
145
+ if (!next) return void 0;
146
+ if (shouldSkipMemoryRefresh({
147
+ busy: input.busy(),
148
+ editing: input.editing?.() === true
149
+ })) return void 0;
150
+ return next;
151
+ }
152
+ //#endregion
153
+ //#region src/client.tsx
154
+ const name = "dsh-memory-client";
155
+ const inject = [
156
+ "slots",
157
+ "connection",
158
+ "sessions",
159
+ "locale",
160
+ "uiWorkspace",
161
+ "uiSession"
162
+ ];
163
+ function parseSeatProps(props) {
164
+ const row = props && typeof props === "object" ? props : {};
165
+ const nested = row.owner && typeof row.owner === "object" ? row.owner : void 0;
166
+ return {
167
+ sessionId: typeof row.sessionId === "string" && row.sessionId ? row.sessionId : typeof nested?.sessionId === "string" ? nested.sessionId : "",
168
+ locale: row.locale === "en" || nested?.locale === "en" ? "en" : "zh",
169
+ hidden: row.hidden === true || nested?.hidden === true
170
+ };
171
+ }
172
+ function memoryPanelKey(sessionId, locale) {
173
+ return `${sessionId}:${locale}`;
174
+ }
175
+ function chatSummaryTitle(locale) {
176
+ return locale === "en" ? "Memory" : "记忆";
177
+ }
178
+ function candidateAvailabilityLabel(count, locale) {
179
+ if (count > 0) return locale === "en" ? `${count} to review` : `${count} 条候选`;
180
+ return locale === "en" ? "No candidates" : "暂无候选";
181
+ }
182
+ function kindLabel(kind, locale) {
183
+ if (locale === "en") return kind === "preference" ? "Preference" : kind === "project-fact" ? "Project fact" : kind === "decision" ? "Decision" : "Lesson";
184
+ return kind === "preference" ? "偏好" : kind === "project-fact" ? "项目事实" : kind === "decision" ? "决策" : "教训";
185
+ }
186
+ function statusLabel(status, locale) {
187
+ return locale === "en" ? {
188
+ candidate: "Candidate",
189
+ active: "Active",
190
+ rejected: "Rejected",
191
+ superseded: "Superseded",
192
+ revoked: "Revoked",
193
+ deleted: "Deleted"
194
+ }[status] : {
195
+ candidate: "候选",
196
+ active: "已生效",
197
+ rejected: "已拒绝",
198
+ superseded: "已替代",
199
+ revoked: "已撤销",
200
+ deleted: "已删除"
201
+ }[status];
202
+ }
203
+ function canAccept(record) {
204
+ return record.status === "candidate";
205
+ }
206
+ function canReject(record) {
207
+ return record.status === "candidate";
208
+ }
209
+ function canRevoke(record) {
210
+ return record.status === "active";
211
+ }
212
+ function t(locale, zh, en) {
213
+ return locale === "en" ? en : zh;
214
+ }
215
+ function MemoryChatShell(props) {
216
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", {
217
+ className: "dsh-memory-chat",
218
+ "data-testid": "memory-chat",
219
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("summary", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: chatSummaryTitle(props.locale) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
220
+ className: "dsh-memory-meta",
221
+ children: candidateAvailabilityLabel(props.candidateCount, props.locale)
222
+ })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
223
+ className: "dsh-memory-chat-body",
224
+ children: props.children
225
+ })]
226
+ });
227
+ }
228
+ function MemorySettingsPanel({ client, sessionId, locale }) {
229
+ const gate = (0, react.useRef)(createMemoryGeneration());
230
+ const sessionRef = (0, react.useRef)(sessionId);
231
+ const workRef = (0, react.useRef)(null);
232
+ sessionRef.current = sessionId;
233
+ const [status, setStatus] = (0, react.useState)();
234
+ const [draft, setDraft] = (0, react.useState)();
235
+ const [busy, setBusy] = (0, react.useState)(false);
236
+ const [error, setError] = (0, react.useState)("");
237
+ const [note, setNote] = (0, react.useState)("");
238
+ const busyRef = (0, react.useRef)(false);
239
+ const settingsDirty = (0, react.useRef)(false);
240
+ busyRef.current = busy;
241
+ async function rpc(endpoint, payload, signal) {
242
+ const result = await client.connection.rpc.call(MEMORY_RPC_CHANNEL, endpoint, payload, signal);
243
+ unwrapMemoryResult(result);
244
+ return result;
245
+ }
246
+ (0, react.useEffect)(() => {
247
+ const request = beginMemoryRequest(gate.current, sessionId, workRef.current);
248
+ workRef.current = request.controller;
249
+ setError("");
250
+ setNote("");
251
+ loadMemoryStatus({
252
+ rpc,
253
+ sessionId: request.sessionId,
254
+ token: request.token,
255
+ gate: gate.current,
256
+ signal: request.signal,
257
+ viewSessionId: () => sessionRef.current
258
+ }).then((next) => {
259
+ if (!next) return;
260
+ setStatus(next);
261
+ setDraft(next.settings);
262
+ settingsDirty.current = false;
263
+ }).catch((cause) => {
264
+ if (!memoryRequestStillCurrent({
265
+ token: request.token,
266
+ gate: gate.current,
267
+ signal: request.signal,
268
+ sessionId: request.sessionId,
269
+ viewSessionId: sessionRef.current
270
+ })) return;
271
+ setError(cause instanceof Error ? cause.message : t(locale, "无法读取记忆设置。", "Unable to load memory settings."));
272
+ });
273
+ return () => disposeMemoryRequest(gate.current, workRef.current ?? request.controller);
274
+ }, [
275
+ client,
276
+ sessionId,
277
+ locale
278
+ ]);
279
+ useFeatureRefresh(client, sessionId, () => {
280
+ peekMemoryStatus({
281
+ rpc,
282
+ sessionId: sessionRef.current,
283
+ token: gate.current.current(),
284
+ gate: gate.current,
285
+ viewSessionId: () => sessionRef.current,
286
+ busy: () => busyRef.current,
287
+ editing: () => settingsDirty.current
288
+ }).then((next) => {
289
+ if (next) {
290
+ setStatus(next);
291
+ setDraft(next.settings);
292
+ }
293
+ }).catch(() => {});
294
+ }, false, true);
295
+ async function action(run) {
296
+ const request = beginMemoryRequest(gate.current, sessionId, workRef.current);
297
+ workRef.current = request.controller;
298
+ setBusy(true);
299
+ setNote("");
300
+ setError("");
301
+ const still = () => memoryRequestStillCurrent({
302
+ token: request.token,
303
+ gate: gate.current,
304
+ signal: request.signal,
305
+ sessionId: request.sessionId,
306
+ viewSessionId: sessionRef.current
307
+ });
308
+ try {
309
+ await run(request.sessionId);
310
+ const next = await loadMemoryStatus({
311
+ rpc,
312
+ sessionId: request.sessionId,
313
+ token: request.token,
314
+ gate: gate.current,
315
+ signal: request.signal,
316
+ viewSessionId: () => sessionRef.current
317
+ });
318
+ if (!next || !still()) return;
319
+ setStatus(next);
320
+ setDraft(next.settings);
321
+ settingsDirty.current = false;
322
+ setNote(t(locale, "已保存。", "Saved."));
323
+ } catch (cause) {
324
+ if (!still()) return;
325
+ setError(cause instanceof Error ? cause.message : t(locale, "操作失败。", "Failed."));
326
+ const next = await loadMemoryStatus({
327
+ rpc,
328
+ sessionId: request.sessionId,
329
+ token: request.token,
330
+ gate: gate.current,
331
+ signal: request.signal,
332
+ viewSessionId: () => sessionRef.current
333
+ }).catch(() => void 0);
334
+ if (next && still()) {
335
+ setStatus(next);
336
+ setDraft(next.settings);
337
+ settingsDirty.current = false;
338
+ }
339
+ } finally {
340
+ if (still()) setBusy(false);
341
+ }
342
+ }
343
+ if (!status || !draft) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
344
+ className: "dsh-memory-settings",
345
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
346
+ role: "status",
347
+ children: error || t(locale, "正在读取设置…", "Loading settings…")
348
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
349
+ type: "button",
350
+ onClick: () => void action(async () => {}),
351
+ children: t(locale, "重新连接", "Reconnect")
352
+ })]
353
+ });
354
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
355
+ className: "dsh-memory-settings",
356
+ "data-testid": "memory-settings",
357
+ children: [
358
+ error && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
359
+ role: "alert",
360
+ className: "dsh-memory-error",
361
+ children: error
362
+ }),
363
+ note && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
364
+ role: "status",
365
+ children: note
366
+ }),
367
+ status.storageFailed && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
368
+ role: "alert",
369
+ children: t(locale, "保存失败,已保留原内容。", "Save failed; previous content was kept.")
370
+ }),
371
+ !status.aiAvailable && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
372
+ className: "dsh-memory-meta",
373
+ children: t(locale, "梦境整理需要单独加载 @klarkxy/dsh-ai-services。", "Dream needs @klarkxy/dsh-ai-services loaded separately.")
374
+ }),
375
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("article", {
376
+ className: "dsh-memory-card",
377
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { children: t(locale, "写入提示", "Prompt injection") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
378
+ className: "dsh-memory-meta",
379
+ children: t(locale, "关闭后不再注入记忆;存储保留。", "Turns off injection; stored records remain.")
380
+ })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
381
+ type: "button",
382
+ role: "switch",
383
+ className: `dsh-memory-switch${draft.injectEnabled ? " is-on" : ""}`,
384
+ "aria-checked": draft.injectEnabled,
385
+ "aria-label": draft.injectEnabled ? t(locale, "关闭记忆注入", "Disable memory injection") : t(locale, "启用记忆注入", "Enable memory injection"),
386
+ disabled: busy,
387
+ onClick: () => void action(async () => {
388
+ await rpc("settings.update", {
389
+ expectedRevision: draft.revision,
390
+ settings: {
391
+ ...editable(draft),
392
+ injectEnabled: !draft.injectEnabled
393
+ }
394
+ });
395
+ }),
396
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
397
+ className: "dsh-memory-switch-thumb",
398
+ "aria-hidden": "true"
399
+ })
400
+ })] })
401
+ }),
402
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", {
403
+ className: "dsh-memory-card",
404
+ children: [
405
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { children: t(locale, "闲时梦境", "Idle Dream") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
406
+ className: "dsh-memory-meta",
407
+ children: t(locale, "闲时自动整理记忆(每天至多一次,自动生效)。", "Auto-organizes memory while idle (at most once a day, applies automatically).")
408
+ })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
409
+ type: "button",
410
+ role: "switch",
411
+ className: `dsh-memory-switch${draft.dreamIdleEnabled ? " is-on" : ""}`,
412
+ "aria-checked": draft.dreamIdleEnabled,
413
+ "aria-label": draft.dreamIdleEnabled ? t(locale, "关闭闲时整理", "Disable idle Dream") : t(locale, "启用闲时整理", "Enable idle Dream"),
414
+ disabled: busy,
415
+ onClick: () => void action(async () => {
416
+ await rpc("settings.update", {
417
+ expectedRevision: draft.revision,
418
+ settings: {
419
+ ...editable(draft),
420
+ dreamIdleEnabled: !draft.dreamIdleEnabled
421
+ }
422
+ });
423
+ }),
424
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
425
+ className: "dsh-memory-switch-thumb",
426
+ "aria-hidden": "true"
427
+ })
428
+ })] }),
429
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", { children: [t(locale, "空闲间隔(分钟)", "Idle interval (minutes)"), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
430
+ type: "number",
431
+ min: 1,
432
+ max: 180,
433
+ step: 1,
434
+ disabled: busy,
435
+ value: Math.round(draft.idleMs / 6e4),
436
+ onChange: (event) => {
437
+ settingsDirty.current = true;
438
+ setDraft({
439
+ ...draft,
440
+ idleMs: Math.round(Number(event.target.value) * 6e4)
441
+ });
442
+ }
443
+ })] }),
444
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
445
+ type: "button",
446
+ disabled: busy,
447
+ onClick: () => void action(async () => {
448
+ await rpc("settings.update", {
449
+ expectedRevision: draft.revision,
450
+ settings: editable(draft)
451
+ });
452
+ }),
453
+ children: t(locale, "保存", "Save")
454
+ })
455
+ ]
456
+ })
457
+ ]
458
+ });
459
+ }
460
+ function editable(settings) {
461
+ const { revision: _revision, ...rest } = settings;
462
+ return rest;
463
+ }
464
+ function MemoryChatPanel({ client, sessionId, locale }) {
465
+ const formId = (0, react.useId)();
466
+ const gate = (0, react.useRef)(createMemoryGeneration());
467
+ const sessionRef = (0, react.useRef)(sessionId);
468
+ const workRef = (0, react.useRef)(null);
469
+ sessionRef.current = sessionId;
470
+ const [status, setStatus] = (0, react.useState)();
471
+ const [query, setQuery] = (0, react.useState)("");
472
+ const [title, setTitle] = (0, react.useState)("");
473
+ const [content, setContent] = (0, react.useState)("");
474
+ const [kind, setKind] = (0, react.useState)("preference");
475
+ const [global, setGlobal] = (0, react.useState)(false);
476
+ const [evidence, setEvidence] = (0, react.useState)("");
477
+ const [busy, setBusy] = (0, react.useState)(false);
478
+ const [error, setError] = (0, react.useState)("");
479
+ const [note, setNote] = (0, react.useState)("");
480
+ const [editing, setEditing] = (0, react.useState)(false);
481
+ const busyRef = (0, react.useRef)(false);
482
+ const editingRef = (0, react.useRef)(false);
483
+ busyRef.current = busy;
484
+ editingRef.current = editing;
485
+ async function rpc(endpoint, payload, signal) {
486
+ const result = await client.connection.rpc.call(MEMORY_RPC_CHANNEL, endpoint, payload, signal);
487
+ unwrapMemoryResult(result);
488
+ return result;
489
+ }
490
+ (0, react.useEffect)(() => {
491
+ const request = beginMemoryRequest(gate.current, sessionId, workRef.current);
492
+ workRef.current = request.controller;
493
+ setError("");
494
+ setNote("");
495
+ loadMemoryStatus({
496
+ rpc,
497
+ sessionId: request.sessionId,
498
+ token: request.token,
499
+ gate: gate.current,
500
+ signal: request.signal,
501
+ viewSessionId: () => sessionRef.current
502
+ }).then((next) => {
503
+ if (!next) return;
504
+ setStatus(next);
505
+ }).catch((cause) => {
506
+ if (!memoryRequestStillCurrent({
507
+ token: request.token,
508
+ gate: gate.current,
509
+ signal: request.signal,
510
+ sessionId: request.sessionId,
511
+ viewSessionId: sessionRef.current
512
+ })) return;
513
+ setError(cause instanceof Error ? cause.message : t(locale, "无法读取记忆。", "Unable to load memory."));
514
+ });
515
+ return () => disposeMemoryRequest(gate.current, workRef.current ?? request.controller);
516
+ }, [
517
+ client,
518
+ sessionId,
519
+ locale
520
+ ]);
521
+ useFeatureRefresh(client, sessionId, () => {
522
+ peekMemoryStatus({
523
+ rpc,
524
+ sessionId: sessionRef.current,
525
+ token: gate.current.current(),
526
+ gate: gate.current,
527
+ viewSessionId: () => sessionRef.current,
528
+ busy: () => busyRef.current,
529
+ editing: () => editingRef.current
530
+ }).then((next) => {
531
+ if (next) setStatus(next);
532
+ }).catch(() => {});
533
+ }, Boolean(status?.runningDreams?.length), Boolean(sessionId));
534
+ async function action(run) {
535
+ const request = beginMemoryRequest(gate.current, sessionId, workRef.current);
536
+ workRef.current = request.controller;
537
+ setBusy(true);
538
+ setNote("");
539
+ setError("");
540
+ const still = () => memoryRequestStillCurrent({
541
+ token: request.token,
542
+ gate: gate.current,
543
+ signal: request.signal,
544
+ sessionId: request.sessionId,
545
+ viewSessionId: sessionRef.current
546
+ });
547
+ try {
548
+ await run(request.sessionId);
549
+ const next = await loadMemoryStatus({
550
+ rpc,
551
+ sessionId: request.sessionId,
552
+ token: request.token,
553
+ gate: gate.current,
554
+ signal: request.signal,
555
+ viewSessionId: () => sessionRef.current
556
+ });
557
+ if (!next || !still()) return;
558
+ setStatus(next);
559
+ } catch (cause) {
560
+ if (!still()) return;
561
+ setError(cause instanceof Error ? cause.message : t(locale, "操作失败。", "Failed."));
562
+ const next = await loadMemoryStatus({
563
+ rpc,
564
+ sessionId: request.sessionId,
565
+ token: request.token,
566
+ gate: gate.current,
567
+ signal: request.signal,
568
+ viewSessionId: () => sessionRef.current
569
+ }).catch(() => void 0);
570
+ if (next && still()) setStatus(next);
571
+ } finally {
572
+ if (still()) setBusy(false);
573
+ }
574
+ }
575
+ const records = (status?.records ?? []).filter((record) => {
576
+ if (!query.trim()) return true;
577
+ return `${record.title}\n${record.content}`.toLowerCase().includes(query.trim().toLowerCase());
578
+ });
579
+ const dreams = (status?.dreams ?? []).slice().sort((a, b) => b.updatedAt - a.updatedAt).slice(0, 8);
580
+ const candidateCount = (status?.records ?? []).filter((record) => record.status === "candidate").length;
581
+ const body = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
582
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("header", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
583
+ className: "dsh-memory-meta",
584
+ children: status?.projectId ? t(locale, "当前项目", "This project") : t(locale, "无项目目录;全局写入需勾选。", "No project path; global write must be explicit.")
585
+ }) }),
586
+ error && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
587
+ role: "alert",
588
+ className: "dsh-memory-error",
589
+ children: error
590
+ }),
591
+ note && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
592
+ role: "status",
593
+ children: note
594
+ }),
595
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
596
+ className: "dsh-memory-search",
597
+ children: [t(locale, "搜索", "Search"), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
598
+ value: query,
599
+ onChange: (event) => setQuery(event.target.value),
600
+ disabled: busy,
601
+ "aria-label": t(locale, "搜索记忆", "Search memory")
602
+ })]
603
+ }),
604
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
605
+ className: "dsh-memory-list",
606
+ children: records.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", {
607
+ className: "dsh-memory-meta",
608
+ children: query.trim() ? t(locale, "没有匹配的条目。", "No matching records.") : t(locale, "暂无条目。", "No records.")
609
+ }) : records.map((record) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MemoryRow, {
610
+ record,
611
+ locale,
612
+ busy,
613
+ onEditingChange: setEditing,
614
+ onAccept: () => void action((captured) => rpc("records.accept", {
615
+ sessionId: captured,
616
+ id: record.id,
617
+ expectedRevision: record.revision
618
+ }).then(() => {
619
+ if (sessionRef.current === captured) setNote(t(locale, "已采纳。", "Accepted."));
620
+ })),
621
+ onReject: () => void action((captured) => rpc("records.reject", {
622
+ sessionId: captured,
623
+ id: record.id,
624
+ expectedRevision: record.revision
625
+ }).then(() => {
626
+ if (sessionRef.current === captured) setNote(t(locale, "已拒绝。", "Rejected."));
627
+ })),
628
+ onRevoke: () => void action((captured) => rpc("records.revoke", {
629
+ sessionId: captured,
630
+ id: record.id,
631
+ expectedRevision: record.revision
632
+ }).then(() => {
633
+ if (sessionRef.current === captured) setNote(t(locale, "已撤销。", "Revoked."));
634
+ })),
635
+ onDelete: () => void action((captured) => rpc("records.remove", {
636
+ sessionId: captured,
637
+ id: record.id,
638
+ expectedRevision: record.revision
639
+ }).then(() => {
640
+ if (sessionRef.current === captured) setNote(t(locale, "已删除。", "Deleted."));
641
+ })),
642
+ onSave: (nextTitle, nextContent) => void action((captured) => rpc("records.update", {
643
+ sessionId: captured,
644
+ id: record.id,
645
+ expectedRevision: record.revision,
646
+ title: nextTitle,
647
+ content: nextContent
648
+ }).then(() => {
649
+ if (sessionRef.current === captured) setNote(t(locale, "已更新。", "Updated."));
650
+ }))
651
+ }, record.id))
652
+ }),
653
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("form", {
654
+ className: "dsh-memory-add",
655
+ onSubmit: (event) => {
656
+ event.preventDefault();
657
+ action(async (captured) => {
658
+ await rpc("records.create", {
659
+ sessionId: captured,
660
+ title,
661
+ content,
662
+ kind,
663
+ global,
664
+ evidence: evidence.trim() ? [{
665
+ sessionId: captured,
666
+ seq: 0,
667
+ kind: "manual",
668
+ excerpt: evidence.trim().slice(0, 400)
669
+ }] : []
670
+ });
671
+ if (sessionRef.current !== captured) return;
672
+ setTitle("");
673
+ setContent("");
674
+ setEvidence("");
675
+ setNote(t(locale, "已添加。", "Added."));
676
+ });
677
+ },
678
+ children: [
679
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h4", { children: t(locale, "手动添加", "Add") }),
680
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
681
+ htmlFor: formId + "-title",
682
+ children: [t(locale, "标题", "Title"), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
683
+ id: formId + "-title",
684
+ value: title,
685
+ required: true,
686
+ maxLength: 160,
687
+ disabled: busy,
688
+ onChange: (event) => setTitle(event.target.value)
689
+ })]
690
+ }),
691
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
692
+ htmlFor: formId + "-body",
693
+ children: [t(locale, "内容", "Content"), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", {
694
+ id: formId + "-body",
695
+ value: content,
696
+ required: true,
697
+ maxLength: 4e3,
698
+ disabled: busy,
699
+ rows: 3,
700
+ onChange: (event) => setContent(event.target.value)
701
+ })]
702
+ }),
703
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", { children: [t(locale, "类型", "Kind"), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
704
+ value: kind,
705
+ disabled: busy,
706
+ onChange: (event) => setKind(event.target.value),
707
+ children: [
708
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
709
+ value: "preference",
710
+ children: kindLabel("preference", locale)
711
+ }),
712
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
713
+ value: "project-fact",
714
+ children: kindLabel("project-fact", locale)
715
+ }),
716
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
717
+ value: "decision",
718
+ children: kindLabel("decision", locale)
719
+ })
720
+ ]
721
+ })] }),
722
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
723
+ htmlFor: formId + "-evidence",
724
+ children: [t(locale, "依据(可选)", "Evidence (optional)"), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
725
+ id: formId + "-evidence",
726
+ value: evidence,
727
+ maxLength: 400,
728
+ disabled: busy,
729
+ onChange: (event) => setEvidence(event.target.value)
730
+ })]
731
+ }),
732
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
733
+ className: "dsh-memory-check",
734
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
735
+ type: "checkbox",
736
+ checked: global,
737
+ disabled: busy,
738
+ onChange: (event) => setGlobal(event.target.checked)
739
+ }), t(locale, "写入全局(跨项目)", "Write as global")]
740
+ }),
741
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
742
+ type: "submit",
743
+ disabled: busy,
744
+ children: t(locale, "添加", "Add")
745
+ })
746
+ ]
747
+ }),
748
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DreamPanel, {
749
+ locale,
750
+ busy,
751
+ dreams,
752
+ running: Boolean(status?.runningDreams?.length),
753
+ aiAvailable: status?.aiAvailable === true,
754
+ action,
755
+ rpc
756
+ })
757
+ ] });
758
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MemoryChatShell, {
759
+ locale,
760
+ candidateCount,
761
+ children: body
762
+ });
763
+ }
764
+ function MemoryRow(props) {
765
+ const { record, locale } = props;
766
+ const [editing, setEditing] = (0, react.useState)(false);
767
+ const [title, setTitle] = (0, react.useState)(record.title);
768
+ const [content, setContent] = (0, react.useState)(record.content);
769
+ const scope = record.scope.kind === "global" ? t(locale, "全局", "Global") : t(locale, "项目", "Project");
770
+ function setRowEditing(next) {
771
+ setEditing(next);
772
+ props.onEditingChange?.(next);
773
+ }
774
+ if (editing) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", { children: [
775
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", { children: [t(locale, "标题", "Title"), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
776
+ value: title,
777
+ disabled: props.busy,
778
+ onChange: (event) => setTitle(event.target.value)
779
+ })] }),
780
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", { children: [t(locale, "内容", "Content"), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", {
781
+ value: content,
782
+ disabled: props.busy,
783
+ rows: 3,
784
+ maxLength: 4e3,
785
+ onChange: (event) => setContent(event.target.value)
786
+ })] }),
787
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
788
+ className: "dsh-memory-row-actions",
789
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
790
+ type: "button",
791
+ disabled: props.busy,
792
+ onClick: () => {
793
+ props.onSave(title, content);
794
+ setRowEditing(false);
795
+ },
796
+ children: t(locale, "保存", "Save")
797
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
798
+ type: "button",
799
+ disabled: props.busy,
800
+ onClick: () => setRowEditing(false),
801
+ children: t(locale, "取消", "Cancel")
802
+ })]
803
+ })
804
+ ] });
805
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", { children: [
806
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: record.title }),
807
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
808
+ className: "dsh-memory-meta",
809
+ children: [
810
+ kindLabel(record.kind, locale),
811
+ " · ",
812
+ statusLabel(record.status, locale),
813
+ " · ",
814
+ scope
815
+ ]
816
+ }),
817
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: record.content }),
818
+ record.evidence.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
819
+ className: "dsh-memory-meta",
820
+ children: [
821
+ t(locale, "依据", "Evidence"),
822
+ ":",
823
+ record.evidence.map((item) => item.excerpt ?? `${item.kind}#${item.seq}`).join(";")
824
+ ]
825
+ }),
826
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
827
+ className: "dsh-memory-row-actions",
828
+ children: [
829
+ record.status !== "deleted" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
830
+ type: "button",
831
+ disabled: props.busy,
832
+ onClick: () => {
833
+ setTitle(record.title);
834
+ setContent(record.content);
835
+ setRowEditing(true);
836
+ },
837
+ children: t(locale, "编辑", "Edit")
838
+ }),
839
+ canAccept(record) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
840
+ type: "button",
841
+ disabled: props.busy,
842
+ onClick: props.onAccept,
843
+ children: t(locale, "采纳", "Accept")
844
+ }),
845
+ canReject(record) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
846
+ type: "button",
847
+ disabled: props.busy,
848
+ onClick: props.onReject,
849
+ children: t(locale, "拒绝", "Reject")
850
+ }),
851
+ canRevoke(record) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
852
+ type: "button",
853
+ disabled: props.busy,
854
+ onClick: props.onRevoke,
855
+ children: t(locale, "撤销", "Revoke")
856
+ }),
857
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ConfirmButton, {
858
+ disabled: props.busy,
859
+ label: t(locale, "删除", "Delete"),
860
+ confirmLabel: t(locale, "确认删除?", "Confirm delete?"),
861
+ onConfirm: props.onDelete
862
+ })
863
+ ]
864
+ })
865
+ ] });
866
+ }
867
+ function ConfirmButton(props) {
868
+ const [armed, setArmed] = (0, react.useState)(false);
869
+ const timer = (0, react.useRef)(void 0);
870
+ (0, react.useEffect)(() => () => clearTimeout(timer.current), []);
871
+ function disarm() {
872
+ clearTimeout(timer.current);
873
+ setArmed(false);
874
+ }
875
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
876
+ type: "button",
877
+ className: "dsh-memory-danger",
878
+ disabled: props.disabled,
879
+ onClick: () => {
880
+ if (!armed) {
881
+ setArmed(true);
882
+ timer.current = setTimeout(() => setArmed(false), 3e3);
883
+ return;
884
+ }
885
+ disarm();
886
+ props.onConfirm();
887
+ },
888
+ onBlur: disarm,
889
+ children: armed ? props.confirmLabel : props.label
890
+ });
891
+ }
892
+ function dreamStatusLabel(plan, locale) {
893
+ if (plan.status === "applied") return t(locale, "已应用", "Applied");
894
+ if (plan.status === "noop") return t(locale, "无变化", "No change");
895
+ if (plan.status === "failed" || plan.status === "stale") return t(locale, "失败", "Failed");
896
+ if (plan.status === "cancelled") return t(locale, "已取消", "Cancelled");
897
+ return plan.proposals.length ? t(locale, "未应用", "Not applied") : t(locale, "无变化", "No change");
898
+ }
899
+ function DreamPanel(props) {
900
+ const locale = props.locale;
901
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", {
902
+ className: "dsh-memory-dream",
903
+ children: [
904
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h4", { children: t(locale, "梦境整理", "Dream") }),
905
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
906
+ className: "dsh-memory-meta",
907
+ children: t(locale, "闲置且新材料足够时每天至多自动整理一次,结果自动生效。", "Runs at most once a day when idle with enough new material; results apply automatically.")
908
+ }),
909
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
910
+ className: "dsh-memory-row-actions",
911
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
912
+ type: "button",
913
+ disabled: props.busy || props.running || !props.aiAvailable,
914
+ onClick: () => void props.action(async (captured) => {
915
+ await props.rpc("dream.run", { sessionId: captured });
916
+ }),
917
+ children: t(locale, "立即整理", "Organize now")
918
+ }), props.running && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
919
+ className: "dsh-memory-meta",
920
+ children: t(locale, "整理中…", "Organizing…")
921
+ })]
922
+ }),
923
+ props.dreams.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", { children: props.dreams.map((plan) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", { children: [
924
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: dreamStatusLabel(plan, locale) }),
925
+ " ",
926
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
927
+ className: "dsh-memory-meta",
928
+ children: new Date(plan.createdAt).toLocaleString(locale === "zh" ? "zh-CN" : "en-US")
929
+ }),
930
+ plan.proposals.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
931
+ className: "dsh-memory-meta",
932
+ children: plan.proposals.map((proposal) => proposal.title).join("、")
933
+ }),
934
+ plan.error && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
935
+ className: "dsh-memory-error",
936
+ children: plan.error
937
+ })
938
+ ] }, plan.id)) })
939
+ ]
940
+ });
941
+ }
942
+ function MemorySettings({ client, props }) {
943
+ const seat = useNativeSeat(client, props);
944
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
945
+ className: "dsh-memory-settings-root",
946
+ "data-testid": "memory-settings-root",
947
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(MemorySettingsPanel, {
948
+ client,
949
+ sessionId: seat.sessionId,
950
+ locale: seat.locale
951
+ }, `settings:${memoryPanelKey(seat.sessionId, seat.locale)}`), seat.sessionId && !seat.hidden ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MemoryChatPanel, {
952
+ client,
953
+ sessionId: seat.sessionId,
954
+ locale: seat.locale
955
+ }, `manage:${memoryPanelKey(seat.sessionId, seat.locale)}`) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
956
+ className: "dsh-memory-meta",
957
+ children: t(seat.locale, "选择一个会话后可以管理该会话的记忆。", "Select a session to manage its memory.")
958
+ })]
959
+ });
960
+ }
961
+ const styles = `
962
+ .dsh-memory-settings-root,.dsh-memory-settings,.dsh-memory-chat{max-width:760px;color:inherit;font:400 var(--font-size-2,14px)/1.5 var(--default-font-family,system-ui,sans-serif)}
963
+ .dsh-memory-settings-root,.dsh-memory-settings{display:grid;gap:16px}
964
+ .dsh-memory-chat-body{display:grid;gap:12px;margin-top:8px}
965
+ .dsh-memory-settings p,.dsh-memory-chat p{margin:0;line-height:1.5}
966
+ .dsh-memory-meta,.dsh-memory-chat small{font-size:var(--font-size-1,13px);color:var(--gray-11,inherit)}
967
+ .dsh-memory-error{color:var(--red-11,#b42318)}
968
+ .dsh-memory-card,.dsh-memory-dream,.dsh-memory-add{display:grid;gap:10px;padding:14px 16px;border:1px solid var(--gray-6,color-mix(in srgb,currentColor 15%,transparent));border-radius:12px}
969
+ .dsh-memory-card header,.dsh-memory-chat-body header{display:flex;justify-content:space-between;gap:12px;align-items:center}
970
+ .dsh-memory-card h3,.dsh-memory-add h4,.dsh-memory-dream h4{margin:0;font-size:var(--font-size-3,16px);font-weight:600}
971
+ .dsh-memory-settings input,.dsh-memory-chat input,.dsh-memory-chat textarea,.dsh-memory-chat select{box-sizing:border-box;width:100%;min-width:0;padding:8px 10px;border:1px solid var(--gray-6,color-mix(in srgb,currentColor 22%,transparent));border-radius:8px;background:var(--color-surface,transparent);color:inherit;font:inherit;transition:border-color 150ms ease,box-shadow 150ms ease}
972
+ .dsh-memory-settings input:focus,.dsh-memory-chat input:focus,.dsh-memory-chat textarea:focus,.dsh-memory-chat select:focus{border-color:var(--accent-9,#3b82f6);box-shadow:0 0 0 2px color-mix(in srgb,var(--accent-9,#3b82f6) 25%,transparent)}
973
+ .dsh-memory-settings button:not([role="switch"]),.dsh-memory-chat button:not([role="switch"]){min-height:34px;padding:6px 12px;border:1px solid color-mix(in srgb,currentColor 25%,transparent);border-radius:8px;background:transparent;color:inherit;cursor:pointer;font:inherit;justify-self:start;transition:background-color 150ms ease,color 150ms ease,border-color 150ms ease,box-shadow 150ms ease,transform 150ms ease}
974
+ .dsh-memory-settings button:not([role="switch"]):hover:not(:disabled),.dsh-memory-chat button:not([role="switch"]):hover:not(:disabled){background:var(--gray-3,color-mix(in srgb,currentColor 6%,transparent));border-color:color-mix(in srgb,currentColor 35%,transparent)}
975
+ .dsh-memory-settings button:not([role="switch"]):active:not(:disabled),.dsh-memory-chat button:not([role="switch"]):active:not(:disabled){transform:scale(.97)}
976
+ .dsh-memory-danger:hover:not(:disabled){border-color:var(--red-11,#b42318);color:var(--red-11,#b42318);background:color-mix(in srgb,var(--red-11,#b42318) 8%,transparent)}
977
+ .dsh-memory-settings button:disabled,.dsh-memory-chat button:disabled{opacity:.45;cursor:not-allowed}
978
+ .dsh-memory-settings .dsh-memory-switch,.dsh-memory-chat .dsh-memory-switch{all:unset;box-sizing:border-box;position:relative;display:inline-block;width:36px;height:20px;flex:none;border-radius:999px;background:var(--gray-7,color-mix(in srgb,currentColor 28%,transparent));cursor:pointer}
979
+ .dsh-memory-switch.is-on{background:var(--accent-9,#3b82f6)}
980
+ .dsh-memory-switch-thumb{position:absolute;top:3px;left:3px;width:14px;height:14px;border-radius:999px;background:#fff;transition:transform 150ms ease}
981
+ .dsh-memory-switch.is-on .dsh-memory-switch-thumb{transform:translateX(16px)}
982
+ .dsh-memory-settings :focus-visible,.dsh-memory-chat :focus-visible{outline:2px solid var(--accent-9,currentColor);outline-offset:3px}
983
+ .dsh-memory-list{list-style:none;margin:0;padding:0;display:grid;gap:12px}
984
+ .dsh-memory-list li{display:grid;gap:6px;padding:10px 4px;border-top:1px solid var(--gray-6,color-mix(in srgb,currentColor 15%,transparent));border-radius:10px;overflow-wrap:anywhere}
985
+ .dsh-memory-row-actions{display:flex;flex-wrap:wrap;gap:8px}
986
+ .dsh-memory-check{display:flex;gap:8px;align-items:center}
987
+ .dsh-memory-check input{width:auto}
988
+ .dsh-memory-chat>summary{display:flex;flex-wrap:wrap;gap:8px 12px;align-items:baseline;cursor:pointer;min-height:34px;list-style:revert}
989
+ @media(prefers-reduced-motion:reduce){.dsh-memory-switch-thumb{transition:none}.dsh-memory-settings button:not([role="switch"]),.dsh-memory-chat button:not([role="switch"]),.dsh-memory-settings input,.dsh-memory-chat input,.dsh-memory-chat textarea,.dsh-memory-chat select{transition:none}}
990
+ `;
991
+ function apply(ctx) {
992
+ const client = ctx;
993
+ ctx.effect(() => {
994
+ if (typeof document === "undefined") return () => {};
995
+ const style = document.createElement("style");
996
+ style.setAttribute("data-plugin", "@klarkxy/dsh-memory");
997
+ style.textContent = styles;
998
+ document.head.appendChild(style);
999
+ return () => style.remove();
1000
+ }, "dsh-memory.styles");
1001
+ ctx.effect(() => client.slots.inject("settings.section", () => client.slots.register({
1002
+ name: "settings.section",
1003
+ id: "memory",
1004
+ order: 65,
1005
+ label: "记忆"
1006
+ }, (props) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MemorySettings, {
1007
+ client,
1008
+ props
1009
+ }))), "dsh-memory.settings");
1010
+ }
1011
+ //#endregion
1012
+ exports.MemoryChatShell = MemoryChatShell;
1013
+ exports.MemorySettings = MemorySettings;
1014
+ exports.apply = apply;
1015
+ exports.beginMemoryRequest = beginMemoryRequest;
1016
+ exports.canAccept = canAccept;
1017
+ exports.canReject = canReject;
1018
+ exports.canRevoke = canRevoke;
1019
+ exports.candidateAvailabilityLabel = candidateAvailabilityLabel;
1020
+ exports.chatSummaryTitle = chatSummaryTitle;
1021
+ exports.createMemoryGeneration = createMemoryGeneration;
1022
+ exports.disposeMemoryRequest = disposeMemoryRequest;
1023
+ exports.dreamStatusLabel = dreamStatusLabel;
1024
+ exports.inject = inject;
1025
+ exports.kindLabel = kindLabel;
1026
+ exports.loadMemoryStatus = loadMemoryStatus;
1027
+ exports.memoryPanelKey = memoryPanelKey;
1028
+ exports.memoryRequestStillCurrent = memoryRequestStillCurrent;
1029
+ exports.name = name;
1030
+ exports.parseSeatProps = parseSeatProps;
1031
+ exports.peekMemoryStatus = peekMemoryStatus;
1032
+ exports.shouldSkipMemoryRefresh = shouldSkipMemoryRefresh;
1033
+ exports.statusLabel = statusLabel;
1034
+ exports.unwrapMemoryResult = unwrapMemoryResult;
1035
+
1036
+ //# sourceMappingURL=client.inner.cjs.map