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
|
@@ -21,6 +21,7 @@ import calendar
|
|
|
21
21
|
import fnmatch
|
|
22
22
|
import math
|
|
23
23
|
import time
|
|
24
|
+
from typing import Any
|
|
24
25
|
|
|
25
26
|
DAY = 86400.0
|
|
26
27
|
REQUIRED = ("refs", "delete", "put")
|
|
@@ -43,7 +44,8 @@ def supports(store):
|
|
|
43
44
|
|
|
44
45
|
class Forgetting:
|
|
45
46
|
def __init__(self, ledger, archive, curve, *, stores=(), demote_below=0.3, forget_below=0.05,
|
|
46
|
-
archive_days=90, pin_refs=(), max_forget_fraction=0.02, max_forget_min=5,
|
|
47
|
+
archive_days=90, pin_refs=(), max_forget_fraction=0.02, max_forget_min=5, audiences=None,
|
|
48
|
+
wall=time.time):
|
|
47
49
|
self.ledger = ledger
|
|
48
50
|
self.archive = archive
|
|
49
51
|
self.curve = curve
|
|
@@ -54,6 +56,9 @@ class Forgetting:
|
|
|
54
56
|
self.pin_refs = tuple(pin_refs)
|
|
55
57
|
self.max_forget_fraction = max_forget_fraction
|
|
56
58
|
self.max_forget_min = max_forget_min
|
|
59
|
+
# {store or tenants provider name: its declared audience}: what a restored memory that was archived
|
|
60
|
+
# without an audience gets. None (a service built in code) restores such a memory as it was.
|
|
61
|
+
self.audiences = dict(audiences) if audiences else None
|
|
57
62
|
self.wall = wall
|
|
58
63
|
|
|
59
64
|
# ---------------------------------------------------------------- keys and scores
|
|
@@ -137,7 +142,7 @@ class Forgetting:
|
|
|
137
142
|
def record_use(self, key, items, now=None):
|
|
138
143
|
"""items: (ref, date) of the memories that were returned to a caller."""
|
|
139
144
|
now = self.wall() if now is None else now
|
|
140
|
-
seen = {}
|
|
145
|
+
seen: dict[Any, float | None] = {}
|
|
141
146
|
for ref, date in items:
|
|
142
147
|
seen.setdefault(ref, date_to_epoch(date))
|
|
143
148
|
if seen:
|
|
@@ -145,7 +150,7 @@ class Forgetting:
|
|
|
145
150
|
|
|
146
151
|
def _sync_listing(self, key, listing, now):
|
|
147
152
|
known = {entry.ref for entry in self.ledger.entries(key)}
|
|
148
|
-
present = {}
|
|
153
|
+
present: dict[Any, Any] = {}
|
|
149
154
|
for ref, date in listing:
|
|
150
155
|
present.setdefault(ref, date)
|
|
151
156
|
added = [(ref, date_to_epoch(date)) for ref, date in present.items() if ref not in known]
|
|
@@ -196,7 +201,7 @@ class Forgetting:
|
|
|
196
201
|
listings but writes nothing anywhere.
|
|
197
202
|
"""
|
|
198
203
|
now = self.wall() if now is None else now
|
|
199
|
-
report = {"unsupported": []}
|
|
204
|
+
report: dict[str, Any] = {"unsupported": []}
|
|
200
205
|
for key, store in targets.items():
|
|
201
206
|
if not supports(store):
|
|
202
207
|
report["unsupported"].append(key)
|
|
@@ -213,7 +218,7 @@ class Forgetting:
|
|
|
213
218
|
except Exception: # noqa: BLE001 - a store that cannot list is retried next time
|
|
214
219
|
row["failed"] = 1
|
|
215
220
|
return row
|
|
216
|
-
dates = {}
|
|
221
|
+
dates: dict[Any, Any] = {}
|
|
217
222
|
for ref, date in listing:
|
|
218
223
|
dates.setdefault(ref, date)
|
|
219
224
|
if dry_run:
|
|
@@ -250,11 +255,24 @@ class Forgetting:
|
|
|
250
255
|
|
|
251
256
|
def _forget(self, key, store, ref, date, entry, now):
|
|
252
257
|
try:
|
|
253
|
-
|
|
258
|
+
fields = {}
|
|
259
|
+
record = getattr(store, "record", None)
|
|
260
|
+
if callable(record):
|
|
261
|
+
try:
|
|
262
|
+
row = record(ref)
|
|
263
|
+
text, fields = row["text"], dict(row.get("fields") or {})
|
|
264
|
+
except Exception: # noqa: BLE001 - a store that cannot give the record is archived as before
|
|
265
|
+
text, fields = store.read(ref), {}
|
|
266
|
+
else:
|
|
267
|
+
text = store.read(ref)
|
|
254
268
|
if not isinstance(text, str):
|
|
255
269
|
return False
|
|
256
|
-
|
|
257
|
-
|
|
270
|
+
if fields:
|
|
271
|
+
self.archive.add(key, ref, text, date, entry.uses if entry else 0, now,
|
|
272
|
+
now + self.archive_days * DAY, fields=fields)
|
|
273
|
+
else:
|
|
274
|
+
self.archive.add(key, ref, text, date, entry.uses if entry else 0, now,
|
|
275
|
+
now + self.archive_days * DAY)
|
|
258
276
|
except Exception: # noqa: BLE001 - nothing was deleted, so nothing is lost
|
|
259
277
|
return False
|
|
260
278
|
try:
|
|
@@ -274,12 +292,30 @@ class Forgetting:
|
|
|
274
292
|
pass
|
|
275
293
|
return True
|
|
276
294
|
|
|
295
|
+
def audience_of(self, key):
|
|
296
|
+
"""The declared audience of the store behind the ledger key ("name" or "provider:tenant"), or None
|
|
297
|
+
when this service was not told the levels."""
|
|
298
|
+
if not self.audiences:
|
|
299
|
+
return None
|
|
300
|
+
level = self.audiences.get(key)
|
|
301
|
+
return level if level is not None else self.audiences.get(key.partition(":")[0])
|
|
302
|
+
|
|
277
303
|
def restore(self, key, ref, store):
|
|
278
|
-
"""Write an archived memory back to its store and address. False when it is not archived.
|
|
304
|
+
"""Write an archived memory back to its store and address. False when it is not archived.
|
|
305
|
+
|
|
306
|
+
A store that keeps record fields gets the memory's archived fields back; one archived before records
|
|
307
|
+
had an audience is restored with the store's declared audience (never with none)."""
|
|
279
308
|
record = self.archive.get(key, ref)
|
|
280
309
|
if record is None:
|
|
281
310
|
return False
|
|
282
|
-
store
|
|
311
|
+
keeps = getattr(store, "stores_fields", False) is True
|
|
312
|
+
fields = dict(record.fields)
|
|
313
|
+
if keeps and "audience" not in fields and self.audience_of(key) is not None:
|
|
314
|
+
fields["audience"] = self.audience_of(key)
|
|
315
|
+
if fields and keeps:
|
|
316
|
+
store.put(record.text, ref=ref, date=record.date, fields=fields)
|
|
317
|
+
else:
|
|
318
|
+
store.put(record.text, ref=ref, date=record.date)
|
|
283
319
|
self.ledger.revive(key, ref, self.wall())
|
|
284
320
|
self.archive.remove(key, ref)
|
|
285
321
|
return True
|
|
@@ -7,6 +7,8 @@ and the access log gets the note "ledger-failed".
|
|
|
7
7
|
|
|
8
8
|
Standard library only.
|
|
9
9
|
"""
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
10
12
|
from ..core.recall import RecallStage
|
|
11
13
|
from ..errors import ConfigError
|
|
12
14
|
from ..registry import register
|
|
@@ -63,7 +65,7 @@ class Freshness(RecallStage):
|
|
|
63
65
|
before = [(c, c.score) for c in managed]
|
|
64
66
|
try:
|
|
65
67
|
now = f.now()
|
|
66
|
-
by_key = {}
|
|
68
|
+
by_key: dict[Any, list[Any]] = {}
|
|
67
69
|
for c in managed:
|
|
68
70
|
by_key.setdefault(_key(f, c, ctx), []).append(c)
|
|
69
71
|
for key, group in by_key.items():
|
|
@@ -96,7 +98,7 @@ class Freshness(RecallStage):
|
|
|
96
98
|
return
|
|
97
99
|
f = self.forgetting
|
|
98
100
|
managed = [c for c in ctx.accepted if f.manages(c.source)]
|
|
99
|
-
by_key = {}
|
|
101
|
+
by_key: dict[Any, list[Any]] = {}
|
|
100
102
|
for c in self._credited(managed):
|
|
101
103
|
by_key.setdefault(_key(f, c, ctx), []).append((c.ref, c.date))
|
|
102
104
|
if not by_key:
|