@astratra/memory 2.1.1 → 2.1.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astratra/memory",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "description": "Per-person memories for an AI assistant: injected store, embeddings and model, hybrid recall, duplicate merging or reinforcing, undoable corrections, background consolidation, portrait, a ready-made PostgreSQL store, and privacy operations that keep working with the AI switched off.",
5
5
  "engines": {
6
6
  "node": ">=22"
@@ -11,9 +11,6 @@
11
11
  "files": [
12
12
  "src"
13
13
  ],
14
- "scripts": {
15
- "test": "jest"
16
- },
17
14
  "jest": {
18
15
  "testMatch": [
19
16
  "**/__tests__/**/*.test.js"
@@ -37,5 +34,8 @@
37
34
  "@astratra/ai": "^1.3.0 || ^2.0.0",
38
35
  "jest": "30.4.2",
39
36
  "pg": "^8.13.1"
37
+ },
38
+ "scripts": {
39
+ "test": "jest"
40
40
  }
41
- }
41
+ }
@@ -52,7 +52,8 @@ const isObject = (value) => Boolean(value) && typeof value === 'object' && !Arra
52
52
  * failed run, never as "nothing to remember".
53
53
  */
54
54
  function parseModelJson(value) {
55
- const text = String(value ?? '').replace(/^\s*```(?:json)?\s*/i, '').replace(/\s*```\s*$/, '');
55
+ /* (?<!\s) : la recherche ne repart pas de chaque blanc d'une longue suite de blancs. */
56
+ const text = String(value ?? '').replace(/^\s*```(?:json)?\s*/i, '').replace(/(?<!\s)\s*```\s*$/, '');
56
57
  const start = text.indexOf('{');
57
58
  const end = text.lastIndexOf('}');
58
59
  if (start === -1 || end < start) throw new SyntaxError('The model answer holds no JSON object.');
@@ -65,10 +66,16 @@ function parseModelJson(value) {
65
66
  /* Every whole {...} in the text, even when what holds them was cut short. */
66
67
  function wholeObjects(text) {
67
68
  const found = [];
68
- for (let start = text.indexOf('{'); start !== -1; start = text.indexOf('{', start + 1)) {
69
+ /* Chaque accolade ouvrante relit la suite jusqu'à celle qui la ferme. Une réponse faite d'accolades jamais
70
+ fermées coûterait le carré de sa longueur : la lecture a un budget (vingt fois la longueur du texte, bien plus
71
+ qu'il n'en faut à une vraie réponse, même très imbriquée) et rend ce qu'elle a trouvé quand il est épuisé. */
72
+ let budget = text.length * 20 + 100000;
73
+ for (let start = text.indexOf('{'); start !== -1 && budget > 0; start = text.indexOf('{', start + 1)) {
69
74
  let depth = 0;
70
75
  let inString = false;
71
76
  for (let index = start; index < text.length; index += 1) {
77
+ budget -= 1;
78
+ if (budget <= 0) break;
72
79
  const char = text[index];
73
80
  if (inString) {
74
81
  if (char === '\\') index += 1;