dsh-agent-memory-hub 0.1.3 → 0.1.5

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/client.js ADDED
@@ -0,0 +1,103 @@
1
+ /**
2
+ * dsh-agent-memory-hub — DSH Web UI surface (client half).
3
+ *
4
+ * Registers a sidebar entry (`sidebar.panellist`) and its central panel
5
+ * (`main`, keyed by the panel id). The panel embeds the `memhub serve`
6
+ * console (inbox + knowledge browser + audit) via iframe on 127.0.0.1:7777
7
+ * — the same local, human-only channel the standalone console uses, so all
8
+ * data and actions keep flowing through one audited API.
9
+ *
10
+ * When `memhub serve` is not running, the panel shows recovery guidance and
11
+ * keeps polling, so it lights up on its own the moment you start the server.
12
+ * No network beyond 127.0.0.1 is touched.
13
+ */
14
+ window.__ModuleLoader__.load({
15
+ id: 'dsh-agent-memory-hub',
16
+ factory(require) {
17
+ const React = require('react')
18
+ const h = React.createElement
19
+ const PANEL_ID = 'agent-memory-hub-panel'
20
+ const SERVE_BASE = 'http://127.0.0.1:7777'
21
+
22
+ function PanelIcon() {
23
+ // Memory-hub mark: a stacked database/disc glyph — reads at 20px.
24
+ return h('svg', {
25
+ viewBox: '0 0 24 24', width: 20, height: 20, 'aria-hidden': true,
26
+ style: { display: 'block' },
27
+ },
28
+ h('ellipse', { cx: 12, cy: 5.5, rx: 7, ry: 2.8, fill: 'none', stroke: 'currentColor', strokeWidth: 1.6 }),
29
+ h('path', { d: 'M5 5.5v6.5c0 1.55 3.13 2.8 7 2.8s7-1.25 7-2.8V5.5', fill: 'none', stroke: 'currentColor', strokeWidth: 1.6 }),
30
+ h('path', { d: 'M5 12v6.5c0 1.55 3.13 2.8 7 2.8s7-1.25 7-2.8V12', fill: 'none', stroke: 'currentColor', strokeWidth: 1.6 }),
31
+ h('circle', { cx: 17.2, cy: 17.2, r: 3.4, fill: 'currentColor', opacity: 0.9 }),
32
+ h('path', { d: 'M15.6 17.2l1.2 1.2 2-2.2', fill: 'none', stroke: '#fff', strokeWidth: 1.4, strokeLinecap: 'round', strokeLinejoin: 'round' }),
33
+ )
34
+ }
35
+
36
+ function Panel() {
37
+ const [status, setStatus] = React.useState('probing')
38
+
39
+ const probe = React.useCallback(() => {
40
+ setStatus('probing')
41
+ fetch(`${SERVE_BASE}/api/inbox`, { cache: 'no-store', signal: AbortSignal.timeout(2500) })
42
+ .then((r) => { if (r.ok) setStatus('online'); else setStatus('offline') })
43
+ .catch(() => setStatus('offline'))
44
+ }, [])
45
+
46
+ React.useEffect(() => {
47
+ probe()
48
+ if (status === 'offline') {
49
+ const timer = setInterval(probe, 5000)
50
+ return () => clearInterval(timer)
51
+ }
52
+ }, [status, probe])
53
+
54
+ if (status === 'online') {
55
+ return h('iframe', {
56
+ src: `${SERVE_BASE}/`,
57
+ title: 'Agent Memory Hub 审核面板',
58
+ style: { width: '100%', height: '100%', minHeight: 480, border: 'none', flex: 1 },
59
+ })
60
+ }
61
+
62
+ return h('div', { style: {
63
+ display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center',
64
+ gap: 14, padding: 32, height: '100%', minHeight: 480, flex: 1,
65
+ color: 'inherit', font: 'inherit', textAlign: 'center',
66
+ } },
67
+ h('div', { style: { fontSize: 34 } }, PanelIcon()),
68
+ h('div', { style: { fontSize: 16, fontWeight: 600 } }, status === 'probing' ? '正在连接记忆中枢…' : '本地控制台尚未就绪'),
69
+ h('div', { style: { fontSize: 13, opacity: 0.75, lineHeight: 1.7, maxWidth: 460 } },
70
+ 'DSH 宿主会自动启动本地控制台(127.0.0.1:7777),重启 DSH 或稍等片刻即可;也可以在任意终端手动运行下面的命令立即启动。每 5 秒自动重试:'),
71
+ h('code', { style: {
72
+ padding: '8px 14px', borderRadius: 8, fontSize: 13,
73
+ background: 'rgba(127,127,127,0.14)', userSelect: 'all',
74
+ } }, 'memhub serve --root <你的hub目录>'),
75
+ h('button', {
76
+ onClick: probe, disabled: status === 'probing',
77
+ style: {
78
+ marginTop: 6, padding: '7px 18px', borderRadius: 8, border: 'none',
79
+ cursor: status === 'probing' ? 'default' : 'pointer', font: 'inherit', fontSize: 13,
80
+ background: status === 'probing' ? 'rgba(127,127,127,0.2)' : 'rgba(36,123,191,0.9)', color: '#fff',
81
+ },
82
+ }, status === 'probing' ? '连接中…' : '立即重试'),
83
+ )
84
+ }
85
+
86
+ return {
87
+ inject: ['slots'],
88
+ apply(ctx) {
89
+ ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
90
+ name: 'sidebar.panellist',
91
+ id: PANEL_ID,
92
+ order: 50,
93
+ label: '记忆中枢',
94
+ }, PanelIcon))
95
+ ctx.slots.inject('main', () => ctx.slots.register({
96
+ name: 'main',
97
+ key: PANEL_ID,
98
+ inject: () => ({}),
99
+ }, Panel))
100
+ },
101
+ }
102
+ },
103
+ })