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
package/src/changelog.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// The plugin's changelog (CHANGELOG.md, written in Chinese) as data: parsing only, no file or host access.
|
|
2
|
+
//
|
|
3
|
+
// A section starts at a line `## <heading>`; its body is everything up to the next `## ` line (`###`
|
|
4
|
+
// groups stay inside the body). A heading that is a version number ("0.3.2") gives `version`; any other
|
|
5
|
+
// heading ("未发布") gives version null. Nothing here throws, whatever the text looks like.
|
|
6
|
+
|
|
7
|
+
export const MAX_BODY_BYTES = 64 * 1024
|
|
8
|
+
export const CUT_MARKER = '\n\n[…]'
|
|
9
|
+
const VERSION_RE = /^v?(\d+(?:\.\d+){0,3})$/
|
|
10
|
+
|
|
11
|
+
/** The numeric parts of a dotted version ("0.3.2" is [0, 3, 2]); null when it is not one. */
|
|
12
|
+
export function versionParts(text) {
|
|
13
|
+
if (typeof text !== 'string') return null
|
|
14
|
+
const match = VERSION_RE.exec(text.trim())
|
|
15
|
+
return match ? match[1].split('.').map(Number) : null
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** -1, 0 or 1 for a before, equal to or after b (dotted numeric parts; missing parts count as 0); null if either is not a version. */
|
|
19
|
+
export function compareVersions(a, b) {
|
|
20
|
+
const x = versionParts(a)
|
|
21
|
+
const y = versionParts(b)
|
|
22
|
+
if (!x || !y) return null
|
|
23
|
+
for (let i = 0; i < Math.max(x.length, y.length); i++) {
|
|
24
|
+
const d = (x[i] ?? 0) - (y[i] ?? 0)
|
|
25
|
+
if (d !== 0) return d < 0 ? -1 : 1
|
|
26
|
+
}
|
|
27
|
+
return 0
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The sections of a changelog in file order: { version, title, body } (see the top of this file). */
|
|
31
|
+
export function parseChangelog(text) {
|
|
32
|
+
if (typeof text !== 'string' || !text) return []
|
|
33
|
+
const lines = text.replace(/^\uFEFF/, '').split(/\r\n|\r|\n/)
|
|
34
|
+
const sections = []
|
|
35
|
+
let current = null
|
|
36
|
+
for (const line of lines) {
|
|
37
|
+
const heading = /^##[ \t]+(\S.*?)[ \t]*$/.exec(line)
|
|
38
|
+
if (heading && !line.startsWith('###')) {
|
|
39
|
+
current = { title: heading[1], lines: [] }
|
|
40
|
+
sections.push(current)
|
|
41
|
+
} else if (current) {
|
|
42
|
+
current.lines.push(line)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return sections.map(({ title, lines: body }) => ({
|
|
46
|
+
version: versionParts(title) ? title.replace(/^v/, '') : null,
|
|
47
|
+
title,
|
|
48
|
+
body: body.join('\n').trim(),
|
|
49
|
+
}))
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function capBody(body) {
|
|
53
|
+
if (Buffer.byteLength(body, 'utf8') <= MAX_BODY_BYTES) return body
|
|
54
|
+
const cut = Buffer.from(body, 'utf8').subarray(0, MAX_BODY_BYTES).toString('utf8').replace(/�+$/, '')
|
|
55
|
+
return cut + CUT_MARKER
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The released sections: those with a version number not newer than `currentVersion`, newest first, at
|
|
60
|
+
* most `limit`, each body capped at MAX_BODY_BYTES (a marker says when it was cut). A current version that
|
|
61
|
+
* is not a version number gives no entries.
|
|
62
|
+
*/
|
|
63
|
+
export function releasedEntries(text, currentVersion, limit = 20) {
|
|
64
|
+
if (!versionParts(currentVersion)) return []
|
|
65
|
+
const max = Number.isInteger(limit) && limit > 0 ? limit : 20
|
|
66
|
+
return parseChangelog(text)
|
|
67
|
+
.filter((section) => section.version !== null && compareVersions(section.version, currentVersion) <= 0)
|
|
68
|
+
.map((section, index) => ({ section, index }))
|
|
69
|
+
.sort((x, y) => compareVersions(y.section.version, x.section.version) || x.index - y.index)
|
|
70
|
+
.slice(0, max)
|
|
71
|
+
.map(({ section }) => ({ version: section.version, title: section.title, body: capBody(section.body) }))
|
|
72
|
+
}
|
package/src/client.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
//
|
|
3
3
|
// A port of the gateway's Python client (client/http.py). Out of scope in this version:
|
|
4
4
|
// tenants (tenant_id, the tenant token, tenant-bound clients) and from_env. A plugin talks to
|
|
5
|
-
// one gateway with one token.
|
|
5
|
+
// one gateway with one token. recall and remember take an optional "context" (a small flat
|
|
6
|
+
// object of labels) and send it as the request's "context" when it passes the gateway's own
|
|
7
|
+
// check; one that does not is dropped with a warning, and the request goes out without it.
|
|
6
8
|
//
|
|
7
9
|
// Logs go through logger.warn and name only the kind of failure ("http 500 busy", "timeout"):
|
|
8
10
|
// never the query, a memory text, an item id or the token. The error code of an answer is
|
|
@@ -25,8 +27,16 @@ const MAX_REMEMBER_CHARS = 4000 // gateway limit per message for /v1/remember
|
|
|
25
27
|
const MAX_TOTAL_CHARS = 16000 // gateway limit for all messages of one /v1/remember
|
|
26
28
|
const MAX_MESSAGES = 20 // gateway limit of messages per /v1/remember
|
|
27
29
|
const MAX_TIME_CHARS = 40 // gateway limit of a message's optional "time"
|
|
28
|
-
const MAX_SPEAKER_CHARS = 64 // gateway limit of a message's optional "speaker"
|
|
30
|
+
const MAX_SPEAKER_CHARS = 64 // gateway limit of a message's optional "speaker" and "about"
|
|
29
31
|
const MAX_USED = 20 // gateway limit of items per /v1/used
|
|
32
|
+
const MAX_CONTEXT_KEYS = 16 // gateway limit of keys in a request's optional "context"
|
|
33
|
+
const MAX_CONTEXT_KEY_CHARS = 64 // gateway limit of a context key's length
|
|
34
|
+
const MAX_CONTEXT_VALUE_CHARS = 200 // gateway limit of a context string value's length
|
|
35
|
+
// The optional message keys that become record fields of the memory (the gateway's REQUEST_FIELDS).
|
|
36
|
+
const CHANNEL = /^[a-z0-9][a-z0-9_.:-]{0,63}$/
|
|
37
|
+
const ORIGINS = ['said', 'tool', 'curated', 'derived']
|
|
38
|
+
export const KINDS = ['identity', 'preference', 'event', 'plan', 'entity']
|
|
39
|
+
const FIELD_KEYS = ['speaker', 'about', 'channel', 'audience', 'origin', 'event_date', 'kind'] // the keys of a row's "fields"
|
|
30
40
|
const MAX_RESPONSE_BYTES = 256 * 1024
|
|
31
41
|
const MAX_ERROR_BYTES = 4096
|
|
32
42
|
|
|
@@ -58,6 +68,44 @@ function failure(status, code) {
|
|
|
58
68
|
return status >= 400 && status < 500 ? REJECTED : UNSURE
|
|
59
69
|
}
|
|
60
70
|
|
|
71
|
+
// Mirrors the gateway's _valid_context: a plain object of at most MAX_CONTEXT_KEYS keys, each key
|
|
72
|
+
// a non-empty string of at most MAX_CONTEXT_KEY_CHARS characters, each value a boolean, a finite
|
|
73
|
+
// number or a string of at most MAX_CONTEXT_VALUE_CHARS characters.
|
|
74
|
+
export function validContext(value) {
|
|
75
|
+
if (!isObject(value)) return false
|
|
76
|
+
const proto = Object.getPrototypeOf(value)
|
|
77
|
+
if (proto !== Object.prototype && proto !== null) return false
|
|
78
|
+
const keys = Object.keys(value)
|
|
79
|
+
if (keys.length > MAX_CONTEXT_KEYS) return false
|
|
80
|
+
for (const key of keys) {
|
|
81
|
+
if (!key || codePointLength(key) > MAX_CONTEXT_KEY_CHARS) return false
|
|
82
|
+
const item = value[key]
|
|
83
|
+
if (typeof item === 'boolean') continue
|
|
84
|
+
if (typeof item === 'number') {
|
|
85
|
+
if (!Number.isFinite(item)) return false
|
|
86
|
+
continue
|
|
87
|
+
}
|
|
88
|
+
if (typeof item !== 'string' || codePointLength(item) > MAX_CONTEXT_VALUE_CHARS) return false
|
|
89
|
+
}
|
|
90
|
+
return true
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// A real calendar date written YYYY-MM-DD and nothing else (the gateway's _valid_event_date).
|
|
94
|
+
export function validEventDate(value) {
|
|
95
|
+
if (typeof value !== 'string' || !/^\d{4}-\d{2}-\d{2}$/.test(value)) return false
|
|
96
|
+
const [year, month, day] = value.split('-').map(Number)
|
|
97
|
+
if (year < 1 || month < 1 || month > 12 || day < 1) return false
|
|
98
|
+
return day <= new Date(Date.UTC(2000 + (year % 400), month, 0)).getUTCDate()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Whether `value` is acceptable as the optional message key `key` (the gateway's _valid_field).
|
|
102
|
+
function validField(key, value) {
|
|
103
|
+
if (typeof value !== 'string') return false
|
|
104
|
+
if (key === 'channel') return CHANNEL.test(value)
|
|
105
|
+
if (key === 'event_date') return validEventDate(value)
|
|
106
|
+
return (key === 'origin' ? ORIGINS : KINDS).includes(value)
|
|
107
|
+
}
|
|
108
|
+
|
|
61
109
|
const count = (value) => (Number.isInteger(value) && value > 0 ? value : 0)
|
|
62
110
|
|
|
63
111
|
// The messages as the gateway takes them, or null when one breaks a gateway limit.
|
|
@@ -80,11 +128,48 @@ function cleanMessages(messages) {
|
|
|
80
128
|
if (typeof value !== 'string' || codePointLength(value) > cap) return null
|
|
81
129
|
item[key] = value
|
|
82
130
|
}
|
|
131
|
+
for (const key of ['channel', 'origin', 'event_date', 'kind']) {
|
|
132
|
+
const value = m[key]
|
|
133
|
+
if (value === null || value === undefined) continue
|
|
134
|
+
if (!validField(key, value)) return null
|
|
135
|
+
item[key] = value
|
|
136
|
+
}
|
|
137
|
+
const about = m.about
|
|
138
|
+
if (about !== null && about !== undefined) {
|
|
139
|
+
if (typeof about !== 'string' || codePointLength(about) > MAX_SPEAKER_CHARS) return null
|
|
140
|
+
item.about = about
|
|
141
|
+
}
|
|
83
142
|
clean.push(item)
|
|
84
143
|
}
|
|
85
144
|
return clean
|
|
86
145
|
}
|
|
87
146
|
|
|
147
|
+
const OUTCOMES = new Set(['delivered', 'dropped', 'deferred', 'over_limit', 'not_reached'])
|
|
148
|
+
|
|
149
|
+
// One entry of an explained recall as the page may rely on it, or null when it is not well formed.
|
|
150
|
+
function cleanCandidate(c) {
|
|
151
|
+
if (!isObject(c) || typeof c.source !== 'string' || typeof c.id !== 'string') return null
|
|
152
|
+
if (!Number.isFinite(c.found) || !Number.isFinite(c.score) || !OUTCOMES.has(c.outcome)) return null
|
|
153
|
+
const out = {
|
|
154
|
+
source: c.source,
|
|
155
|
+
id: c.id,
|
|
156
|
+
found: c.found,
|
|
157
|
+
score: c.score,
|
|
158
|
+
outcome: c.outcome,
|
|
159
|
+
stage: typeof c.stage === 'string' ? c.stage : null,
|
|
160
|
+
addedBy: typeof c.added_by === 'string' ? c.added_by : null,
|
|
161
|
+
}
|
|
162
|
+
if (typeof c.text === 'string') out.text = c.text
|
|
163
|
+
if (typeof c.date === 'string') out.date = c.date
|
|
164
|
+
if (c.cut === true) out.cut = true
|
|
165
|
+
if (isObject(c.fields)) {
|
|
166
|
+
const fields = {}
|
|
167
|
+
for (const key of FIELD_KEYS) if (typeof c.fields[key] === 'string') fields[key] = c.fields[key]
|
|
168
|
+
if (Object.keys(fields).length) out.fields = fields
|
|
169
|
+
}
|
|
170
|
+
return out
|
|
171
|
+
}
|
|
172
|
+
|
|
88
173
|
function normaliseBase(url) {
|
|
89
174
|
if (typeof url !== 'string') return null
|
|
90
175
|
const trimmed = pyStrip(url).replace(/\/+$/, '')
|
|
@@ -140,7 +225,7 @@ async function errorCode(response) {
|
|
|
140
225
|
}
|
|
141
226
|
}
|
|
142
227
|
|
|
143
|
-
export function createClient({ url, token, fetch: fetchImpl = globalThis.fetch, logger, recallLimit =
|
|
228
|
+
export function createClient({ url, token, fetch: fetchImpl = globalThis.fetch, logger, recallLimit = 8 } = {}) {
|
|
144
229
|
const base = normaliseBase(url)
|
|
145
230
|
const secret = typeof token === 'string' ? pyStrip(token) : ''
|
|
146
231
|
const configured = Boolean(base && secret)
|
|
@@ -153,7 +238,24 @@ export function createClient({ url, token, fetch: fetchImpl = globalThis.fetch,
|
|
|
153
238
|
}
|
|
154
239
|
}
|
|
155
240
|
|
|
156
|
-
//
|
|
241
|
+
// The optional "speaker" of a recall: a string of at most MAX_SPEAKER_CHARS characters goes into the body,
|
|
242
|
+
// anything else is left out (a label never makes a call fail, as with the context).
|
|
243
|
+
function withSpeaker(body, speaker) {
|
|
244
|
+
return typeof speaker === 'string' && speaker && codePointLength(speaker) <= MAX_SPEAKER_CHARS ? { ...body, speaker } : body
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// { context } to add to a body: nothing when absent, nothing (and one warning that does not show
|
|
248
|
+
// it) when invalid. A label never makes a call fail.
|
|
249
|
+
function withContext(body, context, what) {
|
|
250
|
+
if (context === undefined || context === null) return body
|
|
251
|
+
if (!validContext(context)) {
|
|
252
|
+
warn(`memory ${what}: context dropped, it breaks the gateway's limits`)
|
|
253
|
+
return body
|
|
254
|
+
}
|
|
255
|
+
return { ...body, context: { ...context } }
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// One request until an absolute deadline (timeoutMs from now). Returns [object|null, outcome, status]; status is the HTTP status of an error answer, else absent.
|
|
157
259
|
async function request(method, path, payload, timeoutMs, what, signal, withToken) {
|
|
158
260
|
if (!base || (withToken && !secret)) return [null, NOT_SENT]
|
|
159
261
|
if (!(Number.isFinite(timeoutMs) && timeoutMs > 0)) {
|
|
@@ -200,7 +302,7 @@ export function createClient({ url, token, fetch: fetchImpl = globalThis.fetch,
|
|
|
200
302
|
const shown = code !== null && /^[a-z0-9_]{1,40}$/.test(code) ? code : '-'
|
|
201
303
|
warn(`memory ${what} failed: http ${response.status} ${shown}`)
|
|
202
304
|
await response.body?.cancel().catch(() => {})
|
|
203
|
-
return [null, failure(response.status, code)]
|
|
305
|
+
return [null, failure(response.status, code), response.status]
|
|
204
306
|
}
|
|
205
307
|
// One deadline for the whole call: the abort signal also ends a body that drips in slowly.
|
|
206
308
|
const data = JSON.parse(new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(await readBody(response, MAX_RESPONSE_BYTES)))
|
|
@@ -218,14 +320,14 @@ export function createClient({ url, token, fetch: fetchImpl = globalThis.fetch,
|
|
|
218
320
|
}
|
|
219
321
|
}
|
|
220
322
|
|
|
221
|
-
async function recallDetail(query, { timeoutMs = 8500, signal } = {}) {
|
|
323
|
+
async function recallDetail(query, { timeoutMs = 8500, signal, context, speaker } = {}) {
|
|
222
324
|
try {
|
|
223
325
|
if (typeof query !== 'string' || !pyStrip(query)) return null
|
|
224
326
|
if (codePointLength(query) > MAX_QUERY_CHARS) {
|
|
225
327
|
warn(`memory recall not sent: query over ${MAX_QUERY_CHARS} characters`)
|
|
226
328
|
return null
|
|
227
329
|
}
|
|
228
|
-
const [data] = await request('POST', '/v1/recall', { query, limit: recallLimit }, timeoutMs, 'recall', signal, true)
|
|
330
|
+
const [data] = await request('POST', '/v1/recall', withContext(withSpeaker({ query, limit: recallLimit }, speaker), context, 'recall'), timeoutMs, 'recall', signal, true)
|
|
229
331
|
const results = data?.results
|
|
230
332
|
if (!Array.isArray(results)) return null
|
|
231
333
|
return {
|
|
@@ -239,14 +341,41 @@ export function createClient({ url, token, fetch: fetchImpl = globalThis.fetch,
|
|
|
239
341
|
}
|
|
240
342
|
}
|
|
241
343
|
|
|
242
|
-
|
|
344
|
+
// POST /v1/explain: a recall with the reasons. { ok: true, stages, candidates, more, failed, busy,
|
|
345
|
+
// cut } or { ok: false, code }: 'unsupported' when the gateway answers 403, 404 or 405 (an older
|
|
346
|
+
// gateway, or explain is off for this client), 'failed' for anything else.
|
|
347
|
+
async function explainRecall(query, { timeoutMs = 8500, signal, context, limit = recallLimit, speaker } = {}) {
|
|
348
|
+
try {
|
|
349
|
+
if (typeof query !== 'string' || !pyStrip(query)) return { ok: false, code: 'failed' }
|
|
350
|
+
if (codePointLength(query) > MAX_QUERY_CHARS) {
|
|
351
|
+
warn(`memory explain not sent: query over ${MAX_QUERY_CHARS} characters`)
|
|
352
|
+
return { ok: false, code: 'failed' }
|
|
353
|
+
}
|
|
354
|
+
const [data, , status] = await request('POST', '/v1/explain', withContext(withSpeaker({ query, limit }, speaker), context, 'explain'), timeoutMs, 'explain', signal, true)
|
|
355
|
+
if (status === 403 || status === 404 || status === 405) return { ok: false, code: 'unsupported' }
|
|
356
|
+
if (!data || !Array.isArray(data.candidates)) return { ok: false, code: 'failed' }
|
|
357
|
+
return {
|
|
358
|
+
ok: true,
|
|
359
|
+
stages: Array.isArray(data.stages) ? data.stages.filter((s) => typeof s === 'string') : [],
|
|
360
|
+
candidates: data.candidates.map(cleanCandidate).filter((c) => c !== null),
|
|
361
|
+
more: count(data.more),
|
|
362
|
+
failed: count(data.failed),
|
|
363
|
+
busy: count(data.busy),
|
|
364
|
+
cut: data.candidates_cut === true,
|
|
365
|
+
}
|
|
366
|
+
} catch {
|
|
367
|
+
return { ok: false, code: 'failed' }
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
async function rememberMessages(messages, { timeoutMs = 12000, signal, context } = {}) {
|
|
243
372
|
try {
|
|
244
373
|
const clean = cleanMessages(messages)
|
|
245
374
|
if (clean === null) {
|
|
246
375
|
warn("memory remember not sent: messages break the gateway's limits")
|
|
247
376
|
return 'failed'
|
|
248
377
|
}
|
|
249
|
-
const [data, outcome] = await request('POST', '/v1/remember', { messages: clean }, timeoutMs, 'remember', signal, true)
|
|
378
|
+
const [data, outcome] = await request('POST', '/v1/remember', withContext({ messages: clean }, context, 'remember'), timeoutMs, 'remember', signal, true)
|
|
250
379
|
if (outcome === OK) return data.status === 'ok' ? 'saved' : data.status === 'skipped' ? 'skipped' : 'unsure'
|
|
251
380
|
return outcome === UNSURE ? 'unsure' : outcome === LIMITED ? 'limited' : 'failed'
|
|
252
381
|
} catch {
|
|
@@ -256,10 +385,16 @@ export function createClient({ url, token, fetch: fetchImpl = globalThis.fetch,
|
|
|
256
385
|
|
|
257
386
|
// opts.time: the message's own time ("2026-11-17T20:15:03+09:00", at most 40 characters), which the
|
|
258
387
|
// gateway uses to date the memory. Not a Python option: the Python client's remember() takes no time.
|
|
388
|
+
// opts.speaker, opts.origin, opts.kind, opts.eventDate: the message's own "speaker", "origin", "kind" and
|
|
389
|
+
// "event_date" when given; the gateway checks them as cleanMessages does.
|
|
259
390
|
async function rememberStatus(text, opts) {
|
|
260
391
|
if (typeof text !== 'string' || !pyStrip(text)) return 'failed'
|
|
261
392
|
const message = { role: 'user', content: text }
|
|
262
393
|
if (typeof opts?.time === 'string') message.time = opts.time
|
|
394
|
+
if (typeof opts?.speaker === 'string') message.speaker = opts.speaker
|
|
395
|
+
if (typeof opts?.origin === 'string') message.origin = opts.origin
|
|
396
|
+
if (typeof opts?.kind === 'string') message.kind = opts.kind
|
|
397
|
+
if (typeof opts?.eventDate === 'string') message.event_date = opts.eventDate
|
|
263
398
|
return rememberMessages([message], opts)
|
|
264
399
|
}
|
|
265
400
|
|
|
@@ -296,5 +431,5 @@ export function createClient({ url, token, fetch: fetchImpl = globalThis.fetch,
|
|
|
296
431
|
}
|
|
297
432
|
}
|
|
298
433
|
|
|
299
|
-
return { configured, recallDetail, rememberStatus, rememberMessages, reportUsed, health }
|
|
434
|
+
return { configured, recallDetail, explainRecall, rememberStatus, rememberMessages, reportUsed, health }
|
|
300
435
|
}
|
package/src/commands.js
CHANGED
|
@@ -8,6 +8,12 @@
|
|
|
8
8
|
//
|
|
9
9
|
// Replies never contain a secret: secret settings show as "set" or "not set", and a value typed for
|
|
10
10
|
// one is never repeated. Words a person typed are repeated only when they look like a name.
|
|
11
|
+
//
|
|
12
|
+
// `/memgate feedback` answers with the address of GitHub's new-issue page, with the plugin's version
|
|
13
|
+
// numbers and state names filled in. The address is built by the settings page's own module
|
|
14
|
+
// (client/src/model/feedback.cjs, plain CommonJS with no dependency on a browser), so the command and
|
|
15
|
+
// the page's Feedback tab cannot drift apart. The command sends nothing; it only prints the link.
|
|
16
|
+
import feedback from '../client/src/model/feedback.cjs'
|
|
11
17
|
import { FIELDS, parseSetting, SETTING_KEYS } from './config.js'
|
|
12
18
|
import { ADDON_CONFIRM, describeFailure } from './setup.js'
|
|
13
19
|
import { TIER_CHOICES, TIERS } from './tiers.js'
|
|
@@ -38,10 +44,19 @@ const TEXT = {
|
|
|
38
44
|
' use <model> switch to a downloaded model',
|
|
39
45
|
' remove <model> delete a downloaded model that is not in use',
|
|
40
46
|
' cancel stop the running add-on installation or model download',
|
|
47
|
+
' changelog what the newest released version changed (the text is in Chinese)',
|
|
48
|
+
' feedback where to tell the project an idea or a problem (a link, nothing is sent)',
|
|
41
49
|
].join('\n'),
|
|
42
50
|
oneLine: 'The command takes one line.',
|
|
43
51
|
unknownSub: (w) => `Unknown subcommand${w ? ` ${w}` : ''}.`,
|
|
44
52
|
noArgs: (sub) => `/memgate ${sub} takes no arguments.`,
|
|
53
|
+
noChangelog: 'The changelog could not be shown.',
|
|
54
|
+
feedback: (url) => [
|
|
55
|
+
'Ideas and problems go to the project\u2019s issues on GitHub. They are public, and you need a GitHub account.',
|
|
56
|
+
'This link opens a new issue with the plugin\u2019s version numbers and state names filled in, and nothing else. You write the rest there and decide whether to submit it; the plugin sends nothing.',
|
|
57
|
+
url,
|
|
58
|
+
'The settings page has a Feedback tab that does the same with a text box.',
|
|
59
|
+
].join('\n'),
|
|
45
60
|
needKeyValue: 'Usage: /memgate set <key> <value>',
|
|
46
61
|
needKey: (sub) => `Usage: /memgate ${sub} <key>`,
|
|
47
62
|
needModule: (sub) => `Usage: /memgate ${sub} <feature>. Features: ${MODULE_KEYS.join(', ')}.`,
|
|
@@ -100,71 +115,80 @@ const TEXT = {
|
|
|
100
115
|
' status 网关、Python、存储、检索方式、向量插件、复制进度',
|
|
101
116
|
' config 每项设置的当前值和默认值',
|
|
102
117
|
' set <键> <值> 修改一项设置(键名见 /memgate config)',
|
|
103
|
-
' reset <键>
|
|
104
|
-
' on <功能>
|
|
118
|
+
' reset <键> 将设置恢复为默认值',
|
|
119
|
+
' on <功能> 开启一项功能(见 modules.* 设置)',
|
|
105
120
|
' off <功能> 关闭一项功能',
|
|
106
|
-
' tiers
|
|
121
|
+
' tiers 各检索方式:是否可用、所需条件,以及混合检索是否开启',
|
|
107
122
|
' use <方式> 选择检索方式:auto、keyword、endpoint 或 local',
|
|
108
123
|
' models 本地向量模型:大小、内存、语言、许可和状态',
|
|
109
124
|
' install <模型> [--accept-licence <许可名称>] [--confirm]',
|
|
110
|
-
'
|
|
111
|
-
' builds allow|deny
|
|
112
|
-
' use <模型>
|
|
113
|
-
' remove <模型>
|
|
114
|
-
' cancel
|
|
125
|
+
' 下载并启用模型;需先安装向量插件时,阅读说明后加 --confirm',
|
|
126
|
+
' builds allow|deny 回答安装向量插件时的安装脚本问题',
|
|
127
|
+
' use <模型> 切换到已下载的模型',
|
|
128
|
+
' remove <模型> 删除未在使用的已下载模型',
|
|
129
|
+
' cancel 停止正在进行的向量插件安装或模型下载',
|
|
130
|
+
' changelog 最新版本的更新内容',
|
|
131
|
+
' feedback 提交建议或问题的入口(仅显示链接,不发送任何内容)',
|
|
115
132
|
].join('\n'),
|
|
116
133
|
oneLine: '命令只能写一行。',
|
|
117
|
-
unknownSub: (w) =>
|
|
118
|
-
noArgs: (sub) => `/memgate ${sub}
|
|
134
|
+
unknownSub: (w) => `未知子命令${w ? ` ${w}` : ''}。`,
|
|
135
|
+
noArgs: (sub) => `/memgate ${sub} 不接受参数。`,
|
|
136
|
+
noChangelog: '无法显示更新日志。',
|
|
137
|
+
feedback: (url) => [
|
|
138
|
+
'建议和问题请提交到项目在 GitHub 上的 issue。issue 是公开的,需要 GitHub 账号。',
|
|
139
|
+
'下方链接会打开新建 issue 的页面,其中仅预填插件的版本号和状态,其余内容由你填写,是否提交由你决定;插件不发送任何内容。',
|
|
140
|
+
url,
|
|
141
|
+
'设置页面的“反馈”标签页提供相同功能,并带有输入框。',
|
|
142
|
+
].join('\n'),
|
|
119
143
|
needKeyValue: '用法:/memgate set <键> <值>',
|
|
120
144
|
needKey: (sub) => `用法:/memgate ${sub} <键>`,
|
|
121
|
-
needModule: (sub) => `用法:/memgate ${sub}
|
|
122
|
-
needTier: `用法:/memgate use
|
|
123
|
-
unknownKey: (w) =>
|
|
124
|
-
ambiguous: (w, list) => `${w} 对应多项设置:${list.join('、')}
|
|
125
|
-
unknownModule: (w) =>
|
|
126
|
-
unknownTier: (w) =>
|
|
145
|
+
needModule: (sub) => `用法:/memgate ${sub} <功能>。可用功能:${MODULE_KEYS.join('、')}。`,
|
|
146
|
+
needTier: `用法:/memgate use <方式>。可选方式:${TIER_CHOICES.join('、')}。`,
|
|
147
|
+
unknownKey: (w) => `未知设置项${w ? ` ${w}` : ''}。可用 /memgate config 查看全部设置项。`,
|
|
148
|
+
ambiguous: (w, list) => `${w} 对应多项设置:${list.join('、')}。请使用完整键名。`,
|
|
149
|
+
unknownModule: (w) => `未知功能${w ? ` ${w}` : ''}。可用功能:${MODULE_KEYS.join('、')}。`,
|
|
150
|
+
unknownTier: (w) => `未知检索方式${w ? ` ${w}` : ''}。可选方式:${TIER_CHOICES.join('、')}。`,
|
|
127
151
|
invalid: {
|
|
128
152
|
boolean: (k) => `${k} 只能是 on 或 off。`,
|
|
129
153
|
integer: (k, f) => `${k} 只能是 ${f.min} 到 ${f.max} 之间的整数。`,
|
|
130
154
|
choice: (k, f) => `${k} 只能是:${f.options.map((o) => o.value).join('、')}。`,
|
|
131
155
|
url: (k) => `${k} 需要 http:// 或 https:// 开头的地址。`,
|
|
132
|
-
empty: (k) => `${k}
|
|
156
|
+
empty: (k) => `${k} 需要一个值;如需清空,请使用 /memgate reset ${k}。`,
|
|
133
157
|
},
|
|
134
|
-
noSettings: '
|
|
135
|
-
refused: (kind) =>
|
|
136
|
-
saved: (k, v, was) => `已保存:${k} = ${v}
|
|
158
|
+
noSettings: '未保存:当前宿主没有设置服务,只能在配置文件中修改设置。',
|
|
159
|
+
refused: (kind) => `未保存:宿主拒绝了此次修改(${kind})。`,
|
|
160
|
+
saved: (k, v, was) => `已保存:${k} = ${v}(原值 ${was})。`,
|
|
137
161
|
savedSecret: (k) => `已保存:${k} 已设置(不显示内容)。`,
|
|
138
|
-
resetDone: (k, v) =>
|
|
139
|
-
resetSecret: (k) =>
|
|
140
|
-
already: (k, v) => `${k}
|
|
141
|
-
on: '
|
|
142
|
-
tierNow: (t) => `auto
|
|
143
|
-
tierUnavailable: (needs) =>
|
|
162
|
+
resetDone: (k, v) => `已恢复默认值:${k} = ${v}。`,
|
|
163
|
+
resetSecret: (k) => `已恢复默认值:${k} 已清空。`,
|
|
164
|
+
already: (k, v) => `${k} 已为 ${v},未作修改。`,
|
|
165
|
+
on: '开启', off: '关闭', set: '已设置', notSet: '未设置', empty: '(空)', secret: '保密',
|
|
166
|
+
tierNow: (t) => `auto 当前使用 ${t}。`,
|
|
167
|
+
tierUnavailable: (needs) => `暂不可用:需要${needs}。在此之前记忆功能保持关闭。`,
|
|
144
168
|
configTitle: 'feiyu-memgate 设置(当前值,然后是默认值):',
|
|
145
169
|
statusTitle: 'feiyu-memgate 状态',
|
|
146
170
|
tiersTitle: (setting, active) => `检索方式设置:${setting}${active ? `,正在使用:${active}` : ''}。`,
|
|
147
|
-
tiersExternal: '
|
|
171
|
+
tiersExternal: '检索方式仅适用于内置网关;外部网关使用自身的配置。',
|
|
148
172
|
hybridWord: '关键词(混合)',
|
|
149
|
-
hybridLine: (on, active) =>
|
|
150
|
-
tierLine: (t) => `- ${t.name}:${t.available ? '可用' : '不可用'}${t.active ? '(正在使用)' : ''}。需要:${t.needs}。${t.missing.length ?
|
|
173
|
+
hybridLine: (on, active) => `混合检索(关键词与向量同时检索,retrieval.hybrid):${on ? (active ? '开启' : '已开启,但当前检索方式下不生效') : '关闭'}。`,
|
|
174
|
+
tierLine: (t) => `- ${t.name}:${t.available ? '可用' : '不可用'}${t.active ? '(正在使用)' : ''}。需要:${t.needs}。${t.missing.length ? `缺少:${t.missing.join('、')}。` : ''}`,
|
|
151
175
|
labels: {
|
|
152
176
|
gateway: '网关', python: 'Python', retrieval: '检索', store: '存储', embed: '向量插件',
|
|
153
|
-
migration: '从关键词存储复制', features: '
|
|
177
|
+
migration: '从关键词存储复制', features: '已开启的功能',
|
|
154
178
|
},
|
|
155
179
|
states: {
|
|
156
|
-
idle: '未启动', starting: '
|
|
157
|
-
failed: '多次失败后已停止', stopped: '已停止', unused: '
|
|
180
|
+
idle: '未启动', starting: '正在启动', running: '运行中', restarting: '正在重启', off: '已关闭',
|
|
181
|
+
failed: '多次失败后已停止', stopped: '已停止', unused: '未运行(未开启任何需要记忆的功能)',
|
|
158
182
|
configured: '已配置', incomplete: '需要 external.url 和 external.token',
|
|
159
|
-
ready: '就绪', loading: '
|
|
160
|
-
done: '
|
|
183
|
+
ready: '就绪', loading: '正在加载', 'no-model': '未安装模型', error: '错误',
|
|
184
|
+
done: '已完成', partial: '进行中', 'not-started': '未开始',
|
|
161
185
|
},
|
|
162
|
-
pythonNone: '
|
|
186
|
+
pythonNone: '未找到(需要 3.11 或更高版本)',
|
|
163
187
|
pythonUnknown: '未检查',
|
|
164
188
|
notInstalled: '未安装',
|
|
165
189
|
memories: (n) => `${n} 条记忆`,
|
|
166
190
|
countUnknown: '条数未知',
|
|
167
|
-
progress: (m) => `已复制 ${m.copied ?? 0} / ${m.total ?? 0}${m.refused ?
|
|
191
|
+
progress: (m) => `已复制 ${m.copied ?? 0} / ${m.total ?? 0}${m.refused ? `,向量模型拒绝 ${m.refused} 条` : ''}`,
|
|
168
192
|
approximate: '分数未校准',
|
|
169
193
|
none: '无',
|
|
170
194
|
},
|
|
@@ -191,6 +215,20 @@ export function resolveSetting(name, t = TEXT.en) {
|
|
|
191
215
|
return { error: t.unknownKey(quote(name)) }
|
|
192
216
|
}
|
|
193
217
|
|
|
218
|
+
/** One changelog entry ({ version, title, body }) as plain text: the Markdown marks are left out. */
|
|
219
|
+
export function formatChangelog(entry, lang = 'en') {
|
|
220
|
+
const body = String(entry?.body ?? '')
|
|
221
|
+
.replace(/\r\n?/g, '\n')
|
|
222
|
+
.replace(/^#{1,6}[ \t]+/gm, '')
|
|
223
|
+
.replace(/\*\*([^*\n]+)\*\*/g, '$1')
|
|
224
|
+
.replace(/`([^`\n]+)`/g, '$1')
|
|
225
|
+
.replace(/\[([^\]\n]+)\]\(([^)\s]+)\)/g, '$1 ($2)')
|
|
226
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
227
|
+
.trim()
|
|
228
|
+
const head = lang === 'zh' ? `更新日志 ${entry?.title ?? ''}` : `Changelog ${entry?.title ?? ''} (written in Chinese)`
|
|
229
|
+
return `${head.trim()}\n\n${body}`
|
|
230
|
+
}
|
|
231
|
+
|
|
194
232
|
/** The status object (src/plugin.js, status()) as text. */
|
|
195
233
|
export function formatStatus(s, lang) {
|
|
196
234
|
const t = TEXT[lang] ?? TEXT.en
|
|
@@ -270,43 +308,43 @@ const MODEL_TEXT = {
|
|
|
270
308
|
notInstalled: (id) => `${id} is not downloaded. Download it: /memgate install ${id}`,
|
|
271
309
|
},
|
|
272
310
|
zh: {
|
|
273
|
-
title: (addon, link) => `本地向量模型(向量插件:${addon}
|
|
274
|
-
addon: { present: '已安装', outdated: '
|
|
275
|
-
states: { absent: '未下载', downloading: '下载中', installed: '已下载', active: '使用中', loading: '
|
|
311
|
+
title: (addon, link) => `本地向量模型(向量插件:${addon})。各检索方式的检索效果:${link}`,
|
|
312
|
+
addon: { present: '已安装', outdated: '已安装,版本过旧,不支持一键设置', installing: '正在安装', starting: '已安装,正在启动', absent: '未安装' },
|
|
313
|
+
states: { absent: '未下载', downloading: '下载中', installed: '已下载', active: '使用中', loading: '正在加载', paused: '已中断,执行 /memgate install 可继续下载' },
|
|
276
314
|
languages: { zh: '中文', en: '英文', multilingual: '多语言' },
|
|
277
315
|
line: (m, tier, size, memory, langs, licence, state) => `- ${m.id}${tier ? `(${tier})` : ''}:下载 ${size},${memory},${langs},${licence}。状态:${state}。`,
|
|
278
|
-
memory: (mb) => (mb ? `运行内存约 ${mb} MB` : '
|
|
316
|
+
memory: (mb) => (mb ? `运行内存约 ${mb} MB` : '运行内存未测量'),
|
|
279
317
|
acceptance: (l) => ` 需要先同意 ${l.name}${l.url ? `(${l.url})` : ''}。`,
|
|
280
|
-
phases: { addon: '正在安装向量插件', builds: '
|
|
318
|
+
phases: { addon: '正在安装向量插件', builds: '等待你决定是否允许安装脚本', 'addon-starting': '等待向量插件启动', restart: '等待 DSH 重启', model: '下载中', paused: '下载已中断', activating: '正在启用', done: '使用中', idle: '', failed: '已停止' },
|
|
281
319
|
needBuilds: '用法:/memgate builds allow 或 /memgate builds deny',
|
|
282
|
-
buildsAllowed: '
|
|
283
|
-
noBuilds: '
|
|
284
|
-
buildsAsk: '
|
|
285
|
-
confirmWith: (command) =>
|
|
286
|
-
pinnedMark: '
|
|
320
|
+
buildsAllowed: '已允许。正在重新安装向量插件,并允许其安装脚本。进度:/memgate models',
|
|
321
|
+
noBuilds: '没有待决定的安装脚本。',
|
|
322
|
+
buildsAsk: '请使用 /memgate builds allow 或 /memgate builds deny 回答。',
|
|
323
|
+
confirmWith: (command) => `确认安装请执行:${command}`,
|
|
324
|
+
pinnedMark: ' 已在向量插件的设置中指定此模型。',
|
|
287
325
|
chain: (phase, id, percent) => `${id} 的设置:${phase}${percent !== null && percent !== undefined ? ` ${percent}%` : ''}。`,
|
|
288
326
|
failure: (f) => `${f.title.zh}${f.todo.zh}`,
|
|
289
327
|
hint: '下载并启用:/memgate install <模型>',
|
|
290
|
-
noModels: '
|
|
291
|
-
needModel: (sub) => `用法:/memgate ${sub}
|
|
292
|
-
needAccept: (id, l, size) => `${id}
|
|
328
|
+
noModels: '当前宿主不支持本地模型。',
|
|
329
|
+
needModel: (sub) => `用法:/memgate ${sub} <模型>。可用 /memgate models 查看模型列表。`,
|
|
330
|
+
needAccept: (id, l, size) => `${id} 的权重适用 ${l.name}${l.url ? `:${l.url}` : ''}。\n阅读并同意后请执行:/memgate install ${id} --accept-licence ${l.name}\n同意前不会下载任何内容(${size})。`,
|
|
293
331
|
replies: {
|
|
294
|
-
'installing-addon': (id, size) => `正在通过宿主的插件管理器安装向量插件(dsh-feiyu-memgate-embed
|
|
332
|
+
'installing-addon': (id, size) => `正在通过宿主的插件管理器安装向量插件(dsh-feiyu-memgate-embed),随后下载 ${id}(${size})。进度:/memgate models`,
|
|
295
333
|
started: (id, size) => `正在下载 ${id}(${size}),完成后自动启用。进度:/memgate models`,
|
|
296
|
-
running: (id) => `${id}
|
|
297
|
-
'starting-addon': (id) =>
|
|
298
|
-
'enabling-addon': (id) =>
|
|
299
|
-
installed: (id) => `${id}
|
|
300
|
-
active: (id) => `${id}
|
|
301
|
-
activating: (id) => `正在切换到 ${id}
|
|
334
|
+
running: (id) => `${id} 正在设置中。进度:/memgate models`,
|
|
335
|
+
'starting-addon': (id) => `向量插件已安装,启动后将下载 ${id}。进度:/memgate models`,
|
|
336
|
+
'enabling-addon': (id) => `向量插件已安装,但未在当前配置中启用;正在通过宿主的插件管理器启用,随后下载 ${id}。进度:/memgate models`,
|
|
337
|
+
installed: (id) => `${id} 已下载,正在启用。`,
|
|
338
|
+
active: (id) => `${id} 使用中。`,
|
|
339
|
+
activating: (id) => `正在切换到 ${id},模型正在加载。`,
|
|
302
340
|
removed: (id) => `已删除 ${id} 的文件。`,
|
|
303
341
|
cancelled: () => '已取消。',
|
|
304
342
|
},
|
|
305
343
|
notRunning: '没有正在进行的安装或下载。',
|
|
306
|
-
tooLate: '
|
|
307
|
-
isActive: (id) => `${id}
|
|
308
|
-
isDownloading: (id) => `${id}
|
|
309
|
-
notInstalled: (id) => `${id}
|
|
344
|
+
tooLate: '已无法取消:插件正在应用。',
|
|
345
|
+
isActive: (id) => `${id} 正在使用,请先切换到其他模型。`,
|
|
346
|
+
isDownloading: (id) => `${id} 正在下载,请先取消:/memgate cancel`,
|
|
347
|
+
notInstalled: (id) => `${id} 未下载。下载:/memgate install ${id}`,
|
|
310
348
|
},
|
|
311
349
|
}
|
|
312
350
|
|
|
@@ -373,7 +411,7 @@ function formatTiers(s, lang) {
|
|
|
373
411
|
* models the model setup (src/setup.js): view, install, use, remove, cancel; the same
|
|
374
412
|
* functions the settings page calls
|
|
375
413
|
*/
|
|
376
|
-
export function createMemgateCommand({ settings, language, status, write, models = null }) {
|
|
414
|
+
export function createMemgateCommand({ settings, language, status, write, models = null, changelog = null }) {
|
|
377
415
|
const ok = (text) => ({ kind: 'success', text })
|
|
378
416
|
const fail = (text) => ({ kind: 'error', text })
|
|
379
417
|
// A failure with this profile's file names filled in (the setup knows them).
|
|
@@ -485,6 +523,18 @@ export function createMemgateCommand({ settings, language, status, write, models
|
|
|
485
523
|
case 'config':
|
|
486
524
|
if (words.length) return fail(t.noArgs(sub))
|
|
487
525
|
return ok(formatConfig(settings(), t))
|
|
526
|
+
case 'changelog': {
|
|
527
|
+
if (words.length) return fail(t.noArgs(sub))
|
|
528
|
+
const found = typeof changelog === 'function' ? changelog() : null
|
|
529
|
+
const entry = found?.entries?.[0]
|
|
530
|
+
return ok(entry ? formatChangelog(entry, lang) : t.noChangelog)
|
|
531
|
+
}
|
|
532
|
+
case 'feedback': {
|
|
533
|
+
// No text is taken here: whatever a person typed would come back inside the address.
|
|
534
|
+
if (words.length) return fail(t.noArgs(sub))
|
|
535
|
+
const report = feedback.compose({ kind: 'other', text: '', environment: feedback.environment(await status()) })
|
|
536
|
+
return ok(t.feedback(report.url))
|
|
537
|
+
}
|
|
488
538
|
case 'tiers':
|
|
489
539
|
if (words.length) return fail(t.noArgs(sub))
|
|
490
540
|
return ok(formatTiers(await status(), lang))
|
|
@@ -549,7 +599,7 @@ export function createMemgateCommand({ settings, language, status, write, models
|
|
|
549
599
|
return {
|
|
550
600
|
name: COMMAND_NAME,
|
|
551
601
|
description: 'Long-term memory: status, settings, retrieval tiers and local models (feiyu-memgate)',
|
|
552
|
-
input: { hint: 'status | config | set <key> <value> | reset <key> | on|off <feature> | tiers | use <tier|model> | models | install <model> [--confirm] | builds allow|deny | remove <model> | cancel' },
|
|
602
|
+
input: { hint: 'status | config | set <key> <value> | reset <key> | on|off <feature> | tiers | use <tier|model> | models | install <model> [--confirm] | builds allow|deny | remove <model> | cancel | changelog | feedback' },
|
|
553
603
|
// The input may hold a secret (`set external.token ...`): keep it out of the session log; the
|
|
554
604
|
// reply says what changed without repeating it (commands/src/index.ts:70-75, :376).
|
|
555
605
|
recordInput: false,
|