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.
Files changed (103) hide show
  1. package/CHANGELOG.md +73 -12
  2. package/README.md +68 -11
  3. package/README.zh.md +93 -36
  4. package/client/README.md +267 -0
  5. package/client/art/mascot-asleep.webp +0 -0
  6. package/client/art/mascot-busy.webp +0 -0
  7. package/client/art/mascot-nag.webp +0 -0
  8. package/client/art/mascot-ready.webp +0 -0
  9. package/client/art/mascot-trouble.webp +0 -0
  10. package/client/client.js +4226 -1269
  11. package/client/src/clipboard.cjs +52 -0
  12. package/client/src/constants.cjs +43 -0
  13. package/client/src/fields.cjs +960 -0
  14. package/client/src/hooks.cjs +220 -0
  15. package/client/src/i18n.cjs +444 -0
  16. package/client/src/index.cjs +69 -0
  17. package/client/src/kit/controls.cjs +189 -0
  18. package/client/src/kit/icons.cjs +40 -0
  19. package/client/src/kit/layout.cjs +124 -0
  20. package/client/src/layout.cjs +143 -0
  21. package/client/src/model/changelog.cjs +29 -0
  22. package/client/src/model/feedback.cjs +168 -0
  23. package/client/src/model/form.cjs +83 -0
  24. package/client/src/model/models.cjs +87 -0
  25. package/client/src/model/overview.cjs +111 -0
  26. package/client/src/model/page.cjs +104 -0
  27. package/client/src/model/status.cjs +57 -0
  28. package/client/src/model/trial.cjs +111 -0
  29. package/client/src/net.cjs +101 -0
  30. package/client/src/react.cjs +11 -0
  31. package/client/src/theme/page.css +1284 -0
  32. package/client/src/theme/styles.cjs +43 -0
  33. package/client/src/view/feedback.cjs +180 -0
  34. package/client/src/view/field-row.cjs +98 -0
  35. package/client/src/view/hero.cjs +54 -0
  36. package/client/src/view/markdown.cjs +96 -0
  37. package/client/src/view/models.cjs +154 -0
  38. package/client/src/view/page.cjs +199 -0
  39. package/client/src/view/settings-tab.cjs +78 -0
  40. package/client/src/view/tabs.cjs +71 -0
  41. package/client/src/view/trial.cjs +84 -0
  42. package/docs/DETAIL.en.md +55 -6
  43. package/docs/DETAIL.md +63 -14
  44. package/locale/zh.json +1 -1
  45. package/package.json +2 -1
  46. package/python/GATEWAY_VERSION.json +37 -31
  47. package/python/feiyu_memgate/backends/_sqlfile.py +293 -0
  48. package/python/feiyu_memgate/backends/base.py +121 -6
  49. package/python/feiyu_memgate/backends/embedding.py +265 -178
  50. package/python/feiyu_memgate/backends/hybrid.py +330 -83
  51. package/python/feiyu_memgate/backends/inmemory.py +115 -24
  52. package/python/feiyu_memgate/backends/openviking.py +7 -10
  53. package/python/feiyu_memgate/backends/sqlite.py +129 -145
  54. package/python/feiyu_memgate/builtins.py +1 -0
  55. package/python/feiyu_memgate/cli.py +124 -20
  56. package/python/feiyu_memgate/client/block.py +4 -2
  57. package/python/feiyu_memgate/client/http.py +106 -19
  58. package/python/feiyu_memgate/client/local.py +4 -3
  59. package/python/feiyu_memgate/config.py +118 -24
  60. package/python/feiyu_memgate/core/limits.py +2 -1
  61. package/python/feiyu_memgate/core/pool.py +29 -2
  62. package/python/feiyu_memgate/core/recall.py +179 -10
  63. package/python/feiyu_memgate/core/redact.py +4 -2
  64. package/python/feiyu_memgate/core/stages.py +52 -9
  65. package/python/feiyu_memgate/core/tidy.py +2 -1
  66. package/python/feiyu_memgate/core/watch.py +3 -2
  67. package/python/feiyu_memgate/core/write.py +9 -3
  68. package/python/feiyu_memgate/forgetting/archive.py +38 -10
  69. package/python/feiyu_memgate/forgetting/engine.py +46 -10
  70. package/python/feiyu_memgate/forgetting/stage.py +4 -2
  71. package/python/feiyu_memgate/gateway/app.py +168 -272
  72. package/python/feiyu_memgate/gateway/fields.py +121 -0
  73. package/python/feiyu_memgate/gateway/policies.py +162 -0
  74. package/python/feiyu_memgate/gateway/server.py +12 -4
  75. package/python/feiyu_memgate/gateway/tokens.py +137 -0
  76. package/python/feiyu_memgate/gateway/validate.py +120 -0
  77. package/python/feiyu_memgate/identity.py +152 -0
  78. package/python/feiyu_memgate/model.py +170 -2
  79. package/python/feiyu_memgate/registry.py +6 -3
  80. package/python/feiyu_memgate/tools/crypto.py +5 -4
  81. package/python/feiyu_memgate/tools/evaluate.py +2 -1
  82. package/python/feiyu_memgate/tools/tenants.py +2 -0
  83. package/src/block.js +9 -3
  84. package/src/capture.js +98 -0
  85. package/src/catalogue.js +4 -4
  86. package/src/changelog.js +72 -0
  87. package/src/client.js +145 -10
  88. package/src/commands.js +112 -62
  89. package/src/config.js +139 -62
  90. package/src/followup.js +139 -0
  91. package/src/gateway.js +79 -4
  92. package/src/migrate.py +54 -9
  93. package/src/mirror.py +44 -7
  94. package/src/plugin.js +416 -412
  95. package/src/pool.js +298 -0
  96. package/src/recent.js +68 -0
  97. package/src/relevance.js +80 -0
  98. package/src/routes.js +320 -0
  99. package/src/setup.js +36 -36
  100. package/src/shared.js +77 -0
  101. package/src/tiers.js +4 -4
  102. package/src/time.js +27 -0
  103. package/src/tools.js +164 -0
@@ -0,0 +1,52 @@
1
+ 'use strict'
2
+ // Puts a text on the clipboard: the one place of the page that touches it. The page copies only on a
3
+ // click, and only the report the person has in front of them (view/feedback.cjs).
4
+ //
5
+ // The browser's clipboard interface needs a secure context (https or localhost), which a DSH page
6
+ // is. Where it is missing or refuses, the older way is tried: a text area outside the visible page,
7
+ // selected and copied. Whether the text arrived is reported, never assumed.
8
+
9
+ // The older way. Returns whether the browser said it copied.
10
+ function copyThroughSelection(text, doc) {
11
+ if (!doc || !doc.body || typeof doc.createElement !== 'function' || typeof doc.execCommand !== 'function') return false
12
+ const area = doc.createElement('textarea')
13
+ area.value = text
14
+ area.setAttribute('readonly', '')
15
+ area.setAttribute('aria-hidden', 'true')
16
+ area.style.position = 'fixed'
17
+ area.style.top = '-1000px'
18
+ area.style.opacity = '0'
19
+ doc.body.appendChild(area)
20
+ let copied = false
21
+ try {
22
+ area.select()
23
+ copied = doc.execCommand('copy') === true
24
+ } catch {
25
+ copied = false
26
+ }
27
+ doc.body.removeChild(area)
28
+ return copied
29
+ }
30
+
31
+ /**
32
+ * @param {string} text
33
+ * @param {{ navigator?: object, document?: object }} [env] the browser's objects; tests pass their own
34
+ * @returns {Promise<boolean>} whether the text is on the clipboard now
35
+ */
36
+ function copyText(text, env) {
37
+ const given = env || {}
38
+ const nav = 'navigator' in given ? given.navigator : typeof navigator !== 'undefined' ? navigator : undefined
39
+ const doc = 'document' in given ? given.document : typeof document !== 'undefined' ? document : undefined
40
+ if (nav && nav.clipboard && typeof nav.clipboard.writeText === 'function') {
41
+ let attempt
42
+ try {
43
+ attempt = nav.clipboard.writeText(text)
44
+ } catch {
45
+ attempt = Promise.reject(new Error('refused'))
46
+ }
47
+ return Promise.resolve(attempt).then(() => true, () => copyThroughSelection(text, doc))
48
+ }
49
+ return Promise.resolve(copyThroughSelection(text, doc))
50
+ }
51
+
52
+ module.exports = { copyText }
@@ -0,0 +1,43 @@
1
+ 'use strict'
2
+
3
+ // Names and numbers the page agrees on with the host half: the settings namespace, the slot key,
4
+ // the routes and how often each one is polled, and the public addresses the page links to. Plain values
5
+ // only; no logic, no host modules.
6
+
7
+ const NS = 'feiyuMemgate'
8
+ const ROW_KEY = 'dsh-feiyu-memgate#feiyu-memgate'
9
+ const STATUS_ROUTE = 'feiyu-memgate/status'
10
+ const STATUS_POLL_MS = 10000
11
+ const CHANGELOG_ROUTE = 'feiyu-memgate/changelog'
12
+ // The model list: GET reads it, POST is a click (install, cancel, use, remove); src/setup.js.
13
+ const MODELS_ROUTE = 'feiyu-memgate/models'
14
+ const MODELS_POLL_MS = 10000
15
+ const MODELS_BUSY_POLL_MS = 1500
16
+ // The trial recall (Retrieval tab): POST { query }, the host half asks the gateway to explain a recall (src/plugin.js).
17
+ const TRY_ROUTE = 'feiyu-memgate/try'
18
+ // How long a sentence to try may be (the gateway's limit for a query).
19
+ const TRIAL_MAX_CHARS = 500
20
+ // The mascot's drawings: GET <ART_ROUTE><mood>.webp (src/plugin.js serves the files of client/art).
21
+ const ART_ROUTE = 'feiyu-memgate/art/'
22
+ // How long a confirmation ("Saved", "Copied") stays before it goes away.
23
+ const SAVED_NOTE_MS = 2600
24
+ // The project's feedback receiver (feedback-worker/): the address the Feedback tab posts a report to
25
+ // when a person presses Send. An empty text switches Send off and leaves the link to GitHub and the
26
+ // copy button. It is the one address outside the host that the page ever calls.
27
+ const FEEDBACK_ENDPOINT = 'https://feiyu-memgate-feedback.feiyu-memgate.workers.dev/'
28
+ // How long the page waits for the receiver before it says the report was not sent.
29
+ const FEEDBACK_TIMEOUT_MS = 15000
30
+ // The prefix of every element id the page makes, so that none can meet an id of the host's page.
31
+ const ID_PREFIX = 'feiyu-memgate'
32
+ const LINKS = {
33
+ docs: 'https://github.com/N0rmal-114/feiyu-memgate/tree/main/plugins/dsh-feiyu-memgate#readme',
34
+ source: 'https://github.com/N0rmal-114/feiyu-memgate',
35
+ issues: 'https://github.com/N0rmal-114/feiyu-memgate/issues',
36
+ // GitHub's page for a new issue; model/feedback.cjs adds the title and the text to it.
37
+ newIssue: 'https://github.com/N0rmal-114/feiyu-memgate/issues/new',
38
+ }
39
+
40
+ module.exports = {
41
+ NS, ROW_KEY, STATUS_ROUTE, STATUS_POLL_MS, CHANGELOG_ROUTE, MODELS_ROUTE, MODELS_POLL_MS, MODELS_BUSY_POLL_MS, TRY_ROUTE, TRIAL_MAX_CHARS,
42
+ ART_ROUTE, SAVED_NOTE_MS, FEEDBACK_ENDPOINT, FEEDBACK_TIMEOUT_MS, ID_PREFIX, LINKS,
43
+ }