dsh-feiyu-memgate 0.3.2 → 0.4.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.
- package/CHANGELOG.md +73 -12
- package/README.md +68 -11
- package/README.zh.md +93 -36
- package/client/README.md +267 -0
- package/client/art/mascot-asleep.webp +0 -0
- package/client/art/mascot-busy.webp +0 -0
- package/client/art/mascot-nag.webp +0 -0
- package/client/art/mascot-ready.webp +0 -0
- package/client/art/mascot-trouble.webp +0 -0
- package/client/client.js +4226 -1269
- package/client/src/clipboard.cjs +52 -0
- package/client/src/constants.cjs +43 -0
- package/client/src/fields.cjs +960 -0
- package/client/src/hooks.cjs +220 -0
- package/client/src/i18n.cjs +444 -0
- package/client/src/index.cjs +69 -0
- package/client/src/kit/controls.cjs +189 -0
- package/client/src/kit/icons.cjs +40 -0
- package/client/src/kit/layout.cjs +124 -0
- package/client/src/layout.cjs +143 -0
- package/client/src/model/changelog.cjs +29 -0
- package/client/src/model/feedback.cjs +168 -0
- package/client/src/model/form.cjs +83 -0
- package/client/src/model/models.cjs +87 -0
- package/client/src/model/overview.cjs +111 -0
- package/client/src/model/page.cjs +104 -0
- package/client/src/model/status.cjs +57 -0
- package/client/src/model/trial.cjs +111 -0
- package/client/src/net.cjs +101 -0
- package/client/src/react.cjs +11 -0
- package/client/src/theme/page.css +1284 -0
- package/client/src/theme/styles.cjs +43 -0
- package/client/src/view/feedback.cjs +180 -0
- package/client/src/view/field-row.cjs +98 -0
- package/client/src/view/hero.cjs +54 -0
- package/client/src/view/markdown.cjs +96 -0
- package/client/src/view/models.cjs +154 -0
- package/client/src/view/page.cjs +199 -0
- package/client/src/view/settings-tab.cjs +78 -0
- package/client/src/view/tabs.cjs +71 -0
- package/client/src/view/trial.cjs +84 -0
- package/docs/DETAIL.en.md +55 -6
- package/docs/DETAIL.md +63 -14
- package/locale/zh.json +1 -1
- package/package.json +2 -1
- package/python/GATEWAY_VERSION.json +37 -31
- package/python/feiyu_memgate/backends/_sqlfile.py +293 -0
- package/python/feiyu_memgate/backends/base.py +121 -6
- package/python/feiyu_memgate/backends/embedding.py +265 -178
- package/python/feiyu_memgate/backends/hybrid.py +330 -83
- package/python/feiyu_memgate/backends/inmemory.py +115 -24
- package/python/feiyu_memgate/backends/openviking.py +7 -10
- package/python/feiyu_memgate/backends/sqlite.py +129 -145
- package/python/feiyu_memgate/builtins.py +1 -0
- package/python/feiyu_memgate/cli.py +124 -20
- package/python/feiyu_memgate/client/block.py +4 -2
- package/python/feiyu_memgate/client/http.py +106 -19
- package/python/feiyu_memgate/client/local.py +4 -3
- package/python/feiyu_memgate/config.py +118 -24
- package/python/feiyu_memgate/core/limits.py +2 -1
- package/python/feiyu_memgate/core/pool.py +29 -2
- package/python/feiyu_memgate/core/recall.py +179 -10
- package/python/feiyu_memgate/core/redact.py +4 -2
- package/python/feiyu_memgate/core/stages.py +52 -9
- package/python/feiyu_memgate/core/tidy.py +2 -1
- package/python/feiyu_memgate/core/watch.py +3 -2
- package/python/feiyu_memgate/core/write.py +9 -3
- package/python/feiyu_memgate/forgetting/archive.py +38 -10
- package/python/feiyu_memgate/forgetting/engine.py +46 -10
- package/python/feiyu_memgate/forgetting/stage.py +4 -2
- package/python/feiyu_memgate/gateway/app.py +168 -272
- package/python/feiyu_memgate/gateway/fields.py +121 -0
- package/python/feiyu_memgate/gateway/policies.py +162 -0
- package/python/feiyu_memgate/gateway/server.py +12 -4
- package/python/feiyu_memgate/gateway/tokens.py +137 -0
- package/python/feiyu_memgate/gateway/validate.py +120 -0
- package/python/feiyu_memgate/identity.py +152 -0
- package/python/feiyu_memgate/model.py +170 -2
- package/python/feiyu_memgate/registry.py +6 -3
- package/python/feiyu_memgate/tools/crypto.py +5 -4
- package/python/feiyu_memgate/tools/evaluate.py +2 -1
- package/python/feiyu_memgate/tools/tenants.py +2 -0
- package/src/block.js +9 -3
- package/src/capture.js +98 -0
- package/src/catalogue.js +4 -4
- package/src/changelog.js +72 -0
- package/src/client.js +145 -10
- package/src/commands.js +112 -62
- package/src/config.js +139 -62
- package/src/followup.js +139 -0
- package/src/gateway.js +79 -4
- package/src/migrate.py +54 -9
- package/src/mirror.py +44 -7
- package/src/plugin.js +416 -412
- package/src/pool.js +298 -0
- package/src/recent.js +68 -0
- package/src/relevance.js +80 -0
- package/src/routes.js +320 -0
- package/src/setup.js +36 -36
- package/src/shared.js +77 -0
- package/src/tiers.js +4 -4
- package/src/time.js +27 -0
- package/src/tools.js +164 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
// The controls of the page: button, tag, switch, text input, text area, number stepper, list of choices.
|
|
3
|
+
//
|
|
4
|
+
// They are the page's own (not the host's primitives) so that the page looks the same on every host
|
|
5
|
+
// version it supports and can be drawn outside a host (scripts/preview-client.mjs). Their sizes
|
|
6
|
+
// follow the host's: 13px text, a 36 by 20 switch, 30 to 34px high controls.
|
|
7
|
+
//
|
|
8
|
+
// Each control is a plain function of its props: it keeps no state, the form does. All of them use
|
|
9
|
+
// native elements and ARIA roles, so the keyboard and a screen reader get them without extra code:
|
|
10
|
+
// a switch is a button with role="switch", a list of choices is a radio group with arrow keys.
|
|
11
|
+
|
|
12
|
+
const { h } = require('../react.cjs')
|
|
13
|
+
const { cx } = require('../theme/styles.cjs')
|
|
14
|
+
const { Icon } = require('./icons.cjs')
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {{ variant?: 'primary' | 'text', disabled?: boolean, onClick?: () => void, label?: string,
|
|
18
|
+
* children?: any }} props `label` is the accessible name of a button that shows only an icon.
|
|
19
|
+
*/
|
|
20
|
+
function Button(props) {
|
|
21
|
+
return h('button', {
|
|
22
|
+
type: 'button',
|
|
23
|
+
className: cx('fmg-button', props.variant && 'fmg-button--' + props.variant),
|
|
24
|
+
disabled: props.disabled || undefined,
|
|
25
|
+
'aria-label': props.label,
|
|
26
|
+
onClick: props.onClick,
|
|
27
|
+
}, props.children)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** A small label. tone: undefined (neutral) | 'sea' | 'blush' | 'warn' | 'ok'. */
|
|
31
|
+
function Tag(props) {
|
|
32
|
+
return h('span', { className: cx('fmg-tag', props.tone && 'fmg-tag--' + props.tone) }, props.children)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* An on/off switch.
|
|
37
|
+
* @param {{ id: string, checked: boolean, label: string, describedBy?: string, disabled?: boolean,
|
|
38
|
+
* onChange: (next: boolean) => void }} props `label` names it for a screen reader; the visible
|
|
39
|
+
* label of the row points at it with htmlFor, so a click on the text flips it too.
|
|
40
|
+
*/
|
|
41
|
+
function Switch(props) {
|
|
42
|
+
return h('button', {
|
|
43
|
+
type: 'button',
|
|
44
|
+
id: props.id,
|
|
45
|
+
className: 'fmg-switch',
|
|
46
|
+
role: 'switch',
|
|
47
|
+
'aria-checked': props.checked ? 'true' : 'false',
|
|
48
|
+
'aria-label': props.label,
|
|
49
|
+
'aria-describedby': props.describedBy,
|
|
50
|
+
disabled: props.disabled || undefined,
|
|
51
|
+
onClick: () => props.onChange(!props.checked),
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* A line of text. `onChange` gets the text, not the event. `label` names it for a screen reader when
|
|
57
|
+
* no visible label points at it.
|
|
58
|
+
* @param {{ id: string, value: string, type?: string, invalid?: boolean, disabled?: boolean, maxLength?: number,
|
|
59
|
+
* placeholder?: string, label?: string, describedBy?: string, autoComplete?: string, onChange: (text: string) => void }} props
|
|
60
|
+
*/
|
|
61
|
+
function TextInput(props) {
|
|
62
|
+
return h('input', {
|
|
63
|
+
id: props.id,
|
|
64
|
+
className: 'fmg-input',
|
|
65
|
+
type: props.type || 'text',
|
|
66
|
+
value: props.value,
|
|
67
|
+
maxLength: props.maxLength,
|
|
68
|
+
placeholder: props.placeholder,
|
|
69
|
+
autoComplete: props.autoComplete || 'off',
|
|
70
|
+
spellCheck: false,
|
|
71
|
+
disabled: props.disabled || undefined,
|
|
72
|
+
'aria-label': props.label,
|
|
73
|
+
'aria-invalid': props.invalid ? 'true' : undefined,
|
|
74
|
+
'aria-describedby': props.describedBy,
|
|
75
|
+
onChange: (event) => props.onChange(event.target.value),
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Several lines of text; the person can drag it taller. `onChange` gets the text, not the event.
|
|
81
|
+
* `label` names it for a screen reader when no visible label points at it.
|
|
82
|
+
* @param {{ id: string, value: string, rows?: number, maxLength?: number, placeholder?: string,
|
|
83
|
+
* label?: string, describedBy?: string, disabled?: boolean, onChange: (text: string) => void }} props
|
|
84
|
+
*/
|
|
85
|
+
function TextArea(props) {
|
|
86
|
+
return h('textarea', {
|
|
87
|
+
id: props.id,
|
|
88
|
+
className: 'fmg-input fmg-input--area',
|
|
89
|
+
value: props.value,
|
|
90
|
+
rows: props.rows || 6,
|
|
91
|
+
maxLength: props.maxLength,
|
|
92
|
+
placeholder: props.placeholder,
|
|
93
|
+
autoComplete: 'off',
|
|
94
|
+
disabled: props.disabled || undefined,
|
|
95
|
+
'aria-label': props.label,
|
|
96
|
+
'aria-describedby': props.describedBy,
|
|
97
|
+
onChange: (event) => props.onChange(event.target.value),
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The text a step leads to: one more or one less than the number on screen, kept inside the range.
|
|
103
|
+
* A text that is no number steps from the nearer end of the range, so the buttons always lead out
|
|
104
|
+
* of an invalid entry.
|
|
105
|
+
*/
|
|
106
|
+
function stepText(text, delta, min, max) {
|
|
107
|
+
const raw = String(text).trim()
|
|
108
|
+
const current = /^-?\d{1,9}$/.test(raw) ? Number(raw) : (delta > 0 ? min - 1 : max + 1)
|
|
109
|
+
return String(Math.min(max, Math.max(min, current + delta)))
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* A whole number with a minus and a plus. The text is kept as typed (the form decides whether it is
|
|
114
|
+
* valid), so a half-typed number is never rewritten under the cursor.
|
|
115
|
+
* @param {{ id: string, text: string, min: number, max: number, invalid?: boolean, disabled?: boolean,
|
|
116
|
+
* describedBy?: string, labels: { down: string, up: string }, onChange: (text: string) => void }} props
|
|
117
|
+
*/
|
|
118
|
+
function Stepper(props) {
|
|
119
|
+
const { text, min, max, disabled } = props
|
|
120
|
+
const number = /^-?\d{1,9}$/.test(String(text).trim()) ? Number(text) : null
|
|
121
|
+
const step = (delta) => () => props.onChange(stepText(text, delta, min, max))
|
|
122
|
+
return h('span', { className: 'fmg-stepper', 'data-invalid': props.invalid ? 'true' : undefined },
|
|
123
|
+
h('button', { type: 'button', 'aria-label': props.labels.down, disabled: disabled || (number !== null && number <= min) || undefined, onClick: step(-1) },
|
|
124
|
+
h(Icon, { name: 'minus', size: 14 })),
|
|
125
|
+
h('input', {
|
|
126
|
+
id: props.id,
|
|
127
|
+
type: 'text',
|
|
128
|
+
inputMode: 'numeric',
|
|
129
|
+
value: text,
|
|
130
|
+
autoComplete: 'off',
|
|
131
|
+
disabled: disabled || undefined,
|
|
132
|
+
'aria-invalid': props.invalid ? 'true' : undefined,
|
|
133
|
+
'aria-describedby': props.describedBy,
|
|
134
|
+
onChange: (event) => props.onChange(event.target.value),
|
|
135
|
+
}),
|
|
136
|
+
h('button', { type: 'button', 'aria-label': props.labels.up, disabled: disabled || (number !== null && number >= max) || undefined, onClick: step(1) },
|
|
137
|
+
h(Icon, { name: 'plus', size: 14 })))
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Arrow keys move the choice, as in a native radio group: the neighbour is chosen and focused.
|
|
141
|
+
function onChoiceKey(event, props) {
|
|
142
|
+
const forward = event.key === 'ArrowRight' || event.key === 'ArrowDown'
|
|
143
|
+
const backward = event.key === 'ArrowLeft' || event.key === 'ArrowUp'
|
|
144
|
+
if (!forward && !backward) return
|
|
145
|
+
event.preventDefault()
|
|
146
|
+
const values = props.options.map((option) => option.value)
|
|
147
|
+
const at = Math.max(0, values.indexOf(props.value))
|
|
148
|
+
const next = (at + (forward ? 1 : values.length - 1)) % values.length
|
|
149
|
+
props.onChange(values[next])
|
|
150
|
+
const buttons = event.currentTarget.querySelectorAll('[role="radio"]')
|
|
151
|
+
if (buttons[next]) buttons[next].focus()
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* One of a few options, each shown with what it means. A radio group: Tab reaches the chosen option,
|
|
156
|
+
* the arrow keys change it.
|
|
157
|
+
* @param {{ labelledBy: string, describedBy?: string, value: string, disabled?: boolean,
|
|
158
|
+
* options: { value: string, name: string, note: string }[], onChange: (value: string) => void }} props
|
|
159
|
+
*/
|
|
160
|
+
function Choices(props) {
|
|
161
|
+
const known = props.options.some((option) => option.value === props.value)
|
|
162
|
+
return h('div', {
|
|
163
|
+
className: 'fmg-choices',
|
|
164
|
+
// The stylesheet lays four options out two by two, so that none is left alone on a line.
|
|
165
|
+
'data-count': String(props.options.length),
|
|
166
|
+
role: 'radiogroup',
|
|
167
|
+
'aria-labelledby': props.labelledBy,
|
|
168
|
+
'aria-describedby': props.describedBy,
|
|
169
|
+
onKeyDown: props.disabled ? undefined : (event) => onChoiceKey(event, props),
|
|
170
|
+
}, props.options.map((option, index) => {
|
|
171
|
+
const checked = option.value === props.value
|
|
172
|
+
return h('button', {
|
|
173
|
+
key: option.value,
|
|
174
|
+
type: 'button',
|
|
175
|
+
className: 'fmg-choice',
|
|
176
|
+
role: 'radio',
|
|
177
|
+
'aria-checked': checked ? 'true' : 'false',
|
|
178
|
+
// Roving focus: the chosen option takes Tab; with no known choice the first one does.
|
|
179
|
+
tabIndex: checked || (!known && index === 0) ? 0 : -1,
|
|
180
|
+
disabled: props.disabled || undefined,
|
|
181
|
+
onClick: () => props.onChange(option.value),
|
|
182
|
+
},
|
|
183
|
+
h('span', { className: 'fmg-choice__dot', 'aria-hidden': 'true' }),
|
|
184
|
+
h('span', { className: 'fmg-choice__name' }, option.name,
|
|
185
|
+
option.note ? h('span', { className: 'fmg-choice__note' }, option.note) : null))
|
|
186
|
+
}))
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
module.exports = { Button, Tag, Switch, TextInput, TextArea, stepText, Stepper, Choices }
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
// The few line icons of the page, drawn here so that the page needs no icon font and no sprite of the
|
|
3
|
+
// host. All share one 16-unit grid and one stroke, and take their colour from the text around them.
|
|
4
|
+
|
|
5
|
+
const { h } = require('../react.cjs')
|
|
6
|
+
|
|
7
|
+
// One path each, on a 16 by 16 grid, stroke only.
|
|
8
|
+
const PATHS = {
|
|
9
|
+
chevron: 'M6 3.5 10.5 8 6 12.5',
|
|
10
|
+
check: 'M3.5 8.5 6.5 11.5 12.5 4.5',
|
|
11
|
+
minus: 'M4 8h8',
|
|
12
|
+
plus: 'M8 4v8M4 8h8',
|
|
13
|
+
refresh: 'M13 8a5 5 0 1 1-1.5-3.6M13 3v2.5h-2.5',
|
|
14
|
+
external: 'M9.5 3H13v3.5M13 3 7.5 8.5M11 9.5V13H3V5h3.5',
|
|
15
|
+
alert: 'M8 6v3M8 11.2h.01M8 2.2 14.3 13H1.7L8 2.2Z',
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A decorative icon: hidden from assistive technology, so the control it sits in needs its own text
|
|
20
|
+
* or label.
|
|
21
|
+
* @param {{ name: keyof PATHS, size?: number, className?: string }} props
|
|
22
|
+
*/
|
|
23
|
+
function Icon(props) {
|
|
24
|
+
const size = props.size || 16
|
|
25
|
+
return h('svg', {
|
|
26
|
+
className: props.className,
|
|
27
|
+
width: size,
|
|
28
|
+
height: size,
|
|
29
|
+
viewBox: '0 0 16 16',
|
|
30
|
+
fill: 'none',
|
|
31
|
+
stroke: 'currentColor',
|
|
32
|
+
strokeWidth: 1.5,
|
|
33
|
+
strokeLinecap: 'round',
|
|
34
|
+
strokeLinejoin: 'round',
|
|
35
|
+
'aria-hidden': 'true',
|
|
36
|
+
focusable: 'false',
|
|
37
|
+
}, h('path', { d: PATHS[props.name] || '' }))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = { ICON_NAMES: Object.keys(PATHS), Icon }
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
// The structural parts of the page: tabs, a part that opens and closes, a folding group, the bordered
|
|
3
|
+
// list of rows, label and value pairs, a notice, a progress bar. Like the controls they keep no
|
|
4
|
+
// state; the page owns which tab is selected and which group is open.
|
|
5
|
+
|
|
6
|
+
const { h } = require('../react.cjs')
|
|
7
|
+
const { cx } = require('../theme/styles.cjs')
|
|
8
|
+
const { Icon } = require('./icons.cjs')
|
|
9
|
+
|
|
10
|
+
// The ids that tie a tab to its panel, both ways (aria-controls and aria-labelledby).
|
|
11
|
+
const tabId = (prefix, id) => prefix + '-tab-' + id
|
|
12
|
+
const panelId = (prefix, id) => prefix + '-panel-' + id
|
|
13
|
+
|
|
14
|
+
// Arrow keys, Home and End move between tabs and select at once, as the tabs pattern asks.
|
|
15
|
+
function onTabKey(event, props) {
|
|
16
|
+
const ids = props.tabs.map((tab) => tab.id)
|
|
17
|
+
const at = ids.indexOf(props.value)
|
|
18
|
+
let next = -1
|
|
19
|
+
if (event.key === 'ArrowRight') next = (at + 1) % ids.length
|
|
20
|
+
else if (event.key === 'ArrowLeft') next = (at + ids.length - 1) % ids.length
|
|
21
|
+
else if (event.key === 'Home') next = 0
|
|
22
|
+
else if (event.key === 'End') next = ids.length - 1
|
|
23
|
+
if (next < 0) return
|
|
24
|
+
event.preventDefault()
|
|
25
|
+
props.onChange(ids[next])
|
|
26
|
+
const buttons = event.currentTarget.querySelectorAll('[role="tab"]')
|
|
27
|
+
if (buttons[next]) buttons[next].focus()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The row of tabs.
|
|
32
|
+
* @param {{ idPrefix: string, label: string, value: string, onChange: (id: string) => void,
|
|
33
|
+
* tabs: { id: string, label: string, mark?: 'edited' | 'invalid' | null, markLabel?: string }[] }} props
|
|
34
|
+
* `mark` puts a dot after the label: the tab holds unsaved edits, or one that cannot be saved;
|
|
35
|
+
* `markLabel` says so to a screen reader.
|
|
36
|
+
*/
|
|
37
|
+
function Tabs(props) {
|
|
38
|
+
return h('div', { className: 'fmg-tabs', role: 'tablist', 'aria-label': props.label, onKeyDown: (event) => onTabKey(event, props) },
|
|
39
|
+
props.tabs.map((tab) => {
|
|
40
|
+
const selected = tab.id === props.value
|
|
41
|
+
return h('button', {
|
|
42
|
+
key: tab.id,
|
|
43
|
+
type: 'button',
|
|
44
|
+
id: tabId(props.idPrefix, tab.id),
|
|
45
|
+
className: 'fmg-tab',
|
|
46
|
+
role: 'tab',
|
|
47
|
+
'aria-selected': selected ? 'true' : 'false',
|
|
48
|
+
// Only the selected tab's panel is in the document, so only that tab can point at one.
|
|
49
|
+
'aria-controls': selected ? panelId(props.idPrefix, tab.id) : undefined,
|
|
50
|
+
tabIndex: selected ? 0 : -1,
|
|
51
|
+
onClick: () => props.onChange(tab.id),
|
|
52
|
+
},
|
|
53
|
+
tab.label,
|
|
54
|
+
tab.mark ? h('span', { className: cx('fmg-mark', tab.mark === 'invalid' && 'fmg-mark--invalid'), role: 'img', 'aria-label': tab.markLabel }) : null)
|
|
55
|
+
}))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The content of the selected tab. */
|
|
59
|
+
function TabPanel(props) {
|
|
60
|
+
return h('div', {
|
|
61
|
+
className: 'fmg-panel',
|
|
62
|
+
role: 'tabpanel',
|
|
63
|
+
id: panelId(props.idPrefix, props.id),
|
|
64
|
+
'aria-labelledby': tabId(props.idPrefix, props.id),
|
|
65
|
+
}, props.children)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* A part that opens and closes with a short height animation. The content stays in the document
|
|
70
|
+
* while closed (that is what makes the animation possible); the stylesheet hides it then
|
|
71
|
+
* (`visibility: hidden`), which also takes it out of the tab order and away from a screen reader.
|
|
72
|
+
* `aria-hidden` says the same in the markup, for a reader of the tree and for the tests.
|
|
73
|
+
*/
|
|
74
|
+
function Reveal(props) {
|
|
75
|
+
return h('div', { className: 'fmg-reveal', 'data-open': props.open ? 'true' : 'false', 'aria-hidden': props.open ? undefined : 'true' },
|
|
76
|
+
h('div', { id: props.id }, props.children))
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* A group with a header that folds it.
|
|
81
|
+
* @param {{ id: string, title: string, help?: string, open: boolean, onToggle: () => void,
|
|
82
|
+
* accessory?: any, children?: any }} props `accessory` sits at the right end of the header
|
|
83
|
+
* (a tag saying how many settings inside are changed).
|
|
84
|
+
*/
|
|
85
|
+
function Fold(props) {
|
|
86
|
+
return h('div', { className: 'fmg-fold' },
|
|
87
|
+
h('button', { type: 'button', className: 'fmg-fold__head', 'aria-expanded': props.open ? 'true' : 'false', 'aria-controls': props.id, onClick: props.onToggle },
|
|
88
|
+
h(Icon, { name: 'chevron', className: 'fmg-fold__chevron' }),
|
|
89
|
+
h('span', null,
|
|
90
|
+
h('span', { className: 'fmg-fold__title' }, props.title),
|
|
91
|
+
props.help ? h('span', { className: 'fmg-fold__help' }, props.help) : null),
|
|
92
|
+
props.accessory || null),
|
|
93
|
+
h(Reveal, { open: props.open, id: props.id }, h('div', { className: 'fmg-fold__body fmg-rows' }, props.children)))
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The bordered list the rows of a section sit in. */
|
|
97
|
+
function Group(props) {
|
|
98
|
+
return h('div', { className: 'fmg-group fmg-rows' }, props.children)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Label and value pairs. rows: [label, value][] */
|
|
102
|
+
function Facts(props) {
|
|
103
|
+
return h('dl', { className: 'fmg-facts' }, props.rows.flatMap((row, index) => [
|
|
104
|
+
h('dt', { key: 'dt' + index }, row[0]),
|
|
105
|
+
h('dd', { key: 'dd' + index }, row[1]),
|
|
106
|
+
]))
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* A boxed message. tone 'warn' for something the person should act on; `role` is 'status' for news
|
|
111
|
+
* that can wait and 'alert' for a failure.
|
|
112
|
+
*/
|
|
113
|
+
function Notice(props) {
|
|
114
|
+
return h('div', { className: cx('fmg-notice', props.tone && 'fmg-notice--' + props.tone), role: props.role, 'aria-label': props.label }, props.children)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** A thin bar for a known share of work done (0 to 100). */
|
|
118
|
+
function Progress(props) {
|
|
119
|
+
const percent = Math.min(100, Math.max(0, Number(props.percent) || 0))
|
|
120
|
+
return h('div', { className: 'fmg-progress', role: 'progressbar', 'aria-valuemin': 0, 'aria-valuemax': 100, 'aria-valuenow': percent, 'aria-label': props.label },
|
|
121
|
+
h('i', { style: { width: percent + '%' } }))
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
module.exports = { tabId, panelId, Tabs, TabPanel, Reveal, Fold, Group, Facts, Notice, Progress }
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
// Where each setting sits on the page: tabs, the sections of a tab, the settings of a section.
|
|
3
|
+
//
|
|
4
|
+
// The settings themselves (keys, kinds, defaults, texts, `needs`) come from src/config.js through
|
|
5
|
+
// fields.cjs. This table is only about presentation, which is why it lives here and not there: the
|
|
6
|
+
// stored keys group settings by what they configure (`modules`, `advanced`, ...), the page groups them
|
|
7
|
+
// by what a person is trying to do. A setting therefore may sit in a tab that does not match its key
|
|
8
|
+
// (advanced.captureMinChars sits under the capture switch it belongs to).
|
|
9
|
+
//
|
|
10
|
+
// Rules, checked by tests/client-modules.test.js:
|
|
11
|
+
// - every setting of FIELDS is placed exactly once;
|
|
12
|
+
// - a setting with `needs` sits in the same section as the setting it depends on, after it
|
|
13
|
+
// (the page draws it as a sub-row that appears while the other setting has a fitting value).
|
|
14
|
+
//
|
|
15
|
+
// Three tabs hold no settings and are not listed here: the overview (status), the changelog and feedback.
|
|
16
|
+
// `panel` names a part of the page that is not a settings row and is drawn after the section's rows.
|
|
17
|
+
|
|
18
|
+
const TABS = [
|
|
19
|
+
{
|
|
20
|
+
id: 'features',
|
|
21
|
+
label: { en: 'Features', zh: '功能' },
|
|
22
|
+
sections: [
|
|
23
|
+
{
|
|
24
|
+
id: 'recall',
|
|
25
|
+
label: { en: 'Recall', zh: '召回' },
|
|
26
|
+
help: {
|
|
27
|
+
en: 'What is provided without a model request: related memories each turn, and a note on how to use them.',
|
|
28
|
+
zh: '无需模型请求即可提供的内容:每轮对话的相关记忆,以及记忆的使用说明。',
|
|
29
|
+
},
|
|
30
|
+
fields: ['modules.autoRecall', 'modules.promptSection'],
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: 'tools',
|
|
34
|
+
label: { en: 'Tools', zh: '工具' },
|
|
35
|
+
help: {
|
|
36
|
+
en: 'What the model and you can use on your own initiative.',
|
|
37
|
+
zh: '模型和你可以主动使用的功能。',
|
|
38
|
+
},
|
|
39
|
+
fields: ['modules.rememberTool', 'advanced.toolFields', 'modules.searchTool', 'modules.commands'],
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: 'capture',
|
|
43
|
+
label: { en: 'Capture', zh: '记录' },
|
|
44
|
+
help: {
|
|
45
|
+
en: 'Saving what you say without the model deciding.',
|
|
46
|
+
zh: '不经模型判断,直接保存用户发送的消息。',
|
|
47
|
+
},
|
|
48
|
+
fields: ['modules.autoCapture', 'advanced.captureMinChars'],
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: 'retrieval',
|
|
54
|
+
label: { en: 'Retrieval', zh: '检索' },
|
|
55
|
+
sections: [
|
|
56
|
+
{
|
|
57
|
+
id: 'tier',
|
|
58
|
+
label: { en: 'Retrieval method', zh: '检索方式' },
|
|
59
|
+
help: {
|
|
60
|
+
en: 'Each way keeps its own store file: memories saved under one are not searched under another unless they were copied, and switching back finds them again.',
|
|
61
|
+
zh: '各检索方式分别使用独立的存储文件:在一种方式下记录的记忆,切换方式后不会被检索到,除非已复制过去;切换回来后仍可找到。',
|
|
62
|
+
},
|
|
63
|
+
fields: [
|
|
64
|
+
'retrieval.tier', 'retrieval.url', 'retrieval.model', 'retrieval.apiKey',
|
|
65
|
+
'retrieval.hybrid', 'modules.migrateOnTierChange',
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
id: 'models',
|
|
70
|
+
label: { en: 'Local embedding models', zh: '本地向量模型' },
|
|
71
|
+
panel: 'models',
|
|
72
|
+
fields: [],
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
id: 'trial',
|
|
76
|
+
label: { en: 'Try a recall', zh: '试一下召回' },
|
|
77
|
+
panel: 'trial',
|
|
78
|
+
fields: [],
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: 'advanced',
|
|
84
|
+
label: { en: 'Advanced', zh: '高级' },
|
|
85
|
+
note: {
|
|
86
|
+
en: 'The defaults suit most conversations. Each group opens on its own and shows how many of its settings were changed.',
|
|
87
|
+
zh: '默认值适用于大多数对话。各组可单独展开,组名右侧显示已修改的设置项数量。',
|
|
88
|
+
},
|
|
89
|
+
collapsible: true,
|
|
90
|
+
sections: [
|
|
91
|
+
{
|
|
92
|
+
id: 'tuning',
|
|
93
|
+
label: { en: 'Recall details', zh: '召回细节' },
|
|
94
|
+
help: { en: 'How many memories a turn gets and how strict the match is.', zh: '每轮提供的记忆条数,以及匹配的严格程度。' },
|
|
95
|
+
fields: [
|
|
96
|
+
'advanced.recallLimit', 'advanced.profile', 'advanced.maxNewPerTurn', 'advanced.recallTimeoutMs',
|
|
97
|
+
'advanced.linkedRecall', 'advanced.skipRepeats',
|
|
98
|
+
],
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
id: 'block',
|
|
102
|
+
label: { en: 'Memory block', zh: '记忆块' },
|
|
103
|
+
help: { en: 'How the recalled memories are presented to the model.', zh: '召回的记忆交给模型时的呈现方式。' },
|
|
104
|
+
fields: ['advanced.language', 'advanced.blockTone', 'advanced.showAge', 'advanced.failureNote'],
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
id: 'experiments',
|
|
108
|
+
label: { en: 'Experimental features', zh: '实验性功能' },
|
|
109
|
+
help: {
|
|
110
|
+
en: 'Measured offline only, not yet verified in everyday chats. All off by default; each states its cost.',
|
|
111
|
+
zh: '仅做过离线测量,尚未在日常对话中验证。默认全部关闭,每项都注明了代价。',
|
|
112
|
+
},
|
|
113
|
+
fields: [
|
|
114
|
+
'advanced.relevanceCheck', 'advanced.relevanceProvider', 'advanced.relevanceModel', 'advanced.relevanceTimeoutMs',
|
|
115
|
+
'advanced.afterthought', 'advanced.afterthoughtMax',
|
|
116
|
+
'advanced.conversationPool', 'advanced.poolSize',
|
|
117
|
+
'advanced.recentPool', 'advanced.recentSize', 'advanced.recentDays',
|
|
118
|
+
],
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
id: 'gateway',
|
|
122
|
+
label: { en: 'Gateway', zh: '网关' },
|
|
123
|
+
help: {
|
|
124
|
+
en: 'Where memories are kept: the gateway bundled with the plugin, or an external one you run yourself.',
|
|
125
|
+
zh: '记忆的存放位置:插件内置的网关,或你自己运行的外部网关。',
|
|
126
|
+
},
|
|
127
|
+
fields: [
|
|
128
|
+
'gateway.mode', 'gateway.python', 'gateway.dataDir', 'external.url', 'external.token', 'advanced.speakerAccount',
|
|
129
|
+
'advanced.dailyWrites', 'advanced.redaction', 'advanced.newerFirst', 'advanced.forgetting',
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
},
|
|
134
|
+
]
|
|
135
|
+
|
|
136
|
+
/** Every placed setting key, in page order. */
|
|
137
|
+
function placedKeys() {
|
|
138
|
+
const keys = []
|
|
139
|
+
for (const tab of TABS) for (const section of tab.sections) for (const key of section.fields) keys.push(key)
|
|
140
|
+
return keys
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
module.exports = { TABS, placedKeys }
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
// The changelog as plain data: the answer of GET feiyu-memgate/changelog turned into the list of
|
|
3
|
+
// releases the page shows. Pure; drawing the Markdown of a release is view/markdown.cjs.
|
|
4
|
+
|
|
5
|
+
/** The date a changelog entry gives on its date line ("日期:2026-11-18"), or ''. */
|
|
6
|
+
function entryDate(body) {
|
|
7
|
+
const match = /日期[::]\s*(\d{4}-\d{2}-\d{2})/.exec(String(body || ''))
|
|
8
|
+
return match ? match[1] : ''
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The releases of a changelog answer, newest first as the host half sent them.
|
|
13
|
+
* @param {{ version?: string, entries?: object[] } | null} data
|
|
14
|
+
* @returns {{ id: string, name: string, date: string, body: string, installed: boolean }[]}
|
|
15
|
+
* `installed` marks the release whose version is the one running now. Entries without a text body
|
|
16
|
+
* are left out.
|
|
17
|
+
*/
|
|
18
|
+
function releases(data) {
|
|
19
|
+
const entries = data && Array.isArray(data.entries) ? data.entries : []
|
|
20
|
+
const current = data && data.version ? String(data.version) : ''
|
|
21
|
+
return entries
|
|
22
|
+
.filter((entry) => entry && typeof entry.body === 'string')
|
|
23
|
+
.map((entry, index) => {
|
|
24
|
+
const name = String(entry.version || entry.title || '')
|
|
25
|
+
return { id: name || String(index), name, date: entryDate(entry.body), body: entry.body, installed: Boolean(current) && String(entry.version || '') === current }
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = { entryDate, releases }
|