@skedulo/memory-hub-mcp 0.2.4 → 0.2.5
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/assets/user-prompt-submit.sh +15 -6
- package/dist/chunk.js +75 -0
- package/dist/client.js +19 -4
- package/package.json +1 -1
|
@@ -13,11 +13,12 @@ FUNCTION_URL="${MEMORY_HUB_FUNCTION_URL:-https://dev-api.test.skl.io/function/me
|
|
|
13
13
|
BUDGET="${MEMORY_HUB_PROMPT_MAX_CHARS:-6000}"
|
|
14
14
|
[ "$BUDGET" -gt 9000 ] && BUDGET=9000
|
|
15
15
|
FACTS_N="${MEMORY_HUB_PROMPT_FACTS:-5}"
|
|
16
|
-
#
|
|
17
|
-
|
|
18
|
-
MIN_SIMILARITY="${MEMORY_HUB_PROMPT_MIN_SIMILARITY:-0.35}"
|
|
16
|
+
# 0.45 and 0.25 come from memory-hub-mcp/eval: at 0.35, 3 of 10 prompts with no relevant memory still injected some.
|
|
17
|
+
MIN_SIMILARITY="${MEMORY_HUB_PROMPT_MIN_SIMILARITY:-0.45}"
|
|
19
18
|
SIMILARITY_BAND="${MEMORY_HUB_PROMPT_SIMILARITY_BAND:-0.25}"
|
|
20
19
|
SKILLS_N="${MEMORY_HUB_PROMPT_SKILLS:-3}"
|
|
20
|
+
WIKI_N="${MEMORY_HUB_PROMPT_WIKI:-2}"
|
|
21
|
+
SCENARIOS_N="${MEMORY_HUB_PROMPT_SCENARIOS:-2}"
|
|
21
22
|
ITEM_CAP=500
|
|
22
23
|
NL=$'\n'
|
|
23
24
|
|
|
@@ -86,6 +87,8 @@ call() {
|
|
|
86
87
|
|
|
87
88
|
call "/memory/recall" "$TMP_DIR/facts.json" &
|
|
88
89
|
call "/memory/list-skills" "$TMP_DIR/skills.json" &
|
|
90
|
+
call "/memory/recall-wiki" "$TMP_DIR/wiki.json" &
|
|
91
|
+
call "/memory/recall-scenarios" "$TMP_DIR/scenarios.json" &
|
|
89
92
|
wait
|
|
90
93
|
|
|
91
94
|
CLOSE_FENCE='if ([match("```"; "g")] | length) % 2 == 1 then . + "\n```" else . end'
|
|
@@ -93,11 +96,15 @@ INDENT='gsub("\n"; "\n ")'
|
|
|
93
96
|
STAMP='(if .lastModifiedDate then " (updated " + .lastModifiedDate[0:10] + ")" else "" end)'
|
|
94
97
|
ELIDE="if length >= $ITEM_CAP then . + \"…\" else . end"
|
|
95
98
|
cut_pointer() {
|
|
96
|
-
printf '(if .truncated then " [cut at \\(
|
|
99
|
+
printf '(if .truncated then " [cut at \\(.%s | length) of \\(.fullLength) — memory_get type=%s uid=\\(.uid)]" else "" end)' "${2:-content}" "$1"
|
|
97
100
|
}
|
|
98
101
|
|
|
99
|
-
# Judged across
|
|
100
|
-
BEST
|
|
102
|
+
# Judged across every list: one list alone may have no strong match, and would keep its weak ones.
|
|
103
|
+
BEST=""
|
|
104
|
+
for kind in facts skills wiki scenarios; do
|
|
105
|
+
top=$(jq -r '[(.facts // [])[], (.skills // [])[], (.pages // [])[], (.scenarios // [])[]] | map(.similarity // empty) | max // empty' "$TMP_DIR/$kind.json" 2>/dev/null)
|
|
106
|
+
if [ -n "$top" ] && { [ -z "$BEST" ] || [ "$(jq -n --argjson a "$top" --argjson b "$BEST" '$a > $b' 2>/dev/null)" = true ]; }; then BEST="$top"; fi
|
|
107
|
+
done
|
|
101
108
|
FLOOR=-1
|
|
102
109
|
[ -n "$BEST" ] && FLOOR=$(jq -n --argjson best "$BEST" --argjson band "$SIMILARITY_BAND" '$best - $band')
|
|
103
110
|
KEEP='select(.similarity == null or .similarity >= $floor)'
|
|
@@ -117,6 +124,8 @@ while IFS= read -r -d $'\x1e' item; do
|
|
|
117
124
|
done < <(
|
|
118
125
|
jq -j --argjson floor "$FLOOR" "[.facts[]? | $KEEP][:$FACTS_N][] | ((\"- \" + (.content | $ELIDE) + $(cut_pointer Fact) + $STAMP) | $CLOSE_FENCE | $INDENT), \"\\u001e\"" "$TMP_DIR/facts.json" 2>/dev/null
|
|
119
126
|
jq -j --argjson floor "$FLOOR" "[.skills[]? | $KEEP][:$SKILLS_N][] | ((\"- \" + .title + \": \" + (.content | $ELIDE) + $(cut_pointer Skill) + $STAMP) | $CLOSE_FENCE | $INDENT), \"\\u001e\"" "$TMP_DIR/skills.json" 2>/dev/null
|
|
127
|
+
jq -j --argjson floor "$FLOOR" "[.pages[]? | $KEEP][:$WIKI_N][] | ((\"- \" + .title + \": \" + (.content | $ELIDE) + $(cut_pointer Wiki) + $STAMP) | $CLOSE_FENCE | $INDENT), \"\\u001e\"" "$TMP_DIR/wiki.json" 2>/dev/null
|
|
128
|
+
jq -j --argjson floor "$FLOOR" "[.scenarios[]? | $KEEP][:$SCENARIOS_N][] | ((\"- \" + (.summary | $ELIDE) + $(cut_pointer Scenario summary) + $STAMP) | $CLOSE_FENCE | $INDENT), \"\\u001e\"" "$TMP_DIR/scenarios.json" 2>/dev/null
|
|
120
129
|
)
|
|
121
130
|
[ -n "$BODY" ] || exit 0
|
|
122
131
|
|
package/dist/chunk.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.chunkText = void 0;
|
|
4
|
+
const DEFAULTS = { target: 900, max: 1400, overlap: 300 };
|
|
5
|
+
// A block ends at a blank line and a new one starts at each markdown heading, so a heading stays with its text.
|
|
6
|
+
function blocks(text) {
|
|
7
|
+
const out = [];
|
|
8
|
+
let blockStart = -1;
|
|
9
|
+
let cursor = 0;
|
|
10
|
+
for (const line of text.split('\n')) {
|
|
11
|
+
const lineEnd = cursor + line.length;
|
|
12
|
+
const blank = line.trim() === '';
|
|
13
|
+
const heading = /^#{1,6}\s/.test(line);
|
|
14
|
+
if (blank) {
|
|
15
|
+
if (blockStart >= 0)
|
|
16
|
+
out.push({ start: blockStart, end: cursor - 1 });
|
|
17
|
+
blockStart = -1;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
if (heading && blockStart >= 0)
|
|
21
|
+
out.push({ start: blockStart, end: cursor - 1 });
|
|
22
|
+
if (heading || blockStart < 0)
|
|
23
|
+
blockStart = cursor;
|
|
24
|
+
}
|
|
25
|
+
cursor = lineEnd + 1;
|
|
26
|
+
}
|
|
27
|
+
if (blockStart >= 0)
|
|
28
|
+
out.push({ start: blockStart, end: text.length });
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
function splitLong(text, block, max) {
|
|
32
|
+
if (block.end - block.start <= max)
|
|
33
|
+
return [block];
|
|
34
|
+
const parts = [];
|
|
35
|
+
let start = block.start;
|
|
36
|
+
while (block.end - start > max) {
|
|
37
|
+
const window = text.slice(start, start + max);
|
|
38
|
+
const cut = Math.max(window.lastIndexOf('\n'), window.lastIndexOf('. '));
|
|
39
|
+
const end = start + (cut > max / 2 ? cut + 1 : max);
|
|
40
|
+
parts.push({ start, end });
|
|
41
|
+
start = end;
|
|
42
|
+
while (start < block.end && /\s/.test(text[start]))
|
|
43
|
+
start += 1;
|
|
44
|
+
}
|
|
45
|
+
if (start < block.end)
|
|
46
|
+
parts.push({ start, end: block.end });
|
|
47
|
+
return parts;
|
|
48
|
+
}
|
|
49
|
+
function chunkText(text, options = {}) {
|
|
50
|
+
const { target, max, overlap } = { ...DEFAULTS, ...options };
|
|
51
|
+
const pieces = blocks(text).flatMap((block) => splitLong(text, block, max));
|
|
52
|
+
if (pieces.length === 0)
|
|
53
|
+
return [];
|
|
54
|
+
const chunks = [];
|
|
55
|
+
let current = [];
|
|
56
|
+
const span = (list) => list[list.length - 1].end - list[0].start;
|
|
57
|
+
const flush = () => {
|
|
58
|
+
if (current.length === 0)
|
|
59
|
+
return;
|
|
60
|
+
const start = current[0].start;
|
|
61
|
+
const end = current[current.length - 1].end;
|
|
62
|
+
chunks.push({ start, end, text: text.slice(start, end) });
|
|
63
|
+
};
|
|
64
|
+
for (const piece of pieces) {
|
|
65
|
+
if (current.length > 0 && span([...current, piece]) > target) {
|
|
66
|
+
flush();
|
|
67
|
+
const last = current[current.length - 1];
|
|
68
|
+
current = last.end - last.start <= overlap && current.length > 1 ? [last] : [];
|
|
69
|
+
}
|
|
70
|
+
current.push(piece);
|
|
71
|
+
}
|
|
72
|
+
flush();
|
|
73
|
+
return chunks;
|
|
74
|
+
}
|
|
75
|
+
exports.chunkText = chunkText;
|
package/dist/client.js
CHANGED
|
@@ -6,16 +6,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.MemoryHubClient = void 0;
|
|
7
7
|
// memory-hub-mcp/src/client.ts
|
|
8
8
|
const axios_1 = __importDefault(require("axios"));
|
|
9
|
+
// axios only says "status code 400"; the function puts the reason in { error } on the body.
|
|
10
|
+
function withServerMessage(err) {
|
|
11
|
+
const response = err?.response;
|
|
12
|
+
const reason = response?.data?.error;
|
|
13
|
+
if (typeof reason !== 'string' || !reason)
|
|
14
|
+
return err;
|
|
15
|
+
const wrapped = new Error(response?.status ? `${reason} (HTTP ${response.status})` : reason);
|
|
16
|
+
wrapped.cause = err;
|
|
17
|
+
return wrapped;
|
|
18
|
+
}
|
|
9
19
|
class MemoryHubClient {
|
|
10
20
|
config;
|
|
11
21
|
constructor(config) {
|
|
12
22
|
this.config = config;
|
|
13
23
|
}
|
|
14
24
|
async post(path, body) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
25
|
+
try {
|
|
26
|
+
const res = await axios_1.default.post(`${this.config.baseUrl}${path}`, body, {
|
|
27
|
+
headers: { Authorization: `Bearer ${this.config.apiToken}`, 'Content-Type': 'application/json' },
|
|
28
|
+
});
|
|
29
|
+
return res.data;
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
throw withServerMessage(err);
|
|
33
|
+
}
|
|
19
34
|
}
|
|
20
35
|
recall(input) {
|
|
21
36
|
return this.post('/memory/recall', input);
|
package/package.json
CHANGED