@slashml/memory 1.0.5 → 1.0.7
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/README.md +7 -1
- package/bin/cli.js +92 -47
- package/dist/index.d.ts +6 -0
- package/dist/index.js +10 -1
- package/dist/index.mjs +11 -2
- package/package.json +1 -1
- package/src/index.ts +17 -2
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# `@slashml/memory`
|
|
1
|
+
# `@slashml/memory` -- TypeScript / Node.js SDK
|
|
2
2
|
|
|
3
3
|
Official TypeScript & Node.js client and MCP launcher for the **/ ml** Memory Cloud API (`https://api.slashml.ai`).
|
|
4
4
|
|
|
@@ -89,3 +89,9 @@ const decision = await client.intervene("aws ec2 run-instances --placement Avail
|
|
|
89
89
|
userId: "team_infra",
|
|
90
90
|
});
|
|
91
91
|
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
Apache-2.0
|
package/bin/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* @slashml/memory
|
|
3
|
+
* @slashml/memory -- Self-Contained CLI & MCP Stdio Server (/ml-memory)
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
const fs = require("fs");
|
|
@@ -10,10 +10,10 @@ const readline = require("readline");
|
|
|
10
10
|
|
|
11
11
|
const DEFAULT_BASE_URL = "https://api.slashml.ai";
|
|
12
12
|
const DEFAULT_CONSOLE_URL = "https://app.slashml.ai";
|
|
13
|
-
const PACKAGE_VERSION = "1.0.
|
|
13
|
+
const PACKAGE_VERSION = "1.0.7";
|
|
14
14
|
|
|
15
15
|
function printHelp() {
|
|
16
|
-
console.log(`@slashml/memory v${PACKAGE_VERSION}
|
|
16
|
+
console.log(`@slashml/memory v${PACKAGE_VERSION} -- Official CLI & MCP Stdio Server for / ml (SlashML · https://slashml.ai)
|
|
17
17
|
Publisher: SlashML (https://slashml.ai)
|
|
18
18
|
|
|
19
19
|
Usage:
|
|
@@ -527,12 +527,12 @@ function installAmbientHooks(apiKey) {
|
|
|
527
527
|
fs.writeFileSync(claudeSettingsPath, JSON.stringify(settings, null, 2) + "\n", "utf8");
|
|
528
528
|
console.log(`Configured / ml ambient lifecycle hooks in ${claudeSettingsPath}`);
|
|
529
529
|
|
|
530
|
-
// Also configure
|
|
531
|
-
const
|
|
532
|
-
if (fs.existsSync(path.join(home, ".gemini", "config")) || fs.existsSync(
|
|
533
|
-
fs.mkdirSync(
|
|
534
|
-
const
|
|
535
|
-
const
|
|
530
|
+
// Also configure Gemini CLI plugin hooks if ~/.gemini/config exists
|
|
531
|
+
const geminiPluginDir = path.join(home, ".gemini", "config", "plugins", "slashml-memory");
|
|
532
|
+
if (fs.existsSync(path.join(home, ".gemini", "config")) || fs.existsSync(geminiPluginDir)) {
|
|
533
|
+
fs.mkdirSync(geminiPluginDir, { recursive: true });
|
|
534
|
+
const geminiHooksPath = path.join(geminiPluginDir, "hooks.json");
|
|
535
|
+
const geminiHooks = {
|
|
536
536
|
"slashml-ambient-memory": {
|
|
537
537
|
PreInvocation: [
|
|
538
538
|
{
|
|
@@ -574,8 +574,8 @@ function installAmbientHooks(apiKey) {
|
|
|
574
574
|
],
|
|
575
575
|
},
|
|
576
576
|
};
|
|
577
|
-
fs.writeFileSync(
|
|
578
|
-
console.log(`Configured / ml ambient lifecycle hooks in ${
|
|
577
|
+
fs.writeFileSync(geminiHooksPath, JSON.stringify(geminiHooks, null, 2) + "\n", "utf8");
|
|
578
|
+
console.log(`Configured / ml ambient lifecycle hooks in ${geminiHooksPath}`);
|
|
579
579
|
}
|
|
580
580
|
}
|
|
581
581
|
|
|
@@ -769,9 +769,25 @@ function extractLastPlannerResponseFromTranscript(transcriptPath) {
|
|
|
769
769
|
if (!line || !line.startsWith("{")) continue;
|
|
770
770
|
try {
|
|
771
771
|
const entry = JSON.parse(line);
|
|
772
|
-
if (entry
|
|
772
|
+
if (!entry) continue;
|
|
773
|
+
if (entry.type === "PLANNER_RESPONSE" && typeof entry.content === "string" && entry.content.trim()) {
|
|
773
774
|
return entry.content.trim();
|
|
774
775
|
}
|
|
776
|
+
const msgObj = entry.message && typeof entry.message === "object" ? entry.message : entry;
|
|
777
|
+
if (msgObj && msgObj.role === "assistant") {
|
|
778
|
+
if (typeof msgObj.content === "string" && msgObj.content.trim()) {
|
|
779
|
+
return msgObj.content.trim();
|
|
780
|
+
}
|
|
781
|
+
if (Array.isArray(msgObj.content)) {
|
|
782
|
+
const textParts = msgObj.content
|
|
783
|
+
.filter((b) => b && (b.type === "text" || typeof b.text === "string"))
|
|
784
|
+
.map((b) => String(b.text || "").trim())
|
|
785
|
+
.filter(Boolean);
|
|
786
|
+
if (textParts.length > 0) {
|
|
787
|
+
return textParts.join("\n").trim();
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
}
|
|
775
791
|
} catch {
|
|
776
792
|
// ignore partial line at start of buffer
|
|
777
793
|
}
|
|
@@ -831,8 +847,8 @@ function extractWhisperedContextFromCurrentTurn(transcriptPath) {
|
|
|
831
847
|
return { ids: Array.from(ids), blocks: Array.from(blocks) };
|
|
832
848
|
}
|
|
833
849
|
|
|
834
|
-
function writeDefaultHookOutput(
|
|
835
|
-
if (
|
|
850
|
+
function writeDefaultHookOutput(isGeminiHook, rawEventName) {
|
|
851
|
+
if (isGeminiHook && rawEventName === "PreToolUse") {
|
|
836
852
|
process.stdout.write(JSON.stringify({ decision: "allow" }) + "\n");
|
|
837
853
|
} else {
|
|
838
854
|
process.stdout.write("{}\n");
|
|
@@ -889,7 +905,7 @@ async function runAmbientHookMode(opts) {
|
|
|
889
905
|
payload = { hook_event_name: cliEvent || "UserPromptSubmit", prompt: rawInput };
|
|
890
906
|
}
|
|
891
907
|
|
|
892
|
-
const
|
|
908
|
+
const isGeminiHook = Boolean(
|
|
893
909
|
cliEvent === "PreInvocation" ||
|
|
894
910
|
payload.invocationNum !== undefined ||
|
|
895
911
|
payload.toolCall !== undefined ||
|
|
@@ -903,7 +919,7 @@ async function runAmbientHookMode(opts) {
|
|
|
903
919
|
cliEvent || payload.hook_event_name || payload.hook_event || payload.event || ""
|
|
904
920
|
).trim();
|
|
905
921
|
if (!rawEventName) {
|
|
906
|
-
if (
|
|
922
|
+
if (isGeminiHook) {
|
|
907
923
|
if (payload.toolCall !== undefined) {
|
|
908
924
|
rawEventName =
|
|
909
925
|
payload.toolResponse !== undefined || payload.toolResult !== undefined
|
|
@@ -921,14 +937,20 @@ async function runAmbientHookMode(opts) {
|
|
|
921
937
|
|
|
922
938
|
const hookEvent = rawEventName === "PreInvocation" ? "UserPromptSubmit" : rawEventName;
|
|
923
939
|
|
|
924
|
-
// On
|
|
925
|
-
if (
|
|
940
|
+
// On Gemini CLI Stop, only evaluate normal completion turns (NO_TOOL_CALL)
|
|
941
|
+
if (isGeminiHook && rawEventName === "Stop") {
|
|
926
942
|
if (payload.terminationReason && payload.terminationReason !== "NO_TOOL_CALL") {
|
|
927
|
-
writeDefaultHookOutput(
|
|
943
|
+
writeDefaultHookOutput(isGeminiHook, rawEventName);
|
|
928
944
|
return;
|
|
929
945
|
}
|
|
930
946
|
}
|
|
931
947
|
|
|
948
|
+
// On Claude Code Stop, never re-block if stop_hook_active is already true
|
|
949
|
+
if (!isGeminiHook && rawEventName === "Stop" && payload.stop_hook_active) {
|
|
950
|
+
writeDefaultHookOutput(isGeminiHook, rawEventName);
|
|
951
|
+
return;
|
|
952
|
+
}
|
|
953
|
+
|
|
932
954
|
const toolCallObj =
|
|
933
955
|
payload.toolCall && typeof payload.toolCall === "object" ? payload.toolCall : null;
|
|
934
956
|
const toolName =
|
|
@@ -991,7 +1013,7 @@ async function runAmbientHookMode(opts) {
|
|
|
991
1013
|
if (HOOK_READ_ONLY_TOOLS.has(toolName.toLowerCase())) {
|
|
992
1014
|
persistPendingToolContext();
|
|
993
1015
|
recordLocalHookDrop(rawEventTokens);
|
|
994
|
-
writeDefaultHookOutput(
|
|
1016
|
+
writeDefaultHookOutput(isGeminiHook, rawEventName);
|
|
995
1017
|
return;
|
|
996
1018
|
}
|
|
997
1019
|
}
|
|
@@ -1023,7 +1045,7 @@ async function runAmbientHookMode(opts) {
|
|
|
1023
1045
|
if (isReadOnlyCmd) {
|
|
1024
1046
|
persistPendingToolContext();
|
|
1025
1047
|
recordLocalHookDrop(rawEventTokens);
|
|
1026
|
-
writeDefaultHookOutput(
|
|
1048
|
+
writeDefaultHookOutput(isGeminiHook, rawEventName);
|
|
1027
1049
|
return;
|
|
1028
1050
|
}
|
|
1029
1051
|
}
|
|
@@ -1039,11 +1061,12 @@ async function runAmbientHookMode(opts) {
|
|
|
1039
1061
|
""
|
|
1040
1062
|
);
|
|
1041
1063
|
} else if (hookEvent === "Stop") {
|
|
1064
|
+
const transcriptFile = payload.transcriptPath || payload.transcript_path;
|
|
1042
1065
|
rawCandidateText = String(
|
|
1043
1066
|
payload.last_assistant_message ||
|
|
1044
1067
|
payload.assistant_message ||
|
|
1045
1068
|
payload.response ||
|
|
1046
|
-
extractLastPlannerResponseFromTranscript(
|
|
1069
|
+
extractLastPlannerResponseFromTranscript(transcriptFile) ||
|
|
1047
1070
|
""
|
|
1048
1071
|
);
|
|
1049
1072
|
} else {
|
|
@@ -1065,7 +1088,7 @@ async function runAmbientHookMode(opts) {
|
|
|
1065
1088
|
/^(ok|okay|thanks|thank you|yes|no|sure|cool|lgtm)[.!]*$/i.test(deltaText)
|
|
1066
1089
|
) {
|
|
1067
1090
|
recordLocalHookDrop(rawEventTokens);
|
|
1068
|
-
writeDefaultHookOutput(
|
|
1091
|
+
writeDefaultHookOutput(isGeminiHook, rawEventName);
|
|
1069
1092
|
return;
|
|
1070
1093
|
}
|
|
1071
1094
|
|
|
@@ -1082,13 +1105,13 @@ async function runAmbientHookMode(opts) {
|
|
|
1082
1105
|
.slice(0, 16);
|
|
1083
1106
|
if (Array.isArray(dedupState.hashes) && dedupState.hashes.includes(deltaHash)) {
|
|
1084
1107
|
recordLocalHookDrop(rawEventTokens);
|
|
1085
|
-
writeDefaultHookOutput(
|
|
1108
|
+
writeDefaultHookOutput(isGeminiHook, rawEventName);
|
|
1086
1109
|
return;
|
|
1087
1110
|
}
|
|
1088
1111
|
|
|
1089
1112
|
if (!opts.apiKey) {
|
|
1090
1113
|
recordLocalHookDrop(rawEventTokens);
|
|
1091
|
-
writeDefaultHookOutput(
|
|
1114
|
+
writeDefaultHookOutput(isGeminiHook, rawEventName);
|
|
1092
1115
|
return;
|
|
1093
1116
|
}
|
|
1094
1117
|
|
|
@@ -1101,20 +1124,23 @@ async function runAmbientHookMode(opts) {
|
|
|
1101
1124
|
if (!dedupState.whispered_blocks_by_session || typeof dedupState.whispered_blocks_by_session !== "object") {
|
|
1102
1125
|
dedupState.whispered_blocks_by_session = {};
|
|
1103
1126
|
}
|
|
1127
|
+
const whisperKey = sessionKey || scopeStateKey;
|
|
1104
1128
|
const isMidTurnContinuation =
|
|
1105
1129
|
rawEventName === "PreInvocation" && Number(payload.invocationNum || 1) > 1;
|
|
1106
|
-
if (hookEvent === "UserPromptSubmit" && !isMidTurnContinuation &&
|
|
1107
|
-
dedupState.whispered_by_session[
|
|
1108
|
-
dedupState.whispered_blocks_by_session[
|
|
1130
|
+
if (hookEvent === "UserPromptSubmit" && !isMidTurnContinuation && whisperKey) {
|
|
1131
|
+
dedupState.whispered_by_session[whisperKey] = [];
|
|
1132
|
+
dedupState.whispered_blocks_by_session[whisperKey] = [];
|
|
1109
1133
|
}
|
|
1110
|
-
const transcriptWhispered = extractWhisperedContextFromCurrentTurn(
|
|
1134
|
+
const transcriptWhispered = extractWhisperedContextFromCurrentTurn(
|
|
1135
|
+
payload.transcriptPath || payload.transcript_path
|
|
1136
|
+
);
|
|
1111
1137
|
const sessionWhispered =
|
|
1112
|
-
|
|
1113
|
-
? dedupState.whispered_by_session[
|
|
1138
|
+
whisperKey && Array.isArray(dedupState.whispered_by_session[whisperKey])
|
|
1139
|
+
? dedupState.whispered_by_session[whisperKey]
|
|
1114
1140
|
: [];
|
|
1115
1141
|
const sessionWhisperedBlocks =
|
|
1116
|
-
|
|
1117
|
-
? dedupState.whispered_blocks_by_session[
|
|
1142
|
+
whisperKey && Array.isArray(dedupState.whispered_blocks_by_session[whisperKey])
|
|
1143
|
+
? dedupState.whispered_blocks_by_session[whisperKey]
|
|
1118
1144
|
: [];
|
|
1119
1145
|
const whisperedMemoryIds = Array.from(new Set([...transcriptWhispered.ids, ...sessionWhispered]));
|
|
1120
1146
|
const whisperedBlocks = Array.from(new Set([...transcriptWhispered.blocks, ...sessionWhisperedBlocks]));
|
|
@@ -1147,6 +1173,12 @@ async function runAmbientHookMode(opts) {
|
|
|
1147
1173
|
hook_event_name: hookEvent,
|
|
1148
1174
|
prompt: payload.prompt || payload.lastUserInput || deltaText,
|
|
1149
1175
|
text: streamTextForIntervene,
|
|
1176
|
+
...(hookEvent === "Stop"
|
|
1177
|
+
? {
|
|
1178
|
+
last_assistant_message: deltaText,
|
|
1179
|
+
stop_hook_active: Boolean(payload.stop_hook_active),
|
|
1180
|
+
}
|
|
1181
|
+
: {}),
|
|
1150
1182
|
tool_name: toolName,
|
|
1151
1183
|
tool_input: effectiveToolIn,
|
|
1152
1184
|
tool_response: payload.tool_response || payload.toolResponse || null,
|
|
@@ -1179,22 +1211,26 @@ async function runAmbientHookMode(opts) {
|
|
|
1179
1211
|
}
|
|
1180
1212
|
if (resp.should_intervene) {
|
|
1181
1213
|
telem.amnesia_episodes_intercepted = (telem.amnesia_episodes_intercepted || 0) + 1;
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1214
|
+
const triggeredIds = [
|
|
1215
|
+
...(Array.isArray(resp.violated_memory_ids) ? resp.violated_memory_ids : []),
|
|
1216
|
+
...(resp.violated_memory_id ? [resp.violated_memory_id] : []),
|
|
1217
|
+
...(resp.triggered_memory_id ? [resp.triggered_memory_id] : []),
|
|
1218
|
+
].filter(Boolean);
|
|
1219
|
+
if (whisperKey && triggeredIds.length > 0) {
|
|
1220
|
+
const prev = Array.isArray(dedupState.whispered_by_session[whisperKey])
|
|
1221
|
+
? dedupState.whispered_by_session[whisperKey]
|
|
1185
1222
|
: [];
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
}
|
|
1223
|
+
const merged = Array.from(new Set([...prev, ...triggeredIds]));
|
|
1224
|
+
dedupState.whispered_by_session[whisperKey] = merged.slice(-16);
|
|
1189
1225
|
}
|
|
1190
|
-
if (
|
|
1226
|
+
if (whisperKey && resp.intervention_message) {
|
|
1191
1227
|
const msgTags = String(resp.intervention_message).match(/<memory>[\s\S]*?<\/memory>/gi);
|
|
1192
1228
|
if (msgTags) {
|
|
1193
|
-
const prevBlocks = Array.isArray(dedupState.whispered_blocks_by_session[
|
|
1194
|
-
? dedupState.whispered_blocks_by_session[
|
|
1229
|
+
const prevBlocks = Array.isArray(dedupState.whispered_blocks_by_session[whisperKey])
|
|
1230
|
+
? dedupState.whispered_blocks_by_session[whisperKey]
|
|
1195
1231
|
: [];
|
|
1196
1232
|
const nextBlocks = Array.from(new Set([...prevBlocks, ...msgTags.map((t) => t.trim())]));
|
|
1197
|
-
dedupState.whispered_blocks_by_session[
|
|
1233
|
+
dedupState.whispered_blocks_by_session[whisperKey] = nextBlocks.slice(-8);
|
|
1198
1234
|
}
|
|
1199
1235
|
}
|
|
1200
1236
|
}
|
|
@@ -1215,7 +1251,7 @@ async function runAmbientHookMode(opts) {
|
|
|
1215
1251
|
saveHookTelemetry(telem);
|
|
1216
1252
|
|
|
1217
1253
|
let out = {};
|
|
1218
|
-
if (
|
|
1254
|
+
if (isGeminiHook) {
|
|
1219
1255
|
if (rawEventName === "PreInvocation") {
|
|
1220
1256
|
if (resp && resp.should_intervene && resp.intervention_message) {
|
|
1221
1257
|
out = {
|
|
@@ -1261,7 +1297,7 @@ async function runAmbientHookMode(opts) {
|
|
|
1261
1297
|
process.stdout.write(JSON.stringify(out) + "\n");
|
|
1262
1298
|
} catch {
|
|
1263
1299
|
// Fail-open on network errors so the IDE is never blocked
|
|
1264
|
-
writeDefaultHookOutput(
|
|
1300
|
+
writeDefaultHookOutput(isGeminiHook, rawEventName);
|
|
1265
1301
|
}
|
|
1266
1302
|
}
|
|
1267
1303
|
|
|
@@ -1294,7 +1330,7 @@ const STANDARD_TOOLS = [
|
|
|
1294
1330
|
{
|
|
1295
1331
|
name: "add_memory",
|
|
1296
1332
|
description:
|
|
1297
|
-
"Explicitly store a memory in `/ ml` Cloud ONLY when the user directly asks you to call `add_memory`. Do NOT call `add_memory` proactively on normal user prompts, rules, or preferences
|
|
1333
|
+
"Explicitly store a memory in `/ ml` Cloud ONLY when the user directly asks you to call `add_memory`. Do NOT call `add_memory` proactively on normal user prompts, rules, or preferences -- ambient lifecycle hooks automatically assimilate user rules, constraints, and state mutations in the background.",
|
|
1298
1334
|
inputSchema: {
|
|
1299
1335
|
type: "object",
|
|
1300
1336
|
properties: {
|
|
@@ -1625,15 +1661,24 @@ async function dispatchTool(opts, name, args = {}) {
|
|
|
1625
1661
|
}
|
|
1626
1662
|
if (name === "search_memories") {
|
|
1627
1663
|
const k = Number(args.limit || args.top_k || 5);
|
|
1664
|
+
const mergedFilters = {
|
|
1665
|
+
...(args.filters && typeof args.filters === "object" ? args.filters : {}),
|
|
1666
|
+
...(args.include_code !== undefined ? { include_code: Boolean(args.include_code) } : {}),
|
|
1667
|
+
...(args.kind ? { kind: String(args.kind) } : {}),
|
|
1668
|
+
};
|
|
1628
1669
|
return apiRequest(opts, "POST", "/v1/memories/search", {
|
|
1629
1670
|
query: args.query,
|
|
1630
1671
|
user_id: uid,
|
|
1631
1672
|
limit: k,
|
|
1632
1673
|
top_k: k,
|
|
1674
|
+
...(Object.keys(mergedFilters).length > 0 ? { filters: mergedFilters } : {}),
|
|
1633
1675
|
});
|
|
1634
1676
|
}
|
|
1635
1677
|
if (name === "get_memories") {
|
|
1636
|
-
const
|
|
1678
|
+
const paramsObj = { user_id: uid, limit: String(args.limit || 50) };
|
|
1679
|
+
if (args.include_code !== undefined) paramsObj.include_code = String(Boolean(args.include_code));
|
|
1680
|
+
if (args.kind) paramsObj.kind = String(args.kind);
|
|
1681
|
+
const q = new URLSearchParams(paramsObj);
|
|
1637
1682
|
return apiRequest(opts, "GET", `/v1/memories?${q.toString()}`);
|
|
1638
1683
|
}
|
|
1639
1684
|
if (name === "forget_memory") {
|
package/dist/index.d.ts
CHANGED
|
@@ -65,6 +65,12 @@ export interface InterveneOptions {
|
|
|
65
65
|
hookEventName?: string;
|
|
66
66
|
prompt?: string;
|
|
67
67
|
text?: string;
|
|
68
|
+
last_assistant_message?: string | null;
|
|
69
|
+
lastAssistantMessage?: string | null;
|
|
70
|
+
stop_hook_active?: boolean;
|
|
71
|
+
stopHookActive?: boolean;
|
|
72
|
+
whispered_memory_ids?: string[] | null;
|
|
73
|
+
whisperedMemoryIds?: string[] | null;
|
|
68
74
|
tool_name?: string | null;
|
|
69
75
|
toolName?: string | null;
|
|
70
76
|
tool_input?: Record<string, unknown> | null;
|
package/dist/index.js
CHANGED
|
@@ -182,7 +182,7 @@ class MemoryClient {
|
|
|
182
182
|
const headers = {
|
|
183
183
|
Accept: "application/json",
|
|
184
184
|
"Content-Type": "application/json",
|
|
185
|
-
"User-Agent": "slashml-memory-ts/1.0.
|
|
185
|
+
"User-Agent": "slashml-memory-ts/1.0.7",
|
|
186
186
|
};
|
|
187
187
|
if (this.apiKey) {
|
|
188
188
|
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
@@ -279,11 +279,20 @@ class MemoryClient {
|
|
|
279
279
|
const resolvedModel = opts.model ?? this.model;
|
|
280
280
|
const resolvedProjectId = opts.project_id ?? opts.projectId ?? this.projectId ?? null;
|
|
281
281
|
const resolvedSessionId = opts.session_id ?? opts.sessionId ?? null;
|
|
282
|
+
const lastAssistantMsg =
|
|
283
|
+
opts.last_assistant_message ?? opts.lastAssistantMessage ?? undefined;
|
|
284
|
+
const stopHookActive =
|
|
285
|
+
opts.stop_hook_active ?? opts.stopHookActive ?? undefined;
|
|
286
|
+
const whisperedIds =
|
|
287
|
+
opts.whispered_memory_ids ?? opts.whisperedMemoryIds ?? undefined;
|
|
282
288
|
return this.request("POST", "/v1/memory/intervene", {
|
|
283
289
|
jsonBody: {
|
|
284
290
|
hook_event_name: opts.hook_event_name ?? opts.hookEventName ?? "UserPromptSubmit",
|
|
285
291
|
prompt: opts.prompt ?? resolvedText,
|
|
286
292
|
text: resolvedText,
|
|
293
|
+
...(lastAssistantMsg !== undefined ? { last_assistant_message: lastAssistantMsg } : {}),
|
|
294
|
+
...(stopHookActive !== undefined ? { stop_hook_active: Boolean(stopHookActive) } : {}),
|
|
295
|
+
...(whisperedIds && whisperedIds.length > 0 ? { whispered_memory_ids: whisperedIds } : {}),
|
|
287
296
|
tool_name: opts.tool_name ?? opts.toolName ?? null,
|
|
288
297
|
tool_input: opts.tool_input ?? opts.toolInput ?? null,
|
|
289
298
|
tool_response: opts.tool_response ?? opts.toolResponse ?? null,
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @slashml/memory
|
|
2
|
+
* @slashml/memory -- Official TypeScript / Node.js SDK for the / ml Memory API (ESM)
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
export const DEFAULT_BASE_URL = "https://api.slashml.ai";
|
|
@@ -184,7 +184,7 @@ export class MemoryClient {
|
|
|
184
184
|
const headers = {
|
|
185
185
|
Accept: "application/json",
|
|
186
186
|
"Content-Type": "application/json",
|
|
187
|
-
"User-Agent": "slashml-memory-ts/1.0.
|
|
187
|
+
"User-Agent": "slashml-memory-ts/1.0.7",
|
|
188
188
|
};
|
|
189
189
|
if (this.apiKey) {
|
|
190
190
|
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
@@ -281,11 +281,20 @@ export class MemoryClient {
|
|
|
281
281
|
const resolvedModel = opts.model ?? this.model;
|
|
282
282
|
const resolvedProjectId = opts.project_id ?? opts.projectId ?? this.projectId ?? null;
|
|
283
283
|
const resolvedSessionId = opts.session_id ?? opts.sessionId ?? null;
|
|
284
|
+
const lastAssistantMsg =
|
|
285
|
+
opts.last_assistant_message ?? opts.lastAssistantMessage ?? undefined;
|
|
286
|
+
const stopHookActive =
|
|
287
|
+
opts.stop_hook_active ?? opts.stopHookActive ?? undefined;
|
|
288
|
+
const whisperedIds =
|
|
289
|
+
opts.whispered_memory_ids ?? opts.whisperedMemoryIds ?? undefined;
|
|
284
290
|
return this.request("POST", "/v1/memory/intervene", {
|
|
285
291
|
jsonBody: {
|
|
286
292
|
hook_event_name: opts.hook_event_name ?? opts.hookEventName ?? "UserPromptSubmit",
|
|
287
293
|
prompt: opts.prompt ?? resolvedText,
|
|
288
294
|
text: resolvedText,
|
|
295
|
+
...(lastAssistantMsg !== undefined ? { last_assistant_message: lastAssistantMsg } : {}),
|
|
296
|
+
...(stopHookActive !== undefined ? { stop_hook_active: Boolean(stopHookActive) } : {}),
|
|
297
|
+
...(whisperedIds && whisperedIds.length > 0 ? { whispered_memory_ids: whisperedIds } : {}),
|
|
289
298
|
tool_name: opts.tool_name ?? opts.toolName ?? null,
|
|
290
299
|
tool_input: opts.tool_input ?? opts.toolInput ?? null,
|
|
291
300
|
tool_response: opts.tool_response ?? opts.toolResponse ?? null,
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @slashml/memory
|
|
2
|
+
* @slashml/memory -- Official TypeScript / Node.js SDK for the / ml Memory API
|
|
3
3
|
*
|
|
4
4
|
* 100% drop-in replacement for `mem0ai` (`MemoryClient`, `AsyncMemoryClient`, `Memory`, `AsyncMemory`).
|
|
5
5
|
* Zero external runtime dependencies (uses native Node.js 18+ / Web `fetch`).
|
|
@@ -72,6 +72,12 @@ export interface InterveneOptions {
|
|
|
72
72
|
hookEventName?: string;
|
|
73
73
|
prompt?: string;
|
|
74
74
|
text?: string;
|
|
75
|
+
last_assistant_message?: string | null;
|
|
76
|
+
lastAssistantMessage?: string | null;
|
|
77
|
+
stop_hook_active?: boolean;
|
|
78
|
+
stopHookActive?: boolean;
|
|
79
|
+
whispered_memory_ids?: string[] | null;
|
|
80
|
+
whisperedMemoryIds?: string[] | null;
|
|
75
81
|
tool_name?: string | null;
|
|
76
82
|
toolName?: string | null;
|
|
77
83
|
tool_input?: Record<string, unknown> | null;
|
|
@@ -324,7 +330,7 @@ export class MemoryClient {
|
|
|
324
330
|
const headers: Record<string, string> = {
|
|
325
331
|
Accept: "application/json",
|
|
326
332
|
"Content-Type": "application/json",
|
|
327
|
-
"User-Agent": "slashml-memory-ts/1.0.
|
|
333
|
+
"User-Agent": "slashml-memory-ts/1.0.7",
|
|
328
334
|
};
|
|
329
335
|
if (this.apiKey) {
|
|
330
336
|
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
@@ -437,11 +443,20 @@ export class MemoryClient {
|
|
|
437
443
|
const resolvedModel = opts.model ?? this.model;
|
|
438
444
|
const resolvedProjectId = opts.project_id ?? opts.projectId ?? this.projectId ?? null;
|
|
439
445
|
const resolvedSessionId = opts.session_id ?? opts.sessionId ?? null;
|
|
446
|
+
const lastAssistantMsg =
|
|
447
|
+
opts.last_assistant_message ?? opts.lastAssistantMessage ?? undefined;
|
|
448
|
+
const stopHookActive =
|
|
449
|
+
opts.stop_hook_active ?? opts.stopHookActive ?? undefined;
|
|
450
|
+
const whisperedIds =
|
|
451
|
+
opts.whispered_memory_ids ?? opts.whisperedMemoryIds ?? undefined;
|
|
440
452
|
return this.request("POST", "/v1/memory/intervene", {
|
|
441
453
|
jsonBody: {
|
|
442
454
|
hook_event_name: opts.hook_event_name ?? opts.hookEventName ?? "UserPromptSubmit",
|
|
443
455
|
prompt: opts.prompt ?? resolvedText,
|
|
444
456
|
text: resolvedText,
|
|
457
|
+
...(lastAssistantMsg !== undefined ? { last_assistant_message: lastAssistantMsg } : {}),
|
|
458
|
+
...(stopHookActive !== undefined ? { stop_hook_active: Boolean(stopHookActive) } : {}),
|
|
459
|
+
...(whisperedIds && whisperedIds.length > 0 ? { whispered_memory_ids: whisperedIds } : {}),
|
|
445
460
|
tool_name: opts.tool_name ?? opts.toolName ?? null,
|
|
446
461
|
tool_input: opts.tool_input ?? opts.toolInput ?? null,
|
|
447
462
|
tool_response: opts.tool_response ?? opts.toolResponse ?? null,
|