dsh-miloco-bridge 0.1.4 → 0.1.6
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 +28 -11
- package/cordis.patch.yml +13 -2
- package/docs/ARCHITECTURE.md +96 -17
- package/docs/INSTALL.md +29 -13
- package/docs/TOOLS.md +1 -1
- package/docs/VERIFICATION.md +50 -18
- package/docs/images/miloco-overview.png +0 -0
- package/docs/images/miloco-settings.png +0 -0
- package/docs/images/miloco-setup.png +0 -0
- package/lib/client.js +1386 -54
- package/lib/home.js +319 -0
- package/lib/index.js +57 -1
- package/lib/miloco-client.js +13 -5
- package/lib/overlay.js +53 -7
- package/lib/paths.js +18 -0
- package/lib/push.js +328 -48
- package/lib/settings-api.js +435 -7
- package/lib/state.js +62 -2
- package/lib/tools-entry.js +3 -1
- package/lib/tools.js +37 -7
- package/package.json +7 -2
package/lib/client.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* dsh-miloco-bridge — browser half.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* The settings half opens from the 「Miloco 家庭助手」 page (its 「配置」
|
|
5
|
+
* button) and covers:
|
|
5
6
|
*
|
|
6
7
|
* 1. whether Miloco is reachable; if not, one-click deploy or connect;
|
|
7
|
-
* 2. household
|
|
8
|
+
* 2. the household workspace directory and whether it stays registered;
|
|
8
9
|
* 3. push destination: a conversation and an optional model;
|
|
9
10
|
* 4. the dedicated agent's operating mode.
|
|
10
11
|
*
|
|
12
|
+
* The household overview itself lives on the 「Miloco 家庭助手」 page.
|
|
13
|
+
*
|
|
11
14
|
* Model selection deliberately has no "deployment default" pseudo-entry:
|
|
12
15
|
* leaving it empty means the conversation keeps its own model.
|
|
13
16
|
*
|
|
@@ -22,15 +25,20 @@ window.__ModuleLoader__.load({
|
|
|
22
25
|
const React = require('react')
|
|
23
26
|
const h = React.createElement
|
|
24
27
|
|
|
25
|
-
/**
|
|
26
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Client services this half declares.
|
|
30
|
+
*
|
|
31
|
+
* - `slots` — the slot registry every registration goes through.
|
|
32
|
+
* - `uiWorkspace` — session navigation (open/start).
|
|
33
|
+
* - `workspaces` — workspace snapshot source and idempotent `create`,
|
|
34
|
+
* used only when the host reports no household `workspaceId`.
|
|
35
|
+
* - `uiConversation` — conversation Definition registry.
|
|
36
|
+
*/
|
|
37
|
+
const inject = ['slots', 'uiWorkspace', 'workspaces', 'uiConversation']
|
|
27
38
|
|
|
28
39
|
/** Settings API prefix, mirrored from the host half. */
|
|
29
40
|
const API = '/dsh-miloco-bridge/api'
|
|
30
41
|
|
|
31
|
-
/** Tab identity inside 「设置 → 插件」. */
|
|
32
|
-
const TAB_ID = 'dsh-miloco-bridge'
|
|
33
|
-
|
|
34
42
|
const STYLE_ID = 'dsh-miloco-bridge-settings-style'
|
|
35
43
|
const SESSION_LIST_ID = 'dsh-miloco-bridge-session-list'
|
|
36
44
|
|
|
@@ -85,6 +93,11 @@ window.__ModuleLoader__.load({
|
|
|
85
93
|
.dsh-miloco-bridge-settings .field > label { color: var(--mc-text-2); font-size: 12px; }
|
|
86
94
|
.dsh-miloco-bridge-settings .fieldRow { display: flex; align-items: center; gap: 8px; }
|
|
87
95
|
.dsh-miloco-bridge-settings .fieldRow input:not([type="checkbox"]):not([type="radio"]) { flex: 1 1 auto; width: auto; min-width: 0; }
|
|
96
|
+
.dsh-miloco-bridge-settings .switchRow {
|
|
97
|
+
display: flex; align-items: center; gap: 8px; cursor: pointer;
|
|
98
|
+
color: var(--mc-text-1); font-size: 13px;
|
|
99
|
+
}
|
|
100
|
+
.dsh-miloco-bridge-settings .switchRow input { width: 15px; height: 15px; accent-color: var(--mc-accent, #4a7edc); }
|
|
88
101
|
.dsh-miloco-bridge-settings .row > select,
|
|
89
102
|
.dsh-miloco-bridge-settings .row > input:not([type="checkbox"]):not([type="radio"]) { flex: 1 1 220px; width: auto; }
|
|
90
103
|
.dsh-miloco-bridge-settings .statusRow {
|
|
@@ -238,6 +251,309 @@ window.__ModuleLoader__.load({
|
|
|
238
251
|
border: 1px solid var(--mc-border-soft); font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
239
252
|
font-size: 11.5px; line-height: 1.5; white-space: pre-wrap;
|
|
240
253
|
}
|
|
254
|
+
|
|
255
|
+
/* ---- Miloco 家庭概览(main 面板内容) ---- */
|
|
256
|
+
.dsh-miloco-dash {
|
|
257
|
+
max-width: 980px; margin: 0 auto; padding: 24px 28px 40px; color: var(--dsw-alias-label-primary, inherit);
|
|
258
|
+
font-size: var(--dsh-content-font-size-secondary, 13px); line-height: 1.6;
|
|
259
|
+
/* The host panel clips its column (overflow hidden), so the dashboard
|
|
260
|
+
scrolls itself instead of growing past the viewport. */
|
|
261
|
+
max-height: 100%; overflow-y: auto; overscroll-behavior: contain;
|
|
262
|
+
}
|
|
263
|
+
/* The header keeps the title and its two actions on one line, however narrow
|
|
264
|
+
the panel gets: the title gives up space first, the actions never wrap. */
|
|
265
|
+
.dsh-miloco-dash-head { display: flex; align-items: center; gap: 12px; flex-wrap: nowrap; }
|
|
266
|
+
.dsh-miloco-dash-head-main { flex: 1 1 auto; min-width: 0; }
|
|
267
|
+
.dsh-miloco-dash-title {
|
|
268
|
+
font-size: 20px; font-weight: 600; line-height: 28px; letter-spacing: .01em;
|
|
269
|
+
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
270
|
+
}
|
|
271
|
+
.dsh-miloco-dash-actions { flex: none; display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; }
|
|
272
|
+
.dsh-miloco-dash-actions button {
|
|
273
|
+
white-space: nowrap; flex: none;
|
|
274
|
+
height: 30px; padding: 0 13px; border-radius: var(--dsw-radius-md, 8px);
|
|
275
|
+
border: 1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.24));
|
|
276
|
+
background: transparent; color: inherit; font: inherit; font-size: 12.5px; cursor: pointer;
|
|
277
|
+
transition: background-color .15s ease, border-color .15s ease, opacity .15s ease;
|
|
278
|
+
}
|
|
279
|
+
@media (hover: hover) {
|
|
280
|
+
.dsh-miloco-dash-actions button:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover, rgba(128,128,128,.12)); }
|
|
281
|
+
}
|
|
282
|
+
.dsh-miloco-dash-actions button.primary {
|
|
283
|
+
background: var(--dsw-alias-brand-primary, #4a7edc); border-color: transparent; color: #fff; font-weight: 500;
|
|
284
|
+
}
|
|
285
|
+
.dsh-miloco-dash-actions button:disabled { opacity: .45; cursor: default; }
|
|
286
|
+
.dsh-miloco-dash-chips { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 14px 0 2px; }
|
|
287
|
+
.dsh-miloco-dash-chip {
|
|
288
|
+
display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
|
|
289
|
+
padding: 3px 9px; border-radius: 999px; border: .5px solid var(--dsw-alias-border-l2, rgba(128,128,128,.24));
|
|
290
|
+
background: var(--dsw-alias-bg-l1, rgba(128,128,128,.04)); color: var(--dsw-alias-label-secondary, rgba(128,128,128,.95));
|
|
291
|
+
font-size: 12px; line-height: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
|
|
292
|
+
}
|
|
293
|
+
.dsh-miloco-dash-chip.warn { border-color: var(--dsw-alias-state-warning-primary, #c58a2a); color: var(--dsw-alias-state-warning-primary, #c58a2a); }
|
|
294
|
+
.dsh-miloco-dash-chipdot { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--dsw-alias-label-tertiary, rgba(128,128,128,.72)); }
|
|
295
|
+
.dsh-miloco-dash-chip.ok .dsh-miloco-dash-chipdot { background: var(--dsw-alias-state-success-primary, #3c9a5a); }
|
|
296
|
+
.dsh-miloco-dash-chip.warn .dsh-miloco-dash-chipdot { background: currentColor; }
|
|
297
|
+
.dsh-miloco-dash-card {
|
|
298
|
+
border: .5px solid var(--dsw-alias-border-l1, rgba(128,128,128,.14));
|
|
299
|
+
border-radius: var(--dsw-radius-xl, 12px); padding: 14px 16px 6px; margin-top: 12px;
|
|
300
|
+
background: var(--dsw-alias-bg-l1, rgba(128,128,128,.02));
|
|
301
|
+
}
|
|
302
|
+
.dsh-miloco-dash-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-bottom: 8px; }
|
|
303
|
+
.dsh-miloco-dash-card-title { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
|
|
304
|
+
.dsh-miloco-dash-card-head h3 { margin: 0; font-size: 14px; font-weight: 600; white-space: nowrap; }
|
|
305
|
+
.dsh-miloco-dash-meta { color: var(--dsw-alias-label-tertiary, rgba(128,128,128,.72)); font-size: 12px; white-space: nowrap; }
|
|
306
|
+
.dsh-miloco-dash-score {
|
|
307
|
+
flex: none; padding: 1px 8px; border-radius: 999px; font-size: 11.5px;
|
|
308
|
+
color: var(--dsw-alias-state-success-primary, #3c9a5a);
|
|
309
|
+
border: .5px solid var(--dsw-alias-state-success-primary, #3c9a5a);
|
|
310
|
+
}
|
|
311
|
+
.dsh-miloco-dash-rooms { columns: 210px 3; column-gap: 8px; padding-bottom: 10px; }
|
|
312
|
+
.dsh-miloco-dash-room {
|
|
313
|
+
break-inside: avoid; margin-bottom: 8px;
|
|
314
|
+
border: .5px solid var(--dsw-alias-border-l1, rgba(128,128,128,.14));
|
|
315
|
+
border-radius: 10px; padding: 0 10px; background: transparent;
|
|
316
|
+
}
|
|
317
|
+
.dsh-miloco-dash-room > summary {
|
|
318
|
+
display: flex; align-items: center; gap: 8px; padding: 8px 0; cursor: pointer;
|
|
319
|
+
list-style: none; color: var(--dsw-alias-label-secondary, rgba(128,128,128,.95)); font-size: 12.5px;
|
|
320
|
+
user-select: none;
|
|
321
|
+
}
|
|
322
|
+
.dsh-miloco-dash-room > summary::-webkit-details-marker { display: none; }
|
|
323
|
+
.dsh-miloco-dash-room > summary:hover { color: var(--dsw-alias-label-primary, inherit); }
|
|
324
|
+
.dsh-miloco-dash-chev {
|
|
325
|
+
flex: none; width: 12px; text-align: center; font-size: 15px; line-height: 1;
|
|
326
|
+
color: var(--dsw-alias-label-tertiary, rgba(128,128,128,.72)); transition: transform .15s ease;
|
|
327
|
+
}
|
|
328
|
+
.dsh-miloco-dash-room[open] > summary .dsh-miloco-dash-chev { transform: rotate(90deg); }
|
|
329
|
+
.dsh-miloco-dash-room-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
330
|
+
.dsh-miloco-dash-room-count { flex: none; font-variant-numeric: tabular-nums; color: var(--dsw-alias-label-tertiary, rgba(128,128,128,.72)); }
|
|
331
|
+
.dsh-miloco-dash-room-count.ok { color: var(--dsw-alias-state-success-primary, #3c9a5a); }
|
|
332
|
+
.dsh-miloco-dash-room-count.off { color: var(--dsw-alias-state-error-primary, #c85a50); }
|
|
333
|
+
.dsh-miloco-dash-room-bar { flex: none; width: 54px; height: 4px; border-radius: 2px; overflow: hidden; background: var(--dsw-alias-border-l1, rgba(128,128,128,.14)); }
|
|
334
|
+
.dsh-miloco-dash-room-bar i { display: block; height: 100%; border-radius: 2px; background: var(--dsw-alias-state-success-primary, #3c9a5a); }
|
|
335
|
+
.dsh-miloco-dash-list { list-style: none; margin: 0 0 6px; padding: 0; max-height: 300px; overflow: auto; }
|
|
336
|
+
.dsh-miloco-dash-room .dsh-miloco-dash-list { padding-left: 0; max-height: 220px; border-top: .5px solid var(--dsw-alias-border-l1, rgba(128,128,128,.1)); }
|
|
337
|
+
.dsh-miloco-dash-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: .5px solid var(--dsw-alias-border-l1, rgba(128,128,128,.1)); min-width: 0; }
|
|
338
|
+
.dsh-miloco-dash-devdot { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--dsw-alias-label-tertiary, rgba(128,128,128,.5)); }
|
|
339
|
+
.dsh-miloco-dash-devdot.ok { background: var(--dsw-alias-state-success-primary, #3c9a5a); }
|
|
340
|
+
.dsh-miloco-dash-main { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
|
|
341
|
+
.dsh-miloco-dash-tag {
|
|
342
|
+
flex: none; padding: 0 6px; border-radius: 999px; font-size: 10.5px; line-height: 16px;
|
|
343
|
+
color: var(--dsw-alias-label-tertiary, rgba(128,128,128,.72));
|
|
344
|
+
border: .5px solid var(--dsw-alias-border-l2, rgba(128,128,128,.24));
|
|
345
|
+
}
|
|
346
|
+
.dsh-miloco-dash-link { border: 0; background: transparent; color: inherit; font: inherit; padding: 0; cursor: pointer; text-align: left; }
|
|
347
|
+
@media (hover: hover) { .dsh-miloco-dash-link:hover { color: var(--dsw-alias-brand-primary, #4a7edc); } }
|
|
348
|
+
.dsh-miloco-dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; margin-top: 12px; }
|
|
349
|
+
.dsh-miloco-dash-grid .dsh-miloco-dash-card { margin-top: 0; }
|
|
350
|
+
.dsh-miloco-dash-summary .dsh-miloco-dash-chips { margin: 0 0 8px; }
|
|
351
|
+
.dsh-miloco-dash-stats {
|
|
352
|
+
display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 8px;
|
|
353
|
+
padding: 2px 0 12px;
|
|
354
|
+
}
|
|
355
|
+
.dsh-miloco-dash-stat {
|
|
356
|
+
display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border-radius: 10px;
|
|
357
|
+
border: .5px solid var(--dsw-alias-border-l1, rgba(128,128,128,.14));
|
|
358
|
+
background: var(--dsw-alias-bg-l2, rgba(128,128,128,.04));
|
|
359
|
+
}
|
|
360
|
+
.dsh-miloco-dash-stat .k { color: var(--dsw-alias-label-tertiary, rgba(128,128,128,.72)); font-size: 11px; }
|
|
361
|
+
.dsh-miloco-dash-stat .v {
|
|
362
|
+
font-size: 15px; font-weight: 600; line-height: 1.4; overflow: hidden;
|
|
363
|
+
text-overflow: ellipsis; white-space: nowrap;
|
|
364
|
+
}
|
|
365
|
+
.dsh-miloco-dash-config-backdrop {
|
|
366
|
+
position: fixed; inset: 0; z-index: 1200; display: flex; align-items: center; justify-content: center;
|
|
367
|
+
padding: 24px; background: rgba(0, 0, 0, .38);
|
|
368
|
+
}
|
|
369
|
+
.dsh-miloco-dash-config {
|
|
370
|
+
display: flex; flex-direction: column;
|
|
371
|
+
width: min(920px, 94vw); max-height: 88vh; overflow: hidden; border-radius: 14px;
|
|
372
|
+
border: .5px solid var(--dsw-alias-border-l2, rgba(128,128,128,.24));
|
|
373
|
+
background: var(--dsw-alias-bg-module-platform, var(--dsw-alias-bg-l1, #fff));
|
|
374
|
+
box-shadow: 0 18px 50px rgba(0, 0, 0, .28);
|
|
375
|
+
}
|
|
376
|
+
.dsh-miloco-dash-config-body {
|
|
377
|
+
flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
|
|
378
|
+
}
|
|
379
|
+
.dsh-miloco-dash-config-head {
|
|
380
|
+
position: sticky; top: 0; z-index: 1; flex: none;
|
|
381
|
+
display: flex; align-items: center; justify-content: space-between;
|
|
382
|
+
gap: 12px; padding: 12px 18px; border-bottom: .5px solid var(--dsw-alias-border-l1, rgba(128,128,128,.14));
|
|
383
|
+
background: inherit;
|
|
384
|
+
}
|
|
385
|
+
.dsh-miloco-dash-config-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
|
|
386
|
+
.dsh-miloco-dash-config-close {
|
|
387
|
+
border: 0; background: transparent; color: var(--dsw-alias-label-secondary, rgba(128,128,128,.95));
|
|
388
|
+
font-size: 20px; line-height: 1; padding: 2px 6px; border-radius: 6px; cursor: pointer;
|
|
389
|
+
}
|
|
390
|
+
@media (hover: hover) { .dsh-miloco-dash-config-close:hover { background: var(--dsw-alias-interactive-bg-hover, rgba(128,128,128,.12)); } }
|
|
391
|
+
.dsh-miloco-dash-config-body > .dsh-miloco-bridge-settings { max-width: none; padding: 16px 18px 22px; }
|
|
392
|
+
.dsh-miloco-dash-empty { padding: 18px 2px 20px; color: var(--dsw-alias-label-tertiary, rgba(128,128,128,.72)); font-size: 12.5px; }
|
|
393
|
+
.dsh-miloco-dash-loading { padding: 28px 2px; color: var(--dsw-alias-label-tertiary, rgba(128,128,128,.72)); font-size: 12.5px; }
|
|
394
|
+
|
|
395
|
+
/* ---- 独立状态页:加载中 / 未配置 / 读取失败(整页居中,不复用仪表盘布局) ---- */
|
|
396
|
+
.dsh-miloco-dash-state {
|
|
397
|
+
display: flex; flex-direction: column; align-items: center; justify-content: center;
|
|
398
|
+
gap: 14px; min-height: 100%; max-height: 100%; box-sizing: border-box;
|
|
399
|
+
overflow-y: auto; overscroll-behavior: contain;
|
|
400
|
+
padding: 40px 24px 48px;
|
|
401
|
+
color: var(--dsw-alias-label-primary, inherit); text-align: center;
|
|
402
|
+
font-size: var(--dsh-content-font-size-secondary, 13px); line-height: 1.6;
|
|
403
|
+
}
|
|
404
|
+
.dsh-miloco-dash-state-card {
|
|
405
|
+
width: min(520px, 100%); padding: 26px 26px 24px; border-radius: 16px;
|
|
406
|
+
border: .5px solid var(--dsw-alias-border-l1, rgba(128,128,128,.14));
|
|
407
|
+
background: var(--dsw-alias-bg-l1, rgba(128,128,128,.02));
|
|
408
|
+
}
|
|
409
|
+
.dsh-miloco-dash-state-mark {
|
|
410
|
+
display: inline-flex; align-items: center; justify-content: center;
|
|
411
|
+
width: 44px; height: 44px; margin-bottom: 14px; border-radius: 14px;
|
|
412
|
+
border: .5px solid var(--dsw-alias-border-l1, rgba(128,128,128,.14));
|
|
413
|
+
background: var(--dsw-alias-bg-l2, rgba(128,128,128,.05));
|
|
414
|
+
color: var(--dsw-alias-label-secondary, rgba(128,128,128,.95));
|
|
415
|
+
}
|
|
416
|
+
.dsh-miloco-dash-state-title { font-size: 18px; font-weight: 600; line-height: 26px; }
|
|
417
|
+
.dsh-miloco-dash-state-sub {
|
|
418
|
+
margin-top: 8px; color: var(--dsw-alias-label-secondary, rgba(128,128,128,.95));
|
|
419
|
+
font-size: 13px; line-height: 1.75;
|
|
420
|
+
}
|
|
421
|
+
.dsh-miloco-dash-state-error {
|
|
422
|
+
margin-top: 8px; color: var(--dsw-alias-state-error-primary, #c85a50);
|
|
423
|
+
font-size: 12.5px; line-height: 1.7; overflow-wrap: anywhere;
|
|
424
|
+
}
|
|
425
|
+
.dsh-miloco-dash-steps {
|
|
426
|
+
list-style: none; margin: 20px 0 0; padding: 0; display: flex; flex-direction: column; gap: 12px;
|
|
427
|
+
text-align: left;
|
|
428
|
+
}
|
|
429
|
+
.dsh-miloco-dash-step { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 10px; }
|
|
430
|
+
.dsh-miloco-dash-step-mark {
|
|
431
|
+
flex: none; width: 20px; height: 20px; margin-top: 1px; border-radius: 50%;
|
|
432
|
+
display: inline-flex; align-items: center; justify-content: center;
|
|
433
|
+
border: .5px solid var(--dsw-alias-border-l2, rgba(128,128,128,.24));
|
|
434
|
+
font-size: 11px; line-height: 1; color: var(--dsw-alias-label-tertiary, rgba(128,128,128,.72));
|
|
435
|
+
}
|
|
436
|
+
.dsh-miloco-dash-step.done .dsh-miloco-dash-step-mark {
|
|
437
|
+
border-color: var(--dsw-alias-state-success-primary, #3c9a5a);
|
|
438
|
+
color: var(--dsw-alias-state-success-primary, #3c9a5a);
|
|
439
|
+
}
|
|
440
|
+
.dsh-miloco-dash-step-text { flex: 1 1 240px; min-width: 0; }
|
|
441
|
+
.dsh-miloco-dash-step-text strong { display: block; font-size: 13px; font-weight: 600; }
|
|
442
|
+
.dsh-miloco-dash-step-text span {
|
|
443
|
+
display: block; margin-top: 2px; color: var(--dsw-alias-label-tertiary, rgba(128,128,128,.72));
|
|
444
|
+
font-size: 12px; line-height: 1.65; overflow-wrap: anywhere;
|
|
445
|
+
}
|
|
446
|
+
.dsh-miloco-dash-state-actions {
|
|
447
|
+
margin-top: 22px; display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap;
|
|
448
|
+
}
|
|
449
|
+
.dsh-miloco-dash-state-actions button {
|
|
450
|
+
height: 32px; padding: 0 16px; border-radius: var(--dsw-radius-md, 8px);
|
|
451
|
+
border: 1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.24));
|
|
452
|
+
background: transparent; color: inherit; font: inherit; font-size: 12.5px; cursor: pointer;
|
|
453
|
+
transition: background-color .15s ease, border-color .15s ease, opacity .15s ease;
|
|
454
|
+
}
|
|
455
|
+
@media (hover: hover) {
|
|
456
|
+
.dsh-miloco-dash-state-actions button:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover, rgba(128,128,128,.12)); }
|
|
457
|
+
}
|
|
458
|
+
.dsh-miloco-dash-state-actions button.primary {
|
|
459
|
+
background: var(--dsw-alias-brand-primary, #4a7edc); border-color: transparent; color: #fff; font-weight: 500;
|
|
460
|
+
}
|
|
461
|
+
.dsh-miloco-dash-state-actions button:disabled { opacity: .45; cursor: default; }
|
|
462
|
+
.dsh-miloco-dash-note {
|
|
463
|
+
max-width: 520px; color: var(--dsw-alias-label-tertiary, rgba(128,128,128,.72));
|
|
464
|
+
font-size: 11.5px; line-height: 1.75; text-align: left;
|
|
465
|
+
}
|
|
466
|
+
.dsh-miloco-dash-bind {
|
|
467
|
+
flex: 1 1 100%; margin-top: 2px; padding: 10px 12px; border-radius: 10px;
|
|
468
|
+
border: .5px solid var(--dsw-alias-border-l1, rgba(128,128,128,.14));
|
|
469
|
+
background: var(--dsw-alias-bg-l2, rgba(128,128,128,.04));
|
|
470
|
+
}
|
|
471
|
+
.dsh-miloco-dash-bind-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
|
|
472
|
+
.dsh-miloco-dash-extlink {
|
|
473
|
+
color: var(--dsw-alias-brand-primary, #4a7edc); text-decoration: none; font-size: 12.5px;
|
|
474
|
+
}
|
|
475
|
+
@media (hover: hover) { .dsh-miloco-dash-extlink:hover { text-decoration: underline; } }
|
|
476
|
+
.dsh-miloco-dash-bind-steps {
|
|
477
|
+
margin: 10px 0 0; padding-left: 18px; display: flex; flex-direction: column; gap: 8px;
|
|
478
|
+
font-size: 12px; color: var(--dsw-alias-label-secondary, rgba(128,128,128,.95));
|
|
479
|
+
}
|
|
480
|
+
.dsh-miloco-dash-bind-steps li { display: flex; flex-direction: column; gap: 4px; }
|
|
481
|
+
.dsh-miloco-dash-bind-btn {
|
|
482
|
+
align-self: flex-start; height: 28px; padding: 0 12px; border-radius: var(--dsw-radius-md, 8px);
|
|
483
|
+
border: 1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.24));
|
|
484
|
+
background: transparent; color: inherit; font: inherit; font-size: 12px; cursor: pointer;
|
|
485
|
+
}
|
|
486
|
+
@media (hover: hover) {
|
|
487
|
+
.dsh-miloco-dash-bind-btn:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover, rgba(128,128,128,.12)); }
|
|
488
|
+
}
|
|
489
|
+
.dsh-miloco-dash-bind-btn:disabled { opacity: .45; cursor: default; }
|
|
490
|
+
.dsh-miloco-dash-bind-input {
|
|
491
|
+
width: 100%; box-sizing: border-box; min-height: 58px; resize: vertical; padding: 6px 8px;
|
|
492
|
+
border-radius: 7px; border: .5px solid var(--dsw-alias-border-l2, rgba(128,128,128,.24));
|
|
493
|
+
background: var(--dsw-alias-bg-base, transparent); color: inherit; font: inherit; font-size: 12px;
|
|
494
|
+
}
|
|
495
|
+
.dsh-miloco-dash-bind-hint {
|
|
496
|
+
color: var(--dsw-alias-label-tertiary, rgba(128,128,128,.72)); font-size: 11.5px; line-height: 1.6;
|
|
497
|
+
}
|
|
498
|
+
.dsh-miloco-dash-bind-ok {
|
|
499
|
+
margin-top: 8px; color: var(--dsw-alias-state-success-primary, #3c9a5a); font-size: 12px;
|
|
500
|
+
}
|
|
501
|
+
.dsh-miloco-dash-spinner {
|
|
502
|
+
width: 20px; height: 20px; border-radius: 50%;
|
|
503
|
+
border: 2px solid var(--dsw-alias-border-l2, rgba(128,128,128,.24));
|
|
504
|
+
border-top-color: var(--dsw-alias-brand-primary, #4a7edc);
|
|
505
|
+
animation: dsh-miloco-spin .9s linear infinite;
|
|
506
|
+
}
|
|
507
|
+
@media (prefers-reduced-motion: reduce) {
|
|
508
|
+
.dsh-miloco-dash-spinner { animation: none; }
|
|
509
|
+
}
|
|
510
|
+
.dsh-miloco-dash-error {
|
|
511
|
+
display: flex; align-items: center; justify-content: space-between; gap: 8px;
|
|
512
|
+
margin: 12px 0 0; padding: 8px 10px; border-radius: var(--dsw-radius-md, 8px);
|
|
513
|
+
border: .5px solid var(--dsw-alias-state-error-primary, #c85a50);
|
|
514
|
+
color: var(--dsw-alias-state-error-primary, #c85a50);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/* ---- 折叠推送卡片(照抄 DSH 定时任务触发通知卡片) ---- */
|
|
518
|
+
.dsh-miloco-push-root {
|
|
519
|
+
min-width: 0;
|
|
520
|
+
border: 0.5px solid var(--dsw-alias-border-l1);
|
|
521
|
+
border-radius: var(--dsw-radius-xl, var(--dsw-alias-radius-xl, 12px));
|
|
522
|
+
background: var(--dsw-alias-turn-trigger-bg, var(--dsw-alias-markdown-code-block));
|
|
523
|
+
transition: background-color 100ms ease;
|
|
524
|
+
}
|
|
525
|
+
@media (hover: hover) {
|
|
526
|
+
.dsh-miloco-push-root:hover {
|
|
527
|
+
background: var(--dsw-alias-turn-trigger-bg-hover, var(--dsw-alias-interactive-bg-hover));
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
.dsh-miloco-push-header {
|
|
531
|
+
display: flex; align-items: center; gap: 10px; width: 100%; padding: 12px 16px;
|
|
532
|
+
border: 0; background: none; color: var(--dsw-alias-label-tertiary);
|
|
533
|
+
transition: color 100ms ease; font: inherit; text-align: left; cursor: pointer;
|
|
534
|
+
}
|
|
535
|
+
@media (hover: hover) {
|
|
536
|
+
.dsh-miloco-push-header:hover { color: var(--dsw-alias-label-secondary); }
|
|
537
|
+
}
|
|
538
|
+
.dsh-miloco-push-icon { display: inline-flex; flex: none; color: inherit; }
|
|
539
|
+
.dsh-miloco-push-title {
|
|
540
|
+
flex: 1; min-width: 0; overflow-wrap: anywhere;
|
|
541
|
+
font-size: var(--dsh-content-font-size, 14px);
|
|
542
|
+
}
|
|
543
|
+
.dsh-miloco-push-time { flex: none; margin-left: auto; color: inherit; font: var(--dsw-font-xxs-12); }
|
|
544
|
+
.dsh-miloco-push-chevron { flex: none; color: inherit; }
|
|
545
|
+
.dsh-miloco-push-chevron.open { transform: rotate(180deg); }
|
|
546
|
+
.dsh-miloco-push-body { padding: 0 16px 12px 40px; }
|
|
547
|
+
.dsh-miloco-push-explanation {
|
|
548
|
+
margin: 8px 0; color: var(--dsw-alias-label-secondary); font: var(--dsw-font-xxs-12);
|
|
549
|
+
}
|
|
550
|
+
.dsh-miloco-push-content {
|
|
551
|
+
max-height: 240px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere;
|
|
552
|
+
font: var(--dsw-font-xxs-12);
|
|
553
|
+
}
|
|
554
|
+
@media (prefers-reduced-motion: reduce) {
|
|
555
|
+
.dsh-miloco-push-root, .dsh-miloco-push-header { transition: none; }
|
|
556
|
+
}
|
|
241
557
|
`
|
|
242
558
|
document.head.appendChild(style)
|
|
243
559
|
}
|
|
@@ -499,6 +815,15 @@ window.__ModuleLoader__.load({
|
|
|
499
815
|
const [upgradeConfirmOpen, setUpgradeConfirmOpen] = React.useState(false)
|
|
500
816
|
const [upgradeBusy, setUpgradeBusy] = React.useState(false)
|
|
501
817
|
const [upgradePolling, setUpgradePolling] = React.useState(false)
|
|
818
|
+
const [targetMode, setTargetMode] = React.useState('archive')
|
|
819
|
+
const [homePath, setHomePath] = React.useState('')
|
|
820
|
+
const [homeDraft, setHomeDraft] = React.useState('')
|
|
821
|
+
const [homeSource, setHomeSource] = React.useState('')
|
|
822
|
+
const [homeArchiveId, setHomeArchiveId] = React.useState('')
|
|
823
|
+
const [homeEnabled, setHomeEnabled] = React.useState(true)
|
|
824
|
+
const [homeBusy, setHomeBusy] = React.useState(false)
|
|
825
|
+
const [homeNotice, setHomeNotice] = React.useState(null)
|
|
826
|
+
const [homeError, setHomeError] = React.useState(null)
|
|
502
827
|
|
|
503
828
|
const reload = React.useCallback(() => {
|
|
504
829
|
setError(null)
|
|
@@ -516,8 +841,18 @@ window.__ModuleLoader__.load({
|
|
|
516
841
|
setConnectUrl(payload.connection?.baseUrl ?? '')
|
|
517
842
|
setMode(payload.mode?.id ?? 'readonly')
|
|
518
843
|
setPerceptionLevel(payload.overlay?.push?.perception?.minLevel ?? payload.push?.perception?.minLevel ?? 'all')
|
|
844
|
+
setTargetMode(payload.overlay?.push?.target?.mode || payload.push?.target?.mode || 'archive')
|
|
519
845
|
})
|
|
520
846
|
.catch((cause) => setError(cause instanceof Error ? cause.message : String(cause)))
|
|
847
|
+
call('/home')
|
|
848
|
+
.then((payload) => {
|
|
849
|
+
setHomePath(payload.path ?? '')
|
|
850
|
+
setHomeDraft(payload.path ?? '')
|
|
851
|
+
setHomeSource(payload.dirSource ?? '')
|
|
852
|
+
setHomeArchiveId(payload.archiveSessionId ?? '')
|
|
853
|
+
setHomeEnabled(payload.enabled !== false)
|
|
854
|
+
})
|
|
855
|
+
.catch(() => { /* 工作区不可用时保留空值,页面允许继续操作其它设置 */ })
|
|
521
856
|
}, [])
|
|
522
857
|
|
|
523
858
|
const loadVersion = React.useCallback((refresh = false) => {
|
|
@@ -618,6 +953,7 @@ window.__ModuleLoader__.load({
|
|
|
618
953
|
model: modelValue ? model : '',
|
|
619
954
|
reasoningEffort: effort,
|
|
620
955
|
perceptionLevel,
|
|
956
|
+
mode: targetMode,
|
|
621
957
|
}),
|
|
622
958
|
})
|
|
623
959
|
.then((payload) => {
|
|
@@ -626,7 +962,59 @@ window.__ModuleLoader__.load({
|
|
|
626
962
|
})
|
|
627
963
|
.catch((cause) => setError(cause instanceof Error ? cause.message : String(cause)))
|
|
628
964
|
.finally(() => setBusy(false))
|
|
629
|
-
}, [sessionId, modelValue, reasoningEffort, perceptionLevel, status])
|
|
965
|
+
}, [sessionId, modelValue, reasoningEffort, perceptionLevel, targetMode, status])
|
|
966
|
+
|
|
967
|
+
const saveHome = React.useCallback(() => {
|
|
968
|
+
const dir = homeDraft.trim()
|
|
969
|
+
if (!dir) {
|
|
970
|
+
setHomeError('目录不能为空')
|
|
971
|
+
return
|
|
972
|
+
}
|
|
973
|
+
setHomeBusy(true)
|
|
974
|
+
setHomeError(null)
|
|
975
|
+
setHomeNotice(null)
|
|
976
|
+
call('/home', {
|
|
977
|
+
method: 'POST',
|
|
978
|
+
headers: { 'content-type': 'application/json' },
|
|
979
|
+
body: JSON.stringify({ dir }),
|
|
980
|
+
})
|
|
981
|
+
.then((payload) => {
|
|
982
|
+
setHomePath(payload.path ?? dir)
|
|
983
|
+
setHomeDraft(payload.path ?? dir)
|
|
984
|
+
setHomeSource(payload.dirSource ?? 'overlay')
|
|
985
|
+
setHomeArchiveId(payload.archiveSessionId ?? '')
|
|
986
|
+
setHomeEnabled(payload.enabled !== false)
|
|
987
|
+
setHomeNotice(payload.previousPath && payload.previousPath !== payload.path
|
|
988
|
+
? `已切换目录;旧注册 ${payload.previousPath} 保留`
|
|
989
|
+
: '已保存')
|
|
990
|
+
})
|
|
991
|
+
.catch((cause) => setHomeError(cause instanceof Error ? cause.message : String(cause)))
|
|
992
|
+
.finally(() => setHomeBusy(false))
|
|
993
|
+
}, [homeDraft])
|
|
994
|
+
|
|
995
|
+
/**
|
|
996
|
+
* Turn the pinned household workspace on or off.
|
|
997
|
+
* @param {boolean} value - The wanted state.
|
|
998
|
+
* @returns {void}
|
|
999
|
+
*/
|
|
1000
|
+
const saveHomeEnabled = React.useCallback((value) => {
|
|
1001
|
+
setHomeBusy(true)
|
|
1002
|
+
setHomeError(null)
|
|
1003
|
+
setHomeNotice(null)
|
|
1004
|
+
call('/home', {
|
|
1005
|
+
method: 'POST',
|
|
1006
|
+
headers: { 'content-type': 'application/json' },
|
|
1007
|
+
body: JSON.stringify({ enabled: value }),
|
|
1008
|
+
})
|
|
1009
|
+
.then((payload) => {
|
|
1010
|
+
setHomeEnabled(payload.enabled !== false)
|
|
1011
|
+
setHomeNotice(payload.enabled === false
|
|
1012
|
+
? '已关闭置顶工作区;家庭会话归到「未分组」'
|
|
1013
|
+
: '已启用置顶工作区')
|
|
1014
|
+
})
|
|
1015
|
+
.catch((cause) => setHomeError(cause instanceof Error ? cause.message : String(cause)))
|
|
1016
|
+
.finally(() => setHomeBusy(false))
|
|
1017
|
+
}, [])
|
|
630
1018
|
|
|
631
1019
|
const deploy = React.useCallback(() => {
|
|
632
1020
|
setBusy(true)
|
|
@@ -725,7 +1113,6 @@ window.__ModuleLoader__.load({
|
|
|
725
1113
|
const backend = status.backend ?? {}
|
|
726
1114
|
const connection = status.connection ?? {}
|
|
727
1115
|
const push = status.push ?? {}
|
|
728
|
-
const overview = status.overview ?? null
|
|
729
1116
|
const adapter = status.adapter ?? {}
|
|
730
1117
|
const reachable = Boolean(backend.reachable)
|
|
731
1118
|
const cards = []
|
|
@@ -778,37 +1165,6 @@ window.__ModuleLoader__.load({
|
|
|
778
1165
|
deployLog ? h('pre', null, deployLog) : null))
|
|
779
1166
|
}
|
|
780
1167
|
|
|
781
|
-
// ---------------------------------------------------------------- 家庭概览
|
|
782
|
-
if (reachable && overview) {
|
|
783
|
-
cards.push(h('div', { className: 'card', key: 'overview' },
|
|
784
|
-
h('h3', null, '家庭概览'),
|
|
785
|
-
h('div', { className: 'grid' },
|
|
786
|
-
h('div', { className: 'stat' },
|
|
787
|
-
h('span', { className: 'k' }, '米家账号'),
|
|
788
|
-
h('span', { className: 'v', title: overview.account?.nickname || '' }, overview.account?.nickname || (overview.accountBound ? '已绑定' : '未绑定'))),
|
|
789
|
-
h('div', { className: 'stat' },
|
|
790
|
-
h('span', { className: 'k' }, '设备'),
|
|
791
|
-
h('span', { className: 'v' }, overview.deviceCount ?? '—')),
|
|
792
|
-
h('div', { className: 'stat' },
|
|
793
|
-
h('span', { className: 'k' }, '摄像头'),
|
|
794
|
-
h('span', { className: 'v' }, overview.cameraCount ?? '—')),
|
|
795
|
-
h('div', { className: 'stat' },
|
|
796
|
-
h('span', { className: 'k' }, '规则 / 任务'),
|
|
797
|
-
h('span', { className: 'v' }, `${overview.ruleCount ?? '—'} / ${overview.taskCount ?? '—'}`)),
|
|
798
|
-
h('div', { className: 'stat' },
|
|
799
|
-
h('span', { className: 'k' }, '感知引擎'),
|
|
800
|
-
h('span', { className: 'v' }, overview.perceptionRunning ? '运行中' : '未运行')),
|
|
801
|
-
h('div', { className: 'stat' },
|
|
802
|
-
h('span', { className: 'k' }, '感知源'),
|
|
803
|
-
h('span', { className: 'v' }, overview.perceptionSources ?? '—')),
|
|
804
|
-
h('div', { className: 'stat' },
|
|
805
|
-
h('span', { className: 'k' }, 'token 记录'),
|
|
806
|
-
h('span', { className: 'v' }, overview.tokenEvents ?? '—')),
|
|
807
|
-
h('div', { className: 'stat' },
|
|
808
|
-
h('span', { className: 'k' }, 'token 合计'),
|
|
809
|
-
h('span', { className: 'v' }, overview.tokenTotal ?? '—')))))
|
|
810
|
-
}
|
|
811
|
-
|
|
812
1168
|
// ---------------------------------------------------------------- 运行模式
|
|
813
1169
|
const modes = status.modes ?? []
|
|
814
1170
|
cards.push(h('div', { className: 'card', key: 'mode' },
|
|
@@ -848,7 +1204,7 @@ window.__ModuleLoader__.load({
|
|
|
848
1204
|
h('ul', null,
|
|
849
1205
|
h('li', null, '新建会话时选择「Miloco 家庭助手」;其他对话不会出现 miloco_* 工具。'),
|
|
850
1206
|
h('li', null, '在本页选择运行模式;切换后重启 DSH 或重新挂载预设生效。'),
|
|
851
|
-
h('li', null, '
|
|
1207
|
+
h('li', null, '推送目标:默认投到归档会话;切到「指定会话」后,会话留空 = 上一次触发 Miloco 的会话,也可以指定任意会话。'),
|
|
852
1208
|
h('li', null, '模型留空 = 跟随该对话;选择模型后,该对话会用指定模型处理推送。')),
|
|
853
1209
|
h('h4', null, '可以这样问'),
|
|
854
1210
|
h('ul', null,
|
|
@@ -858,6 +1214,48 @@ window.__ModuleLoader__.load({
|
|
|
858
1214
|
h('li', null, '“最近 token 用量多少?” / “为什么这条规则没触发?”')))))
|
|
859
1215
|
}
|
|
860
1216
|
|
|
1217
|
+
// ---------------------------------------------------------------- 家庭工作区
|
|
1218
|
+
const sourceLabel = homeSource === 'overlay'
|
|
1219
|
+
? '设置页覆盖'
|
|
1220
|
+
: homeSource === 'config'
|
|
1221
|
+
? '插件配置'
|
|
1222
|
+
: '默认目录'
|
|
1223
|
+
cards.push(h('div', { className: 'card', key: 'workspace' },
|
|
1224
|
+
h('h3', null, '家庭工作区'),
|
|
1225
|
+
h('div', { className: 'field' },
|
|
1226
|
+
h('label', null, '目录'),
|
|
1227
|
+
h('div', { className: 'fieldRow' },
|
|
1228
|
+
h('input', {
|
|
1229
|
+
type: 'text',
|
|
1230
|
+
value: homeDraft,
|
|
1231
|
+
placeholder: homePath || '家庭工作区目录',
|
|
1232
|
+
onChange: (event) => setHomeDraft(event.target.value),
|
|
1233
|
+
}),
|
|
1234
|
+
h('button', { type: 'button', disabled: homeBusy, onClick: saveHome }, homeBusy ? '保存中…' : '保存'))),
|
|
1235
|
+
h('div', { className: 'field' },
|
|
1236
|
+
h('label', null, '启用置顶工作区'),
|
|
1237
|
+
h('label', { className: 'switchRow' },
|
|
1238
|
+
h('input', {
|
|
1239
|
+
type: 'checkbox',
|
|
1240
|
+
checked: homeEnabled,
|
|
1241
|
+
disabled: homeBusy,
|
|
1242
|
+
onChange: (event) => saveHomeEnabled(event.target.checked),
|
|
1243
|
+
}),
|
|
1244
|
+
h('span', null, homeEnabled ? '已启用:家庭工作区置顶显示' : '已关闭:家庭会话归到「未分组」'))),
|
|
1245
|
+
h('div', { className: 'muted' }, `当前:${homePath || '—'}(${sourceLabel})`),
|
|
1246
|
+
homeArchiveId ? h('div', { className: 'muted' }, `推送归档会话:${homeArchiveId}`) : null,
|
|
1247
|
+
h('div', { className: 'muted' },
|
|
1248
|
+
'修改目录会注册新的工作区;旧目录的工作区注册不会自动删除,目录与其中的会话不受影响。'),
|
|
1249
|
+
h('div', { className: 'muted' },
|
|
1250
|
+
'工作区从侧边栏被删除后,插件会在 30 秒内自动恢复。'),
|
|
1251
|
+
h('div', { className: 'muted' },
|
|
1252
|
+
'关闭「启用置顶工作区」后不再注册工作区,已经在里面的家庭会话会归到「未分组」。'),
|
|
1253
|
+
homeNotice || homeError
|
|
1254
|
+
? h('div', { className: 'row' },
|
|
1255
|
+
homeNotice ? h('span', { className: 'pill ok' }, homeNotice) : null,
|
|
1256
|
+
homeError ? h('span', { className: 'pill bad' }, homeError) : null)
|
|
1257
|
+
: null))
|
|
1258
|
+
|
|
861
1259
|
// ---------------------------------------------------------------- 推送目标
|
|
862
1260
|
const lastSession = status.lastMilocoSession ?? ''
|
|
863
1261
|
const selectedSession = (status.sessions ?? []).find(session => session.id === sessionId)
|
|
@@ -873,7 +1271,17 @@ window.__ModuleLoader__.load({
|
|
|
873
1271
|
cards.push(h('div', { className: 'card', key: 'target' },
|
|
874
1272
|
h('h3', null, '推送目标'),
|
|
875
1273
|
h('div', { className: 'field' },
|
|
876
|
-
h('label', null, '
|
|
1274
|
+
h('label', null, '投递方式'),
|
|
1275
|
+
h('select', {
|
|
1276
|
+
value: targetMode,
|
|
1277
|
+
onChange: (event) => setTargetMode(event.target.value),
|
|
1278
|
+
}, [
|
|
1279
|
+
h('option', { key: 'archive', value: 'archive' }, '归档会话'),
|
|
1280
|
+
h('option', { key: 'session', value: 'session' }, '指定会话'),
|
|
1281
|
+
])),
|
|
1282
|
+
targetMode === 'session'
|
|
1283
|
+
? h('div', { className: 'field' },
|
|
1284
|
+
h('label', null, '对话会话'),
|
|
877
1285
|
h('div', { className: 'fieldRow' },
|
|
878
1286
|
h('input', {
|
|
879
1287
|
type: 'text',
|
|
@@ -906,10 +1314,13 @@ window.__ModuleLoader__.load({
|
|
|
906
1314
|
},
|
|
907
1315
|
}),
|
|
908
1316
|
h('datalist', { id: SESSION_LIST_ID }, sessionOptions(status)),
|
|
909
|
-
h('button', { type: 'button', disabled: busy, onClick: refreshSessions }, '刷新会话'))),
|
|
910
|
-
|
|
911
|
-
'
|
|
912
|
-
|
|
1317
|
+
h('button', { type: 'button', disabled: busy, onClick: refreshSessions }, '刷新会话'))) : null,
|
|
1318
|
+
targetMode === 'archive'
|
|
1319
|
+
? h('div', { className: 'muted' },
|
|
1320
|
+
`所有推送进入固定归档会话 ${homeArchiveId || 'miloco-archive'}(不可修改),可在家庭概览页直接打开。`)
|
|
1321
|
+
: h('div', { className: 'muted' },
|
|
1322
|
+
'留空 = 投到「上一次触发 miloco 的会话」,也就是最近一次调用过米家工具的对话。'
|
|
1323
|
+
+ '也可以从下拉里选任意对话,或直接填会话 id。'),
|
|
913
1324
|
h('div', { className: 'formGrid' },
|
|
914
1325
|
h('div', { className: 'field' },
|
|
915
1326
|
h('label', null, '模型'),
|
|
@@ -1219,27 +1630,948 @@ window.__ModuleLoader__.load({
|
|
|
1219
1630
|
}, uninstallBusy ? '卸载中…' : '确认卸载')))
|
|
1220
1631
|
: null))
|
|
1221
1632
|
|
|
1222
|
-
//
|
|
1223
|
-
const order = ['deploy', '
|
|
1633
|
+
// 运行状态固定排在第二格(未连接时在部署卡之后)。
|
|
1634
|
+
const order = ['deploy', 'runtime', 'workspace', 'mode', 'guide', 'target']
|
|
1224
1635
|
cards.sort((a, b) => order.indexOf(a.key) - order.indexOf(b.key))
|
|
1225
1636
|
|
|
1226
1637
|
return h('div', { className: 'dsh-miloco-bridge-settings' }, cards)
|
|
1227
1638
|
}
|
|
1228
1639
|
|
|
1640
|
+
/* ================================================================
|
|
1641
|
+
* 「Miloco 家庭助手」侧栏入口 + 专属工作区面板 + 折叠推送卡片
|
|
1642
|
+
* ================================================================ */
|
|
1643
|
+
|
|
1644
|
+
/** Sidebar row id and main panel key share one identity. */
|
|
1645
|
+
const PANEL_ID = 'miloco'
|
|
1646
|
+
|
|
1647
|
+
/** Message source kind carried by an inbound Miloco push. */
|
|
1648
|
+
const PUSH_SOURCE_KIND = 'miloco-push'
|
|
1649
|
+
|
|
1650
|
+
/** Agent preset the Miloco conversations run with. */
|
|
1651
|
+
const AGENT_PRESET = 'miloco'
|
|
1652
|
+
|
|
1653
|
+
/** Stable DOM id counter for the push card's disclosure body. */
|
|
1654
|
+
let pushBodySeq = 0
|
|
1655
|
+
|
|
1656
|
+
/**
|
|
1657
|
+
* Read the plain text of a message's content blocks.
|
|
1658
|
+
* @param {any} content - ContentBlock list of a user message.
|
|
1659
|
+
* @returns {string} The joined text blocks.
|
|
1660
|
+
*/
|
|
1661
|
+
function contentText(content) {
|
|
1662
|
+
if (!Array.isArray(content)) return ''
|
|
1663
|
+
return content
|
|
1664
|
+
.filter(block => block && block.type === 'text' && typeof block.text === 'string')
|
|
1665
|
+
.map(block => block.text)
|
|
1666
|
+
.join('\n')
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1669
|
+
/**
|
|
1670
|
+
* First non-empty line of a text blob.
|
|
1671
|
+
* @param {string} text - Source text.
|
|
1672
|
+
* @returns {string} The trimmed first line, or an empty string.
|
|
1673
|
+
*/
|
|
1674
|
+
function firstLine(text) {
|
|
1675
|
+
const line = String(text ?? '')
|
|
1676
|
+
.split('\n')
|
|
1677
|
+
.map(part => part.trim())
|
|
1678
|
+
.find(part => part.length > 0)
|
|
1679
|
+
return line ?? ''
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
/**
|
|
1683
|
+
* Short display form of a Miloco version.
|
|
1684
|
+
* @param {any} value - Version string.
|
|
1685
|
+
* @returns {string} The stable part, or ''.
|
|
1686
|
+
*/
|
|
1687
|
+
function formatShortVersion(value) {
|
|
1688
|
+
const text = String(value ?? '').trim()
|
|
1689
|
+
if (!text) return ''
|
|
1690
|
+
return text.split('+')[0].replace(/\.(post|dev|rc)\d*.*$/, '')
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
/**
|
|
1694
|
+
* Compact local message clock, matching DSH's message chrome.
|
|
1695
|
+
* @param {any} value - ISO string, epoch millis, or Date.
|
|
1696
|
+
* @param {number} [now] - Reference instant.
|
|
1697
|
+
* @returns {string} Local clock, or an empty string for an invalid instant.
|
|
1698
|
+
*/
|
|
1699
|
+
function formatMessageClock(value, now = Date.now()) {
|
|
1700
|
+
if (value === undefined || value === null || value === '') return ''
|
|
1701
|
+
const date = value instanceof Date ? value : new Date(value)
|
|
1702
|
+
if (Number.isNaN(date.getTime())) return ''
|
|
1703
|
+
const reference = new Date(now)
|
|
1704
|
+
const pad = part => String(part).padStart(2, '0')
|
|
1705
|
+
const clock = `${pad(date.getHours())}:${pad(date.getMinutes())}`
|
|
1706
|
+
if (date.getFullYear() === reference.getFullYear()
|
|
1707
|
+
&& date.getMonth() === reference.getMonth()
|
|
1708
|
+
&& date.getDate() === reference.getDate()) return clock
|
|
1709
|
+
const md = `${date.getMonth() + 1}月${date.getDate()}日`
|
|
1710
|
+
return date.getFullYear() === reference.getFullYear()
|
|
1711
|
+
? `${md} ${clock}`
|
|
1712
|
+
: `${date.getFullYear()}年${md} ${clock}`
|
|
1713
|
+
}
|
|
1714
|
+
|
|
1715
|
+
/**
|
|
1716
|
+
* Event time from the overview's normalised field, or the raw backend names.
|
|
1717
|
+
* @param {any} item - Event row.
|
|
1718
|
+
* @returns {string} The formatted clock, or ''.
|
|
1719
|
+
*/
|
|
1720
|
+
function eventClock(item) {
|
|
1721
|
+
const raw = item?.timestamp ?? item?.ts ?? item?.created_at ?? item?.time
|
|
1722
|
+
if (typeof raw === 'number') return formatMessageClock(raw < 1e12 ? raw * 1000 : raw)
|
|
1723
|
+
return formatMessageClock(raw)
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
/**
|
|
1727
|
+
* Event label from the overview's normalised field, or the raw names.
|
|
1728
|
+
* @param {any} item - Event row.
|
|
1729
|
+
* @returns {string} The event label.
|
|
1730
|
+
*/
|
|
1731
|
+
function eventKind(item) {
|
|
1732
|
+
return String(item?.kind ?? item?.type ?? item?.event_type ?? '事件')
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1735
|
+
/**
|
|
1736
|
+
* Event source from the overview's normalised field, or the raw names.
|
|
1737
|
+
* @param {any} item - Event row.
|
|
1738
|
+
* @returns {string} The source label.
|
|
1739
|
+
*/
|
|
1740
|
+
function eventSource(item) {
|
|
1741
|
+
return String(item?.source ?? item?.device_name ?? item?.did ?? '—')
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
/**
|
|
1745
|
+
* Event one-line text from the overview's normalised field.
|
|
1746
|
+
* @param {any} item - Event row.
|
|
1747
|
+
* @returns {string} The summary, or ''.
|
|
1748
|
+
*/
|
|
1749
|
+
function eventSummary(item) {
|
|
1750
|
+
return String(item?.summary ?? '').trim()
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
/**
|
|
1754
|
+
* Event urgency chip label, when the row carries one.
|
|
1755
|
+
* @param {any} item - Event row.
|
|
1756
|
+
* @returns {string} `高` / `中` / `低`, or '' when absent.
|
|
1757
|
+
*/
|
|
1758
|
+
function eventPriority(item) {
|
|
1759
|
+
const value = String(item?.priority ?? '').trim().toLowerCase()
|
|
1760
|
+
return value === 'high' ? '高' : value === 'medium' ? '中' : value === 'low' ? '低' : ''
|
|
1761
|
+
}
|
|
1762
|
+
|
|
1763
|
+
/**
|
|
1764
|
+
* The sidebar row glyph: a house outline drawn at the requested edge.
|
|
1765
|
+
* The sidebar owns the row, its label, and the selected state, so the
|
|
1766
|
+
* glyph only inherits the row's color, exactly like the shipped panels.
|
|
1767
|
+
* @param {{size?: number, active?: boolean}} props - Sidebar icon share.
|
|
1768
|
+
* @returns {any} The SVG element.
|
|
1769
|
+
*/
|
|
1770
|
+
function MilocoPanelIcon(props) {
|
|
1771
|
+
const size = typeof props?.size === 'number' && props.size > 0 ? props.size : 16
|
|
1772
|
+
return h('svg', {
|
|
1773
|
+
viewBox: '0 0 24 24',
|
|
1774
|
+
width: size,
|
|
1775
|
+
height: size,
|
|
1776
|
+
fill: 'none',
|
|
1777
|
+
stroke: 'currentColor',
|
|
1778
|
+
strokeWidth: 1.6,
|
|
1779
|
+
strokeLinecap: 'round',
|
|
1780
|
+
strokeLinejoin: 'round',
|
|
1781
|
+
'aria-hidden': 'true',
|
|
1782
|
+
focusable: 'false',
|
|
1783
|
+
},
|
|
1784
|
+
h('path', { d: 'M3.6 10.4 12 4l8.4 6.4' }),
|
|
1785
|
+
h('path', { d: 'M5.6 9.3V19a1 1 0 0 0 1 1h10.8a1 1 0 0 0 1-1V9.3' }),
|
|
1786
|
+
h('path', { d: 'M9.6 20v-4.6h4.8V20' }))
|
|
1787
|
+
}
|
|
1788
|
+
|
|
1789
|
+
/**
|
|
1790
|
+
* The push card's source glyph: an external event (webhook family).
|
|
1791
|
+
* @param {number} size - Requested square edge.
|
|
1792
|
+
* @returns {any} The SVG element.
|
|
1793
|
+
*/
|
|
1794
|
+
function MilocoPushSourceIcon(size) {
|
|
1795
|
+
return h('svg', {
|
|
1796
|
+
viewBox: '0 0 24 24',
|
|
1797
|
+
width: size,
|
|
1798
|
+
height: size,
|
|
1799
|
+
fill: 'none',
|
|
1800
|
+
stroke: 'currentColor',
|
|
1801
|
+
strokeWidth: 1.6,
|
|
1802
|
+
strokeLinecap: 'round',
|
|
1803
|
+
strokeLinejoin: 'round',
|
|
1804
|
+
'aria-hidden': 'true',
|
|
1805
|
+
focusable: 'false',
|
|
1806
|
+
},
|
|
1807
|
+
h('circle', { cx: 12, cy: 12, r: 8.4 }),
|
|
1808
|
+
h('path', { d: 'M3.6 12h16.8' }),
|
|
1809
|
+
h('path', { d: 'M12 3.6c2.6 2.4 2.6 14.4 0 16.8' }),
|
|
1810
|
+
h('path', { d: 'M12 3.6c-2.6 2.4-2.6 14.4 0 16.8' }))
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
/**
|
|
1814
|
+
* The push card's chevron.
|
|
1815
|
+
* @param {number} size - Requested square edge.
|
|
1816
|
+
* @returns {any} The SVG element.
|
|
1817
|
+
*/
|
|
1818
|
+
function MilocoPushChevronIcon(size) {
|
|
1819
|
+
return h('svg', {
|
|
1820
|
+
viewBox: '0 0 24 24',
|
|
1821
|
+
width: size,
|
|
1822
|
+
height: size,
|
|
1823
|
+
fill: 'none',
|
|
1824
|
+
stroke: 'currentColor',
|
|
1825
|
+
strokeWidth: 1.8,
|
|
1826
|
+
strokeLinecap: 'round',
|
|
1827
|
+
strokeLinejoin: 'round',
|
|
1828
|
+
'aria-hidden': 'true',
|
|
1829
|
+
focusable: 'false',
|
|
1830
|
+
},
|
|
1831
|
+
h('path', { d: 'M6 9.5 12 15.5 18 9.5' }))
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1834
|
+
/**
|
|
1835
|
+
* Decide which view the household page shows.
|
|
1836
|
+
*
|
|
1837
|
+
* The dashboard is only for a working installation: an unconfigured one
|
|
1838
|
+
* gets its own centred onboarding page, a failed request gets its own
|
|
1839
|
+
* error page, and the very first render is a bare loading state. All
|
|
1840
|
+
* three are separate pages — none of them reuses the dashboard layout.
|
|
1841
|
+
*
|
|
1842
|
+
* @param {any} overview - The last `/home/overview` payload, or null.
|
|
1843
|
+
* @param {any} error - The last request error, or null.
|
|
1844
|
+
* @returns {{kind: 'loading'|'error'|'setup'|'dashboard', error?: string}} The page kind.
|
|
1845
|
+
*/
|
|
1846
|
+
function milocoPanelState(overview, error) {
|
|
1847
|
+
if (!overview && !error) return { kind: 'loading' }
|
|
1848
|
+
if (error && !overview) {
|
|
1849
|
+
return { kind: 'error', error: String(error) || '读取失败' }
|
|
1850
|
+
}
|
|
1851
|
+
const status = overview?.status ?? null
|
|
1852
|
+
const setup = overview?.setup ?? null
|
|
1853
|
+
// Older hosts answer without the `setup` block: fall back to the
|
|
1854
|
+
// reachability and the account state the overview already reports.
|
|
1855
|
+
const reachable = setup
|
|
1856
|
+
? Boolean(setup.connection?.reachable)
|
|
1857
|
+
: Boolean(status?.ok)
|
|
1858
|
+
const bound = setup
|
|
1859
|
+
? Boolean(setup.account?.bound ?? setup.accountBound)
|
|
1860
|
+
: Boolean(status?.accountBound)
|
|
1861
|
+
// A reachable backend without a bound account is still "not set up":
|
|
1862
|
+
// the household overview would be empty without a household.
|
|
1863
|
+
if (!reachable || !bound) return { kind: 'setup' }
|
|
1864
|
+
return { kind: 'dashboard' }
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
/**
|
|
1868
|
+
* The centred loading state.
|
|
1869
|
+
* @param {any} [modal] - The configuration modal, rendered inside the page.
|
|
1870
|
+
* @returns {any} The element.
|
|
1871
|
+
*/
|
|
1872
|
+
function milocoLoadingPage(modal) {
|
|
1873
|
+
return h('div', { className: 'dsh-miloco-dash-state' },
|
|
1874
|
+
h('div', { className: 'dsh-miloco-dash-spinner', 'aria-hidden': 'true' }),
|
|
1875
|
+
h('div', { className: 'dsh-miloco-dash-state-sub' }, '正在读取家庭概览…'),
|
|
1876
|
+
modal ?? null)
|
|
1877
|
+
}
|
|
1878
|
+
|
|
1879
|
+
/**
|
|
1880
|
+
* The centred error state.
|
|
1881
|
+
* @param {string} error - The failure reason.
|
|
1882
|
+
* @param {() => void} onRetry - Reload the overview.
|
|
1883
|
+
* @param {() => void} onConfig - Open the configuration modal.
|
|
1884
|
+
* @param {any} [modal] - The configuration modal, rendered inside the page.
|
|
1885
|
+
* @returns {any} The element.
|
|
1886
|
+
*/
|
|
1887
|
+
function milocoErrorPage(error, onRetry, onConfig, modal) {
|
|
1888
|
+
return h('div', { className: 'dsh-miloco-dash-state' },
|
|
1889
|
+
h('div', { className: 'dsh-miloco-dash-state-card' },
|
|
1890
|
+
h('div', { className: 'dsh-miloco-dash-state-mark' }, MilocoPanelIcon({ size: 22 })),
|
|
1891
|
+
h('div', { className: 'dsh-miloco-dash-state-title' }, '家庭助手暂时读不到数据'),
|
|
1892
|
+
h('div', { className: 'dsh-miloco-dash-state-error' }, error),
|
|
1893
|
+
h('div', { className: 'dsh-miloco-dash-state-actions' },
|
|
1894
|
+
h('button', { type: 'button', className: 'primary', onClick: onRetry }, '重试'),
|
|
1895
|
+
h('button', { type: 'button', onClick: onConfig }, '打开配置'))),
|
|
1896
|
+
modal ?? null)
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1899
|
+
/**
|
|
1900
|
+
* The centred onboarding page for an installation that cannot reach
|
|
1901
|
+
* Miloco yet. It lists the three setup steps and their state instead of
|
|
1902
|
+
* pretending to be a configured household.
|
|
1903
|
+
* @param {any} overview - The `/home/overview` payload.
|
|
1904
|
+
* @param {() => void} onConfig - Open the configuration modal.
|
|
1905
|
+
* @param {() => void} onReload - Re-read the overview.
|
|
1906
|
+
* @param {any} [modal] - The configuration modal, rendered inside the page.
|
|
1907
|
+
* @returns {any} The element.
|
|
1908
|
+
*/
|
|
1909
|
+
function milocoSetupPage(overview, onConfig, onReload, modal) {
|
|
1910
|
+
const setup = overview?.setup ?? null
|
|
1911
|
+
const status = overview?.status ?? null
|
|
1912
|
+
const push = overview?.push ?? null
|
|
1913
|
+
const connection = setup?.connection ?? {}
|
|
1914
|
+
const account = setup?.account ?? {}
|
|
1915
|
+
const reachable = setup
|
|
1916
|
+
? Boolean(connection.reachable)
|
|
1917
|
+
: Boolean(status?.ok)
|
|
1918
|
+
const bound = setup
|
|
1919
|
+
? Boolean(account.bound ?? setup.accountBound)
|
|
1920
|
+
: Boolean(status?.accountBound)
|
|
1921
|
+
const milocoUrl = String(setup?.milocoUrl ?? connection.baseUrl ?? '').trim()
|
|
1922
|
+
const steps = [
|
|
1923
|
+
{
|
|
1924
|
+
id: 'connection',
|
|
1925
|
+
done: reachable,
|
|
1926
|
+
title: '部署或连接 Miloco',
|
|
1927
|
+
hint: connection.baseUrl
|
|
1928
|
+
? `当前地址:${connection.baseUrl}`
|
|
1929
|
+
: '还没有填写连接地址',
|
|
1930
|
+
},
|
|
1931
|
+
{
|
|
1932
|
+
id: 'account',
|
|
1933
|
+
done: bound,
|
|
1934
|
+
title: '绑定米家账号',
|
|
1935
|
+
hint: bound
|
|
1936
|
+
? `已绑定${account.nickname ? `:${account.nickname}` : ''}`
|
|
1937
|
+
: '在 Miloco 里登录米家账号,才能看到家里的设备',
|
|
1938
|
+
},
|
|
1939
|
+
{
|
|
1940
|
+
id: 'push',
|
|
1941
|
+
done: Boolean(setup?.pushTokenSet ?? push?.tokenSet),
|
|
1942
|
+
title: '接收 Miloco 推送',
|
|
1943
|
+
hint: '生成推送令牌后,Miloco 的主动事件会进入 DSH',
|
|
1944
|
+
},
|
|
1945
|
+
]
|
|
1946
|
+
return h('div', { className: 'dsh-miloco-dash-state' },
|
|
1947
|
+
h('div', { className: 'dsh-miloco-dash-state-card' },
|
|
1948
|
+
h('div', { className: 'dsh-miloco-dash-state-mark' }, MilocoPanelIcon({ size: 22 })),
|
|
1949
|
+
h('div', { className: 'dsh-miloco-dash-state-title' }, '家庭助手还没有初始化'),
|
|
1950
|
+
h('div', { className: 'dsh-miloco-dash-state-sub' },
|
|
1951
|
+
reachable
|
|
1952
|
+
? 'Miloco 已经连上,但还没有绑定米家账号。绑定之后,这一页会变成家庭概览:'
|
|
1953
|
+
+ '设备、房间、感知事件与推送记录。'
|
|
1954
|
+
: '家庭助手需要一个能连上的 Miloco 后端。完成下面三步之后,'
|
|
1955
|
+
+ '这一页会变成家庭概览:设备、房间、感知事件与推送记录。'),
|
|
1956
|
+
h('ul', { className: 'dsh-miloco-dash-steps' }, steps.map((step, index) => h('li', {
|
|
1957
|
+
key: step.title,
|
|
1958
|
+
className: `dsh-miloco-dash-step${step.done ? ' done' : ''}`,
|
|
1959
|
+
},
|
|
1960
|
+
h('span', { className: 'dsh-miloco-dash-step-mark', 'aria-hidden': 'true' },
|
|
1961
|
+
step.done ? '✓' : String(index + 1)),
|
|
1962
|
+
h('span', { className: 'dsh-miloco-dash-step-text' },
|
|
1963
|
+
h('strong', null, step.title),
|
|
1964
|
+
h('span', null, step.hint)),
|
|
1965
|
+
// The account step carries the binding actions: the recommended way
|
|
1966
|
+
// is Miloco's own page, the in-page flow is the fallback.
|
|
1967
|
+
step.id === 'account' && reachable && !bound
|
|
1968
|
+
? h(MilocoBindBox, { milocoUrl, onBound: onReload })
|
|
1969
|
+
: null))),
|
|
1970
|
+
setup?.error
|
|
1971
|
+
? h('div', { className: 'dsh-miloco-dash-state-error' }, setup.error)
|
|
1972
|
+
: null,
|
|
1973
|
+
h('div', { className: 'dsh-miloco-dash-state-actions' },
|
|
1974
|
+
h('button', { type: 'button', className: 'primary', onClick: onConfig }, '开始配置'),
|
|
1975
|
+
h('button', { type: 'button', onClick: onReload }, '重新检测'))),
|
|
1976
|
+
h('div', { className: 'dsh-miloco-dash-note' },
|
|
1977
|
+
'隐私说明:本插件只与本机 Miloco 通信,不会把账号、令牌或家庭数据上传到任何第三方;'
|
|
1978
|
+
+ '绑定建议优先在 Miloco 自己的页面完成。'),
|
|
1979
|
+
modal ?? null)
|
|
1980
|
+
}
|
|
1981
|
+
|
|
1982
|
+
/**
|
|
1983
|
+
* The account binding actions of the onboarding page.
|
|
1984
|
+
*
|
|
1985
|
+
* Two ways, in the order the user should prefer them:
|
|
1986
|
+
* 1. open Miloco's own page (its account dialog does the whole flow);
|
|
1987
|
+
* 2. do it here — fetch the Xiaomi authorization link, let the user paste
|
|
1988
|
+
* the payload the callback page shows, then hand it to Miloco.
|
|
1989
|
+
*
|
|
1990
|
+
* @param {{milocoUrl?: string, onBound?: () => void}} props - Component props.
|
|
1991
|
+
* @returns {any} The element.
|
|
1992
|
+
*/
|
|
1993
|
+
function MilocoBindBox(props) {
|
|
1994
|
+
const milocoUrl = String(props?.milocoUrl ?? '').trim()
|
|
1995
|
+
const onBound = props?.onBound
|
|
1996
|
+
const [open, setOpen] = React.useState(false)
|
|
1997
|
+
const [oauthUrl, setOauthUrl] = React.useState('')
|
|
1998
|
+
const [payload, setPayload] = React.useState('')
|
|
1999
|
+
const [busy, setBusy] = React.useState(false)
|
|
2000
|
+
const [error, setError] = React.useState('')
|
|
2001
|
+
const [done, setDone] = React.useState('')
|
|
2002
|
+
|
|
2003
|
+
const fetchLink = () => {
|
|
2004
|
+
setBusy(true)
|
|
2005
|
+
setError('')
|
|
2006
|
+
call('/miot/bind', { method: 'POST' })
|
|
2007
|
+
.then((payload_) => {
|
|
2008
|
+
setOauthUrl(String(payload_?.oauthUrl ?? ''))
|
|
2009
|
+
if (!payload_?.oauthUrl) setError('Miloco 没有返回授权链接')
|
|
2010
|
+
})
|
|
2011
|
+
.catch((cause) => setError(cause instanceof Error ? cause.message : String(cause)))
|
|
2012
|
+
.finally(() => setBusy(false))
|
|
2013
|
+
}
|
|
2014
|
+
|
|
2015
|
+
const submit = () => {
|
|
2016
|
+
if (!payload.trim()) {
|
|
2017
|
+
setError('请先粘贴小米回调页给出的内容')
|
|
2018
|
+
return
|
|
2019
|
+
}
|
|
2020
|
+
setBusy(true)
|
|
2021
|
+
setError('')
|
|
2022
|
+
call('/miot/authorize', {
|
|
2023
|
+
method: 'POST',
|
|
2024
|
+
headers: { 'content-type': 'application/json' },
|
|
2025
|
+
body: JSON.stringify({ payload }),
|
|
2026
|
+
})
|
|
2027
|
+
.then(() => {
|
|
2028
|
+
setDone('绑定成功,正在刷新…(若设备为空,请在 Miloco 里选择家庭)')
|
|
2029
|
+
setPayload('')
|
|
2030
|
+
onBound?.()
|
|
2031
|
+
})
|
|
2032
|
+
.catch((cause) => setError(cause instanceof Error ? cause.message : String(cause)))
|
|
2033
|
+
.finally(() => setBusy(false))
|
|
2034
|
+
}
|
|
2035
|
+
|
|
2036
|
+
return h('div', { className: 'dsh-miloco-dash-bind' },
|
|
2037
|
+
h('div', { className: 'dsh-miloco-dash-bind-row' },
|
|
2038
|
+
milocoUrl
|
|
2039
|
+
? h('a', {
|
|
2040
|
+
className: 'dsh-miloco-dash-extlink',
|
|
2041
|
+
href: milocoUrl,
|
|
2042
|
+
target: '_blank',
|
|
2043
|
+
rel: 'noopener noreferrer',
|
|
2044
|
+
}, '在 Miloco 中绑定 ↗')
|
|
2045
|
+
: null,
|
|
2046
|
+
h('button', {
|
|
2047
|
+
type: 'button',
|
|
2048
|
+
className: 'dsh-miloco-dash-link',
|
|
2049
|
+
onClick: () => setOpen(!open),
|
|
2050
|
+
}, open ? '收起本页绑定' : '或在本页绑定')),
|
|
2051
|
+
open
|
|
2052
|
+
? h('div', null,
|
|
2053
|
+
h('ol', { className: 'dsh-miloco-dash-bind-steps' },
|
|
2054
|
+
h('li', null,
|
|
2055
|
+
h('button', {
|
|
2056
|
+
type: 'button',
|
|
2057
|
+
className: 'dsh-miloco-dash-bind-btn',
|
|
2058
|
+
disabled: busy,
|
|
2059
|
+
onClick: fetchLink,
|
|
2060
|
+
}, busy && !oauthUrl ? '获取中…' : '① 获取小米授权链接'),
|
|
2061
|
+
oauthUrl
|
|
2062
|
+
? h('a', {
|
|
2063
|
+
className: 'dsh-miloco-dash-extlink',
|
|
2064
|
+
href: oauthUrl,
|
|
2065
|
+
target: '_blank',
|
|
2066
|
+
rel: 'noopener noreferrer',
|
|
2067
|
+
}, '打开小米授权页 ↗')
|
|
2068
|
+
: null),
|
|
2069
|
+
h('li', null,
|
|
2070
|
+
h('div', null, '② 粘贴小米回调页给出的整段内容'),
|
|
2071
|
+
h('div', { className: 'dsh-miloco-dash-bind-hint' },
|
|
2072
|
+
'① 只点一次:重新获取授权链接会让刚才复制的内容失效。'),
|
|
2073
|
+
h('textarea', {
|
|
2074
|
+
className: 'dsh-miloco-dash-bind-input',
|
|
2075
|
+
value: payload,
|
|
2076
|
+
placeholder: '回调页上的授权内容',
|
|
2077
|
+
onChange: (event) => setPayload(event.target.value),
|
|
2078
|
+
})),
|
|
2079
|
+
h('li', null,
|
|
2080
|
+
h('button', {
|
|
2081
|
+
type: 'button',
|
|
2082
|
+
className: 'dsh-miloco-dash-bind-btn',
|
|
2083
|
+
disabled: busy,
|
|
2084
|
+
onClick: submit,
|
|
2085
|
+
}, busy ? '绑定中…' : '③ 完成绑定'))),
|
|
2086
|
+
done ? h('div', { className: 'dsh-miloco-dash-bind-ok' }, done) : null,
|
|
2087
|
+
error ? h('div', { className: 'dsh-miloco-dash-state-error' }, error) : null)
|
|
2088
|
+
: null)
|
|
2089
|
+
}
|
|
2090
|
+
|
|
2091
|
+
/**
|
|
2092
|
+
* Build the 「Miloco 家庭助手」 main panel bound to one plugin context.
|
|
2093
|
+
* The panel is a read-only household overview: workspace path and state,
|
|
2094
|
+
* devices by room, recent events, and recent pushes. Session management
|
|
2095
|
+
* (pin/rename/archive) deliberately lives nowhere else.
|
|
2096
|
+
* @param {any} ctx - Browser plugin context.
|
|
2097
|
+
* @returns {Function} The panel component.
|
|
2098
|
+
*/
|
|
2099
|
+
function createMilocoHomePanel(ctx) {
|
|
2100
|
+
function MilocoHomePanel() {
|
|
2101
|
+
const [overview, setOverview] = React.useState(null)
|
|
2102
|
+
const [error, setError] = React.useState(null)
|
|
2103
|
+
const [configOpen, setConfigOpen] = React.useState(false)
|
|
2104
|
+
const inFlight = React.useRef(false)
|
|
2105
|
+
const mounted = React.useRef(false)
|
|
2106
|
+
|
|
2107
|
+
const load = React.useCallback(() => {
|
|
2108
|
+
if (inFlight.current) return
|
|
2109
|
+
inFlight.current = true
|
|
2110
|
+
call('/home/overview')
|
|
2111
|
+
.then((payload) => {
|
|
2112
|
+
if (!mounted.current) return
|
|
2113
|
+
setOverview(payload)
|
|
2114
|
+
setError(null)
|
|
2115
|
+
})
|
|
2116
|
+
.catch((cause) => {
|
|
2117
|
+
if (!mounted.current) return
|
|
2118
|
+
setError(cause instanceof Error ? cause.message : String(cause))
|
|
2119
|
+
})
|
|
2120
|
+
.finally(() => {
|
|
2121
|
+
inFlight.current = false
|
|
2122
|
+
})
|
|
2123
|
+
}, [])
|
|
2124
|
+
|
|
2125
|
+
React.useEffect(() => {
|
|
2126
|
+
mounted.current = true
|
|
2127
|
+
load()
|
|
2128
|
+
const timer = window.setInterval(() => {
|
|
2129
|
+
if (document.visibilityState === 'visible') load()
|
|
2130
|
+
}, 60_000)
|
|
2131
|
+
return () => {
|
|
2132
|
+
mounted.current = false
|
|
2133
|
+
window.clearInterval(timer)
|
|
2134
|
+
}
|
|
2135
|
+
}, [load])
|
|
2136
|
+
|
|
2137
|
+
React.useEffect(() => {
|
|
2138
|
+
if (!configOpen) return undefined
|
|
2139
|
+
const onKeyDown = (event) => {
|
|
2140
|
+
if (event.key === 'Escape') setConfigOpen(false)
|
|
2141
|
+
}
|
|
2142
|
+
window.addEventListener('keydown', onKeyDown)
|
|
2143
|
+
return () => window.removeEventListener('keydown', onKeyDown)
|
|
2144
|
+
}, [configOpen])
|
|
2145
|
+
|
|
2146
|
+
// Host without `workspaceRegistry`: adopt the path through the public API
|
|
2147
|
+
// so the page still gets a workspace id. Idempotent for a known path.
|
|
2148
|
+
const adopting = React.useRef(false)
|
|
2149
|
+
React.useEffect(() => {
|
|
2150
|
+
const homeState = overview?.home
|
|
2151
|
+
if (!homeState?.path || homeState.workspaceId || adopting.current) return
|
|
2152
|
+
if (!ctx.workspaces || typeof ctx.workspaces.create !== 'function') return
|
|
2153
|
+
adopting.current = true
|
|
2154
|
+
ctx.workspaces.create({ path: homeState.path })
|
|
2155
|
+
.then(async (workspace) => {
|
|
2156
|
+
const workspaceId = workspace?.workspaceId ?? ''
|
|
2157
|
+
if (!workspaceId) return
|
|
2158
|
+
if (homeState.title && typeof ctx.workspaces.rename === 'function') {
|
|
2159
|
+
await ctx.workspaces.rename(workspaceId, homeState.title).catch(() => {})
|
|
2160
|
+
}
|
|
2161
|
+
if (typeof ctx.workspaces.insertBefore === 'function') {
|
|
2162
|
+
const list = ctx.workspaces.list
|
|
2163
|
+
const items = typeof list?.getSnapshot === 'function'
|
|
2164
|
+
? (list.getSnapshot()?.items ?? [])
|
|
2165
|
+
: []
|
|
2166
|
+
const first = items.find(item => item?.workspaceId !== workspaceId)
|
|
2167
|
+
if (first) await ctx.workspaces.insertBefore(workspaceId, first.workspaceId).catch(() => {})
|
|
2168
|
+
}
|
|
2169
|
+
if (!mounted.current) return
|
|
2170
|
+
setOverview(previous => previous
|
|
2171
|
+
? { ...previous, home: { ...previous.home, workspaceId } }
|
|
2172
|
+
: previous)
|
|
2173
|
+
})
|
|
2174
|
+
.catch((cause) => {
|
|
2175
|
+
if (mounted.current) {
|
|
2176
|
+
setError(`无法注册家庭工作区:${cause instanceof Error ? cause.message : String(cause)}`)
|
|
2177
|
+
}
|
|
2178
|
+
})
|
|
2179
|
+
.finally(() => { adopting.current = false })
|
|
2180
|
+
}, [overview?.home?.path, overview?.home?.workspaceId, overview?.home?.title])
|
|
2181
|
+
|
|
2182
|
+
const home = overview?.home ?? null
|
|
2183
|
+
const status = overview?.status ?? null
|
|
2184
|
+
const version = overview?.version ?? null
|
|
2185
|
+
const devices = overview?.devices ?? null
|
|
2186
|
+
const events = overview?.events ?? null
|
|
2187
|
+
const pushes = overview?.pushes ?? null
|
|
2188
|
+
const push = overview?.push ?? null
|
|
2189
|
+
const stats = overview?.overview ?? null
|
|
2190
|
+
// 页面形态:加载中 / 读取失败 / 未配置 / 仪表盘,四种互斥。
|
|
2191
|
+
const view = milocoPanelState(overview, error)
|
|
2192
|
+
|
|
2193
|
+
const startSession = () => {
|
|
2194
|
+
if (!home?.workspaceId) return
|
|
2195
|
+
try {
|
|
2196
|
+
ctx.uiWorkspace.startSession(home.workspaceId, {
|
|
2197
|
+
agentPreset: home.agentPreset || AGENT_PRESET,
|
|
2198
|
+
})
|
|
2199
|
+
} catch (cause) {
|
|
2200
|
+
setError(cause instanceof Error ? cause.message : String(cause))
|
|
2201
|
+
}
|
|
2202
|
+
}
|
|
2203
|
+
|
|
2204
|
+
const openSession = (sessionId) => {
|
|
2205
|
+
if (typeof sessionId !== 'string' || !sessionId) return
|
|
2206
|
+
try {
|
|
2207
|
+
ctx.uiWorkspace.openSession(sessionId)
|
|
2208
|
+
} catch (cause) {
|
|
2209
|
+
setError(cause instanceof Error ? cause.message : String(cause))
|
|
2210
|
+
}
|
|
2211
|
+
}
|
|
2212
|
+
|
|
2213
|
+
const rooms = devices?.ok && Array.isArray(devices.rooms) ? devices.rooms : []
|
|
2214
|
+
const eventItems = events?.ok && Array.isArray(events.items) ? events.items : []
|
|
2215
|
+
const pushItems = pushes?.ok && Array.isArray(pushes.items) ? pushes.items.slice(0, 10) : []
|
|
2216
|
+
|
|
2217
|
+
const sectionError = text => h('div', { className: 'dsh-miloco-dash-error' },
|
|
2218
|
+
h('span', null, text || '读取失败'),
|
|
2219
|
+
h('button', { type: 'button', className: 'dsh-miloco-dash-link', onClick: load }, '重试'))
|
|
2220
|
+
|
|
2221
|
+
const chip = (key, tone, label, title) => h('span', {
|
|
2222
|
+
key,
|
|
2223
|
+
className: `dsh-miloco-dash-chip${tone ? ` ${tone}` : ''}`,
|
|
2224
|
+
title: title || undefined,
|
|
2225
|
+
},
|
|
2226
|
+
tone === 'ok' || tone === 'warn'
|
|
2227
|
+
? h('i', { className: 'dsh-miloco-dash-chipdot', 'aria-hidden': 'true' })
|
|
2228
|
+
: null,
|
|
2229
|
+
h('span', null, label))
|
|
2230
|
+
|
|
2231
|
+
const stat = (key, label, value, title) => h('div', { className: 'dsh-miloco-dash-stat', key },
|
|
2232
|
+
h('span', { className: 'k' }, label),
|
|
2233
|
+
h('span', { className: 'v', title: title || undefined }, value))
|
|
2234
|
+
|
|
2235
|
+
const header = h('div', { className: 'dsh-miloco-dash-head' },
|
|
2236
|
+
h('div', { className: 'dsh-miloco-dash-head-main' },
|
|
2237
|
+
h('div', { className: 'dsh-miloco-dash-title' }, '家庭助手')),
|
|
2238
|
+
h('div', { className: 'dsh-miloco-dash-actions' },
|
|
2239
|
+
h('button', {
|
|
2240
|
+
type: 'button',
|
|
2241
|
+
className: 'primary',
|
|
2242
|
+
disabled: !home?.workspaceId,
|
|
2243
|
+
onClick: startSession,
|
|
2244
|
+
}, '新建家庭会话'),
|
|
2245
|
+
h('button', { type: 'button', onClick: () => setConfigOpen(true) }, '配置')))
|
|
2246
|
+
|
|
2247
|
+
// 配置弹层:仪表盘、初始化页、错误页共用同一个弹层。
|
|
2248
|
+
const configModal = configOpen
|
|
2249
|
+
? h('div', {
|
|
2250
|
+
className: 'dsh-miloco-dash-config-backdrop',
|
|
2251
|
+
onClick: (event) => {
|
|
2252
|
+
if (event.target === event.currentTarget) setConfigOpen(false)
|
|
2253
|
+
},
|
|
2254
|
+
},
|
|
2255
|
+
h('div', { className: 'dsh-miloco-dash-config' },
|
|
2256
|
+
h('div', { className: 'dsh-miloco-dash-config-head' },
|
|
2257
|
+
h('h3', null, 'Miloco 配置'),
|
|
2258
|
+
h('button', {
|
|
2259
|
+
type: 'button',
|
|
2260
|
+
className: 'dsh-miloco-dash-config-close',
|
|
2261
|
+
onClick: () => setConfigOpen(false),
|
|
2262
|
+
'aria-label': '关闭配置',
|
|
2263
|
+
}, '×')),
|
|
2264
|
+
h('div', { className: 'dsh-miloco-dash-config-body' }, h(MilocoSettingsTab))))
|
|
2265
|
+
: null
|
|
2266
|
+
|
|
2267
|
+
// ---------------------------------------------------------------- 加载中
|
|
2268
|
+
// 加载中不渲染仪表盘头部:按钮此时还没有意义,页面只留一个居中的
|
|
2269
|
+
// 进度提示,避免「标题 + 按钮悬在顶上」的半成品样子。
|
|
2270
|
+
if (view.kind === 'loading') {
|
|
2271
|
+
return milocoLoadingPage(configModal)
|
|
2272
|
+
}
|
|
2273
|
+
|
|
2274
|
+
// 整体请求失败(插件未加载、版本不匹配、服务端异常)时给一页独立的
|
|
2275
|
+
// 错误说明,而不是把空仪表盘铺在页面上。
|
|
2276
|
+
if (view.kind === 'error') {
|
|
2277
|
+
return milocoErrorPage(view.error, load, () => setConfigOpen(true), configModal)
|
|
2278
|
+
}
|
|
2279
|
+
|
|
2280
|
+
// 没连上 Miloco 时,页面是一张独立的初始化引导,而不是「配好了」的
|
|
2281
|
+
// 仪表盘:两者信息量完全不同,不能共用一套布局。
|
|
2282
|
+
if (view.kind === 'setup') {
|
|
2283
|
+
return milocoSetupPage(overview, () => setConfigOpen(true), load, configModal)
|
|
2284
|
+
}
|
|
2285
|
+
|
|
2286
|
+
return h('div', { className: 'dsh-miloco-dash' },
|
|
2287
|
+
header,
|
|
2288
|
+
|
|
2289
|
+
error ? sectionError(error) : null,
|
|
2290
|
+
|
|
2291
|
+
h('section', { className: 'dsh-miloco-dash-card dsh-miloco-dash-summary' },
|
|
2292
|
+
h('div', { className: 'dsh-miloco-dash-card-head' },
|
|
2293
|
+
h('div', { className: 'dsh-miloco-dash-card-title' },
|
|
2294
|
+
h('h3', null, '家庭概览'),
|
|
2295
|
+
status?.perceptionRunning
|
|
2296
|
+
? h('span', { className: 'dsh-miloco-dash-meta' }, '感知运行中')
|
|
2297
|
+
: null)),
|
|
2298
|
+
h('div', { className: 'dsh-miloco-dash-chips' },
|
|
2299
|
+
chip('status', status?.reachable ? 'ok' : 'warn',
|
|
2300
|
+
status?.ok ? (status.reachable ? '已连接' : '未连接') : '状态不可用'),
|
|
2301
|
+
version?.current
|
|
2302
|
+
? chip('version', '', `v${formatShortVersion(version.current)}`, version.current)
|
|
2303
|
+
: null,
|
|
2304
|
+
version?.hasUpdate ? chip('update', 'warn', '有更新') : null,
|
|
2305
|
+
status?.accountBound
|
|
2306
|
+
? chip('account', '', '账号已绑定', status.account?.nickname || '')
|
|
2307
|
+
: chip('account', 'warn', '账号未绑定'),
|
|
2308
|
+
push
|
|
2309
|
+
? chip('push', push.tokenSet ? 'ok' : 'warn',
|
|
2310
|
+
push.tokenSet ? '推送已启用' : '推送未配置', push.path)
|
|
2311
|
+
: null),
|
|
2312
|
+
h('div', { className: 'dsh-miloco-dash-stats' },
|
|
2313
|
+
stat('account', '米家账号',
|
|
2314
|
+
stats?.account?.nickname || (stats?.accountBound ? '已绑定' : '未绑定'),
|
|
2315
|
+
stats?.account?.nickname || ''),
|
|
2316
|
+
stat('devices', '设备', stats?.deviceCount ?? '—'),
|
|
2317
|
+
stat('cameras', '摄像头', stats?.cameraCount ?? '—'),
|
|
2318
|
+
stat('rules', '规则 / 任务', `${stats?.ruleCount ?? '—'} / ${stats?.taskCount ?? '—'}`),
|
|
2319
|
+
stat('engine', '感知引擎', stats?.perceptionRunning ? '运行中' : '未运行'),
|
|
2320
|
+
stat('sources', '感知源', stats?.perceptionSources ?? '—'),
|
|
2321
|
+
stat('tokenEvents', 'token 记录', stats?.tokenEvents ?? '—'),
|
|
2322
|
+
stat('tokenTotal', 'token 合计', stats?.tokenTotal ?? '—'))),
|
|
2323
|
+
|
|
2324
|
+
h('section', { className: 'dsh-miloco-dash-card' },
|
|
2325
|
+
h('div', { className: 'dsh-miloco-dash-card-head' },
|
|
2326
|
+
h('div', { className: 'dsh-miloco-dash-card-title' },
|
|
2327
|
+
h('h3', null, '设备与房间'),
|
|
2328
|
+
devices?.ok
|
|
2329
|
+
? h('span', { className: 'dsh-miloco-dash-meta' },
|
|
2330
|
+
`${rooms.length} 个房间 · ${devices.total} 台设备`)
|
|
2331
|
+
: null),
|
|
2332
|
+
devices?.ok
|
|
2333
|
+
? h('span', { className: 'dsh-miloco-dash-score' }, `${devices.online} 在线`)
|
|
2334
|
+
: null),
|
|
2335
|
+
devices?.ok
|
|
2336
|
+
? (rooms.length > 0
|
|
2337
|
+
? h('div', { className: 'dsh-miloco-dash-rooms' }, rooms.map(room => h('details', { className: 'dsh-miloco-dash-room', key: room.name },
|
|
2338
|
+
h('summary', { className: 'dsh-miloco-dash-room-head' },
|
|
2339
|
+
h('span', { className: 'dsh-miloco-dash-room-name' }, room.name),
|
|
2340
|
+
h('span', {
|
|
2341
|
+
className: `dsh-miloco-dash-room-count${room.online === room.total ? ' ok' : room.online === 0 ? ' off' : ''}`,
|
|
2342
|
+
}, `${room.online}/${room.total}`),
|
|
2343
|
+
h('span', { className: 'dsh-miloco-dash-room-bar', 'aria-hidden': 'true' },
|
|
2344
|
+
h('i', {
|
|
2345
|
+
style: { width: `${room.total ? Math.round((room.online / room.total) * 100) : 0}%` },
|
|
2346
|
+
})),
|
|
2347
|
+
h('span', { className: 'dsh-miloco-dash-chev', 'aria-hidden': 'true' }, '›')),
|
|
2348
|
+
h('ul', { className: 'dsh-miloco-dash-list' }, (room.devices ?? []).map((device, index) => h('li', {
|
|
2349
|
+
key: device.did || device.name || String(index),
|
|
2350
|
+
className: 'dsh-miloco-dash-row',
|
|
2351
|
+
},
|
|
2352
|
+
h('span', {
|
|
2353
|
+
className: `dsh-miloco-dash-devdot${device.online ? ' ok' : ''}`,
|
|
2354
|
+
'aria-hidden': 'true',
|
|
2355
|
+
}),
|
|
2356
|
+
h('span', { className: 'dsh-miloco-dash-main', title: device.name || device.did || undefined }, device.name || device.did || '未命名设备'),
|
|
2357
|
+
device.online ? null : h('span', { className: 'dsh-miloco-dash-tag' }, '离线')))))))
|
|
2358
|
+
: h('div', { className: 'dsh-miloco-dash-empty' }, '没有设备'))
|
|
2359
|
+
: sectionError(devices?.error || '读取设备失败')),
|
|
2360
|
+
|
|
2361
|
+
h('div', { className: 'dsh-miloco-dash-grid' },
|
|
2362
|
+
h('section', { className: 'dsh-miloco-dash-card' },
|
|
2363
|
+
h('div', { className: 'dsh-miloco-dash-card-head' },
|
|
2364
|
+
h('div', { className: 'dsh-miloco-dash-card-title' },
|
|
2365
|
+
h('h3', null, '最近事件'),
|
|
2366
|
+
events?.ok && eventItems.length > 0
|
|
2367
|
+
? h('span', { className: 'dsh-miloco-dash-meta' }, `${eventItems.length} 条`)
|
|
2368
|
+
: null)),
|
|
2369
|
+
events?.ok
|
|
2370
|
+
? (eventItems.length > 0
|
|
2371
|
+
? h('ul', { className: 'dsh-miloco-dash-list' }, eventItems.map((item, index) => {
|
|
2372
|
+
const summary = eventSummary(item)
|
|
2373
|
+
const source = eventSource(item)
|
|
2374
|
+
const priority = eventPriority(item)
|
|
2375
|
+
return h('li', {
|
|
2376
|
+
key: `${eventKind(item)}-${index}`,
|
|
2377
|
+
className: 'dsh-miloco-dash-row',
|
|
2378
|
+
},
|
|
2379
|
+
h('span', {
|
|
2380
|
+
className: 'dsh-miloco-dash-main',
|
|
2381
|
+
title: summary && source ? `${source} · ${summary}` : summary || source || undefined,
|
|
2382
|
+
}, summary || eventKind(item)),
|
|
2383
|
+
priority ? h('span', { className: 'dsh-miloco-dash-tag' }, priority) : null,
|
|
2384
|
+
h('span', { className: 'dsh-miloco-dash-meta' }, eventClock(item) || '—'))
|
|
2385
|
+
}))
|
|
2386
|
+
: h('div', { className: 'dsh-miloco-dash-empty' }, '最近没有事件'))
|
|
2387
|
+
: sectionError(events?.error || '读取事件失败')),
|
|
2388
|
+
|
|
2389
|
+
h('section', { className: 'dsh-miloco-dash-card' },
|
|
2390
|
+
h('div', { className: 'dsh-miloco-dash-card-head' },
|
|
2391
|
+
h('div', { className: 'dsh-miloco-dash-card-title' },
|
|
2392
|
+
h('h3', null, '推送记录'),
|
|
2393
|
+
pushItems.length > 0
|
|
2394
|
+
? h('span', { className: 'dsh-miloco-dash-meta' }, `${pushItems.length} 条`)
|
|
2395
|
+
: null),
|
|
2396
|
+
home?.archive?.exists
|
|
2397
|
+
? h('button', {
|
|
2398
|
+
type: 'button',
|
|
2399
|
+
className: 'dsh-miloco-dash-link dsh-miloco-dash-meta',
|
|
2400
|
+
onClick: () => openSession(home.archive.sessionId),
|
|
2401
|
+
}, '打开归档会话')
|
|
2402
|
+
: null),
|
|
2403
|
+
pushes?.ok
|
|
2404
|
+
? (pushItems.length > 0
|
|
2405
|
+
? h('ul', { className: 'dsh-miloco-dash-list' }, pushItems.map((item, index) => h('li', {
|
|
2406
|
+
key: item.runId || String(index),
|
|
2407
|
+
className: 'dsh-miloco-dash-row',
|
|
2408
|
+
},
|
|
2409
|
+
h('button', {
|
|
2410
|
+
type: 'button',
|
|
2411
|
+
className: 'dsh-miloco-dash-link dsh-miloco-dash-main',
|
|
2412
|
+
onClick: () => openSession(item.sessionId),
|
|
2413
|
+
}, item.title || item.summary || '推送'),
|
|
2414
|
+
h('span', { className: 'dsh-miloco-dash-meta' }, `${item.at ? formatMessageClock(item.at) : '—'}${item.status ? ` · ${item.status}` : ''}`))))
|
|
2415
|
+
: h('div', { className: 'dsh-miloco-dash-empty' }, '还没有推送记录'))
|
|
2416
|
+
: sectionError(pushes?.error || '读取推送失败'))),
|
|
2417
|
+
|
|
2418
|
+
configModal)
|
|
2419
|
+
}
|
|
2420
|
+
|
|
2421
|
+
return MilocoHomePanel
|
|
2422
|
+
}
|
|
2423
|
+
|
|
2424
|
+
/**
|
|
2425
|
+
* The conversation Definition that claims an inbound Miloco push.
|
|
2426
|
+
*
|
|
2427
|
+
* `exclusive: true` claims the event on the `chat` target, so the
|
|
2428
|
+
* built-in non-exclusive `input-message` Definition never sees it and the
|
|
2429
|
+
* push is rendered exactly once, by our own renderer.
|
|
2430
|
+
*/
|
|
2431
|
+
const milocoPushDefinition = {
|
|
2432
|
+
kind: PUSH_SOURCE_KIND,
|
|
2433
|
+
target: 'chat',
|
|
2434
|
+
match: (event) => {
|
|
2435
|
+
if (event?.type !== 'user/message') return null
|
|
2436
|
+
const source = event.data?.source
|
|
2437
|
+
if (source?.kind !== PUSH_SOURCE_KIND) return null
|
|
2438
|
+
return { id: String(event.data.id), role: 'start', exclusive: true }
|
|
2439
|
+
},
|
|
2440
|
+
start: (_context, match) => {
|
|
2441
|
+
const event = match.event
|
|
2442
|
+
const content = contentText(event.data?.content)
|
|
2443
|
+
const summary = typeof event.data?.source?.summary === 'string' ? event.data.source.summary : ''
|
|
2444
|
+
return {
|
|
2445
|
+
seq: event.seq,
|
|
2446
|
+
time: event.time,
|
|
2447
|
+
title: summary || firstLine(content) || 'Miloco 推送',
|
|
2448
|
+
summary,
|
|
2449
|
+
content,
|
|
2450
|
+
}
|
|
2451
|
+
},
|
|
2452
|
+
update: context => context.state,
|
|
2453
|
+
buildViewNode: (context) => {
|
|
2454
|
+
const state = context.state
|
|
2455
|
+
if (!state) return null
|
|
2456
|
+
const location = context.start?.location
|
|
2457
|
+
?? context.matches[0]?.location
|
|
2458
|
+
?? { kind: 'unresolved' }
|
|
2459
|
+
return {
|
|
2460
|
+
key: context.key,
|
|
2461
|
+
kind: PUSH_SOURCE_KIND,
|
|
2462
|
+
id: context.id,
|
|
2463
|
+
target: 'chat',
|
|
2464
|
+
anchorSeq: state.seq,
|
|
2465
|
+
location,
|
|
2466
|
+
visibility: 'visible',
|
|
2467
|
+
groupTree: 'input',
|
|
2468
|
+
data: {
|
|
2469
|
+
title: state.title,
|
|
2470
|
+
summary: state.summary,
|
|
2471
|
+
time: state.time,
|
|
2472
|
+
content: state.content,
|
|
2473
|
+
},
|
|
2474
|
+
}
|
|
2475
|
+
},
|
|
2476
|
+
}
|
|
2477
|
+
|
|
2478
|
+
/**
|
|
2479
|
+
* The collapsed push card. Its look copies DSH's scheduled-task trigger
|
|
2480
|
+
* notice: a rounded card with an icon, the push title, a local clock, and
|
|
2481
|
+
* a chevron; the detail body shows only after expanding.
|
|
2482
|
+
* @param {{node?: any}} props - The keyed Chat node renderer share.
|
|
2483
|
+
* @returns {any} The card element.
|
|
2484
|
+
*/
|
|
2485
|
+
function MilocoPushNodeView(props) {
|
|
2486
|
+
const data = props?.node?.data ?? {}
|
|
2487
|
+
const [open, setOpen] = React.useState(false)
|
|
2488
|
+
const bodyId = React.useMemo(() => {
|
|
2489
|
+
pushBodySeq += 1
|
|
2490
|
+
return `dsh-miloco-push-body-${pushBodySeq}`
|
|
2491
|
+
}, [])
|
|
2492
|
+
const time = formatMessageClock(data.time)
|
|
2493
|
+
let iso = ''
|
|
2494
|
+
try {
|
|
2495
|
+
const date = data.time ? new Date(data.time) : null
|
|
2496
|
+
iso = date && !Number.isNaN(date.getTime()) ? date.toISOString() : ''
|
|
2497
|
+
} catch {
|
|
2498
|
+
iso = ''
|
|
2499
|
+
}
|
|
2500
|
+
return h('section', { className: 'dsh-miloco-push-root', 'data-miloco-push': '' },
|
|
2501
|
+
h('button', {
|
|
2502
|
+
className: 'dsh-miloco-push-header',
|
|
2503
|
+
type: 'button',
|
|
2504
|
+
'aria-expanded': open,
|
|
2505
|
+
'aria-controls': bodyId,
|
|
2506
|
+
onClick: () => setOpen(!open),
|
|
2507
|
+
},
|
|
2508
|
+
h('span', { className: 'dsh-miloco-push-icon', 'aria-hidden': 'true' }, MilocoPushSourceIcon(14)),
|
|
2509
|
+
h('span', { className: 'dsh-miloco-push-title' }, data.title || 'Miloco 推送'),
|
|
2510
|
+
time
|
|
2511
|
+
? h('time', { className: 'dsh-miloco-push-time', dateTime: iso }, time)
|
|
2512
|
+
: null,
|
|
2513
|
+
h('span', {
|
|
2514
|
+
className: `dsh-miloco-push-chevron${open ? ' open' : ''}`,
|
|
2515
|
+
'aria-hidden': 'true',
|
|
2516
|
+
}, MilocoPushChevronIcon(12))),
|
|
2517
|
+
open
|
|
2518
|
+
? h('div', { id: bodyId, className: 'dsh-miloco-push-body' },
|
|
2519
|
+
h('p', { className: 'dsh-miloco-push-explanation' }, '这条通知触发了本轮回复。'),
|
|
2520
|
+
h('div', { className: 'dsh-miloco-push-content' }, data.content || ''))
|
|
2521
|
+
: null)
|
|
2522
|
+
}
|
|
2523
|
+
|
|
1229
2524
|
function apply(ctx) {
|
|
1230
2525
|
ensureStyles()
|
|
1231
2526
|
installPresetGuide(ctx)
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
2527
|
+
|
|
2528
|
+
// 配置入口在家庭助手页面(新建家庭会话右侧的「配置」按钮),不再注册
|
|
2529
|
+
// 内置「设置 → 插件」标签页。
|
|
2530
|
+
// 侧栏入口:面板列表的最后一行,正好在「更多」按钮的上一行。
|
|
2531
|
+
ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
|
|
2532
|
+
name: 'sidebar.panellist',
|
|
2533
|
+
id: PANEL_ID,
|
|
2534
|
+
order: 1000,
|
|
2535
|
+
label: () => 'Miloco 家庭助手',
|
|
2536
|
+
}, MilocoPanelIcon))
|
|
2537
|
+
|
|
2538
|
+
// 同名 main 面板:没有它,点击侧栏行会抛错。
|
|
2539
|
+
ctx.slots.inject('main', () => ctx.slots.register({
|
|
2540
|
+
name: 'main',
|
|
2541
|
+
key: PANEL_ID,
|
|
2542
|
+
}, createMilocoHomePanel(ctx)))
|
|
2543
|
+
|
|
2544
|
+
// 折叠推送卡片:先认领事件,再渲染它。
|
|
2545
|
+
// 注册随本 fiber 的生命周期结束,卸载后不会留下重复的 kind。
|
|
2546
|
+
ctx.effect(() => {
|
|
2547
|
+
let dispose = null
|
|
2548
|
+
try {
|
|
2549
|
+
dispose = ctx.uiConversation.events.register(milocoPushDefinition)
|
|
2550
|
+
} catch {
|
|
2551
|
+
// 上一个实例已经占用这个 kind;沿用它即可。
|
|
2552
|
+
dispose = null
|
|
2553
|
+
}
|
|
2554
|
+
return () => { if (dispose) dispose() }
|
|
2555
|
+
}, 'dsh-miloco: push conversation definition')
|
|
2556
|
+
ctx.slots.inject('conversation.chat.node', () => ctx.slots.register({
|
|
2557
|
+
name: 'conversation.chat.node',
|
|
2558
|
+
key: PUSH_SOURCE_KIND,
|
|
2559
|
+
}, MilocoPushNodeView))
|
|
1238
2560
|
}
|
|
1239
2561
|
|
|
1240
2562
|
exports.apply = apply
|
|
1241
2563
|
exports.inject = inject
|
|
1242
2564
|
exports.MilocoSettingsTab = MilocoSettingsTab
|
|
2565
|
+
exports.MilocoPanelIcon = MilocoPanelIcon
|
|
2566
|
+
exports.milocoPanelState = milocoPanelState
|
|
2567
|
+
exports.milocoLoadingPage = milocoLoadingPage
|
|
2568
|
+
exports.milocoErrorPage = milocoErrorPage
|
|
2569
|
+
exports.milocoSetupPage = milocoSetupPage
|
|
2570
|
+
exports.MilocoBindBox = MilocoBindBox
|
|
2571
|
+
exports.MilocoPushNodeView = MilocoPushNodeView
|
|
2572
|
+
exports.createMilocoHomePanel = createMilocoHomePanel
|
|
2573
|
+
exports.formatMessageClock = formatMessageClock
|
|
2574
|
+
exports.milocoPushDefinition = milocoPushDefinition
|
|
1243
2575
|
exports.modelOptions = modelOptions
|
|
1244
2576
|
exports.sessionOptions = sessionOptions
|
|
1245
2577
|
exports.effortOptions = effortOptions
|