@agentmemory/agentmemory 0.8.0 → 0.8.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/README.md +573 -702
- package/dist/cli.mjs +419 -95
- package/dist/cli.mjs.map +1 -1
- package/dist/docker-compose.yml +5 -5
- package/dist/iii-config.docker.yaml +51 -0
- package/dist/iii-config.yaml +2 -2
- package/dist/index.mjs +408 -184
- package/dist/index.mjs.map +1 -1
- package/dist/{src-qOdKVNQz.mjs → src-BuDB8dPq.mjs} +410 -1328
- package/dist/src-BuDB8dPq.mjs.map +1 -0
- package/dist/standalone-CxAvUMQk.mjs +267 -0
- package/dist/standalone-CxAvUMQk.mjs.map +1 -0
- package/dist/standalone.d.mts +22 -1
- package/dist/standalone.d.mts.map +1 -0
- package/dist/standalone.mjs +94 -61
- package/dist/standalone.mjs.map +1 -1
- package/dist/tools-registry-B9EXJvIf.mjs +1089 -0
- package/dist/tools-registry-B9EXJvIf.mjs.map +1 -0
- package/dist/viewer/index.html +2970 -0
- package/docker-compose.yml +5 -5
- package/iii-config.yaml +2 -2
- package/package.json +11 -4
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/dist/src-qOdKVNQz.mjs.map +0 -1
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { a as jaccardSimilarity, i as generateId, n as STREAM, r as fingerprintId, t as KV } from "./cli.mjs";
|
|
2
|
+
import { a as getEnvVar, c as isGraphExtractionEnabled, d as loadEmbeddingConfig, f as loadFallbackConfig, i as getConsolidationDecayDays, l as loadClaudeBridgeConfig, m as loadTeamConfig, n as VERSION, p as loadSnapshotConfig, r as detectEmbeddingProvider, s as isConsolidationEnabled, t as getVisibleTools, u as loadConfig } from "./tools-registry-B9EXJvIf.mjs";
|
|
1
3
|
import { execFile } from "node:child_process";
|
|
2
4
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { dirname, join, resolve } from "node:path";
|
|
5
|
+
import { dirname, join, resolve, sep } from "node:path";
|
|
4
6
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { getContext, init } from "iii-sdk";
|
|
6
7
|
import { homedir } from "node:os";
|
|
7
|
-
import Anthropic from "@anthropic-ai/sdk";
|
|
8
8
|
import { createHash, createHmac, randomBytes, timingSafeEqual } from "node:crypto";
|
|
9
|
+
import { getContext, init } from "iii-sdk";
|
|
10
|
+
import Anthropic from "@anthropic-ai/sdk";
|
|
9
11
|
import { z } from "zod";
|
|
10
12
|
import { promisify } from "node:util";
|
|
11
13
|
import { lookup } from "node:dns/promises";
|
|
@@ -13,163 +15,6 @@ import { isIP } from "node:net";
|
|
|
13
15
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
14
16
|
import { createServer } from "node:http";
|
|
15
17
|
|
|
16
|
-
//#region src/config.ts
|
|
17
|
-
function safeParseInt(value, fallback) {
|
|
18
|
-
if (!value) return fallback;
|
|
19
|
-
const parsed = parseInt(value, 10);
|
|
20
|
-
return Number.isNaN(parsed) ? fallback : parsed;
|
|
21
|
-
}
|
|
22
|
-
const DATA_DIR = join(homedir(), ".agentmemory");
|
|
23
|
-
const ENV_FILE = join(DATA_DIR, ".env");
|
|
24
|
-
function loadEnvFile() {
|
|
25
|
-
if (!existsSync(ENV_FILE)) return {};
|
|
26
|
-
const content = readFileSync(ENV_FILE, "utf-8");
|
|
27
|
-
const vars = {};
|
|
28
|
-
for (const line of content.split("\n")) {
|
|
29
|
-
const trimmed = line.trim();
|
|
30
|
-
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
31
|
-
const eqIdx = trimmed.indexOf("=");
|
|
32
|
-
if (eqIdx === -1) continue;
|
|
33
|
-
const key = trimmed.slice(0, eqIdx).trim();
|
|
34
|
-
let val = trimmed.slice(eqIdx + 1).trim();
|
|
35
|
-
if (val.startsWith("\"") && val.endsWith("\"") || val.startsWith("'") && val.endsWith("'")) val = val.slice(1, -1);
|
|
36
|
-
vars[key] = val;
|
|
37
|
-
}
|
|
38
|
-
return vars;
|
|
39
|
-
}
|
|
40
|
-
function detectProvider(env) {
|
|
41
|
-
const maxTokens = parseInt(env["MAX_TOKENS"] || "4096", 10);
|
|
42
|
-
if (env["MINIMAX_API_KEY"]) return {
|
|
43
|
-
provider: "minimax",
|
|
44
|
-
model: env["MINIMAX_MODEL"] || "MiniMax-M2.7",
|
|
45
|
-
maxTokens
|
|
46
|
-
};
|
|
47
|
-
if (env["ANTHROPIC_API_KEY"]) return {
|
|
48
|
-
provider: "anthropic",
|
|
49
|
-
model: env["ANTHROPIC_MODEL"] || "claude-sonnet-4-20250514",
|
|
50
|
-
maxTokens,
|
|
51
|
-
baseURL: env["ANTHROPIC_BASE_URL"]
|
|
52
|
-
};
|
|
53
|
-
if (env["GEMINI_API_KEY"]) return {
|
|
54
|
-
provider: "gemini",
|
|
55
|
-
model: env["GEMINI_MODEL"] || "gemini-2.0-flash",
|
|
56
|
-
maxTokens
|
|
57
|
-
};
|
|
58
|
-
if (env["OPENROUTER_API_KEY"]) return {
|
|
59
|
-
provider: "openrouter",
|
|
60
|
-
model: env["OPENROUTER_MODEL"] || "anthropic/claude-sonnet-4-20250514",
|
|
61
|
-
maxTokens
|
|
62
|
-
};
|
|
63
|
-
return {
|
|
64
|
-
provider: "agent-sdk",
|
|
65
|
-
model: "claude-sonnet-4-20250514",
|
|
66
|
-
maxTokens: 4096
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
function loadConfig() {
|
|
70
|
-
const env = getMergedEnv();
|
|
71
|
-
const provider = detectProvider(env);
|
|
72
|
-
return {
|
|
73
|
-
engineUrl: env["III_ENGINE_URL"] || "ws://localhost:49134",
|
|
74
|
-
restPort: parseInt(env["III_REST_PORT"] || "3111", 10) || 3111,
|
|
75
|
-
streamsPort: parseInt(env["III_STREAMS_PORT"] || "3112", 10) || 3112,
|
|
76
|
-
provider,
|
|
77
|
-
tokenBudget: safeParseInt(env["TOKEN_BUDGET"], 2e3),
|
|
78
|
-
maxObservationsPerSession: safeParseInt(env["MAX_OBS_PER_SESSION"], 500),
|
|
79
|
-
compressionModel: provider.model,
|
|
80
|
-
dataDir: DATA_DIR
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
function getMergedEnv(overrides) {
|
|
84
|
-
return {
|
|
85
|
-
...loadEnvFile(),
|
|
86
|
-
...process.env,
|
|
87
|
-
...overrides
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
function getEnvVar(key) {
|
|
91
|
-
return getMergedEnv()[key];
|
|
92
|
-
}
|
|
93
|
-
function loadEmbeddingConfig() {
|
|
94
|
-
const env = getMergedEnv();
|
|
95
|
-
let bm25Weight = parseFloat(env["BM25_WEIGHT"] || "0.4");
|
|
96
|
-
let vectorWeight = parseFloat(env["VECTOR_WEIGHT"] || "0.6");
|
|
97
|
-
bm25Weight = isNaN(bm25Weight) || bm25Weight < 0 ? .4 : Math.min(bm25Weight, 1);
|
|
98
|
-
vectorWeight = isNaN(vectorWeight) || vectorWeight < 0 ? .6 : Math.min(vectorWeight, 1);
|
|
99
|
-
return {
|
|
100
|
-
provider: env["EMBEDDING_PROVIDER"] || void 0,
|
|
101
|
-
bm25Weight,
|
|
102
|
-
vectorWeight
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
function detectEmbeddingProvider(env) {
|
|
106
|
-
const source = env ?? getMergedEnv();
|
|
107
|
-
const forced = source["EMBEDDING_PROVIDER"];
|
|
108
|
-
if (forced) return forced;
|
|
109
|
-
if (source["GEMINI_API_KEY"]) return "gemini";
|
|
110
|
-
if (source["OPENAI_API_KEY"]) return "openai";
|
|
111
|
-
if (source["VOYAGE_API_KEY"]) return "voyage";
|
|
112
|
-
if (source["COHERE_API_KEY"]) return "cohere";
|
|
113
|
-
if (source["OPENROUTER_API_KEY"]) return "openrouter";
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
function loadClaudeBridgeConfig() {
|
|
117
|
-
const env = getMergedEnv();
|
|
118
|
-
const enabled = env["CLAUDE_MEMORY_BRIDGE"] === "true";
|
|
119
|
-
const projectPath = env["CLAUDE_PROJECT_PATH"] || "";
|
|
120
|
-
const lineBudget = safeParseInt(env["CLAUDE_MEMORY_LINE_BUDGET"], 200);
|
|
121
|
-
let memoryFilePath = "";
|
|
122
|
-
if (enabled && projectPath) {
|
|
123
|
-
const safePath = projectPath.replace(/[/\\]/g, "-").replace(/^-/, "");
|
|
124
|
-
memoryFilePath = join(homedir(), ".claude", "projects", safePath, "memory", "MEMORY.md");
|
|
125
|
-
}
|
|
126
|
-
return {
|
|
127
|
-
enabled,
|
|
128
|
-
projectPath,
|
|
129
|
-
memoryFilePath,
|
|
130
|
-
lineBudget
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
function loadTeamConfig() {
|
|
134
|
-
const env = getMergedEnv();
|
|
135
|
-
const teamId = env["TEAM_ID"];
|
|
136
|
-
const userId = env["USER_ID"];
|
|
137
|
-
if (!teamId || !userId) return null;
|
|
138
|
-
return {
|
|
139
|
-
teamId,
|
|
140
|
-
userId,
|
|
141
|
-
mode: env["TEAM_MODE"] === "shared" ? "shared" : "private"
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
function loadSnapshotConfig() {
|
|
145
|
-
const env = getMergedEnv();
|
|
146
|
-
return {
|
|
147
|
-
enabled: env["SNAPSHOT_ENABLED"] === "true",
|
|
148
|
-
interval: safeParseInt(env["SNAPSHOT_INTERVAL"], 3600),
|
|
149
|
-
dir: env["SNAPSHOT_DIR"] || join(homedir(), ".agentmemory", "snapshots")
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
function isGraphExtractionEnabled() {
|
|
153
|
-
return getMergedEnv()["GRAPH_EXTRACTION_ENABLED"] === "true";
|
|
154
|
-
}
|
|
155
|
-
function isConsolidationEnabled() {
|
|
156
|
-
return getMergedEnv()["CONSOLIDATION_ENABLED"] === "true";
|
|
157
|
-
}
|
|
158
|
-
function getConsolidationDecayDays() {
|
|
159
|
-
return safeParseInt(getMergedEnv()["CONSOLIDATION_DECAY_DAYS"], 30);
|
|
160
|
-
}
|
|
161
|
-
const VALID_PROVIDERS = new Set([
|
|
162
|
-
"anthropic",
|
|
163
|
-
"gemini",
|
|
164
|
-
"openrouter",
|
|
165
|
-
"agent-sdk",
|
|
166
|
-
"minimax"
|
|
167
|
-
]);
|
|
168
|
-
function loadFallbackConfig() {
|
|
169
|
-
return { providers: (getMergedEnv()["FALLBACK_PROVIDERS"] || "").split(",").map((p) => p.trim()).filter((p) => Boolean(p) && VALID_PROVIDERS.has(p)) };
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
//#endregion
|
|
173
18
|
//#region src/providers/agent-sdk.ts
|
|
174
19
|
var AgentSDKProvider = class {
|
|
175
20
|
name = "agent-sdk";
|
|
@@ -861,69 +706,6 @@ var VectorIndex = class VectorIndex {
|
|
|
861
706
|
}
|
|
862
707
|
};
|
|
863
708
|
|
|
864
|
-
//#endregion
|
|
865
|
-
//#region src/state/schema.ts
|
|
866
|
-
const KV = {
|
|
867
|
-
sessions: "mem:sessions",
|
|
868
|
-
observations: (sessionId) => `mem:obs:${sessionId}`,
|
|
869
|
-
memories: "mem:memories",
|
|
870
|
-
summaries: "mem:summaries",
|
|
871
|
-
config: "mem:config",
|
|
872
|
-
metrics: "mem:metrics",
|
|
873
|
-
health: "mem:health",
|
|
874
|
-
embeddings: (obsId) => `mem:emb:${obsId}`,
|
|
875
|
-
bm25Index: "mem:index:bm25",
|
|
876
|
-
relations: "mem:relations",
|
|
877
|
-
profiles: "mem:profiles",
|
|
878
|
-
claudeBridge: "mem:claude-bridge",
|
|
879
|
-
graphNodes: "mem:graph:nodes",
|
|
880
|
-
graphEdges: "mem:graph:edges",
|
|
881
|
-
semantic: "mem:semantic",
|
|
882
|
-
procedural: "mem:procedural",
|
|
883
|
-
teamShared: (teamId) => `mem:team:${teamId}:shared`,
|
|
884
|
-
teamUsers: (teamId, userId) => `mem:team:${teamId}:users:${userId}`,
|
|
885
|
-
teamProfile: (teamId) => `mem:team:${teamId}:profile`,
|
|
886
|
-
audit: "mem:audit",
|
|
887
|
-
actions: "mem:actions",
|
|
888
|
-
actionEdges: "mem:action-edges",
|
|
889
|
-
leases: "mem:leases",
|
|
890
|
-
routines: "mem:routines",
|
|
891
|
-
routineRuns: "mem:routine-runs",
|
|
892
|
-
signals: "mem:signals",
|
|
893
|
-
checkpoints: "mem:checkpoints",
|
|
894
|
-
mesh: "mem:mesh",
|
|
895
|
-
sketches: "mem:sketches",
|
|
896
|
-
facets: "mem:facets",
|
|
897
|
-
sentinels: "mem:sentinels",
|
|
898
|
-
crystals: "mem:crystals",
|
|
899
|
-
lessons: "mem:lessons",
|
|
900
|
-
insights: "mem:insights",
|
|
901
|
-
graphEdgeHistory: "mem:graph:edge-history",
|
|
902
|
-
enrichedChunks: (sessionId) => `mem:enriched:${sessionId}`,
|
|
903
|
-
latentEmbeddings: (obsId) => `mem:latent:${obsId}`,
|
|
904
|
-
retentionScores: "mem:retention"
|
|
905
|
-
};
|
|
906
|
-
const STREAM = {
|
|
907
|
-
name: "mem-live",
|
|
908
|
-
group: (sessionId) => sessionId,
|
|
909
|
-
viewerGroup: "viewer"
|
|
910
|
-
};
|
|
911
|
-
function generateId(prefix) {
|
|
912
|
-
return `${prefix}_${Date.now().toString(36)}_${crypto.randomUUID().replace(/-/g, "").slice(0, 12)}`;
|
|
913
|
-
}
|
|
914
|
-
function fingerprintId(prefix, content) {
|
|
915
|
-
return `${prefix}_${createHash("sha256").update(content).digest("hex").slice(0, 16)}`;
|
|
916
|
-
}
|
|
917
|
-
function jaccardSimilarity(a, b) {
|
|
918
|
-
const setA = new Set(a.split(/\s+/).filter((t) => t.length > 2));
|
|
919
|
-
const setB = new Set(b.split(/\s+/).filter((t) => t.length > 2));
|
|
920
|
-
if (setA.size === 0 && setB.size === 0) return 1;
|
|
921
|
-
if (setA.size === 0 || setB.size === 0) return 0;
|
|
922
|
-
let intersection = 0;
|
|
923
|
-
for (const word of setA) if (setB.has(word)) intersection++;
|
|
924
|
-
return intersection / (setA.size + setB.size - intersection);
|
|
925
|
-
}
|
|
926
|
-
|
|
927
709
|
//#endregion
|
|
928
710
|
//#region src/functions/graph-retrieval.ts
|
|
929
711
|
function buildGraphContext(path) {
|
|
@@ -1950,9 +1732,11 @@ var IndexPersistence = class {
|
|
|
1950
1732
|
const PRIVATE_TAG_RE = /<private>[\s\S]*?<\/private>/gi;
|
|
1951
1733
|
const SECRET_PATTERN_SOURCES = [
|
|
1952
1734
|
/(?:api[_-]?key|secret|token|password|credential|auth)[\s]*[=:]\s*["']?[A-Za-z0-9_\-/.+]{20,}["']?/gi,
|
|
1953
|
-
/
|
|
1735
|
+
/Bearer\s+[A-Za-z0-9._\-+/=]{20,}/gi,
|
|
1736
|
+
/sk-proj-[A-Za-z0-9\-_]{20,}/g,
|
|
1737
|
+
/(?:sk|pk|rk|ak)-[A-Za-z0-9][A-Za-z0-9\-_]{19,}/g,
|
|
1954
1738
|
/sk-ant-[A-Za-z0-9\-_]{20,}/g,
|
|
1955
|
-
/
|
|
1739
|
+
/gh[pus]_[A-Za-z0-9]{36,}/g,
|
|
1956
1740
|
/github_pat_[A-Za-z0-9_]{22,}/g,
|
|
1957
1741
|
/xoxb-[A-Za-z0-9\-]+/g,
|
|
1958
1742
|
/AKIA[0-9A-Z]{16}/g,
|
|
@@ -2153,6 +1937,77 @@ function getXmlChildren(xml, parentTag, childTag) {
|
|
|
2153
1937
|
return items;
|
|
2154
1938
|
}
|
|
2155
1939
|
|
|
1940
|
+
//#endregion
|
|
1941
|
+
//#region src/functions/access-tracker.ts
|
|
1942
|
+
const RECENT_CAP = 20;
|
|
1943
|
+
function emptyAccessLog(memoryId) {
|
|
1944
|
+
return {
|
|
1945
|
+
memoryId,
|
|
1946
|
+
count: 0,
|
|
1947
|
+
lastAt: "",
|
|
1948
|
+
recent: []
|
|
1949
|
+
};
|
|
1950
|
+
}
|
|
1951
|
+
function normalizeAccessLog(raw) {
|
|
1952
|
+
const r = raw ?? {};
|
|
1953
|
+
const rawCount = typeof r.count === "number" && Number.isFinite(r.count) ? r.count : 0;
|
|
1954
|
+
const count = Math.max(0, Math.floor(rawCount));
|
|
1955
|
+
const rawRecent = Array.isArray(r.recent) ? r.recent.filter((x) => typeof x === "number" && Number.isFinite(x)) : [];
|
|
1956
|
+
const recent = rawRecent.length > RECENT_CAP ? rawRecent.slice(-RECENT_CAP) : rawRecent;
|
|
1957
|
+
return {
|
|
1958
|
+
memoryId: typeof r.memoryId === "string" ? r.memoryId : "",
|
|
1959
|
+
count: Math.max(count, recent.length),
|
|
1960
|
+
lastAt: typeof r.lastAt === "string" ? r.lastAt : "",
|
|
1961
|
+
recent
|
|
1962
|
+
};
|
|
1963
|
+
}
|
|
1964
|
+
async function getAccessLog(kv, memoryId) {
|
|
1965
|
+
try {
|
|
1966
|
+
const raw = await kv.get(KV.accessLog, memoryId);
|
|
1967
|
+
if (!raw) return emptyAccessLog(memoryId);
|
|
1968
|
+
const normalized = normalizeAccessLog(raw);
|
|
1969
|
+
if (!normalized.memoryId) normalized.memoryId = memoryId;
|
|
1970
|
+
return normalized;
|
|
1971
|
+
} catch {
|
|
1972
|
+
return emptyAccessLog(memoryId);
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
async function recordAccess(kv, memoryId, timestampMs) {
|
|
1976
|
+
if (!memoryId) return;
|
|
1977
|
+
const ts = timestampMs ?? Date.now();
|
|
1978
|
+
try {
|
|
1979
|
+
await withKeyedLock(`mem:access:${memoryId}`, async () => {
|
|
1980
|
+
const existing = await getAccessLog(kv, memoryId);
|
|
1981
|
+
existing.count += 1;
|
|
1982
|
+
existing.lastAt = new Date(ts).toISOString();
|
|
1983
|
+
existing.recent.push(ts);
|
|
1984
|
+
if (existing.recent.length > RECENT_CAP) existing.recent = existing.recent.slice(-RECENT_CAP);
|
|
1985
|
+
await kv.set(KV.accessLog, memoryId, existing);
|
|
1986
|
+
});
|
|
1987
|
+
} catch (err) {
|
|
1988
|
+
try {
|
|
1989
|
+
getContext().logger.warn("recordAccess failed", {
|
|
1990
|
+
memoryId,
|
|
1991
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1992
|
+
});
|
|
1993
|
+
} catch {}
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
async function recordAccessBatch(kv, memoryIds, timestampMs) {
|
|
1997
|
+
if (!memoryIds || memoryIds.length === 0) return;
|
|
1998
|
+
const ts = timestampMs ?? Date.now();
|
|
1999
|
+
const unique = Array.from(new Set(memoryIds.filter(Boolean)));
|
|
2000
|
+
await Promise.allSettled(unique.map((id) => recordAccess(kv, id, ts)));
|
|
2001
|
+
}
|
|
2002
|
+
async function deleteAccessLog(kv, memoryId) {
|
|
2003
|
+
if (!memoryId) return;
|
|
2004
|
+
try {
|
|
2005
|
+
await withKeyedLock(`mem:access:${memoryId}`, async () => {
|
|
2006
|
+
await kv.delete(KV.accessLog, memoryId);
|
|
2007
|
+
});
|
|
2008
|
+
} catch {}
|
|
2009
|
+
}
|
|
2010
|
+
|
|
2156
2011
|
//#endregion
|
|
2157
2012
|
//#region src/functions/search.ts
|
|
2158
2013
|
let index = null;
|
|
@@ -2239,6 +2094,7 @@ function registerSearchFunction(sdk, kv) {
|
|
|
2239
2094
|
sessionId: candidates[i].sessionId
|
|
2240
2095
|
});
|
|
2241
2096
|
}
|
|
2097
|
+
recordAccessBatch(kv, enriched.map((r) => r.observation.id));
|
|
2242
2098
|
ctx.logger.info("Search completed", {
|
|
2243
2099
|
query,
|
|
2244
2100
|
results: enriched.length,
|
|
@@ -2634,19 +2490,22 @@ function registerContextFunction(sdk, kv, tokenBudget) {
|
|
|
2634
2490
|
const i = sessionsNeedingObs[j];
|
|
2635
2491
|
const important = obsResults[j].filter((o) => o.title && o.importance >= 5);
|
|
2636
2492
|
if (important.length > 0) {
|
|
2637
|
-
const
|
|
2493
|
+
const top = important.sort((a, b) => b.importance - a.importance).slice(0, 5);
|
|
2494
|
+
const items = top.map((o) => `- [${o.type}] ${o.title}: ${o.narrative}`).join("\n");
|
|
2638
2495
|
const content = `## Session ${sessions[i].id.slice(0, 8)} (${sessions[i].startedAt})\n${items}`;
|
|
2639
2496
|
blocks.push({
|
|
2640
2497
|
type: "observation",
|
|
2641
2498
|
content,
|
|
2642
2499
|
tokens: estimateTokens$1(content),
|
|
2643
|
-
recency: new Date(sessions[i].startedAt).getTime()
|
|
2500
|
+
recency: new Date(sessions[i].startedAt).getTime(),
|
|
2501
|
+
sourceIds: top.map((o) => o.id)
|
|
2644
2502
|
});
|
|
2645
2503
|
}
|
|
2646
2504
|
}
|
|
2647
2505
|
blocks.sort((a, b) => b.recency - a.recency);
|
|
2648
2506
|
let usedTokens = 0;
|
|
2649
2507
|
const selected = [];
|
|
2508
|
+
const accessedIds = [];
|
|
2650
2509
|
const header = `<agentmemory-context project="${escapeXmlAttr(data.project)}">`;
|
|
2651
2510
|
const footer = `</agentmemory-context>`;
|
|
2652
2511
|
usedTokens += estimateTokens$1(header) + estimateTokens$1(footer);
|
|
@@ -2654,7 +2513,9 @@ function registerContextFunction(sdk, kv, tokenBudget) {
|
|
|
2654
2513
|
if (usedTokens + block.tokens > budget) break;
|
|
2655
2514
|
selected.push(block.content);
|
|
2656
2515
|
usedTokens += block.tokens;
|
|
2516
|
+
if (block.sourceIds && block.sourceIds.length > 0) accessedIds.push(...block.sourceIds);
|
|
2657
2517
|
}
|
|
2518
|
+
if (accessedIds.length > 0) recordAccessBatch(kv, accessedIds);
|
|
2658
2519
|
if (selected.length === 0) {
|
|
2659
2520
|
ctx.logger.info("No context available", { project: data.project });
|
|
2660
2521
|
return {
|
|
@@ -2987,6 +2848,9 @@ function registerFileIndexFunction(sdk, kv) {
|
|
|
2987
2848
|
for (const obs of fh.observations) lines.push(`- [${obs.type}] ${obs.title}: ${obs.narrative}`);
|
|
2988
2849
|
}
|
|
2989
2850
|
lines.push("</agentmemory-file-context>");
|
|
2851
|
+
const accessedIds = [];
|
|
2852
|
+
for (const fh of results) for (const obs of fh.observations) accessedIds.push(obs.obsId);
|
|
2853
|
+
recordAccessBatch(kv, accessedIds);
|
|
2990
2854
|
const context = lines.join("\n");
|
|
2991
2855
|
ctx.logger.info("File context generated", {
|
|
2992
2856
|
files: data.files.length,
|
|
@@ -3299,6 +3163,7 @@ function registerRememberFunction(sdk, kv) {
|
|
|
3299
3163
|
let deleted = 0;
|
|
3300
3164
|
if (data.memoryId) {
|
|
3301
3165
|
await kv.delete(KV.memories, data.memoryId);
|
|
3166
|
+
await deleteAccessLog(kv, data.memoryId);
|
|
3302
3167
|
deleted++;
|
|
3303
3168
|
}
|
|
3304
3169
|
if (data.sessionId && data.observationIds && data.observationIds.length > 0) for (const obsId of data.observationIds) {
|
|
@@ -3390,13 +3255,19 @@ function registerEvictFunction(sdk, kv) {
|
|
|
3390
3255
|
if (now > new Date(mem.forgetAfter).getTime()) {
|
|
3391
3256
|
stats.expiredMemories++;
|
|
3392
3257
|
evictedMemIds.add(mem.id);
|
|
3393
|
-
if (!dryRun)
|
|
3258
|
+
if (!dryRun) {
|
|
3259
|
+
await kv.delete(KV.memories, mem.id).catch(() => {});
|
|
3260
|
+
await deleteAccessLog(kv, mem.id);
|
|
3261
|
+
}
|
|
3394
3262
|
}
|
|
3395
3263
|
}
|
|
3396
3264
|
if (!evictedMemIds.has(mem.id) && mem.isLatest === false && mem.createdAt) {
|
|
3397
3265
|
if (now - new Date(mem.createdAt).getTime() > cfg.lowImportanceMaxDays * MS_PER_DAY$1) {
|
|
3398
3266
|
stats.nonLatestMemories++;
|
|
3399
|
-
if (!dryRun)
|
|
3267
|
+
if (!dryRun) {
|
|
3268
|
+
await kv.delete(KV.memories, mem.id).catch(() => {});
|
|
3269
|
+
await deleteAccessLog(kv, mem.id);
|
|
3270
|
+
}
|
|
3400
3271
|
}
|
|
3401
3272
|
}
|
|
3402
3273
|
}
|
|
@@ -3561,6 +3432,7 @@ function registerRelationsFunction(sdk, kv) {
|
|
|
3561
3432
|
});
|
|
3562
3433
|
}
|
|
3563
3434
|
result.sort((a, b) => b.confidence - a.confidence);
|
|
3435
|
+
recordAccessBatch(kv, result.map((r) => r.memory.id));
|
|
3564
3436
|
ctx.logger.info("Related memories retrieved", {
|
|
3565
3437
|
memoryId: data.memoryId,
|
|
3566
3438
|
found: result.length
|
|
@@ -3632,6 +3504,7 @@ function registerTimelineFunction(sdk, kv) {
|
|
|
3632
3504
|
relativePosition: i - anchorIdx
|
|
3633
3505
|
});
|
|
3634
3506
|
}
|
|
3507
|
+
recordAccessBatch(kv, entries.map((e) => e.observation.id));
|
|
3635
3508
|
ctx.logger.info("Timeline retrieved", {
|
|
3636
3509
|
anchor: data.anchor,
|
|
3637
3510
|
entries: entries.length
|
|
@@ -3682,6 +3555,7 @@ function registerSmartSearchFunction(sdk, kv, searchFn) {
|
|
|
3682
3555
|
observation: obs
|
|
3683
3556
|
} : null)));
|
|
3684
3557
|
for (const r of results) if (r) expanded.push(r);
|
|
3558
|
+
recordAccessBatch(kv, expanded.map((e) => e.observation.id));
|
|
3685
3559
|
const truncated = data.expandIds.length > raw.length;
|
|
3686
3560
|
ctx.logger.info("Smart search expanded", {
|
|
3687
3561
|
requested: data.expandIds.length,
|
|
@@ -3709,6 +3583,7 @@ function registerSmartSearchFunction(sdk, kv, searchFn) {
|
|
|
3709
3583
|
score: r.combinedScore,
|
|
3710
3584
|
timestamp: r.observation.timestamp
|
|
3711
3585
|
}));
|
|
3586
|
+
recordAccessBatch(kv, compact.map((r) => r.obsId));
|
|
3712
3587
|
ctx.logger.info("Smart search compact", {
|
|
3713
3588
|
query: data.query,
|
|
3714
3589
|
results: compact.length
|
|
@@ -3840,7 +3715,10 @@ function registerAutoForgetFunction(sdk, kv) {
|
|
|
3840
3715
|
if (now > new Date(mem.forgetAfter).getTime()) {
|
|
3841
3716
|
result.ttlExpired.push(mem.id);
|
|
3842
3717
|
deletedIds.add(mem.id);
|
|
3843
|
-
if (!dryRun)
|
|
3718
|
+
if (!dryRun) {
|
|
3719
|
+
await kv.delete(KV.memories, mem.id);
|
|
3720
|
+
await deleteAccessLog(kv, mem.id);
|
|
3721
|
+
}
|
|
3844
3722
|
}
|
|
3845
3723
|
}
|
|
3846
3724
|
const latestMemories = memories.filter((m) => m.isLatest !== false && !deletedIds.has(m.id)).sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()).slice(0, 1e3);
|
|
@@ -3907,10 +3785,6 @@ function registerAutoForgetFunction(sdk, kv) {
|
|
|
3907
3785
|
});
|
|
3908
3786
|
}
|
|
3909
3787
|
|
|
3910
|
-
//#endregion
|
|
3911
|
-
//#region src/version.ts
|
|
3912
|
-
const VERSION = "0.8.0";
|
|
3913
|
-
|
|
3914
3788
|
//#endregion
|
|
3915
3789
|
//#region src/functions/export-import.ts
|
|
3916
3790
|
function registerExportImportFunction(sdk, kv) {
|
|
@@ -3937,7 +3811,7 @@ function registerExportImportFunction(sdk, kv) {
|
|
|
3937
3811
|
const uniqueProjects = [...new Set(paginatedSessions.map((s) => s.project))];
|
|
3938
3812
|
const profileResults = await Promise.all(uniqueProjects.map((project) => kv.get(KV.profiles, project).catch(() => null)));
|
|
3939
3813
|
for (const profile of profileResults) if (profile) profiles.push(profile);
|
|
3940
|
-
const [graphNodes, graphEdges, semanticMemories, proceduralMemories, actions, actionEdges, sentinels, sketches, crystals, facets, lessons, insights, routines, signals, checkpoints] = await Promise.all([
|
|
3814
|
+
const [graphNodes, graphEdges, semanticMemories, proceduralMemories, actions, actionEdges, sentinels, sketches, crystals, facets, lessons, insights, routines, signals, checkpoints, accessLogs] = await Promise.all([
|
|
3941
3815
|
kv.list(KV.graphNodes).catch(() => []),
|
|
3942
3816
|
kv.list(KV.graphEdges).catch(() => []),
|
|
3943
3817
|
kv.list(KV.semantic).catch(() => []),
|
|
@@ -3952,7 +3826,8 @@ function registerExportImportFunction(sdk, kv) {
|
|
|
3952
3826
|
kv.list(KV.insights).catch(() => []),
|
|
3953
3827
|
kv.list(KV.routines).catch(() => []),
|
|
3954
3828
|
kv.list(KV.signals).catch(() => []),
|
|
3955
|
-
kv.list(KV.checkpoints).catch(() => [])
|
|
3829
|
+
kv.list(KV.checkpoints).catch(() => []),
|
|
3830
|
+
kv.list(KV.accessLog).catch(() => [])
|
|
3956
3831
|
]);
|
|
3957
3832
|
const exportData = {
|
|
3958
3833
|
version: VERSION,
|
|
@@ -3976,7 +3851,8 @@ function registerExportImportFunction(sdk, kv) {
|
|
|
3976
3851
|
insights: insights.length > 0 ? insights : void 0,
|
|
3977
3852
|
routines: routines.length > 0 ? routines : void 0,
|
|
3978
3853
|
signals: signals.length > 0 ? signals : void 0,
|
|
3979
|
-
checkpoints: checkpoints.length > 0 ? checkpoints : void 0
|
|
3854
|
+
checkpoints: checkpoints.length > 0 ? checkpoints : void 0,
|
|
3855
|
+
accessLogs: accessLogs.length > 0 ? accessLogs : void 0
|
|
3980
3856
|
};
|
|
3981
3857
|
if (maxSessions !== void 0) exportData.pagination = {
|
|
3982
3858
|
offset,
|
|
@@ -4015,7 +3891,12 @@ function registerExportImportFunction(sdk, kv) {
|
|
|
4015
3891
|
"0.7.6",
|
|
4016
3892
|
"0.7.7",
|
|
4017
3893
|
"0.7.9",
|
|
4018
|
-
"0.8.0"
|
|
3894
|
+
"0.8.0",
|
|
3895
|
+
"0.8.1",
|
|
3896
|
+
"0.8.2",
|
|
3897
|
+
"0.8.3",
|
|
3898
|
+
"0.8.4",
|
|
3899
|
+
"0.8.5"
|
|
4019
3900
|
]).has(importData.version)) return {
|
|
4020
3901
|
success: false,
|
|
4021
3902
|
error: `Unsupported export version: ${importData.version}`
|
|
@@ -4025,6 +3906,7 @@ function registerExportImportFunction(sdk, kv) {
|
|
|
4025
3906
|
const MAX_SUMMARIES = 1e4;
|
|
4026
3907
|
const MAX_OBS_PER_SESSION = 5e3;
|
|
4027
3908
|
const MAX_TOTAL_OBSERVATIONS = 5e5;
|
|
3909
|
+
const MAX_ACCESS_LOGS = 5e4;
|
|
4028
3910
|
if (!Array.isArray(importData.sessions)) return {
|
|
4029
3911
|
success: false,
|
|
4030
3912
|
error: "sessions must be an array"
|
|
@@ -4107,6 +3989,7 @@ function registerExportImportFunction(sdk, kv) {
|
|
|
4107
3989
|
for (const e of await kv.list(KV.graphEdges).catch(() => [])) await kv.delete(KV.graphEdges, e.id);
|
|
4108
3990
|
for (const s of await kv.list(KV.semantic).catch(() => [])) await kv.delete(KV.semantic, s.id);
|
|
4109
3991
|
for (const p of await kv.list(KV.procedural).catch(() => [])) await kv.delete(KV.procedural, p.id);
|
|
3992
|
+
for (const a of await kv.list(KV.accessLog).catch(() => [])) await kv.delete(KV.accessLog, a.memoryId);
|
|
4110
3993
|
}
|
|
4111
3994
|
for (const session of importData.sessions) {
|
|
4112
3995
|
if (strategy === "skip") {
|
|
@@ -4283,6 +4166,28 @@ function registerExportImportFunction(sdk, kv) {
|
|
|
4283
4166
|
}
|
|
4284
4167
|
await kv.set(KV.insights, insight.id, insight);
|
|
4285
4168
|
}
|
|
4169
|
+
if (importData.accessLogs) {
|
|
4170
|
+
if (!Array.isArray(importData.accessLogs)) return {
|
|
4171
|
+
success: false,
|
|
4172
|
+
error: "accessLogs must be an array"
|
|
4173
|
+
};
|
|
4174
|
+
if (importData.accessLogs.length > MAX_ACCESS_LOGS) return {
|
|
4175
|
+
success: false,
|
|
4176
|
+
error: `Too many access logs (max ${MAX_ACCESS_LOGS})`
|
|
4177
|
+
};
|
|
4178
|
+
const memoryIds = new Set(importData.memories.map((m) => m.id));
|
|
4179
|
+
for (const raw of importData.accessLogs) {
|
|
4180
|
+
const log = normalizeAccessLog(raw);
|
|
4181
|
+
if (!log.memoryId || !memoryIds.has(log.memoryId)) continue;
|
|
4182
|
+
if (strategy === "skip") {
|
|
4183
|
+
if (await kv.get(KV.accessLog, log.memoryId).catch(() => null)) {
|
|
4184
|
+
stats.skipped++;
|
|
4185
|
+
continue;
|
|
4186
|
+
}
|
|
4187
|
+
}
|
|
4188
|
+
await kv.set(KV.accessLog, log.memoryId, log);
|
|
4189
|
+
}
|
|
4190
|
+
}
|
|
4286
4191
|
ctx.logger.info("Import complete", {
|
|
4287
4192
|
strategy,
|
|
4288
4193
|
...stats
|
|
@@ -5051,6 +4956,7 @@ function registerGovernanceFunction(sdk, kv) {
|
|
|
5051
4956
|
let deleted = 0;
|
|
5052
4957
|
for (const id of data.memoryIds) if (await kv.get(KV.memories, id)) {
|
|
5053
4958
|
await kv.delete(KV.memories, id);
|
|
4959
|
+
await deleteAccessLog(kv, id);
|
|
5054
4960
|
deleted++;
|
|
5055
4961
|
}
|
|
5056
4962
|
await recordAudit(kv, "delete", "mem::governance-delete", data.memoryIds, {
|
|
@@ -5098,7 +5004,10 @@ function registerGovernanceFunction(sdk, kv) {
|
|
|
5098
5004
|
wouldDelete: candidates.length,
|
|
5099
5005
|
ids: candidates.map((m) => m.id)
|
|
5100
5006
|
};
|
|
5101
|
-
for (const mem of candidates)
|
|
5007
|
+
for (const mem of candidates) {
|
|
5008
|
+
await kv.delete(KV.memories, mem.id);
|
|
5009
|
+
await deleteAccessLog(kv, mem.id);
|
|
5010
|
+
}
|
|
5102
5011
|
await recordAudit(kv, "delete", "mem::governance-bulk", candidates.map((m) => m.id), {
|
|
5103
5012
|
filter: data,
|
|
5104
5013
|
deleted: candidates.length
|
|
@@ -5146,6 +5055,7 @@ function registerSnapshotFunction(sdk, kv, snapshotDir) {
|
|
|
5146
5055
|
const sessions = await kv.list(KV.sessions);
|
|
5147
5056
|
const memories = await kv.list(KV.memories);
|
|
5148
5057
|
const graphNodes = await kv.list(KV.graphNodes);
|
|
5058
|
+
const accessLogs = await kv.list(KV.accessLog).catch(() => []);
|
|
5149
5059
|
const observations = {};
|
|
5150
5060
|
for (const session of sessions) {
|
|
5151
5061
|
const obs = await kv.list(KV.observations(session.id)).catch(() => []);
|
|
@@ -5157,7 +5067,8 @@ function registerSnapshotFunction(sdk, kv, snapshotDir) {
|
|
|
5157
5067
|
sessions,
|
|
5158
5068
|
memories,
|
|
5159
5069
|
graphNodes,
|
|
5160
|
-
observations
|
|
5070
|
+
observations,
|
|
5071
|
+
accessLogs
|
|
5161
5072
|
};
|
|
5162
5073
|
writeFileSync(join(snapshotDir, "state.json"), JSON.stringify(state, null, 2), "utf-8");
|
|
5163
5074
|
await gitExec(snapshotDir, ["add", "."]);
|
|
@@ -5249,6 +5160,7 @@ function registerSnapshotFunction(sdk, kv, snapshotDir) {
|
|
|
5249
5160
|
if (state.memories) for (const memory of state.memories) await kv.set(KV.memories, memory.id, memory);
|
|
5250
5161
|
if (state.graphNodes) for (const node of state.graphNodes) await kv.set(KV.graphNodes, node.id, node);
|
|
5251
5162
|
if (state.observations) for (const [sessionId, obs] of Object.entries(state.observations)) for (const o of obs) await kv.set(KV.observations(sessionId), o.id, o);
|
|
5163
|
+
if (state.accessLogs) for (const log of state.accessLogs) await kv.set(KV.accessLog, log.memoryId, log);
|
|
5252
5164
|
await gitExec(snapshotDir, [
|
|
5253
5165
|
"checkout",
|
|
5254
5166
|
"HEAD",
|
|
@@ -6416,7 +6328,7 @@ async function lwwMergeGraphNodes(kv, items) {
|
|
|
6416
6328
|
}
|
|
6417
6329
|
return count;
|
|
6418
6330
|
}
|
|
6419
|
-
function registerMeshFunction(sdk, kv) {
|
|
6331
|
+
function registerMeshFunction(sdk, kv, meshAuthToken) {
|
|
6420
6332
|
sdk.registerFunction({ id: "mem::mesh-register" }, async (data) => {
|
|
6421
6333
|
if (!data.url || !data.name) return {
|
|
6422
6334
|
success: false,
|
|
@@ -6453,6 +6365,10 @@ function registerMeshFunction(sdk, kv) {
|
|
|
6453
6365
|
};
|
|
6454
6366
|
});
|
|
6455
6367
|
sdk.registerFunction({ id: "mem::mesh-sync" }, async (data) => {
|
|
6368
|
+
if (!meshAuthToken) return {
|
|
6369
|
+
success: false,
|
|
6370
|
+
error: "mesh sync requires AGENTMEMORY_SECRET"
|
|
6371
|
+
};
|
|
6456
6372
|
const direction = data.direction || "both";
|
|
6457
6373
|
let peers;
|
|
6458
6374
|
if (data.peerId) {
|
|
@@ -6488,7 +6404,10 @@ function registerMeshFunction(sdk, kv) {
|
|
|
6488
6404
|
try {
|
|
6489
6405
|
const response = await fetch(`${peer.url}/agentmemory/mesh/receive`, {
|
|
6490
6406
|
method: "POST",
|
|
6491
|
-
headers: {
|
|
6407
|
+
headers: {
|
|
6408
|
+
"Content-Type": "application/json",
|
|
6409
|
+
Authorization: `Bearer ${meshAuthToken}`
|
|
6410
|
+
},
|
|
6492
6411
|
body: JSON.stringify(pushData),
|
|
6493
6412
|
signal: AbortSignal.timeout(3e4),
|
|
6494
6413
|
redirect: "error"
|
|
@@ -6501,6 +6420,7 @@ function registerMeshFunction(sdk, kv) {
|
|
|
6501
6420
|
}
|
|
6502
6421
|
if (direction === "pull" || direction === "both") try {
|
|
6503
6422
|
const response = await fetch(`${peer.url}/agentmemory/mesh/export?since=${peer.lastSyncAt || ""}`, {
|
|
6423
|
+
headers: { Authorization: `Bearer ${meshAuthToken}` },
|
|
6504
6424
|
signal: AbortSignal.timeout(3e4),
|
|
6505
6425
|
redirect: "error"
|
|
6506
6426
|
});
|
|
@@ -8361,7 +8281,16 @@ function registerLessonsFunctions(sdk, kv) {
|
|
|
8361
8281
|
|
|
8362
8282
|
//#endregion
|
|
8363
8283
|
//#region src/functions/obsidian-export.ts
|
|
8364
|
-
const
|
|
8284
|
+
const DEFAULT_EXPORT_ROOT = join(homedir(), ".agentmemory");
|
|
8285
|
+
function getExportRoot() {
|
|
8286
|
+
return resolve(process.env["AGENTMEMORY_EXPORT_ROOT"] || DEFAULT_EXPORT_ROOT);
|
|
8287
|
+
}
|
|
8288
|
+
function resolveVaultDir(vaultDir) {
|
|
8289
|
+
const root = getExportRoot();
|
|
8290
|
+
const resolved = resolve(vaultDir || join(root, "vault"));
|
|
8291
|
+
if (resolved === root || resolved.startsWith(root + sep)) return resolved;
|
|
8292
|
+
return null;
|
|
8293
|
+
}
|
|
8365
8294
|
function sanitize(name) {
|
|
8366
8295
|
return name.replace(/[<>:"/\\|?*\x00-\x1f]/g, "_").slice(0, 100);
|
|
8367
8296
|
}
|
|
@@ -8474,7 +8403,11 @@ function sessionToMd(s) {
|
|
|
8474
8403
|
}
|
|
8475
8404
|
function registerObsidianExportFunction(sdk, kv) {
|
|
8476
8405
|
sdk.registerFunction({ id: "mem::obsidian-export" }, async (data) => {
|
|
8477
|
-
const vaultDir = data.vaultDir
|
|
8406
|
+
const vaultDir = resolveVaultDir(data.vaultDir);
|
|
8407
|
+
if (!vaultDir) return {
|
|
8408
|
+
success: false,
|
|
8409
|
+
error: `vaultDir must be inside ${getExportRoot()}`
|
|
8410
|
+
};
|
|
8478
8411
|
const exportTypes = new Set(data.types || [
|
|
8479
8412
|
"memories",
|
|
8480
8413
|
"lessons",
|
|
@@ -9020,12 +8953,15 @@ function registerWorkingMemoryFunctions(sdk, kv, tokenBudget) {
|
|
|
9020
8953
|
if (Math.abs(strengthDiff) > .2) return strengthDiff;
|
|
9021
8954
|
return new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime();
|
|
9022
8955
|
});
|
|
8956
|
+
const archivalIds = [];
|
|
9023
8957
|
for (const mem of active) {
|
|
9024
8958
|
const tokens = estimateTokens(mem.content);
|
|
9025
8959
|
if (usedTokens + tokens > budget) continue;
|
|
9026
8960
|
archivalLines.push(`- [${mem.type}] ${mem.title}: ${mem.content}`);
|
|
8961
|
+
archivalIds.push(mem.id);
|
|
9027
8962
|
usedTokens += tokens;
|
|
9028
8963
|
}
|
|
8964
|
+
recordAccessBatch(kv, archivalIds);
|
|
9029
8965
|
const pagedOut = active.length - archivalLines.length;
|
|
9030
8966
|
const sections = [];
|
|
9031
8967
|
if (coreLines.length > 0) sections.push(`## Core Memory\n${coreLines.join("\n")}`);
|
|
@@ -9779,17 +9715,15 @@ const DEFAULT_DECAY = {
|
|
|
9779
9715
|
cold: .15
|
|
9780
9716
|
}
|
|
9781
9717
|
};
|
|
9782
|
-
function
|
|
9718
|
+
function computeReinforcementBoost(accessTimestamps, sigma) {
|
|
9783
9719
|
const now = Date.now();
|
|
9784
|
-
|
|
9785
|
-
const temporalDecay = Math.exp(-config.lambda * deltaT);
|
|
9786
|
-
let reinforcementBoost = 0;
|
|
9720
|
+
let boost = 0;
|
|
9787
9721
|
for (const tAccess of accessTimestamps) {
|
|
9722
|
+
if (!Number.isFinite(tAccess)) continue;
|
|
9788
9723
|
const daysSinceAccess = (now - tAccess) / (1e3 * 60 * 60 * 24);
|
|
9789
|
-
if (daysSinceAccess > 0)
|
|
9724
|
+
if (daysSinceAccess > 0) boost += 1 / daysSinceAccess;
|
|
9790
9725
|
}
|
|
9791
|
-
|
|
9792
|
-
return Math.min(1, salience * temporalDecay + reinforcementBoost);
|
|
9726
|
+
return boost * sigma;
|
|
9793
9727
|
}
|
|
9794
9728
|
function computeSalience(memory, accessCount) {
|
|
9795
9729
|
let baseSalience = .5;
|
|
@@ -9815,37 +9749,64 @@ function registerRetentionFunctions(sdk, kv) {
|
|
|
9815
9749
|
...DEFAULT_DECAY,
|
|
9816
9750
|
...data.config
|
|
9817
9751
|
};
|
|
9818
|
-
const memories = await
|
|
9819
|
-
|
|
9752
|
+
const [memories, semanticMems, allLogs] = await Promise.all([
|
|
9753
|
+
kv.list(KV.memories),
|
|
9754
|
+
kv.list(KV.semantic),
|
|
9755
|
+
kv.list(KV.accessLog).catch(() => [])
|
|
9756
|
+
]);
|
|
9757
|
+
const logsById = /* @__PURE__ */ new Map();
|
|
9758
|
+
for (const raw of allLogs) {
|
|
9759
|
+
const log = normalizeAccessLog(raw);
|
|
9760
|
+
if (log.memoryId) logsById.set(log.memoryId, log);
|
|
9761
|
+
}
|
|
9820
9762
|
const scores = [];
|
|
9763
|
+
const computeDecay = (createdAt) => Math.exp(-config.lambda * ((Date.now() - new Date(createdAt).getTime()) / (1e3 * 60 * 60 * 24)));
|
|
9821
9764
|
for (const mem of memories) {
|
|
9822
9765
|
if (!mem.isLatest) continue;
|
|
9823
|
-
const
|
|
9824
|
-
const
|
|
9766
|
+
const log = logsById.get(mem.id) ?? emptyAccessLog(mem.id);
|
|
9767
|
+
const salience = computeSalience(mem, log.count);
|
|
9768
|
+
const temporalDecay = computeDecay(mem.createdAt);
|
|
9769
|
+
const reinforcementBoost = computeReinforcementBoost(log.recent, config.sigma);
|
|
9770
|
+
const score = Math.min(1, salience * temporalDecay + reinforcementBoost);
|
|
9825
9771
|
const entry = {
|
|
9826
9772
|
memoryId: mem.id,
|
|
9827
9773
|
score,
|
|
9828
9774
|
salience,
|
|
9829
|
-
temporalDecay
|
|
9830
|
-
reinforcementBoost
|
|
9831
|
-
lastAccessed: mem.updatedAt,
|
|
9832
|
-
accessCount:
|
|
9775
|
+
temporalDecay,
|
|
9776
|
+
reinforcementBoost,
|
|
9777
|
+
lastAccessed: log.lastAt || mem.updatedAt,
|
|
9778
|
+
accessCount: log.count
|
|
9833
9779
|
};
|
|
9834
9780
|
scores.push(entry);
|
|
9835
9781
|
await kv.set(KV.retentionScores, mem.id, entry);
|
|
9836
9782
|
}
|
|
9837
9783
|
for (const sem of semanticMems) {
|
|
9838
|
-
const
|
|
9839
|
-
|
|
9840
|
-
|
|
9784
|
+
const log = logsById.get(sem.id) ?? emptyAccessLog(sem.id);
|
|
9785
|
+
let accessTimestamps;
|
|
9786
|
+
let effectiveCount;
|
|
9787
|
+
if (log.recent.length > 0 || log.count > 0) {
|
|
9788
|
+
accessTimestamps = log.recent;
|
|
9789
|
+
effectiveCount = log.count;
|
|
9790
|
+
} else if (sem.lastAccessedAt) {
|
|
9791
|
+
const legacyTs = Date.parse(sem.lastAccessedAt);
|
|
9792
|
+
accessTimestamps = Number.isFinite(legacyTs) ? [legacyTs] : [];
|
|
9793
|
+
effectiveCount = sem.accessCount;
|
|
9794
|
+
} else {
|
|
9795
|
+
accessTimestamps = [];
|
|
9796
|
+
effectiveCount = sem.accessCount;
|
|
9797
|
+
}
|
|
9798
|
+
const salience = computeSalience(sem, effectiveCount);
|
|
9799
|
+
const temporalDecay = computeDecay(sem.createdAt);
|
|
9800
|
+
const reinforcementBoost = computeReinforcementBoost(accessTimestamps, config.sigma);
|
|
9801
|
+
const score = Math.min(1, salience * temporalDecay + reinforcementBoost);
|
|
9841
9802
|
const entry = {
|
|
9842
9803
|
memoryId: sem.id,
|
|
9843
9804
|
score,
|
|
9844
9805
|
salience,
|
|
9845
|
-
temporalDecay
|
|
9846
|
-
reinforcementBoost
|
|
9847
|
-
lastAccessed: sem.lastAccessedAt,
|
|
9848
|
-
accessCount:
|
|
9806
|
+
temporalDecay,
|
|
9807
|
+
reinforcementBoost,
|
|
9808
|
+
lastAccessed: log.lastAt || sem.lastAccessedAt,
|
|
9809
|
+
accessCount: effectiveCount
|
|
9849
9810
|
};
|
|
9850
9811
|
scores.push(entry);
|
|
9851
9812
|
await kv.set(KV.retentionScores, sem.id, entry);
|
|
@@ -9889,6 +9850,7 @@ function registerRetentionFunctions(sdk, kv) {
|
|
|
9889
9850
|
for (const candidate of candidates) try {
|
|
9890
9851
|
await kv.delete(KV.memories, candidate.memoryId);
|
|
9891
9852
|
await kv.delete(KV.retentionScores, candidate.memoryId);
|
|
9853
|
+
await deleteAccessLog(kv, candidate.memoryId);
|
|
9892
9854
|
evicted++;
|
|
9893
9855
|
} catch {
|
|
9894
9856
|
continue;
|
|
@@ -10044,14 +10006,57 @@ async function getLatestHealth(kv) {
|
|
|
10044
10006
|
//#endregion
|
|
10045
10007
|
//#region src/auth.ts
|
|
10046
10008
|
const hmacKey = randomBytes(32);
|
|
10009
|
+
const VIEWER_NONCE_PLACEHOLDER = "__AGENTMEMORY_VIEWER_NONCE__";
|
|
10047
10010
|
function timingSafeCompare(a, b) {
|
|
10048
10011
|
return timingSafeEqual(createHmac("sha256", hmacKey).update(a).digest(), createHmac("sha256", hmacKey).update(b).digest());
|
|
10049
10012
|
}
|
|
10050
|
-
|
|
10013
|
+
function createViewerNonce() {
|
|
10014
|
+
return randomBytes(16).toString("base64url");
|
|
10015
|
+
}
|
|
10016
|
+
function buildViewerCsp(nonce) {
|
|
10017
|
+
return [
|
|
10018
|
+
"default-src 'none'",
|
|
10019
|
+
"base-uri 'none'",
|
|
10020
|
+
"frame-ancestors 'none'",
|
|
10021
|
+
"object-src 'none'",
|
|
10022
|
+
"form-action 'none'",
|
|
10023
|
+
`script-src 'nonce-${nonce}'`,
|
|
10024
|
+
"script-src-attr 'none'",
|
|
10025
|
+
"style-src 'unsafe-inline'",
|
|
10026
|
+
"connect-src 'self' http://localhost:* http://127.0.0.1:* ws://localhost:* ws://127.0.0.1:* wss://localhost:* wss://127.0.0.1:*",
|
|
10027
|
+
"img-src 'self'",
|
|
10028
|
+
"font-src 'self'"
|
|
10029
|
+
].join("; ");
|
|
10030
|
+
}
|
|
10031
|
+
|
|
10032
|
+
//#endregion
|
|
10033
|
+
//#region src/viewer/document.ts
|
|
10034
|
+
function loadViewerTemplate() {
|
|
10035
|
+
const base = dirname(fileURLToPath(import.meta.url));
|
|
10036
|
+
const candidates = [
|
|
10037
|
+
join(base, "..", "src", "viewer", "index.html"),
|
|
10038
|
+
join(base, "..", "viewer", "index.html"),
|
|
10039
|
+
join(base, "viewer", "index.html")
|
|
10040
|
+
];
|
|
10041
|
+
for (const path of candidates) try {
|
|
10042
|
+
return readFileSync(path, "utf-8");
|
|
10043
|
+
} catch {}
|
|
10044
|
+
return null;
|
|
10045
|
+
}
|
|
10046
|
+
function renderViewerDocument() {
|
|
10047
|
+
const template = loadViewerTemplate();
|
|
10048
|
+
if (!template) return { found: false };
|
|
10049
|
+
const nonce = createViewerNonce();
|
|
10050
|
+
return {
|
|
10051
|
+
found: true,
|
|
10052
|
+
html: template.replaceAll(VIEWER_NONCE_PLACEHOLDER, nonce),
|
|
10053
|
+
csp: buildViewerCsp(nonce)
|
|
10054
|
+
};
|
|
10055
|
+
}
|
|
10051
10056
|
|
|
10052
10057
|
//#endregion
|
|
10053
10058
|
//#region src/triggers/api.ts
|
|
10054
|
-
function checkAuth
|
|
10059
|
+
function checkAuth(req, secret) {
|
|
10055
10060
|
if (!secret) return null;
|
|
10056
10061
|
const auth = req.headers?.["authorization"] || req.headers?.["Authorization"];
|
|
10057
10062
|
if (typeof auth !== "string" || !timingSafeCompare(auth, `Bearer ${secret}`)) return {
|
|
@@ -10060,6 +10065,13 @@ function checkAuth$1(req, secret) {
|
|
|
10060
10065
|
};
|
|
10061
10066
|
return null;
|
|
10062
10067
|
}
|
|
10068
|
+
function requireConfiguredSecret(secret, feature) {
|
|
10069
|
+
if (secret) return null;
|
|
10070
|
+
return {
|
|
10071
|
+
status_code: 503,
|
|
10072
|
+
body: { error: `${feature} requires AGENTMEMORY_SECRET` }
|
|
10073
|
+
};
|
|
10074
|
+
}
|
|
10063
10075
|
function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
10064
10076
|
sdk.registerFunction({ id: "api::liveness" }, async () => ({
|
|
10065
10077
|
status_code: 200,
|
|
@@ -10077,7 +10089,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10077
10089
|
}
|
|
10078
10090
|
});
|
|
10079
10091
|
sdk.registerFunction({ id: "api::health" }, async (req) => {
|
|
10080
|
-
const authErr = checkAuth
|
|
10092
|
+
const authErr = checkAuth(req, secret);
|
|
10081
10093
|
if (authErr) return authErr;
|
|
10082
10094
|
const health = await getLatestHealth(kv);
|
|
10083
10095
|
const functionMetrics = metricsStore ? await metricsStore.getAll() : [];
|
|
@@ -10104,7 +10116,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10104
10116
|
}
|
|
10105
10117
|
});
|
|
10106
10118
|
sdk.registerFunction({ id: "api::observe" }, async (req) => {
|
|
10107
|
-
const authErr = checkAuth
|
|
10119
|
+
const authErr = checkAuth(req, secret);
|
|
10108
10120
|
if (authErr) return authErr;
|
|
10109
10121
|
return {
|
|
10110
10122
|
status_code: 201,
|
|
@@ -10120,7 +10132,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10120
10132
|
}
|
|
10121
10133
|
});
|
|
10122
10134
|
sdk.registerFunction({ id: "api::context" }, async (req) => {
|
|
10123
|
-
const authErr = checkAuth
|
|
10135
|
+
const authErr = checkAuth(req, secret);
|
|
10124
10136
|
if (authErr) return authErr;
|
|
10125
10137
|
return {
|
|
10126
10138
|
status_code: 200,
|
|
@@ -10136,7 +10148,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10136
10148
|
}
|
|
10137
10149
|
});
|
|
10138
10150
|
sdk.registerFunction({ id: "api::search" }, async (req) => {
|
|
10139
|
-
const authErr = checkAuth
|
|
10151
|
+
const authErr = checkAuth(req, secret);
|
|
10140
10152
|
if (authErr) return authErr;
|
|
10141
10153
|
const body = req.body ?? {};
|
|
10142
10154
|
if (typeof body.query !== "string" || !body.query.trim()) return {
|
|
@@ -10175,7 +10187,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10175
10187
|
}
|
|
10176
10188
|
});
|
|
10177
10189
|
sdk.registerFunction({ id: "api::session::start" }, async (req) => {
|
|
10178
|
-
const authErr = checkAuth
|
|
10190
|
+
const authErr = checkAuth(req, secret);
|
|
10179
10191
|
if (authErr) return authErr;
|
|
10180
10192
|
const { sessionId, project, cwd } = req.body;
|
|
10181
10193
|
const session = {
|
|
@@ -10207,7 +10219,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10207
10219
|
}
|
|
10208
10220
|
});
|
|
10209
10221
|
sdk.registerFunction({ id: "api::session::end" }, async (req) => {
|
|
10210
|
-
const authErr = checkAuth
|
|
10222
|
+
const authErr = checkAuth(req, secret);
|
|
10211
10223
|
if (authErr) return authErr;
|
|
10212
10224
|
const session = await kv.get(KV.sessions, req.body.sessionId);
|
|
10213
10225
|
if (session) await kv.set(KV.sessions, req.body.sessionId, {
|
|
@@ -10229,7 +10241,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10229
10241
|
}
|
|
10230
10242
|
});
|
|
10231
10243
|
sdk.registerFunction({ id: "api::summarize" }, async (req) => {
|
|
10232
|
-
const authErr = checkAuth
|
|
10244
|
+
const authErr = checkAuth(req, secret);
|
|
10233
10245
|
if (authErr) return authErr;
|
|
10234
10246
|
return {
|
|
10235
10247
|
status_code: 200,
|
|
@@ -10245,7 +10257,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10245
10257
|
}
|
|
10246
10258
|
});
|
|
10247
10259
|
sdk.registerFunction({ id: "api::sessions" }, async (req) => {
|
|
10248
|
-
const authErr = checkAuth
|
|
10260
|
+
const authErr = checkAuth(req, secret);
|
|
10249
10261
|
if (authErr) return authErr;
|
|
10250
10262
|
return {
|
|
10251
10263
|
status_code: 200,
|
|
@@ -10261,7 +10273,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10261
10273
|
}
|
|
10262
10274
|
});
|
|
10263
10275
|
sdk.registerFunction({ id: "api::observations" }, async (req) => {
|
|
10264
|
-
const authErr = checkAuth
|
|
10276
|
+
const authErr = checkAuth(req, secret);
|
|
10265
10277
|
if (authErr) return authErr;
|
|
10266
10278
|
const sessionId = req.query_params["sessionId"];
|
|
10267
10279
|
if (!sessionId) return {
|
|
@@ -10282,7 +10294,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10282
10294
|
}
|
|
10283
10295
|
});
|
|
10284
10296
|
sdk.registerFunction({ id: "api::file-context" }, async (req) => {
|
|
10285
|
-
const authErr = checkAuth
|
|
10297
|
+
const authErr = checkAuth(req, secret);
|
|
10286
10298
|
if (authErr) return authErr;
|
|
10287
10299
|
return {
|
|
10288
10300
|
status_code: 200,
|
|
@@ -10298,7 +10310,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10298
10310
|
}
|
|
10299
10311
|
});
|
|
10300
10312
|
sdk.registerFunction({ id: "api::enrich" }, async (req) => {
|
|
10301
|
-
const authErr = checkAuth
|
|
10313
|
+
const authErr = checkAuth(req, secret);
|
|
10302
10314
|
if (authErr) return authErr;
|
|
10303
10315
|
if (!req.body?.sessionId || typeof req.body.sessionId !== "string" || !Array.isArray(req.body?.files) || req.body.files.length === 0 || !req.body.files.every((f) => typeof f === "string")) return {
|
|
10304
10316
|
status_code: 400,
|
|
@@ -10322,7 +10334,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10322
10334
|
}
|
|
10323
10335
|
});
|
|
10324
10336
|
sdk.registerFunction({ id: "api::remember" }, async (req) => {
|
|
10325
|
-
const authErr = checkAuth
|
|
10337
|
+
const authErr = checkAuth(req, secret);
|
|
10326
10338
|
if (authErr) return authErr;
|
|
10327
10339
|
if (!req.body?.content || typeof req.body.content !== "string" || !req.body.content.trim()) return {
|
|
10328
10340
|
status_code: 400,
|
|
@@ -10342,7 +10354,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10342
10354
|
}
|
|
10343
10355
|
});
|
|
10344
10356
|
sdk.registerFunction({ id: "api::forget" }, async (req) => {
|
|
10345
|
-
const authErr = checkAuth
|
|
10357
|
+
const authErr = checkAuth(req, secret);
|
|
10346
10358
|
if (authErr) return authErr;
|
|
10347
10359
|
if (!req.body?.sessionId && !req.body?.memoryId) return {
|
|
10348
10360
|
status_code: 400,
|
|
@@ -10362,7 +10374,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10362
10374
|
}
|
|
10363
10375
|
});
|
|
10364
10376
|
sdk.registerFunction({ id: "api::consolidate" }, async (req) => {
|
|
10365
|
-
const authErr = checkAuth
|
|
10377
|
+
const authErr = checkAuth(req, secret);
|
|
10366
10378
|
if (authErr) return authErr;
|
|
10367
10379
|
return {
|
|
10368
10380
|
status_code: 200,
|
|
@@ -10378,7 +10390,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10378
10390
|
}
|
|
10379
10391
|
});
|
|
10380
10392
|
sdk.registerFunction({ id: "api::patterns" }, async (req) => {
|
|
10381
|
-
const authErr = checkAuth
|
|
10393
|
+
const authErr = checkAuth(req, secret);
|
|
10382
10394
|
if (authErr) return authErr;
|
|
10383
10395
|
return {
|
|
10384
10396
|
status_code: 200,
|
|
@@ -10394,7 +10406,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10394
10406
|
}
|
|
10395
10407
|
});
|
|
10396
10408
|
sdk.registerFunction({ id: "api::generate-rules" }, async (req) => {
|
|
10397
|
-
const authErr = checkAuth
|
|
10409
|
+
const authErr = checkAuth(req, secret);
|
|
10398
10410
|
if (authErr) return authErr;
|
|
10399
10411
|
return {
|
|
10400
10412
|
status_code: 200,
|
|
@@ -10410,7 +10422,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10410
10422
|
}
|
|
10411
10423
|
});
|
|
10412
10424
|
sdk.registerFunction({ id: "api::migrate" }, async (req) => {
|
|
10413
|
-
const authErr = checkAuth
|
|
10425
|
+
const authErr = checkAuth(req, secret);
|
|
10414
10426
|
if (authErr) return authErr;
|
|
10415
10427
|
if (!req.body?.dbPath || typeof req.body.dbPath !== "string") return {
|
|
10416
10428
|
status_code: 400,
|
|
@@ -10430,7 +10442,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10430
10442
|
}
|
|
10431
10443
|
});
|
|
10432
10444
|
sdk.registerFunction({ id: "api::evict" }, async (req) => {
|
|
10433
|
-
const authErr = checkAuth
|
|
10445
|
+
const authErr = checkAuth(req, secret);
|
|
10434
10446
|
if (authErr) return authErr;
|
|
10435
10447
|
const dryRun = req.query_params?.["dryRun"] === "true" || req.body?.dryRun === true;
|
|
10436
10448
|
return {
|
|
@@ -10447,7 +10459,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10447
10459
|
}
|
|
10448
10460
|
});
|
|
10449
10461
|
sdk.registerFunction({ id: "api::smart-search" }, async (req) => {
|
|
10450
|
-
const authErr = checkAuth
|
|
10462
|
+
const authErr = checkAuth(req, secret);
|
|
10451
10463
|
if (authErr) return authErr;
|
|
10452
10464
|
if (!req.body?.query && (!req.body?.expandIds || req.body.expandIds.length === 0)) return {
|
|
10453
10465
|
status_code: 400,
|
|
@@ -10467,7 +10479,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10467
10479
|
}
|
|
10468
10480
|
});
|
|
10469
10481
|
sdk.registerFunction({ id: "api::timeline" }, async (req) => {
|
|
10470
|
-
const authErr = checkAuth
|
|
10482
|
+
const authErr = checkAuth(req, secret);
|
|
10471
10483
|
if (authErr) return authErr;
|
|
10472
10484
|
if (!req.body?.anchor) return {
|
|
10473
10485
|
status_code: 400,
|
|
@@ -10487,7 +10499,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10487
10499
|
}
|
|
10488
10500
|
});
|
|
10489
10501
|
sdk.registerFunction({ id: "api::profile" }, async (req) => {
|
|
10490
|
-
const authErr = checkAuth
|
|
10502
|
+
const authErr = checkAuth(req, secret);
|
|
10491
10503
|
if (authErr) return authErr;
|
|
10492
10504
|
const project = req.query_params["project"];
|
|
10493
10505
|
if (!project) return {
|
|
@@ -10508,7 +10520,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10508
10520
|
}
|
|
10509
10521
|
});
|
|
10510
10522
|
sdk.registerFunction({ id: "api::export" }, async (req) => {
|
|
10511
|
-
const authErr = checkAuth
|
|
10523
|
+
const authErr = checkAuth(req, secret);
|
|
10512
10524
|
if (authErr) return authErr;
|
|
10513
10525
|
return {
|
|
10514
10526
|
status_code: 200,
|
|
@@ -10524,7 +10536,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10524
10536
|
}
|
|
10525
10537
|
});
|
|
10526
10538
|
sdk.registerFunction({ id: "api::import" }, async (req) => {
|
|
10527
|
-
const authErr = checkAuth
|
|
10539
|
+
const authErr = checkAuth(req, secret);
|
|
10528
10540
|
if (authErr) return authErr;
|
|
10529
10541
|
if (!req.body?.exportData) return {
|
|
10530
10542
|
status_code: 400,
|
|
@@ -10544,7 +10556,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10544
10556
|
}
|
|
10545
10557
|
});
|
|
10546
10558
|
sdk.registerFunction({ id: "api::relations" }, async (req) => {
|
|
10547
|
-
const authErr = checkAuth
|
|
10559
|
+
const authErr = checkAuth(req, secret);
|
|
10548
10560
|
if (authErr) return authErr;
|
|
10549
10561
|
if (!req.body?.sourceId || !req.body?.targetId || !req.body?.type) return {
|
|
10550
10562
|
status_code: 400,
|
|
@@ -10564,7 +10576,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10564
10576
|
}
|
|
10565
10577
|
});
|
|
10566
10578
|
sdk.registerFunction({ id: "api::evolve" }, async (req) => {
|
|
10567
|
-
const authErr = checkAuth
|
|
10579
|
+
const authErr = checkAuth(req, secret);
|
|
10568
10580
|
if (authErr) return authErr;
|
|
10569
10581
|
if (!req.body?.memoryId || !req.body?.newContent) return {
|
|
10570
10582
|
status_code: 400,
|
|
@@ -10584,7 +10596,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10584
10596
|
}
|
|
10585
10597
|
});
|
|
10586
10598
|
sdk.registerFunction({ id: "api::auto-forget" }, async (req) => {
|
|
10587
|
-
const authErr = checkAuth
|
|
10599
|
+
const authErr = checkAuth(req, secret);
|
|
10588
10600
|
if (authErr) return authErr;
|
|
10589
10601
|
const dryRun = req.query_params?.["dryRun"] === "true" || req.body?.dryRun === true;
|
|
10590
10602
|
return {
|
|
@@ -10601,7 +10613,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10601
10613
|
}
|
|
10602
10614
|
});
|
|
10603
10615
|
sdk.registerFunction({ id: "api::claude-bridge-read" }, async (req) => {
|
|
10604
|
-
const authErr = checkAuth
|
|
10616
|
+
const authErr = checkAuth(req, secret);
|
|
10605
10617
|
if (authErr) return authErr;
|
|
10606
10618
|
try {
|
|
10607
10619
|
return {
|
|
@@ -10624,7 +10636,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10624
10636
|
}
|
|
10625
10637
|
});
|
|
10626
10638
|
sdk.registerFunction({ id: "api::claude-bridge-sync" }, async (req) => {
|
|
10627
|
-
const authErr = checkAuth
|
|
10639
|
+
const authErr = checkAuth(req, secret);
|
|
10628
10640
|
if (authErr) return authErr;
|
|
10629
10641
|
try {
|
|
10630
10642
|
return {
|
|
@@ -10647,7 +10659,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10647
10659
|
}
|
|
10648
10660
|
});
|
|
10649
10661
|
sdk.registerFunction({ id: "api::graph-query" }, async (req) => {
|
|
10650
|
-
const authErr = checkAuth
|
|
10662
|
+
const authErr = checkAuth(req, secret);
|
|
10651
10663
|
if (authErr) return authErr;
|
|
10652
10664
|
try {
|
|
10653
10665
|
return {
|
|
@@ -10670,7 +10682,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10670
10682
|
}
|
|
10671
10683
|
});
|
|
10672
10684
|
sdk.registerFunction({ id: "api::graph-stats" }, async (req) => {
|
|
10673
|
-
const authErr = checkAuth
|
|
10685
|
+
const authErr = checkAuth(req, secret);
|
|
10674
10686
|
if (authErr) return authErr;
|
|
10675
10687
|
try {
|
|
10676
10688
|
return {
|
|
@@ -10693,7 +10705,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10693
10705
|
}
|
|
10694
10706
|
});
|
|
10695
10707
|
sdk.registerFunction({ id: "api::graph-extract" }, async (req) => {
|
|
10696
|
-
const authErr = checkAuth
|
|
10708
|
+
const authErr = checkAuth(req, secret);
|
|
10697
10709
|
if (authErr) return authErr;
|
|
10698
10710
|
if (!Array.isArray(req.body?.observations) || req.body.observations.length === 0) return {
|
|
10699
10711
|
status_code: 400,
|
|
@@ -10720,7 +10732,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10720
10732
|
}
|
|
10721
10733
|
});
|
|
10722
10734
|
sdk.registerFunction({ id: "api::consolidate-pipeline" }, async (req) => {
|
|
10723
|
-
const authErr = checkAuth
|
|
10735
|
+
const authErr = checkAuth(req, secret);
|
|
10724
10736
|
if (authErr) return authErr;
|
|
10725
10737
|
try {
|
|
10726
10738
|
return {
|
|
@@ -10743,7 +10755,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10743
10755
|
}
|
|
10744
10756
|
});
|
|
10745
10757
|
sdk.registerFunction({ id: "api::team-share" }, async (req) => {
|
|
10746
|
-
const authErr = checkAuth
|
|
10758
|
+
const authErr = checkAuth(req, secret);
|
|
10747
10759
|
if (authErr) return authErr;
|
|
10748
10760
|
if (!req.body?.itemId || !req.body?.itemType) return {
|
|
10749
10761
|
status_code: 400,
|
|
@@ -10770,7 +10782,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10770
10782
|
}
|
|
10771
10783
|
});
|
|
10772
10784
|
sdk.registerFunction({ id: "api::team-feed" }, async (req) => {
|
|
10773
|
-
const authErr = checkAuth
|
|
10785
|
+
const authErr = checkAuth(req, secret);
|
|
10774
10786
|
if (authErr) return authErr;
|
|
10775
10787
|
try {
|
|
10776
10788
|
const limit = parseInt(req.query_params?.["limit"]) || 20;
|
|
@@ -10794,7 +10806,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10794
10806
|
}
|
|
10795
10807
|
});
|
|
10796
10808
|
sdk.registerFunction({ id: "api::team-profile" }, async (req) => {
|
|
10797
|
-
const authErr = checkAuth
|
|
10809
|
+
const authErr = checkAuth(req, secret);
|
|
10798
10810
|
if (authErr) return authErr;
|
|
10799
10811
|
try {
|
|
10800
10812
|
return {
|
|
@@ -10817,7 +10829,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10817
10829
|
}
|
|
10818
10830
|
});
|
|
10819
10831
|
sdk.registerFunction({ id: "api::audit" }, async (req) => {
|
|
10820
|
-
const authErr = checkAuth
|
|
10832
|
+
const authErr = checkAuth(req, secret);
|
|
10821
10833
|
if (authErr) return authErr;
|
|
10822
10834
|
return {
|
|
10823
10835
|
status_code: 200,
|
|
@@ -10836,7 +10848,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10836
10848
|
}
|
|
10837
10849
|
});
|
|
10838
10850
|
sdk.registerFunction({ id: "api::governance-delete" }, async (req) => {
|
|
10839
|
-
const authErr = checkAuth
|
|
10851
|
+
const authErr = checkAuth(req, secret);
|
|
10840
10852
|
if (authErr) return authErr;
|
|
10841
10853
|
if (!req.body?.memoryIds || !Array.isArray(req.body.memoryIds)) return {
|
|
10842
10854
|
status_code: 400,
|
|
@@ -10856,7 +10868,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10856
10868
|
}
|
|
10857
10869
|
});
|
|
10858
10870
|
sdk.registerFunction({ id: "api::governance-bulk" }, async (req) => {
|
|
10859
|
-
const authErr = checkAuth
|
|
10871
|
+
const authErr = checkAuth(req, secret);
|
|
10860
10872
|
if (authErr) return authErr;
|
|
10861
10873
|
return {
|
|
10862
10874
|
status_code: 200,
|
|
@@ -10872,7 +10884,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10872
10884
|
}
|
|
10873
10885
|
});
|
|
10874
10886
|
sdk.registerFunction({ id: "api::snapshots" }, async (req) => {
|
|
10875
|
-
const authErr = checkAuth
|
|
10887
|
+
const authErr = checkAuth(req, secret);
|
|
10876
10888
|
if (authErr) return authErr;
|
|
10877
10889
|
try {
|
|
10878
10890
|
return {
|
|
@@ -10895,7 +10907,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10895
10907
|
}
|
|
10896
10908
|
});
|
|
10897
10909
|
sdk.registerFunction({ id: "api::snapshot-create" }, async (req) => {
|
|
10898
|
-
const authErr = checkAuth
|
|
10910
|
+
const authErr = checkAuth(req, secret);
|
|
10899
10911
|
if (authErr) return authErr;
|
|
10900
10912
|
try {
|
|
10901
10913
|
return {
|
|
@@ -10918,7 +10930,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10918
10930
|
}
|
|
10919
10931
|
});
|
|
10920
10932
|
sdk.registerFunction({ id: "api::snapshot-restore" }, async (req) => {
|
|
10921
|
-
const authErr = checkAuth
|
|
10933
|
+
const authErr = checkAuth(req, secret);
|
|
10922
10934
|
if (authErr) return authErr;
|
|
10923
10935
|
if (!req.body?.commitHash) return {
|
|
10924
10936
|
status_code: 400,
|
|
@@ -10945,7 +10957,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10945
10957
|
}
|
|
10946
10958
|
});
|
|
10947
10959
|
sdk.registerFunction({ id: "api::memories" }, async (req) => {
|
|
10948
|
-
const authErr = checkAuth
|
|
10960
|
+
const authErr = checkAuth(req, secret);
|
|
10949
10961
|
if (authErr) return authErr;
|
|
10950
10962
|
const memories = await kv.list(KV.memories);
|
|
10951
10963
|
return {
|
|
@@ -10962,7 +10974,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10962
10974
|
}
|
|
10963
10975
|
});
|
|
10964
10976
|
sdk.registerFunction({ id: "api::action-create" }, async (req) => {
|
|
10965
|
-
const authErr = checkAuth
|
|
10977
|
+
const authErr = checkAuth(req, secret);
|
|
10966
10978
|
if (authErr) return authErr;
|
|
10967
10979
|
if (!req.body?.title) return {
|
|
10968
10980
|
status_code: 400,
|
|
@@ -10982,7 +10994,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
10982
10994
|
}
|
|
10983
10995
|
});
|
|
10984
10996
|
sdk.registerFunction({ id: "api::action-update" }, async (req) => {
|
|
10985
|
-
const authErr = checkAuth
|
|
10997
|
+
const authErr = checkAuth(req, secret);
|
|
10986
10998
|
if (authErr) return authErr;
|
|
10987
10999
|
if (!req.body?.actionId) return {
|
|
10988
11000
|
status_code: 400,
|
|
@@ -11002,7 +11014,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11002
11014
|
}
|
|
11003
11015
|
});
|
|
11004
11016
|
sdk.registerFunction({ id: "api::action-list" }, async (req) => {
|
|
11005
|
-
const authErr = checkAuth
|
|
11017
|
+
const authErr = checkAuth(req, secret);
|
|
11006
11018
|
if (authErr) return authErr;
|
|
11007
11019
|
return {
|
|
11008
11020
|
status_code: 200,
|
|
@@ -11022,7 +11034,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11022
11034
|
}
|
|
11023
11035
|
});
|
|
11024
11036
|
sdk.registerFunction({ id: "api::action-get" }, async (req) => {
|
|
11025
|
-
const authErr = checkAuth
|
|
11037
|
+
const authErr = checkAuth(req, secret);
|
|
11026
11038
|
if (authErr) return authErr;
|
|
11027
11039
|
const actionId = req.query_params?.["actionId"];
|
|
11028
11040
|
if (!actionId) return {
|
|
@@ -11043,7 +11055,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11043
11055
|
}
|
|
11044
11056
|
});
|
|
11045
11057
|
sdk.registerFunction({ id: "api::action-edge" }, async (req) => {
|
|
11046
|
-
const authErr = checkAuth
|
|
11058
|
+
const authErr = checkAuth(req, secret);
|
|
11047
11059
|
if (authErr) return authErr;
|
|
11048
11060
|
if (!req.body?.sourceActionId || !req.body?.targetActionId || !req.body?.type) return {
|
|
11049
11061
|
status_code: 400,
|
|
@@ -11063,7 +11075,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11063
11075
|
}
|
|
11064
11076
|
});
|
|
11065
11077
|
sdk.registerFunction({ id: "api::frontier" }, async (req) => {
|
|
11066
|
-
const authErr = checkAuth
|
|
11078
|
+
const authErr = checkAuth(req, secret);
|
|
11067
11079
|
if (authErr) return authErr;
|
|
11068
11080
|
return {
|
|
11069
11081
|
status_code: 200,
|
|
@@ -11083,7 +11095,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11083
11095
|
}
|
|
11084
11096
|
});
|
|
11085
11097
|
sdk.registerFunction({ id: "api::next" }, async (req) => {
|
|
11086
|
-
const authErr = checkAuth
|
|
11098
|
+
const authErr = checkAuth(req, secret);
|
|
11087
11099
|
if (authErr) return authErr;
|
|
11088
11100
|
return {
|
|
11089
11101
|
status_code: 200,
|
|
@@ -11102,7 +11114,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11102
11114
|
}
|
|
11103
11115
|
});
|
|
11104
11116
|
sdk.registerFunction({ id: "api::lease-acquire" }, async (req) => {
|
|
11105
|
-
const authErr = checkAuth
|
|
11117
|
+
const authErr = checkAuth(req, secret);
|
|
11106
11118
|
if (authErr) return authErr;
|
|
11107
11119
|
if (!req.body?.actionId || !req.body?.agentId) return {
|
|
11108
11120
|
status_code: 400,
|
|
@@ -11122,7 +11134,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11122
11134
|
}
|
|
11123
11135
|
});
|
|
11124
11136
|
sdk.registerFunction({ id: "api::lease-release" }, async (req) => {
|
|
11125
|
-
const authErr = checkAuth
|
|
11137
|
+
const authErr = checkAuth(req, secret);
|
|
11126
11138
|
if (authErr) return authErr;
|
|
11127
11139
|
if (!req.body?.actionId || !req.body?.agentId) return {
|
|
11128
11140
|
status_code: 400,
|
|
@@ -11142,7 +11154,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11142
11154
|
}
|
|
11143
11155
|
});
|
|
11144
11156
|
sdk.registerFunction({ id: "api::lease-renew" }, async (req) => {
|
|
11145
|
-
const authErr = checkAuth
|
|
11157
|
+
const authErr = checkAuth(req, secret);
|
|
11146
11158
|
if (authErr) return authErr;
|
|
11147
11159
|
if (!req.body?.actionId || !req.body?.agentId) return {
|
|
11148
11160
|
status_code: 400,
|
|
@@ -11162,7 +11174,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11162
11174
|
}
|
|
11163
11175
|
});
|
|
11164
11176
|
sdk.registerFunction({ id: "api::routine-create" }, async (req) => {
|
|
11165
|
-
const authErr = checkAuth
|
|
11177
|
+
const authErr = checkAuth(req, secret);
|
|
11166
11178
|
if (authErr) return authErr;
|
|
11167
11179
|
if (!req.body?.name) return {
|
|
11168
11180
|
status_code: 400,
|
|
@@ -11182,7 +11194,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11182
11194
|
}
|
|
11183
11195
|
});
|
|
11184
11196
|
sdk.registerFunction({ id: "api::routine-list" }, async (req) => {
|
|
11185
|
-
const authErr = checkAuth
|
|
11197
|
+
const authErr = checkAuth(req, secret);
|
|
11186
11198
|
if (authErr) return authErr;
|
|
11187
11199
|
return {
|
|
11188
11200
|
status_code: 200,
|
|
@@ -11198,7 +11210,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11198
11210
|
}
|
|
11199
11211
|
});
|
|
11200
11212
|
sdk.registerFunction({ id: "api::routine-run" }, async (req) => {
|
|
11201
|
-
const authErr = checkAuth
|
|
11213
|
+
const authErr = checkAuth(req, secret);
|
|
11202
11214
|
if (authErr) return authErr;
|
|
11203
11215
|
if (!req.body?.routineId) return {
|
|
11204
11216
|
status_code: 400,
|
|
@@ -11218,7 +11230,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11218
11230
|
}
|
|
11219
11231
|
});
|
|
11220
11232
|
sdk.registerFunction({ id: "api::routine-status" }, async (req) => {
|
|
11221
|
-
const authErr = checkAuth
|
|
11233
|
+
const authErr = checkAuth(req, secret);
|
|
11222
11234
|
if (authErr) return authErr;
|
|
11223
11235
|
const runId = req.query_params?.["runId"];
|
|
11224
11236
|
if (!runId) return {
|
|
@@ -11239,7 +11251,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11239
11251
|
}
|
|
11240
11252
|
});
|
|
11241
11253
|
sdk.registerFunction({ id: "api::signal-send" }, async (req) => {
|
|
11242
|
-
const authErr = checkAuth
|
|
11254
|
+
const authErr = checkAuth(req, secret);
|
|
11243
11255
|
if (authErr) return authErr;
|
|
11244
11256
|
if (!req.body?.from || !req.body?.content) return {
|
|
11245
11257
|
status_code: 400,
|
|
@@ -11259,7 +11271,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11259
11271
|
}
|
|
11260
11272
|
});
|
|
11261
11273
|
sdk.registerFunction({ id: "api::signal-read" }, async (req) => {
|
|
11262
|
-
const authErr = checkAuth
|
|
11274
|
+
const authErr = checkAuth(req, secret);
|
|
11263
11275
|
if (authErr) return authErr;
|
|
11264
11276
|
const agentId = req.query_params?.["agentId"];
|
|
11265
11277
|
if (!agentId) return {
|
|
@@ -11285,7 +11297,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11285
11297
|
}
|
|
11286
11298
|
});
|
|
11287
11299
|
sdk.registerFunction({ id: "api::checkpoint-create" }, async (req) => {
|
|
11288
|
-
const authErr = checkAuth
|
|
11300
|
+
const authErr = checkAuth(req, secret);
|
|
11289
11301
|
if (authErr) return authErr;
|
|
11290
11302
|
if (!req.body?.name) return {
|
|
11291
11303
|
status_code: 400,
|
|
@@ -11305,7 +11317,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11305
11317
|
}
|
|
11306
11318
|
});
|
|
11307
11319
|
sdk.registerFunction({ id: "api::checkpoint-resolve" }, async (req) => {
|
|
11308
|
-
const authErr = checkAuth
|
|
11320
|
+
const authErr = checkAuth(req, secret);
|
|
11309
11321
|
if (authErr) return authErr;
|
|
11310
11322
|
if (!req.body?.checkpointId || !req.body?.status) return {
|
|
11311
11323
|
status_code: 400,
|
|
@@ -11325,7 +11337,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11325
11337
|
}
|
|
11326
11338
|
});
|
|
11327
11339
|
sdk.registerFunction({ id: "api::checkpoint-list" }, async (req) => {
|
|
11328
|
-
const authErr = checkAuth
|
|
11340
|
+
const authErr = checkAuth(req, secret);
|
|
11329
11341
|
if (authErr) return authErr;
|
|
11330
11342
|
return {
|
|
11331
11343
|
status_code: 200,
|
|
@@ -11344,7 +11356,9 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11344
11356
|
}
|
|
11345
11357
|
});
|
|
11346
11358
|
sdk.registerFunction({ id: "api::mesh-register" }, async (req) => {
|
|
11347
|
-
const
|
|
11359
|
+
const secretErr = requireConfiguredSecret(secret, "mesh");
|
|
11360
|
+
if (secretErr) return secretErr;
|
|
11361
|
+
const authErr = checkAuth(req, secret);
|
|
11348
11362
|
if (authErr) return authErr;
|
|
11349
11363
|
if (!req.body?.url || !req.body?.name) return {
|
|
11350
11364
|
status_code: 400,
|
|
@@ -11364,7 +11378,9 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11364
11378
|
}
|
|
11365
11379
|
});
|
|
11366
11380
|
sdk.registerFunction({ id: "api::mesh-list" }, async (req) => {
|
|
11367
|
-
const
|
|
11381
|
+
const secretErr = requireConfiguredSecret(secret, "mesh");
|
|
11382
|
+
if (secretErr) return secretErr;
|
|
11383
|
+
const authErr = checkAuth(req, secret);
|
|
11368
11384
|
if (authErr) return authErr;
|
|
11369
11385
|
return {
|
|
11370
11386
|
status_code: 200,
|
|
@@ -11380,7 +11396,9 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11380
11396
|
}
|
|
11381
11397
|
});
|
|
11382
11398
|
sdk.registerFunction({ id: "api::mesh-sync" }, async (req) => {
|
|
11383
|
-
const
|
|
11399
|
+
const secretErr = requireConfiguredSecret(secret, "mesh");
|
|
11400
|
+
if (secretErr) return secretErr;
|
|
11401
|
+
const authErr = checkAuth(req, secret);
|
|
11384
11402
|
if (authErr) return authErr;
|
|
11385
11403
|
return {
|
|
11386
11404
|
status_code: 200,
|
|
@@ -11396,7 +11414,9 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11396
11414
|
}
|
|
11397
11415
|
});
|
|
11398
11416
|
sdk.registerFunction({ id: "api::mesh-receive" }, async (req) => {
|
|
11399
|
-
const
|
|
11417
|
+
const secretErr = requireConfiguredSecret(secret, "mesh");
|
|
11418
|
+
if (secretErr) return secretErr;
|
|
11419
|
+
const authErr = checkAuth(req, secret);
|
|
11400
11420
|
if (authErr) return authErr;
|
|
11401
11421
|
return {
|
|
11402
11422
|
status_code: 200,
|
|
@@ -11412,7 +11432,9 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11412
11432
|
}
|
|
11413
11433
|
});
|
|
11414
11434
|
sdk.registerFunction({ id: "api::mesh-export" }, async (req) => {
|
|
11415
|
-
const
|
|
11435
|
+
const secretErr = requireConfiguredSecret(secret, "mesh");
|
|
11436
|
+
if (secretErr) return secretErr;
|
|
11437
|
+
const authErr = checkAuth(req, secret);
|
|
11416
11438
|
if (authErr) return authErr;
|
|
11417
11439
|
const since = req.query_params?.["since"];
|
|
11418
11440
|
if (since) {
|
|
@@ -11458,7 +11480,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11458
11480
|
}
|
|
11459
11481
|
});
|
|
11460
11482
|
sdk.registerFunction({ id: "api::flow-compress" }, async (req) => {
|
|
11461
|
-
const authErr = checkAuth
|
|
11483
|
+
const authErr = checkAuth(req, secret);
|
|
11462
11484
|
if (authErr) return authErr;
|
|
11463
11485
|
try {
|
|
11464
11486
|
return {
|
|
@@ -11481,7 +11503,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11481
11503
|
}
|
|
11482
11504
|
});
|
|
11483
11505
|
sdk.registerFunction({ id: "api::branch-detect" }, async (req) => {
|
|
11484
|
-
const authErr = checkAuth
|
|
11506
|
+
const authErr = checkAuth(req, secret);
|
|
11485
11507
|
if (authErr) return authErr;
|
|
11486
11508
|
const cwd = req.query_params?.["cwd"] || process.cwd();
|
|
11487
11509
|
return {
|
|
@@ -11498,7 +11520,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11498
11520
|
}
|
|
11499
11521
|
});
|
|
11500
11522
|
sdk.registerFunction({ id: "api::branch-worktrees" }, async (req) => {
|
|
11501
|
-
const authErr = checkAuth
|
|
11523
|
+
const authErr = checkAuth(req, secret);
|
|
11502
11524
|
if (authErr) return authErr;
|
|
11503
11525
|
const cwd = req.query_params?.["cwd"] || process.cwd();
|
|
11504
11526
|
return {
|
|
@@ -11515,7 +11537,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11515
11537
|
}
|
|
11516
11538
|
});
|
|
11517
11539
|
sdk.registerFunction({ id: "api::branch-sessions" }, async (req) => {
|
|
11518
|
-
const authErr = checkAuth
|
|
11540
|
+
const authErr = checkAuth(req, secret);
|
|
11519
11541
|
if (authErr) return authErr;
|
|
11520
11542
|
const cwd = req.query_params?.["cwd"] || process.cwd();
|
|
11521
11543
|
return {
|
|
@@ -11531,27 +11553,21 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11531
11553
|
http_method: "GET"
|
|
11532
11554
|
}
|
|
11533
11555
|
});
|
|
11534
|
-
sdk.registerFunction({ id: "api::viewer" }, async () => {
|
|
11535
|
-
const
|
|
11536
|
-
|
|
11537
|
-
|
|
11556
|
+
sdk.registerFunction({ id: "api::viewer" }, async (req) => {
|
|
11557
|
+
const denied = checkAuth(req, secret);
|
|
11558
|
+
if (denied) return denied;
|
|
11559
|
+
const rendered = renderViewerDocument();
|
|
11560
|
+
if (rendered.found) return {
|
|
11561
|
+
status_code: 200,
|
|
11562
|
+
headers: {
|
|
11563
|
+
"Content-Type": "text/html",
|
|
11564
|
+
"Content-Security-Policy": rendered.csp
|
|
11565
|
+
},
|
|
11566
|
+
body: rendered.html
|
|
11538
11567
|
};
|
|
11539
|
-
const base = dirname(fileURLToPath(import.meta.url));
|
|
11540
|
-
const candidates = [
|
|
11541
|
-
join(base, "..", "viewer", "index.html"),
|
|
11542
|
-
join(base, "..", "src", "viewer", "index.html"),
|
|
11543
|
-
join(base, "viewer", "index.html")
|
|
11544
|
-
];
|
|
11545
|
-
for (const p of candidates) try {
|
|
11546
|
-
return {
|
|
11547
|
-
status_code: 200,
|
|
11548
|
-
headers,
|
|
11549
|
-
body: readFileSync(p, "utf-8")
|
|
11550
|
-
};
|
|
11551
|
-
} catch {}
|
|
11552
11568
|
return {
|
|
11553
11569
|
status_code: 404,
|
|
11554
|
-
headers,
|
|
11570
|
+
headers: { "Content-Type": "text/html" },
|
|
11555
11571
|
body: "<!DOCTYPE html><html><body><h1>agentmemory</h1><p>viewer not found</p></body></html>"
|
|
11556
11572
|
};
|
|
11557
11573
|
});
|
|
@@ -11564,7 +11580,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11564
11580
|
}
|
|
11565
11581
|
});
|
|
11566
11582
|
sdk.registerFunction({ id: "api::sentinel-create" }, async (req) => {
|
|
11567
|
-
const denied = checkAuth
|
|
11583
|
+
const denied = checkAuth(req, secret);
|
|
11568
11584
|
if (denied) return denied;
|
|
11569
11585
|
const body = req.body;
|
|
11570
11586
|
if (!body?.name) return {
|
|
@@ -11585,7 +11601,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11585
11601
|
}
|
|
11586
11602
|
});
|
|
11587
11603
|
sdk.registerFunction({ id: "api::sentinel-trigger" }, async (req) => {
|
|
11588
|
-
const denied = checkAuth
|
|
11604
|
+
const denied = checkAuth(req, secret);
|
|
11589
11605
|
if (denied) return denied;
|
|
11590
11606
|
const body = req.body;
|
|
11591
11607
|
if (!body?.sentinelId) return {
|
|
@@ -11606,7 +11622,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11606
11622
|
}
|
|
11607
11623
|
});
|
|
11608
11624
|
sdk.registerFunction({ id: "api::sentinel-check" }, async (req) => {
|
|
11609
|
-
const denied = checkAuth
|
|
11625
|
+
const denied = checkAuth(req, secret);
|
|
11610
11626
|
if (denied) return denied;
|
|
11611
11627
|
return {
|
|
11612
11628
|
status_code: 200,
|
|
@@ -11622,7 +11638,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11622
11638
|
}
|
|
11623
11639
|
});
|
|
11624
11640
|
sdk.registerFunction({ id: "api::sentinel-cancel" }, async (req) => {
|
|
11625
|
-
const denied = checkAuth
|
|
11641
|
+
const denied = checkAuth(req, secret);
|
|
11626
11642
|
if (denied) return denied;
|
|
11627
11643
|
const body = req.body;
|
|
11628
11644
|
if (!body?.sentinelId) return {
|
|
@@ -11643,7 +11659,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11643
11659
|
}
|
|
11644
11660
|
});
|
|
11645
11661
|
sdk.registerFunction({ id: "api::sentinel-list" }, async (req) => {
|
|
11646
|
-
const denied = checkAuth
|
|
11662
|
+
const denied = checkAuth(req, secret);
|
|
11647
11663
|
if (denied) return denied;
|
|
11648
11664
|
const params = req.query_params || {};
|
|
11649
11665
|
return {
|
|
@@ -11663,7 +11679,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11663
11679
|
}
|
|
11664
11680
|
});
|
|
11665
11681
|
sdk.registerFunction({ id: "api::sketch-create" }, async (req) => {
|
|
11666
|
-
const denied = checkAuth
|
|
11682
|
+
const denied = checkAuth(req, secret);
|
|
11667
11683
|
if (denied) return denied;
|
|
11668
11684
|
const body = req.body;
|
|
11669
11685
|
if (!body?.title) return {
|
|
@@ -11684,7 +11700,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11684
11700
|
}
|
|
11685
11701
|
});
|
|
11686
11702
|
sdk.registerFunction({ id: "api::sketch-add" }, async (req) => {
|
|
11687
|
-
const denied = checkAuth
|
|
11703
|
+
const denied = checkAuth(req, secret);
|
|
11688
11704
|
if (denied) return denied;
|
|
11689
11705
|
const body = req.body;
|
|
11690
11706
|
if (!body?.sketchId || !body?.title) return {
|
|
@@ -11705,7 +11721,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11705
11721
|
}
|
|
11706
11722
|
});
|
|
11707
11723
|
sdk.registerFunction({ id: "api::sketch-promote" }, async (req) => {
|
|
11708
|
-
const denied = checkAuth
|
|
11724
|
+
const denied = checkAuth(req, secret);
|
|
11709
11725
|
if (denied) return denied;
|
|
11710
11726
|
const body = req.body;
|
|
11711
11727
|
if (!body?.sketchId) return {
|
|
@@ -11726,7 +11742,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11726
11742
|
}
|
|
11727
11743
|
});
|
|
11728
11744
|
sdk.registerFunction({ id: "api::sketch-discard" }, async (req) => {
|
|
11729
|
-
const denied = checkAuth
|
|
11745
|
+
const denied = checkAuth(req, secret);
|
|
11730
11746
|
if (denied) return denied;
|
|
11731
11747
|
const body = req.body;
|
|
11732
11748
|
if (!body?.sketchId) return {
|
|
@@ -11747,7 +11763,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11747
11763
|
}
|
|
11748
11764
|
});
|
|
11749
11765
|
sdk.registerFunction({ id: "api::sketch-list" }, async (req) => {
|
|
11750
|
-
const denied = checkAuth
|
|
11766
|
+
const denied = checkAuth(req, secret);
|
|
11751
11767
|
if (denied) return denied;
|
|
11752
11768
|
const params = req.query_params || {};
|
|
11753
11769
|
return {
|
|
@@ -11767,7 +11783,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11767
11783
|
}
|
|
11768
11784
|
});
|
|
11769
11785
|
sdk.registerFunction({ id: "api::sketch-gc" }, async (req) => {
|
|
11770
|
-
const denied = checkAuth
|
|
11786
|
+
const denied = checkAuth(req, secret);
|
|
11771
11787
|
if (denied) return denied;
|
|
11772
11788
|
return {
|
|
11773
11789
|
status_code: 200,
|
|
@@ -11783,7 +11799,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11783
11799
|
}
|
|
11784
11800
|
});
|
|
11785
11801
|
sdk.registerFunction({ id: "api::crystallize" }, async (req) => {
|
|
11786
|
-
const denied = checkAuth
|
|
11802
|
+
const denied = checkAuth(req, secret);
|
|
11787
11803
|
if (denied) return denied;
|
|
11788
11804
|
const body = req.body;
|
|
11789
11805
|
if (!body?.actionIds) return {
|
|
@@ -11804,7 +11820,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11804
11820
|
}
|
|
11805
11821
|
});
|
|
11806
11822
|
sdk.registerFunction({ id: "api::crystal-list" }, async (req) => {
|
|
11807
|
-
const denied = checkAuth
|
|
11823
|
+
const denied = checkAuth(req, secret);
|
|
11808
11824
|
if (denied) return denied;
|
|
11809
11825
|
const params = req.query_params || {};
|
|
11810
11826
|
return {
|
|
@@ -11825,7 +11841,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11825
11841
|
}
|
|
11826
11842
|
});
|
|
11827
11843
|
sdk.registerFunction({ id: "api::auto-crystallize" }, async (req) => {
|
|
11828
|
-
const denied = checkAuth
|
|
11844
|
+
const denied = checkAuth(req, secret);
|
|
11829
11845
|
if (denied) return denied;
|
|
11830
11846
|
const body = req.body;
|
|
11831
11847
|
return {
|
|
@@ -11842,7 +11858,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11842
11858
|
}
|
|
11843
11859
|
});
|
|
11844
11860
|
sdk.registerFunction({ id: "api::diagnose" }, async (req) => {
|
|
11845
|
-
const denied = checkAuth
|
|
11861
|
+
const denied = checkAuth(req, secret);
|
|
11846
11862
|
if (denied) return denied;
|
|
11847
11863
|
const body = req.body;
|
|
11848
11864
|
return {
|
|
@@ -11859,7 +11875,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11859
11875
|
}
|
|
11860
11876
|
});
|
|
11861
11877
|
sdk.registerFunction({ id: "api::heal" }, async (req) => {
|
|
11862
|
-
const denied = checkAuth
|
|
11878
|
+
const denied = checkAuth(req, secret);
|
|
11863
11879
|
if (denied) return denied;
|
|
11864
11880
|
const body = req.body;
|
|
11865
11881
|
return {
|
|
@@ -11876,7 +11892,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11876
11892
|
}
|
|
11877
11893
|
});
|
|
11878
11894
|
sdk.registerFunction({ id: "api::facet-tag" }, async (req) => {
|
|
11879
|
-
const denied = checkAuth
|
|
11895
|
+
const denied = checkAuth(req, secret);
|
|
11880
11896
|
if (denied) return denied;
|
|
11881
11897
|
const body = req.body;
|
|
11882
11898
|
if (!body?.targetId || !body?.dimension || !body?.value) return {
|
|
@@ -11897,7 +11913,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11897
11913
|
}
|
|
11898
11914
|
});
|
|
11899
11915
|
sdk.registerFunction({ id: "api::facet-untag" }, async (req) => {
|
|
11900
|
-
const denied = checkAuth
|
|
11916
|
+
const denied = checkAuth(req, secret);
|
|
11901
11917
|
if (denied) return denied;
|
|
11902
11918
|
const body = req.body;
|
|
11903
11919
|
if (!body?.targetId || !body?.dimension) return {
|
|
@@ -11918,7 +11934,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11918
11934
|
}
|
|
11919
11935
|
});
|
|
11920
11936
|
sdk.registerFunction({ id: "api::facet-query" }, async (req) => {
|
|
11921
|
-
const denied = checkAuth
|
|
11937
|
+
const denied = checkAuth(req, secret);
|
|
11922
11938
|
if (denied) return denied;
|
|
11923
11939
|
const body = req.body;
|
|
11924
11940
|
return {
|
|
@@ -11935,7 +11951,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11935
11951
|
}
|
|
11936
11952
|
});
|
|
11937
11953
|
sdk.registerFunction({ id: "api::facet-get" }, async (req) => {
|
|
11938
|
-
const denied = checkAuth
|
|
11954
|
+
const denied = checkAuth(req, secret);
|
|
11939
11955
|
if (denied) return denied;
|
|
11940
11956
|
const params = req.query_params || {};
|
|
11941
11957
|
if (!params.targetId) return {
|
|
@@ -11956,7 +11972,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11956
11972
|
}
|
|
11957
11973
|
});
|
|
11958
11974
|
sdk.registerFunction({ id: "api::facet-stats" }, async (req) => {
|
|
11959
|
-
const denied = checkAuth
|
|
11975
|
+
const denied = checkAuth(req, secret);
|
|
11960
11976
|
if (denied) return denied;
|
|
11961
11977
|
const params = req.query_params || {};
|
|
11962
11978
|
return {
|
|
@@ -11973,7 +11989,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11973
11989
|
}
|
|
11974
11990
|
});
|
|
11975
11991
|
sdk.registerFunction({ id: "api::verify" }, async (req) => {
|
|
11976
|
-
const denied = checkAuth
|
|
11992
|
+
const denied = checkAuth(req, secret);
|
|
11977
11993
|
if (denied) return denied;
|
|
11978
11994
|
const body = req.body;
|
|
11979
11995
|
if (!body?.id || typeof body.id !== "string") return {
|
|
@@ -11994,7 +12010,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
11994
12010
|
}
|
|
11995
12011
|
});
|
|
11996
12012
|
sdk.registerFunction({ id: "api::cascade-update" }, async (req) => {
|
|
11997
|
-
const denied = checkAuth
|
|
12013
|
+
const denied = checkAuth(req, secret);
|
|
11998
12014
|
if (denied) return denied;
|
|
11999
12015
|
const body = req.body;
|
|
12000
12016
|
if (!body?.supersededMemoryId || typeof body.supersededMemoryId !== "string") return {
|
|
@@ -12015,7 +12031,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
12015
12031
|
}
|
|
12016
12032
|
});
|
|
12017
12033
|
sdk.registerFunction({ id: "api::lesson-save" }, async (req) => {
|
|
12018
|
-
const denied = checkAuth
|
|
12034
|
+
const denied = checkAuth(req, secret);
|
|
12019
12035
|
if (denied) return denied;
|
|
12020
12036
|
const body = req.body;
|
|
12021
12037
|
if (!body?.content || typeof body.content !== "string") return {
|
|
@@ -12045,7 +12061,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
12045
12061
|
}
|
|
12046
12062
|
});
|
|
12047
12063
|
sdk.registerFunction({ id: "api::lesson-list" }, async (req) => {
|
|
12048
|
-
const denied = checkAuth
|
|
12064
|
+
const denied = checkAuth(req, secret);
|
|
12049
12065
|
if (denied) return denied;
|
|
12050
12066
|
const params = req.query_params || {};
|
|
12051
12067
|
return {
|
|
@@ -12067,7 +12083,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
12067
12083
|
}
|
|
12068
12084
|
});
|
|
12069
12085
|
sdk.registerFunction({ id: "api::lesson-search" }, async (req) => {
|
|
12070
|
-
const denied = checkAuth
|
|
12086
|
+
const denied = checkAuth(req, secret);
|
|
12071
12087
|
if (denied) return denied;
|
|
12072
12088
|
const body = req.body;
|
|
12073
12089
|
if (!body?.query || typeof body.query !== "string") return {
|
|
@@ -12088,7 +12104,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
12088
12104
|
}
|
|
12089
12105
|
});
|
|
12090
12106
|
sdk.registerFunction({ id: "api::lesson-strengthen" }, async (req) => {
|
|
12091
|
-
const denied = checkAuth
|
|
12107
|
+
const denied = checkAuth(req, secret);
|
|
12092
12108
|
if (denied) return denied;
|
|
12093
12109
|
const body = req.body;
|
|
12094
12110
|
if (!body?.lessonId || typeof body.lessonId !== "string") return {
|
|
@@ -12109,7 +12125,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
12109
12125
|
}
|
|
12110
12126
|
});
|
|
12111
12127
|
sdk.registerFunction({ id: "api::obsidian-export" }, async (req) => {
|
|
12112
|
-
const denied = checkAuth
|
|
12128
|
+
const denied = checkAuth(req, secret);
|
|
12113
12129
|
if (denied) return denied;
|
|
12114
12130
|
const body = req.body || {};
|
|
12115
12131
|
const types = typeof body.types === "string" ? body.types.split(",").map((t) => t.trim()).filter(Boolean) : void 0;
|
|
@@ -12130,7 +12146,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
12130
12146
|
}
|
|
12131
12147
|
});
|
|
12132
12148
|
sdk.registerFunction({ id: "api::reflect" }, async (req) => {
|
|
12133
|
-
const denied = checkAuth
|
|
12149
|
+
const denied = checkAuth(req, secret);
|
|
12134
12150
|
if (denied) return denied;
|
|
12135
12151
|
const body = req.body || {};
|
|
12136
12152
|
return {
|
|
@@ -12150,7 +12166,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
12150
12166
|
}
|
|
12151
12167
|
});
|
|
12152
12168
|
sdk.registerFunction({ id: "api::insight-list" }, async (req) => {
|
|
12153
|
-
const denied = checkAuth
|
|
12169
|
+
const denied = checkAuth(req, secret);
|
|
12154
12170
|
if (denied) return denied;
|
|
12155
12171
|
const params = req.query_params || {};
|
|
12156
12172
|
return {
|
|
@@ -12171,7 +12187,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
|
|
|
12171
12187
|
}
|
|
12172
12188
|
});
|
|
12173
12189
|
sdk.registerFunction({ id: "api::insight-search" }, async (req) => {
|
|
12174
|
-
const denied = checkAuth
|
|
12190
|
+
const denied = checkAuth(req, secret);
|
|
12175
12191
|
if (denied) return denied;
|
|
12176
12192
|
const body = req.body;
|
|
12177
12193
|
if (!body?.query || typeof body.query !== "string") return {
|
|
@@ -12252,925 +12268,6 @@ function registerEventTriggers(sdk, kv) {
|
|
|
12252
12268
|
});
|
|
12253
12269
|
}
|
|
12254
12270
|
|
|
12255
|
-
//#endregion
|
|
12256
|
-
//#region src/mcp/tools-registry.ts
|
|
12257
|
-
const CORE_TOOLS = [
|
|
12258
|
-
{
|
|
12259
|
-
name: "memory_recall",
|
|
12260
|
-
description: "Search past session observations for relevant context. Use when you need to recall what happened in previous sessions, find past decisions, or look up how a file was modified before.",
|
|
12261
|
-
inputSchema: {
|
|
12262
|
-
type: "object",
|
|
12263
|
-
properties: {
|
|
12264
|
-
query: {
|
|
12265
|
-
type: "string",
|
|
12266
|
-
description: "Search query (keywords, file names, concepts)"
|
|
12267
|
-
},
|
|
12268
|
-
limit: {
|
|
12269
|
-
type: "number",
|
|
12270
|
-
description: "Max results to return (default 10)"
|
|
12271
|
-
}
|
|
12272
|
-
},
|
|
12273
|
-
required: ["query"]
|
|
12274
|
-
}
|
|
12275
|
-
},
|
|
12276
|
-
{
|
|
12277
|
-
name: "memory_save",
|
|
12278
|
-
description: "Explicitly save an important insight, decision, or pattern to long-term memory.",
|
|
12279
|
-
inputSchema: {
|
|
12280
|
-
type: "object",
|
|
12281
|
-
properties: {
|
|
12282
|
-
content: {
|
|
12283
|
-
type: "string",
|
|
12284
|
-
description: "The insight or decision to remember"
|
|
12285
|
-
},
|
|
12286
|
-
type: {
|
|
12287
|
-
type: "string",
|
|
12288
|
-
description: "Memory type: pattern, preference, architecture, bug, workflow, or fact"
|
|
12289
|
-
},
|
|
12290
|
-
concepts: {
|
|
12291
|
-
type: "string",
|
|
12292
|
-
description: "Comma-separated key concepts"
|
|
12293
|
-
},
|
|
12294
|
-
files: {
|
|
12295
|
-
type: "string",
|
|
12296
|
-
description: "Comma-separated relevant file paths"
|
|
12297
|
-
}
|
|
12298
|
-
},
|
|
12299
|
-
required: ["content"]
|
|
12300
|
-
}
|
|
12301
|
-
},
|
|
12302
|
-
{
|
|
12303
|
-
name: "memory_file_history",
|
|
12304
|
-
description: "Get past observations about specific files.",
|
|
12305
|
-
inputSchema: {
|
|
12306
|
-
type: "object",
|
|
12307
|
-
properties: {
|
|
12308
|
-
files: {
|
|
12309
|
-
type: "string",
|
|
12310
|
-
description: "Comma-separated file paths"
|
|
12311
|
-
},
|
|
12312
|
-
sessionId: {
|
|
12313
|
-
type: "string",
|
|
12314
|
-
description: "Current session ID to exclude"
|
|
12315
|
-
}
|
|
12316
|
-
},
|
|
12317
|
-
required: ["files"]
|
|
12318
|
-
}
|
|
12319
|
-
},
|
|
12320
|
-
{
|
|
12321
|
-
name: "memory_patterns",
|
|
12322
|
-
description: "Detect recurring patterns across sessions.",
|
|
12323
|
-
inputSchema: {
|
|
12324
|
-
type: "object",
|
|
12325
|
-
properties: { project: {
|
|
12326
|
-
type: "string",
|
|
12327
|
-
description: "Project path to analyze"
|
|
12328
|
-
} }
|
|
12329
|
-
}
|
|
12330
|
-
},
|
|
12331
|
-
{
|
|
12332
|
-
name: "memory_sessions",
|
|
12333
|
-
description: "List recent sessions with their status and observation counts.",
|
|
12334
|
-
inputSchema: {
|
|
12335
|
-
type: "object",
|
|
12336
|
-
properties: {}
|
|
12337
|
-
}
|
|
12338
|
-
},
|
|
12339
|
-
{
|
|
12340
|
-
name: "memory_smart_search",
|
|
12341
|
-
description: "Hybrid semantic+keyword search with progressive disclosure.",
|
|
12342
|
-
inputSchema: {
|
|
12343
|
-
type: "object",
|
|
12344
|
-
properties: {
|
|
12345
|
-
query: {
|
|
12346
|
-
type: "string",
|
|
12347
|
-
description: "Search query"
|
|
12348
|
-
},
|
|
12349
|
-
expandIds: {
|
|
12350
|
-
type: "string",
|
|
12351
|
-
description: "Comma-separated observation IDs to expand"
|
|
12352
|
-
},
|
|
12353
|
-
limit: {
|
|
12354
|
-
type: "number",
|
|
12355
|
-
description: "Max results (default 10)"
|
|
12356
|
-
}
|
|
12357
|
-
},
|
|
12358
|
-
required: ["query"]
|
|
12359
|
-
}
|
|
12360
|
-
},
|
|
12361
|
-
{
|
|
12362
|
-
name: "memory_timeline",
|
|
12363
|
-
description: "Chronological observations around an anchor point.",
|
|
12364
|
-
inputSchema: {
|
|
12365
|
-
type: "object",
|
|
12366
|
-
properties: {
|
|
12367
|
-
anchor: {
|
|
12368
|
-
type: "string",
|
|
12369
|
-
description: "Anchor point: ISO date or keyword"
|
|
12370
|
-
},
|
|
12371
|
-
project: {
|
|
12372
|
-
type: "string",
|
|
12373
|
-
description: "Filter by project path"
|
|
12374
|
-
},
|
|
12375
|
-
before: {
|
|
12376
|
-
type: "number",
|
|
12377
|
-
description: "Observations before anchor (default 5)"
|
|
12378
|
-
},
|
|
12379
|
-
after: {
|
|
12380
|
-
type: "number",
|
|
12381
|
-
description: "Observations after anchor (default 5)"
|
|
12382
|
-
}
|
|
12383
|
-
},
|
|
12384
|
-
required: ["anchor"]
|
|
12385
|
-
}
|
|
12386
|
-
},
|
|
12387
|
-
{
|
|
12388
|
-
name: "memory_profile",
|
|
12389
|
-
description: "User/project profile with top concepts and file patterns.",
|
|
12390
|
-
inputSchema: {
|
|
12391
|
-
type: "object",
|
|
12392
|
-
properties: {
|
|
12393
|
-
project: {
|
|
12394
|
-
type: "string",
|
|
12395
|
-
description: "Project path"
|
|
12396
|
-
},
|
|
12397
|
-
refresh: {
|
|
12398
|
-
type: "string",
|
|
12399
|
-
description: "Set to 'true' to force rebuild"
|
|
12400
|
-
}
|
|
12401
|
-
},
|
|
12402
|
-
required: ["project"]
|
|
12403
|
-
}
|
|
12404
|
-
},
|
|
12405
|
-
{
|
|
12406
|
-
name: "memory_export",
|
|
12407
|
-
description: "Export all memory data as JSON.",
|
|
12408
|
-
inputSchema: {
|
|
12409
|
-
type: "object",
|
|
12410
|
-
properties: {}
|
|
12411
|
-
}
|
|
12412
|
-
},
|
|
12413
|
-
{
|
|
12414
|
-
name: "memory_relations",
|
|
12415
|
-
description: "Query the memory relationship graph.",
|
|
12416
|
-
inputSchema: {
|
|
12417
|
-
type: "object",
|
|
12418
|
-
properties: {
|
|
12419
|
-
memoryId: {
|
|
12420
|
-
type: "string",
|
|
12421
|
-
description: "Memory ID to find relations for"
|
|
12422
|
-
},
|
|
12423
|
-
maxHops: {
|
|
12424
|
-
type: "number",
|
|
12425
|
-
description: "Max traversal depth (default 2)"
|
|
12426
|
-
},
|
|
12427
|
-
minConfidence: {
|
|
12428
|
-
type: "number",
|
|
12429
|
-
description: "Min confidence (0-1, default 0)"
|
|
12430
|
-
}
|
|
12431
|
-
},
|
|
12432
|
-
required: ["memoryId"]
|
|
12433
|
-
}
|
|
12434
|
-
}
|
|
12435
|
-
];
|
|
12436
|
-
const V040_TOOLS = [
|
|
12437
|
-
{
|
|
12438
|
-
name: "memory_claude_bridge_sync",
|
|
12439
|
-
description: "Sync memory state to/from Claude Code's native MEMORY.md file.",
|
|
12440
|
-
inputSchema: {
|
|
12441
|
-
type: "object",
|
|
12442
|
-
properties: { direction: {
|
|
12443
|
-
type: "string",
|
|
12444
|
-
description: "'read' to import from MEMORY.md, 'write' to export to MEMORY.md"
|
|
12445
|
-
} },
|
|
12446
|
-
required: ["direction"]
|
|
12447
|
-
}
|
|
12448
|
-
},
|
|
12449
|
-
{
|
|
12450
|
-
name: "memory_graph_query",
|
|
12451
|
-
description: "Query the knowledge graph for entities and relationships.",
|
|
12452
|
-
inputSchema: {
|
|
12453
|
-
type: "object",
|
|
12454
|
-
properties: {
|
|
12455
|
-
startNodeId: {
|
|
12456
|
-
type: "string",
|
|
12457
|
-
description: "Starting node ID for traversal"
|
|
12458
|
-
},
|
|
12459
|
-
nodeType: {
|
|
12460
|
-
type: "string",
|
|
12461
|
-
description: "Filter by node type"
|
|
12462
|
-
},
|
|
12463
|
-
maxDepth: {
|
|
12464
|
-
type: "number",
|
|
12465
|
-
description: "Max BFS depth (default 3, max 5)"
|
|
12466
|
-
},
|
|
12467
|
-
query: {
|
|
12468
|
-
type: "string",
|
|
12469
|
-
description: "Search nodes by name"
|
|
12470
|
-
}
|
|
12471
|
-
}
|
|
12472
|
-
}
|
|
12473
|
-
},
|
|
12474
|
-
{
|
|
12475
|
-
name: "memory_consolidate",
|
|
12476
|
-
description: "Run the 4-tier memory consolidation pipeline (working -> episodic -> semantic -> procedural).",
|
|
12477
|
-
inputSchema: {
|
|
12478
|
-
type: "object",
|
|
12479
|
-
properties: { tier: {
|
|
12480
|
-
type: "string",
|
|
12481
|
-
description: "Target tier: episodic, semantic, or procedural"
|
|
12482
|
-
} }
|
|
12483
|
-
}
|
|
12484
|
-
},
|
|
12485
|
-
{
|
|
12486
|
-
name: "memory_team_share",
|
|
12487
|
-
description: "Share a memory or observation with team members.",
|
|
12488
|
-
inputSchema: {
|
|
12489
|
-
type: "object",
|
|
12490
|
-
properties: {
|
|
12491
|
-
itemId: {
|
|
12492
|
-
type: "string",
|
|
12493
|
-
description: "ID of memory or observation to share"
|
|
12494
|
-
},
|
|
12495
|
-
itemType: {
|
|
12496
|
-
type: "string",
|
|
12497
|
-
description: "Type: observation, memory, or pattern"
|
|
12498
|
-
}
|
|
12499
|
-
},
|
|
12500
|
-
required: ["itemId", "itemType"]
|
|
12501
|
-
}
|
|
12502
|
-
},
|
|
12503
|
-
{
|
|
12504
|
-
name: "memory_team_feed",
|
|
12505
|
-
description: "Get recent shared items from all team members.",
|
|
12506
|
-
inputSchema: {
|
|
12507
|
-
type: "object",
|
|
12508
|
-
properties: { limit: {
|
|
12509
|
-
type: "number",
|
|
12510
|
-
description: "Max items (default 20)"
|
|
12511
|
-
} }
|
|
12512
|
-
}
|
|
12513
|
-
},
|
|
12514
|
-
{
|
|
12515
|
-
name: "memory_audit",
|
|
12516
|
-
description: "View the audit trail of memory operations.",
|
|
12517
|
-
inputSchema: {
|
|
12518
|
-
type: "object",
|
|
12519
|
-
properties: {
|
|
12520
|
-
operation: {
|
|
12521
|
-
type: "string",
|
|
12522
|
-
description: "Filter by operation type"
|
|
12523
|
-
},
|
|
12524
|
-
limit: {
|
|
12525
|
-
type: "number",
|
|
12526
|
-
description: "Max entries (default 50)"
|
|
12527
|
-
}
|
|
12528
|
-
}
|
|
12529
|
-
}
|
|
12530
|
-
},
|
|
12531
|
-
{
|
|
12532
|
-
name: "memory_governance_delete",
|
|
12533
|
-
description: "Delete specific memories with audit trail.",
|
|
12534
|
-
inputSchema: {
|
|
12535
|
-
type: "object",
|
|
12536
|
-
properties: {
|
|
12537
|
-
memoryIds: {
|
|
12538
|
-
type: "string",
|
|
12539
|
-
description: "Comma-separated memory IDs to delete"
|
|
12540
|
-
},
|
|
12541
|
-
reason: {
|
|
12542
|
-
type: "string",
|
|
12543
|
-
description: "Reason for deletion"
|
|
12544
|
-
}
|
|
12545
|
-
},
|
|
12546
|
-
required: ["memoryIds"]
|
|
12547
|
-
}
|
|
12548
|
-
},
|
|
12549
|
-
{
|
|
12550
|
-
name: "memory_snapshot_create",
|
|
12551
|
-
description: "Create a git-versioned snapshot of current memory state.",
|
|
12552
|
-
inputSchema: {
|
|
12553
|
-
type: "object",
|
|
12554
|
-
properties: { message: {
|
|
12555
|
-
type: "string",
|
|
12556
|
-
description: "Snapshot description"
|
|
12557
|
-
} }
|
|
12558
|
-
}
|
|
12559
|
-
}
|
|
12560
|
-
];
|
|
12561
|
-
const V050_TOOLS = [
|
|
12562
|
-
{
|
|
12563
|
-
name: "memory_action_create",
|
|
12564
|
-
description: "Create an actionable work item with typed dependencies. Actions track what agents need to do and how work items relate to each other.",
|
|
12565
|
-
inputSchema: {
|
|
12566
|
-
type: "object",
|
|
12567
|
-
properties: {
|
|
12568
|
-
title: {
|
|
12569
|
-
type: "string",
|
|
12570
|
-
description: "Action title"
|
|
12571
|
-
},
|
|
12572
|
-
description: {
|
|
12573
|
-
type: "string",
|
|
12574
|
-
description: "Detailed description of the work"
|
|
12575
|
-
},
|
|
12576
|
-
priority: {
|
|
12577
|
-
type: "number",
|
|
12578
|
-
description: "Priority 1-10 (10 highest)"
|
|
12579
|
-
},
|
|
12580
|
-
project: {
|
|
12581
|
-
type: "string",
|
|
12582
|
-
description: "Project path"
|
|
12583
|
-
},
|
|
12584
|
-
tags: {
|
|
12585
|
-
type: "string",
|
|
12586
|
-
description: "Comma-separated tags"
|
|
12587
|
-
},
|
|
12588
|
-
parentId: {
|
|
12589
|
-
type: "string",
|
|
12590
|
-
description: "Parent action ID for hierarchical actions"
|
|
12591
|
-
},
|
|
12592
|
-
requires: {
|
|
12593
|
-
type: "string",
|
|
12594
|
-
description: "Comma-separated action IDs that must complete before this"
|
|
12595
|
-
}
|
|
12596
|
-
},
|
|
12597
|
-
required: ["title"]
|
|
12598
|
-
}
|
|
12599
|
-
},
|
|
12600
|
-
{
|
|
12601
|
-
name: "memory_action_update",
|
|
12602
|
-
description: "Update an action's status, priority, or details. Set status to 'done' to complete it and unblock dependent actions.",
|
|
12603
|
-
inputSchema: {
|
|
12604
|
-
type: "object",
|
|
12605
|
-
properties: {
|
|
12606
|
-
actionId: {
|
|
12607
|
-
type: "string",
|
|
12608
|
-
description: "Action ID to update"
|
|
12609
|
-
},
|
|
12610
|
-
status: {
|
|
12611
|
-
type: "string",
|
|
12612
|
-
description: "New status: pending, active, done, blocked, cancelled"
|
|
12613
|
-
},
|
|
12614
|
-
result: {
|
|
12615
|
-
type: "string",
|
|
12616
|
-
description: "Outcome description (when completing)"
|
|
12617
|
-
},
|
|
12618
|
-
priority: {
|
|
12619
|
-
type: "number",
|
|
12620
|
-
description: "New priority 1-10"
|
|
12621
|
-
}
|
|
12622
|
-
},
|
|
12623
|
-
required: ["actionId"]
|
|
12624
|
-
}
|
|
12625
|
-
},
|
|
12626
|
-
{
|
|
12627
|
-
name: "memory_frontier",
|
|
12628
|
-
description: "Get all unblocked actions ranked by priority and urgency. Returns the frontier of actionable work with no unsatisfied dependencies.",
|
|
12629
|
-
inputSchema: {
|
|
12630
|
-
type: "object",
|
|
12631
|
-
properties: {
|
|
12632
|
-
project: {
|
|
12633
|
-
type: "string",
|
|
12634
|
-
description: "Filter by project"
|
|
12635
|
-
},
|
|
12636
|
-
agentId: {
|
|
12637
|
-
type: "string",
|
|
12638
|
-
description: "Agent ID to check lease conflicts"
|
|
12639
|
-
},
|
|
12640
|
-
limit: {
|
|
12641
|
-
type: "number",
|
|
12642
|
-
description: "Max results (default 20)"
|
|
12643
|
-
}
|
|
12644
|
-
}
|
|
12645
|
-
}
|
|
12646
|
-
},
|
|
12647
|
-
{
|
|
12648
|
-
name: "memory_next",
|
|
12649
|
-
description: "Get the single most important next action to work on. Combines dependency resolution, priority, and recency into a score.",
|
|
12650
|
-
inputSchema: {
|
|
12651
|
-
type: "object",
|
|
12652
|
-
properties: {
|
|
12653
|
-
project: {
|
|
12654
|
-
type: "string",
|
|
12655
|
-
description: "Filter by project"
|
|
12656
|
-
},
|
|
12657
|
-
agentId: {
|
|
12658
|
-
type: "string",
|
|
12659
|
-
description: "Current agent ID"
|
|
12660
|
-
}
|
|
12661
|
-
}
|
|
12662
|
-
}
|
|
12663
|
-
},
|
|
12664
|
-
{
|
|
12665
|
-
name: "memory_lease",
|
|
12666
|
-
description: "Acquire, release, or renew an exclusive lease on an action. Prevents multiple agents from working on the same thing.",
|
|
12667
|
-
inputSchema: {
|
|
12668
|
-
type: "object",
|
|
12669
|
-
properties: {
|
|
12670
|
-
actionId: {
|
|
12671
|
-
type: "string",
|
|
12672
|
-
description: "Action ID"
|
|
12673
|
-
},
|
|
12674
|
-
agentId: {
|
|
12675
|
-
type: "string",
|
|
12676
|
-
description: "Agent claiming the action"
|
|
12677
|
-
},
|
|
12678
|
-
operation: {
|
|
12679
|
-
type: "string",
|
|
12680
|
-
description: "acquire, release, or renew"
|
|
12681
|
-
},
|
|
12682
|
-
result: {
|
|
12683
|
-
type: "string",
|
|
12684
|
-
description: "Result when releasing (marks action done)"
|
|
12685
|
-
},
|
|
12686
|
-
ttlMs: {
|
|
12687
|
-
type: "number",
|
|
12688
|
-
description: "Lease duration in ms (default 10min, max 1hr)"
|
|
12689
|
-
}
|
|
12690
|
-
},
|
|
12691
|
-
required: [
|
|
12692
|
-
"actionId",
|
|
12693
|
-
"agentId",
|
|
12694
|
-
"operation"
|
|
12695
|
-
]
|
|
12696
|
-
}
|
|
12697
|
-
},
|
|
12698
|
-
{
|
|
12699
|
-
name: "memory_routine_run",
|
|
12700
|
-
description: "Instantiate a frozen workflow routine, creating actions for each step with proper dependencies.",
|
|
12701
|
-
inputSchema: {
|
|
12702
|
-
type: "object",
|
|
12703
|
-
properties: {
|
|
12704
|
-
routineId: {
|
|
12705
|
-
type: "string",
|
|
12706
|
-
description: "Routine template ID"
|
|
12707
|
-
},
|
|
12708
|
-
project: {
|
|
12709
|
-
type: "string",
|
|
12710
|
-
description: "Project context"
|
|
12711
|
-
},
|
|
12712
|
-
initiatedBy: {
|
|
12713
|
-
type: "string",
|
|
12714
|
-
description: "Agent starting the run"
|
|
12715
|
-
}
|
|
12716
|
-
},
|
|
12717
|
-
required: ["routineId"]
|
|
12718
|
-
}
|
|
12719
|
-
},
|
|
12720
|
-
{
|
|
12721
|
-
name: "memory_signal_send",
|
|
12722
|
-
description: "Send a message to another agent or broadcast. Supports threading, typed messages, and TTL expiration.",
|
|
12723
|
-
inputSchema: {
|
|
12724
|
-
type: "object",
|
|
12725
|
-
properties: {
|
|
12726
|
-
from: {
|
|
12727
|
-
type: "string",
|
|
12728
|
-
description: "Sender agent ID"
|
|
12729
|
-
},
|
|
12730
|
-
to: {
|
|
12731
|
-
type: "string",
|
|
12732
|
-
description: "Recipient agent ID (omit for broadcast)"
|
|
12733
|
-
},
|
|
12734
|
-
content: {
|
|
12735
|
-
type: "string",
|
|
12736
|
-
description: "Message content"
|
|
12737
|
-
},
|
|
12738
|
-
type: {
|
|
12739
|
-
type: "string",
|
|
12740
|
-
description: "Message type: info, request, response, alert, handoff"
|
|
12741
|
-
},
|
|
12742
|
-
replyTo: {
|
|
12743
|
-
type: "string",
|
|
12744
|
-
description: "Signal ID to reply to (auto-threads)"
|
|
12745
|
-
}
|
|
12746
|
-
},
|
|
12747
|
-
required: ["from", "content"]
|
|
12748
|
-
}
|
|
12749
|
-
},
|
|
12750
|
-
{
|
|
12751
|
-
name: "memory_signal_read",
|
|
12752
|
-
description: "Read messages for an agent. Marks delivered messages as read.",
|
|
12753
|
-
inputSchema: {
|
|
12754
|
-
type: "object",
|
|
12755
|
-
properties: {
|
|
12756
|
-
agentId: {
|
|
12757
|
-
type: "string",
|
|
12758
|
-
description: "Agent to read messages for"
|
|
12759
|
-
},
|
|
12760
|
-
unreadOnly: {
|
|
12761
|
-
type: "string",
|
|
12762
|
-
description: "Set to 'true' for unread only"
|
|
12763
|
-
},
|
|
12764
|
-
threadId: {
|
|
12765
|
-
type: "string",
|
|
12766
|
-
description: "Filter by conversation thread"
|
|
12767
|
-
},
|
|
12768
|
-
limit: {
|
|
12769
|
-
type: "number",
|
|
12770
|
-
description: "Max messages (default 50)"
|
|
12771
|
-
}
|
|
12772
|
-
},
|
|
12773
|
-
required: ["agentId"]
|
|
12774
|
-
}
|
|
12775
|
-
},
|
|
12776
|
-
{
|
|
12777
|
-
name: "memory_checkpoint",
|
|
12778
|
-
description: "Create or resolve an external checkpoint (CI result, approval, deploy status) that gates action progress.",
|
|
12779
|
-
inputSchema: {
|
|
12780
|
-
type: "object",
|
|
12781
|
-
properties: {
|
|
12782
|
-
operation: {
|
|
12783
|
-
type: "string",
|
|
12784
|
-
description: "create, resolve, or list"
|
|
12785
|
-
},
|
|
12786
|
-
name: {
|
|
12787
|
-
type: "string",
|
|
12788
|
-
description: "Checkpoint name (for create)"
|
|
12789
|
-
},
|
|
12790
|
-
checkpointId: {
|
|
12791
|
-
type: "string",
|
|
12792
|
-
description: "Checkpoint ID (for resolve)"
|
|
12793
|
-
},
|
|
12794
|
-
status: {
|
|
12795
|
-
type: "string",
|
|
12796
|
-
description: "passed or failed (for resolve)"
|
|
12797
|
-
},
|
|
12798
|
-
type: {
|
|
12799
|
-
type: "string",
|
|
12800
|
-
description: "Checkpoint type: ci, approval, deploy, external, timer"
|
|
12801
|
-
},
|
|
12802
|
-
linkedActionIds: {
|
|
12803
|
-
type: "string",
|
|
12804
|
-
description: "Comma-separated action IDs this checkpoint gates (for create)"
|
|
12805
|
-
}
|
|
12806
|
-
},
|
|
12807
|
-
required: ["operation"]
|
|
12808
|
-
}
|
|
12809
|
-
},
|
|
12810
|
-
{
|
|
12811
|
-
name: "memory_mesh_sync",
|
|
12812
|
-
description: "Sync memories and actions with peer agentmemory instances for multi-agent collaboration.",
|
|
12813
|
-
inputSchema: {
|
|
12814
|
-
type: "object",
|
|
12815
|
-
properties: {
|
|
12816
|
-
peerId: {
|
|
12817
|
-
type: "string",
|
|
12818
|
-
description: "Specific peer ID (omit for all)"
|
|
12819
|
-
},
|
|
12820
|
-
direction: {
|
|
12821
|
-
type: "string",
|
|
12822
|
-
description: "push, pull, or both (default both)"
|
|
12823
|
-
}
|
|
12824
|
-
}
|
|
12825
|
-
}
|
|
12826
|
-
}
|
|
12827
|
-
];
|
|
12828
|
-
const V051_TOOLS = [
|
|
12829
|
-
{
|
|
12830
|
-
name: "memory_sentinel_create",
|
|
12831
|
-
description: "Create an event-driven sentinel that watches for conditions (webhook, timer, threshold, pattern, approval) and auto-unblocks gated actions when triggered.",
|
|
12832
|
-
inputSchema: {
|
|
12833
|
-
type: "object",
|
|
12834
|
-
properties: {
|
|
12835
|
-
name: {
|
|
12836
|
-
type: "string",
|
|
12837
|
-
description: "Sentinel name"
|
|
12838
|
-
},
|
|
12839
|
-
type: {
|
|
12840
|
-
type: "string",
|
|
12841
|
-
description: "Type: webhook, timer, threshold, pattern, approval, custom"
|
|
12842
|
-
},
|
|
12843
|
-
config: {
|
|
12844
|
-
type: "string",
|
|
12845
|
-
description: "JSON config (timer: {durationMs}, threshold: {metric,operator,value}, pattern: {pattern}, webhook: {path})"
|
|
12846
|
-
},
|
|
12847
|
-
linkedActionIds: {
|
|
12848
|
-
type: "string",
|
|
12849
|
-
description: "Comma-separated action IDs to gate"
|
|
12850
|
-
},
|
|
12851
|
-
expiresInMs: {
|
|
12852
|
-
type: "number",
|
|
12853
|
-
description: "Auto-expire after ms"
|
|
12854
|
-
}
|
|
12855
|
-
},
|
|
12856
|
-
required: ["name", "type"]
|
|
12857
|
-
}
|
|
12858
|
-
},
|
|
12859
|
-
{
|
|
12860
|
-
name: "memory_sentinel_trigger",
|
|
12861
|
-
description: "Externally fire a sentinel, providing an optional result payload. Unblocks any gated actions.",
|
|
12862
|
-
inputSchema: {
|
|
12863
|
-
type: "object",
|
|
12864
|
-
properties: {
|
|
12865
|
-
sentinelId: {
|
|
12866
|
-
type: "string",
|
|
12867
|
-
description: "Sentinel ID to trigger"
|
|
12868
|
-
},
|
|
12869
|
-
result: {
|
|
12870
|
-
type: "string",
|
|
12871
|
-
description: "JSON result payload"
|
|
12872
|
-
}
|
|
12873
|
-
},
|
|
12874
|
-
required: ["sentinelId"]
|
|
12875
|
-
}
|
|
12876
|
-
},
|
|
12877
|
-
{
|
|
12878
|
-
name: "memory_sketch_create",
|
|
12879
|
-
description: "Create an ephemeral action graph for exploratory work. Auto-expires after TTL. Can be promoted to permanent actions or discarded.",
|
|
12880
|
-
inputSchema: {
|
|
12881
|
-
type: "object",
|
|
12882
|
-
properties: {
|
|
12883
|
-
title: {
|
|
12884
|
-
type: "string",
|
|
12885
|
-
description: "Sketch title"
|
|
12886
|
-
},
|
|
12887
|
-
description: {
|
|
12888
|
-
type: "string",
|
|
12889
|
-
description: "What this sketch explores"
|
|
12890
|
-
},
|
|
12891
|
-
expiresInMs: {
|
|
12892
|
-
type: "number",
|
|
12893
|
-
description: "TTL in ms (default 1 hour)"
|
|
12894
|
-
},
|
|
12895
|
-
project: {
|
|
12896
|
-
type: "string",
|
|
12897
|
-
description: "Project context"
|
|
12898
|
-
}
|
|
12899
|
-
},
|
|
12900
|
-
required: ["title"]
|
|
12901
|
-
}
|
|
12902
|
-
},
|
|
12903
|
-
{
|
|
12904
|
-
name: "memory_sketch_promote",
|
|
12905
|
-
description: "Promote a sketch's ephemeral actions to permanent actions. Makes the exploratory work official.",
|
|
12906
|
-
inputSchema: {
|
|
12907
|
-
type: "object",
|
|
12908
|
-
properties: {
|
|
12909
|
-
sketchId: {
|
|
12910
|
-
type: "string",
|
|
12911
|
-
description: "Sketch ID to promote"
|
|
12912
|
-
},
|
|
12913
|
-
project: {
|
|
12914
|
-
type: "string",
|
|
12915
|
-
description: "Override project for promoted actions"
|
|
12916
|
-
}
|
|
12917
|
-
},
|
|
12918
|
-
required: ["sketchId"]
|
|
12919
|
-
}
|
|
12920
|
-
},
|
|
12921
|
-
{
|
|
12922
|
-
name: "memory_crystallize",
|
|
12923
|
-
description: "Compress completed action chains into compact crystal digests using LLM summarization. Extracts narrative, key outcomes, files affected, and lessons.",
|
|
12924
|
-
inputSchema: {
|
|
12925
|
-
type: "object",
|
|
12926
|
-
properties: {
|
|
12927
|
-
actionIds: {
|
|
12928
|
-
type: "string",
|
|
12929
|
-
description: "Comma-separated completed action IDs to crystallize"
|
|
12930
|
-
},
|
|
12931
|
-
project: {
|
|
12932
|
-
type: "string",
|
|
12933
|
-
description: "Project context"
|
|
12934
|
-
},
|
|
12935
|
-
sessionId: {
|
|
12936
|
-
type: "string",
|
|
12937
|
-
description: "Session context"
|
|
12938
|
-
}
|
|
12939
|
-
},
|
|
12940
|
-
required: ["actionIds"]
|
|
12941
|
-
}
|
|
12942
|
-
},
|
|
12943
|
-
{
|
|
12944
|
-
name: "memory_diagnose",
|
|
12945
|
-
description: "Run health checks across all subsystems (actions, leases, sentinels, sketches, signals, sessions, memories, mesh). Identifies stuck, orphaned, and inconsistent state.",
|
|
12946
|
-
inputSchema: {
|
|
12947
|
-
type: "object",
|
|
12948
|
-
properties: { categories: {
|
|
12949
|
-
type: "string",
|
|
12950
|
-
description: "Comma-separated categories to check (default all)"
|
|
12951
|
-
} }
|
|
12952
|
-
}
|
|
12953
|
-
},
|
|
12954
|
-
{
|
|
12955
|
-
name: "memory_heal",
|
|
12956
|
-
description: "Auto-fix all fixable issues found by diagnostics. Unblocks stuck actions, expires stale leases, cleans up orphaned data.",
|
|
12957
|
-
inputSchema: {
|
|
12958
|
-
type: "object",
|
|
12959
|
-
properties: {
|
|
12960
|
-
categories: {
|
|
12961
|
-
type: "string",
|
|
12962
|
-
description: "Comma-separated categories to heal (default all)"
|
|
12963
|
-
},
|
|
12964
|
-
dryRun: {
|
|
12965
|
-
type: "string",
|
|
12966
|
-
description: "Set to 'true' for dry run (report but don't fix)"
|
|
12967
|
-
}
|
|
12968
|
-
}
|
|
12969
|
-
}
|
|
12970
|
-
},
|
|
12971
|
-
{
|
|
12972
|
-
name: "memory_facet_tag",
|
|
12973
|
-
description: "Attach a structured tag (dimension:value) to an action, memory, or observation for multi-dimensional categorization.",
|
|
12974
|
-
inputSchema: {
|
|
12975
|
-
type: "object",
|
|
12976
|
-
properties: {
|
|
12977
|
-
targetId: {
|
|
12978
|
-
type: "string",
|
|
12979
|
-
description: "ID of the target to tag"
|
|
12980
|
-
},
|
|
12981
|
-
targetType: {
|
|
12982
|
-
type: "string",
|
|
12983
|
-
description: "Type: action, memory, or observation"
|
|
12984
|
-
},
|
|
12985
|
-
dimension: {
|
|
12986
|
-
type: "string",
|
|
12987
|
-
description: "Tag dimension (e.g., priority, team, status)"
|
|
12988
|
-
},
|
|
12989
|
-
value: {
|
|
12990
|
-
type: "string",
|
|
12991
|
-
description: "Tag value (e.g., urgent, backend, reviewed)"
|
|
12992
|
-
}
|
|
12993
|
-
},
|
|
12994
|
-
required: [
|
|
12995
|
-
"targetId",
|
|
12996
|
-
"targetType",
|
|
12997
|
-
"dimension",
|
|
12998
|
-
"value"
|
|
12999
|
-
]
|
|
13000
|
-
}
|
|
13001
|
-
},
|
|
13002
|
-
{
|
|
13003
|
-
name: "memory_facet_query",
|
|
13004
|
-
description: "Query targets by facet tags with AND/OR logic. Find all actions tagged priority:urgent AND team:backend.",
|
|
13005
|
-
inputSchema: {
|
|
13006
|
-
type: "object",
|
|
13007
|
-
properties: {
|
|
13008
|
-
matchAll: {
|
|
13009
|
-
type: "string",
|
|
13010
|
-
description: "Comma-separated dimension:value pairs (AND logic)"
|
|
13011
|
-
},
|
|
13012
|
-
matchAny: {
|
|
13013
|
-
type: "string",
|
|
13014
|
-
description: "Comma-separated dimension:value pairs (OR logic)"
|
|
13015
|
-
},
|
|
13016
|
-
targetType: {
|
|
13017
|
-
type: "string",
|
|
13018
|
-
description: "Filter by type: action, memory, or observation"
|
|
13019
|
-
}
|
|
13020
|
-
}
|
|
13021
|
-
}
|
|
13022
|
-
}
|
|
13023
|
-
];
|
|
13024
|
-
const V061_TOOLS = [{
|
|
13025
|
-
name: "memory_verify",
|
|
13026
|
-
description: "Verify a memory or observation by tracing its citation chain back to source observations and session context. Returns provenance information including confidence scores.",
|
|
13027
|
-
inputSchema: {
|
|
13028
|
-
type: "object",
|
|
13029
|
-
properties: { id: {
|
|
13030
|
-
type: "string",
|
|
13031
|
-
description: "Memory ID or observation ID to verify"
|
|
13032
|
-
} },
|
|
13033
|
-
required: ["id"]
|
|
13034
|
-
}
|
|
13035
|
-
}];
|
|
13036
|
-
const V070_TOOLS = [
|
|
13037
|
-
{
|
|
13038
|
-
name: "memory_lesson_save",
|
|
13039
|
-
description: "Save a lesson learned from this session. Lessons have confidence scores that strengthen when reinforced and decay when not used. Duplicate content auto-strengthens the existing lesson.",
|
|
13040
|
-
inputSchema: {
|
|
13041
|
-
type: "object",
|
|
13042
|
-
properties: {
|
|
13043
|
-
content: {
|
|
13044
|
-
type: "string",
|
|
13045
|
-
description: "The lesson learned (what worked, what to avoid, when to use X approach)"
|
|
13046
|
-
},
|
|
13047
|
-
context: {
|
|
13048
|
-
type: "string",
|
|
13049
|
-
description: "When/where this lesson applies"
|
|
13050
|
-
},
|
|
13051
|
-
confidence: {
|
|
13052
|
-
type: "number",
|
|
13053
|
-
description: "Initial confidence 0.0-1.0 (default 0.5)"
|
|
13054
|
-
},
|
|
13055
|
-
project: {
|
|
13056
|
-
type: "string",
|
|
13057
|
-
description: "Project this lesson is about"
|
|
13058
|
-
},
|
|
13059
|
-
tags: {
|
|
13060
|
-
type: "string",
|
|
13061
|
-
description: "Comma-separated tags"
|
|
13062
|
-
}
|
|
13063
|
-
},
|
|
13064
|
-
required: ["content"]
|
|
13065
|
-
}
|
|
13066
|
-
},
|
|
13067
|
-
{
|
|
13068
|
-
name: "memory_lesson_recall",
|
|
13069
|
-
description: "Search lessons by query. Returns lessons sorted by confidence and recency. Use to check what the agent has learned before making decisions.",
|
|
13070
|
-
inputSchema: {
|
|
13071
|
-
type: "object",
|
|
13072
|
-
properties: {
|
|
13073
|
-
query: {
|
|
13074
|
-
type: "string",
|
|
13075
|
-
description: "Search query"
|
|
13076
|
-
},
|
|
13077
|
-
project: {
|
|
13078
|
-
type: "string",
|
|
13079
|
-
description: "Filter by project"
|
|
13080
|
-
},
|
|
13081
|
-
minConfidence: {
|
|
13082
|
-
type: "number",
|
|
13083
|
-
description: "Minimum confidence threshold (default 0.1)"
|
|
13084
|
-
},
|
|
13085
|
-
limit: {
|
|
13086
|
-
type: "number",
|
|
13087
|
-
description: "Max results (default 10)"
|
|
13088
|
-
}
|
|
13089
|
-
},
|
|
13090
|
-
required: ["query"]
|
|
13091
|
-
}
|
|
13092
|
-
},
|
|
13093
|
-
{
|
|
13094
|
-
name: "memory_obsidian_export",
|
|
13095
|
-
description: "Export memories, lessons, and crystals as Obsidian-compatible Markdown files with YAML frontmatter and wikilinks for graph view.",
|
|
13096
|
-
inputSchema: {
|
|
13097
|
-
type: "object",
|
|
13098
|
-
properties: {
|
|
13099
|
-
vaultDir: {
|
|
13100
|
-
type: "string",
|
|
13101
|
-
description: "Output directory (default ~/.agentmemory/vault/)"
|
|
13102
|
-
},
|
|
13103
|
-
types: {
|
|
13104
|
-
type: "string",
|
|
13105
|
-
description: "Comma-separated types to export: memories,lessons,crystals,sessions (default all)"
|
|
13106
|
-
}
|
|
13107
|
-
}
|
|
13108
|
-
}
|
|
13109
|
-
}
|
|
13110
|
-
];
|
|
13111
|
-
const V073_TOOLS = [{
|
|
13112
|
-
name: "memory_reflect",
|
|
13113
|
-
description: "Traverse the knowledge graph, group related memories by concept clusters, and synthesize higher-order insights via LLM. Returns new and reinforced insights.",
|
|
13114
|
-
inputSchema: {
|
|
13115
|
-
type: "object",
|
|
13116
|
-
properties: {
|
|
13117
|
-
project: {
|
|
13118
|
-
type: "string",
|
|
13119
|
-
description: "Filter by project"
|
|
13120
|
-
},
|
|
13121
|
-
maxClusters: {
|
|
13122
|
-
type: "number",
|
|
13123
|
-
description: "Max concept clusters to process (default 10, max 20)"
|
|
13124
|
-
}
|
|
13125
|
-
}
|
|
13126
|
-
}
|
|
13127
|
-
}, {
|
|
13128
|
-
name: "memory_insight_list",
|
|
13129
|
-
description: "List synthesized insights — higher-order observations derived from patterns across memories, lessons, and crystals.",
|
|
13130
|
-
inputSchema: {
|
|
13131
|
-
type: "object",
|
|
13132
|
-
properties: {
|
|
13133
|
-
project: {
|
|
13134
|
-
type: "string",
|
|
13135
|
-
description: "Filter by project"
|
|
13136
|
-
},
|
|
13137
|
-
minConfidence: {
|
|
13138
|
-
type: "number",
|
|
13139
|
-
description: "Minimum confidence threshold (default 0)"
|
|
13140
|
-
},
|
|
13141
|
-
limit: {
|
|
13142
|
-
type: "number",
|
|
13143
|
-
description: "Max results (default 50)"
|
|
13144
|
-
}
|
|
13145
|
-
}
|
|
13146
|
-
}
|
|
13147
|
-
}];
|
|
13148
|
-
const ESSENTIAL_TOOLS = new Set([
|
|
13149
|
-
"memory_save",
|
|
13150
|
-
"memory_recall",
|
|
13151
|
-
"memory_consolidate",
|
|
13152
|
-
"memory_smart_search",
|
|
13153
|
-
"memory_sessions",
|
|
13154
|
-
"memory_diagnose",
|
|
13155
|
-
"memory_lesson_save",
|
|
13156
|
-
"memory_reflect"
|
|
13157
|
-
]);
|
|
13158
|
-
function getAllTools() {
|
|
13159
|
-
return [
|
|
13160
|
-
...CORE_TOOLS,
|
|
13161
|
-
...V040_TOOLS,
|
|
13162
|
-
...V050_TOOLS,
|
|
13163
|
-
...V051_TOOLS,
|
|
13164
|
-
...V061_TOOLS,
|
|
13165
|
-
...V070_TOOLS,
|
|
13166
|
-
...V073_TOOLS
|
|
13167
|
-
];
|
|
13168
|
-
}
|
|
13169
|
-
function getVisibleTools() {
|
|
13170
|
-
if ((process.env["AGENTMEMORY_TOOLS"] || "core") === "all") return getAllTools();
|
|
13171
|
-
return getAllTools().filter((t) => ESSENTIAL_TOOLS.has(t.name));
|
|
13172
|
-
}
|
|
13173
|
-
|
|
13174
12271
|
//#endregion
|
|
13175
12272
|
//#region src/mcp/server.ts
|
|
13176
12273
|
function registerMcpEndpoints(sdk, kv, secret) {
|
|
@@ -14440,11 +13537,6 @@ function readBody(req) {
|
|
|
14440
13537
|
req.on("error", reject);
|
|
14441
13538
|
});
|
|
14442
13539
|
}
|
|
14443
|
-
function checkAuth(req, secret) {
|
|
14444
|
-
if (!secret) return true;
|
|
14445
|
-
const auth = req.headers["authorization"] || "";
|
|
14446
|
-
return typeof auth === "string" && timingSafeCompare(auth, `Bearer ${secret}`);
|
|
14447
|
-
}
|
|
14448
13540
|
function startViewerServer(port, _kv, _sdk, secret, restPort) {
|
|
14449
13541
|
const resolvedRestPort = restPort ?? port - 2;
|
|
14450
13542
|
const server = createServer(async (req, res) => {
|
|
@@ -14462,30 +13554,20 @@ function startViewerServer(port, _kv, _sdk, secret, restPort) {
|
|
|
14462
13554
|
return;
|
|
14463
13555
|
}
|
|
14464
13556
|
if (method === "GET" && (pathname === "/" || pathname === "/viewer" || pathname === "/agentmemory/viewer")) {
|
|
14465
|
-
const
|
|
14466
|
-
|
|
14467
|
-
join(base, "..", "src", "viewer", "index.html"),
|
|
14468
|
-
join(base, "..", "viewer", "index.html"),
|
|
14469
|
-
join(base, "viewer", "index.html")
|
|
14470
|
-
];
|
|
14471
|
-
for (const p of candidates) try {
|
|
14472
|
-
const html = readFileSync(p, "utf-8");
|
|
13557
|
+
const rendered = renderViewerDocument();
|
|
13558
|
+
if (rendered.found) {
|
|
14473
13559
|
res.writeHead(200, {
|
|
14474
13560
|
"Content-Type": "text/html; charset=utf-8",
|
|
14475
|
-
"Content-Security-Policy":
|
|
13561
|
+
"Content-Security-Policy": rendered.csp,
|
|
14476
13562
|
"Cache-Control": "no-cache"
|
|
14477
13563
|
});
|
|
14478
|
-
res.end(html);
|
|
13564
|
+
res.end(rendered.html);
|
|
14479
13565
|
return;
|
|
14480
|
-
}
|
|
13566
|
+
}
|
|
14481
13567
|
res.writeHead(404, { "Content-Type": "text/plain" });
|
|
14482
13568
|
res.end("viewer not found");
|
|
14483
13569
|
return;
|
|
14484
13570
|
}
|
|
14485
|
-
if (!checkAuth(req, secret)) {
|
|
14486
|
-
json(res, 401, { error: "unauthorized" }, req);
|
|
14487
|
-
return;
|
|
14488
|
-
}
|
|
14489
13571
|
try {
|
|
14490
13572
|
await proxyToRestApi(resolvedRestPort, pathname, qs, method, req, res, secret);
|
|
14491
13573
|
} catch (err) {
|
|
@@ -14743,7 +13825,7 @@ async function main() {
|
|
|
14743
13825
|
registerRoutinesFunction(sdk, kv);
|
|
14744
13826
|
registerSignalsFunction(sdk, kv);
|
|
14745
13827
|
registerCheckpointsFunction(sdk, kv);
|
|
14746
|
-
registerMeshFunction(sdk, kv);
|
|
13828
|
+
registerMeshFunction(sdk, kv, secret);
|
|
14747
13829
|
registerBranchAwareFunction(sdk, kv);
|
|
14748
13830
|
registerFlowCompressFunction(sdk, kv, provider);
|
|
14749
13831
|
registerSentinelsFunction(sdk, kv);
|
|
@@ -14856,4 +13938,4 @@ main().catch((err) => {
|
|
|
14856
13938
|
|
|
14857
13939
|
//#endregion
|
|
14858
13940
|
export { };
|
|
14859
|
-
//# sourceMappingURL=src-
|
|
13941
|
+
//# sourceMappingURL=src-BuDB8dPq.mjs.map
|