@agentmemory/agentmemory 0.8.1 → 0.8.6

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.
@@ -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-BYzapMJi.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
- /(?:sk|pk|rk|ak)-[A-Za-z0-9]{20,}/g,
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
- /ghp_[A-Za-z0-9]{36}/g,
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 items = important.sort((a, b) => b.importance - a.importance).slice(0, 5).map((o) => `- [${o.type}] ${o.title}: ${o.narrative}`).join("\n");
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) await kv.delete(KV.memories, mem.id).catch(() => {});
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) await kv.delete(KV.memories, mem.id).catch(() => {});
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) await kv.delete(KV.memories, mem.id);
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.1";
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,
@@ -4016,7 +3892,12 @@ function registerExportImportFunction(sdk, kv) {
4016
3892
  "0.7.7",
4017
3893
  "0.7.9",
4018
3894
  "0.8.0",
4019
- "0.8.1"
3895
+ "0.8.1",
3896
+ "0.8.2",
3897
+ "0.8.3",
3898
+ "0.8.4",
3899
+ "0.8.5",
3900
+ "0.8.6"
4020
3901
  ]).has(importData.version)) return {
4021
3902
  success: false,
4022
3903
  error: `Unsupported export version: ${importData.version}`
@@ -4026,6 +3907,7 @@ function registerExportImportFunction(sdk, kv) {
4026
3907
  const MAX_SUMMARIES = 1e4;
4027
3908
  const MAX_OBS_PER_SESSION = 5e3;
4028
3909
  const MAX_TOTAL_OBSERVATIONS = 5e5;
3910
+ const MAX_ACCESS_LOGS = 5e4;
4029
3911
  if (!Array.isArray(importData.sessions)) return {
4030
3912
  success: false,
4031
3913
  error: "sessions must be an array"
@@ -4108,6 +3990,7 @@ function registerExportImportFunction(sdk, kv) {
4108
3990
  for (const e of await kv.list(KV.graphEdges).catch(() => [])) await kv.delete(KV.graphEdges, e.id);
4109
3991
  for (const s of await kv.list(KV.semantic).catch(() => [])) await kv.delete(KV.semantic, s.id);
4110
3992
  for (const p of await kv.list(KV.procedural).catch(() => [])) await kv.delete(KV.procedural, p.id);
3993
+ for (const a of await kv.list(KV.accessLog).catch(() => [])) await kv.delete(KV.accessLog, a.memoryId);
4111
3994
  }
4112
3995
  for (const session of importData.sessions) {
4113
3996
  if (strategy === "skip") {
@@ -4284,6 +4167,28 @@ function registerExportImportFunction(sdk, kv) {
4284
4167
  }
4285
4168
  await kv.set(KV.insights, insight.id, insight);
4286
4169
  }
4170
+ if (importData.accessLogs) {
4171
+ if (!Array.isArray(importData.accessLogs)) return {
4172
+ success: false,
4173
+ error: "accessLogs must be an array"
4174
+ };
4175
+ if (importData.accessLogs.length > MAX_ACCESS_LOGS) return {
4176
+ success: false,
4177
+ error: `Too many access logs (max ${MAX_ACCESS_LOGS})`
4178
+ };
4179
+ const memoryIds = new Set(importData.memories.map((m) => m.id));
4180
+ for (const raw of importData.accessLogs) {
4181
+ const log = normalizeAccessLog(raw);
4182
+ if (!log.memoryId || !memoryIds.has(log.memoryId)) continue;
4183
+ if (strategy === "skip") {
4184
+ if (await kv.get(KV.accessLog, log.memoryId).catch(() => null)) {
4185
+ stats.skipped++;
4186
+ continue;
4187
+ }
4188
+ }
4189
+ await kv.set(KV.accessLog, log.memoryId, log);
4190
+ }
4191
+ }
4287
4192
  ctx.logger.info("Import complete", {
4288
4193
  strategy,
4289
4194
  ...stats
@@ -5052,6 +4957,7 @@ function registerGovernanceFunction(sdk, kv) {
5052
4957
  let deleted = 0;
5053
4958
  for (const id of data.memoryIds) if (await kv.get(KV.memories, id)) {
5054
4959
  await kv.delete(KV.memories, id);
4960
+ await deleteAccessLog(kv, id);
5055
4961
  deleted++;
5056
4962
  }
5057
4963
  await recordAudit(kv, "delete", "mem::governance-delete", data.memoryIds, {
@@ -5099,7 +5005,10 @@ function registerGovernanceFunction(sdk, kv) {
5099
5005
  wouldDelete: candidates.length,
5100
5006
  ids: candidates.map((m) => m.id)
5101
5007
  };
5102
- for (const mem of candidates) await kv.delete(KV.memories, mem.id);
5008
+ for (const mem of candidates) {
5009
+ await kv.delete(KV.memories, mem.id);
5010
+ await deleteAccessLog(kv, mem.id);
5011
+ }
5103
5012
  await recordAudit(kv, "delete", "mem::governance-bulk", candidates.map((m) => m.id), {
5104
5013
  filter: data,
5105
5014
  deleted: candidates.length
@@ -5147,6 +5056,7 @@ function registerSnapshotFunction(sdk, kv, snapshotDir) {
5147
5056
  const sessions = await kv.list(KV.sessions);
5148
5057
  const memories = await kv.list(KV.memories);
5149
5058
  const graphNodes = await kv.list(KV.graphNodes);
5059
+ const accessLogs = await kv.list(KV.accessLog).catch(() => []);
5150
5060
  const observations = {};
5151
5061
  for (const session of sessions) {
5152
5062
  const obs = await kv.list(KV.observations(session.id)).catch(() => []);
@@ -5158,7 +5068,8 @@ function registerSnapshotFunction(sdk, kv, snapshotDir) {
5158
5068
  sessions,
5159
5069
  memories,
5160
5070
  graphNodes,
5161
- observations
5071
+ observations,
5072
+ accessLogs
5162
5073
  };
5163
5074
  writeFileSync(join(snapshotDir, "state.json"), JSON.stringify(state, null, 2), "utf-8");
5164
5075
  await gitExec(snapshotDir, ["add", "."]);
@@ -5250,6 +5161,7 @@ function registerSnapshotFunction(sdk, kv, snapshotDir) {
5250
5161
  if (state.memories) for (const memory of state.memories) await kv.set(KV.memories, memory.id, memory);
5251
5162
  if (state.graphNodes) for (const node of state.graphNodes) await kv.set(KV.graphNodes, node.id, node);
5252
5163
  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);
5164
+ if (state.accessLogs) for (const log of state.accessLogs) await kv.set(KV.accessLog, log.memoryId, log);
5253
5165
  await gitExec(snapshotDir, [
5254
5166
  "checkout",
5255
5167
  "HEAD",
@@ -6417,7 +6329,7 @@ async function lwwMergeGraphNodes(kv, items) {
6417
6329
  }
6418
6330
  return count;
6419
6331
  }
6420
- function registerMeshFunction(sdk, kv) {
6332
+ function registerMeshFunction(sdk, kv, meshAuthToken) {
6421
6333
  sdk.registerFunction({ id: "mem::mesh-register" }, async (data) => {
6422
6334
  if (!data.url || !data.name) return {
6423
6335
  success: false,
@@ -6454,6 +6366,10 @@ function registerMeshFunction(sdk, kv) {
6454
6366
  };
6455
6367
  });
6456
6368
  sdk.registerFunction({ id: "mem::mesh-sync" }, async (data) => {
6369
+ if (!meshAuthToken) return {
6370
+ success: false,
6371
+ error: "mesh sync requires AGENTMEMORY_SECRET"
6372
+ };
6457
6373
  const direction = data.direction || "both";
6458
6374
  let peers;
6459
6375
  if (data.peerId) {
@@ -6489,7 +6405,10 @@ function registerMeshFunction(sdk, kv) {
6489
6405
  try {
6490
6406
  const response = await fetch(`${peer.url}/agentmemory/mesh/receive`, {
6491
6407
  method: "POST",
6492
- headers: { "Content-Type": "application/json" },
6408
+ headers: {
6409
+ "Content-Type": "application/json",
6410
+ Authorization: `Bearer ${meshAuthToken}`
6411
+ },
6493
6412
  body: JSON.stringify(pushData),
6494
6413
  signal: AbortSignal.timeout(3e4),
6495
6414
  redirect: "error"
@@ -6502,6 +6421,7 @@ function registerMeshFunction(sdk, kv) {
6502
6421
  }
6503
6422
  if (direction === "pull" || direction === "both") try {
6504
6423
  const response = await fetch(`${peer.url}/agentmemory/mesh/export?since=${peer.lastSyncAt || ""}`, {
6424
+ headers: { Authorization: `Bearer ${meshAuthToken}` },
6505
6425
  signal: AbortSignal.timeout(3e4),
6506
6426
  redirect: "error"
6507
6427
  });
@@ -8362,7 +8282,16 @@ function registerLessonsFunctions(sdk, kv) {
8362
8282
 
8363
8283
  //#endregion
8364
8284
  //#region src/functions/obsidian-export.ts
8365
- const DEFAULT_VAULT = join(homedir(), ".agentmemory", "vault");
8285
+ const DEFAULT_EXPORT_ROOT = join(homedir(), ".agentmemory");
8286
+ function getExportRoot() {
8287
+ return resolve(process.env["AGENTMEMORY_EXPORT_ROOT"] || DEFAULT_EXPORT_ROOT);
8288
+ }
8289
+ function resolveVaultDir(vaultDir) {
8290
+ const root = getExportRoot();
8291
+ const resolved = resolve(vaultDir || join(root, "vault"));
8292
+ if (resolved === root || resolved.startsWith(root + sep)) return resolved;
8293
+ return null;
8294
+ }
8366
8295
  function sanitize(name) {
8367
8296
  return name.replace(/[<>:"/\\|?*\x00-\x1f]/g, "_").slice(0, 100);
8368
8297
  }
@@ -8475,7 +8404,11 @@ function sessionToMd(s) {
8475
8404
  }
8476
8405
  function registerObsidianExportFunction(sdk, kv) {
8477
8406
  sdk.registerFunction({ id: "mem::obsidian-export" }, async (data) => {
8478
- const vaultDir = data.vaultDir || DEFAULT_VAULT;
8407
+ const vaultDir = resolveVaultDir(data.vaultDir);
8408
+ if (!vaultDir) return {
8409
+ success: false,
8410
+ error: `vaultDir must be inside ${getExportRoot()}`
8411
+ };
8479
8412
  const exportTypes = new Set(data.types || [
8480
8413
  "memories",
8481
8414
  "lessons",
@@ -9021,12 +8954,15 @@ function registerWorkingMemoryFunctions(sdk, kv, tokenBudget) {
9021
8954
  if (Math.abs(strengthDiff) > .2) return strengthDiff;
9022
8955
  return new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime();
9023
8956
  });
8957
+ const archivalIds = [];
9024
8958
  for (const mem of active) {
9025
8959
  const tokens = estimateTokens(mem.content);
9026
8960
  if (usedTokens + tokens > budget) continue;
9027
8961
  archivalLines.push(`- [${mem.type}] ${mem.title}: ${mem.content}`);
8962
+ archivalIds.push(mem.id);
9028
8963
  usedTokens += tokens;
9029
8964
  }
8965
+ recordAccessBatch(kv, archivalIds);
9030
8966
  const pagedOut = active.length - archivalLines.length;
9031
8967
  const sections = [];
9032
8968
  if (coreLines.length > 0) sections.push(`## Core Memory\n${coreLines.join("\n")}`);
@@ -9780,17 +9716,15 @@ const DEFAULT_DECAY = {
9780
9716
  cold: .15
9781
9717
  }
9782
9718
  };
9783
- function computeRetention(salience, createdAt, accessTimestamps, config) {
9719
+ function computeReinforcementBoost(accessTimestamps, sigma) {
9784
9720
  const now = Date.now();
9785
- const deltaT = (now - new Date(createdAt).getTime()) / (1e3 * 60 * 60 * 24);
9786
- const temporalDecay = Math.exp(-config.lambda * deltaT);
9787
- let reinforcementBoost = 0;
9721
+ let boost = 0;
9788
9722
  for (const tAccess of accessTimestamps) {
9723
+ if (!Number.isFinite(tAccess)) continue;
9789
9724
  const daysSinceAccess = (now - tAccess) / (1e3 * 60 * 60 * 24);
9790
- if (daysSinceAccess > 0) reinforcementBoost += 1 / daysSinceAccess;
9725
+ if (daysSinceAccess > 0) boost += 1 / daysSinceAccess;
9791
9726
  }
9792
- reinforcementBoost *= config.sigma;
9793
- return Math.min(1, salience * temporalDecay + reinforcementBoost);
9727
+ return boost * sigma;
9794
9728
  }
9795
9729
  function computeSalience(memory, accessCount) {
9796
9730
  let baseSalience = .5;
@@ -9816,37 +9750,64 @@ function registerRetentionFunctions(sdk, kv) {
9816
9750
  ...DEFAULT_DECAY,
9817
9751
  ...data.config
9818
9752
  };
9819
- const memories = await kv.list(KV.memories);
9820
- const semanticMems = await kv.list(KV.semantic);
9753
+ const [memories, semanticMems, allLogs] = await Promise.all([
9754
+ kv.list(KV.memories),
9755
+ kv.list(KV.semantic),
9756
+ kv.list(KV.accessLog).catch(() => [])
9757
+ ]);
9758
+ const logsById = /* @__PURE__ */ new Map();
9759
+ for (const raw of allLogs) {
9760
+ const log = normalizeAccessLog(raw);
9761
+ if (log.memoryId) logsById.set(log.memoryId, log);
9762
+ }
9821
9763
  const scores = [];
9764
+ const computeDecay = (createdAt) => Math.exp(-config.lambda * ((Date.now() - new Date(createdAt).getTime()) / (1e3 * 60 * 60 * 24)));
9822
9765
  for (const mem of memories) {
9823
9766
  if (!mem.isLatest) continue;
9824
- const salience = computeSalience(mem, 0);
9825
- const score = computeRetention(salience, mem.createdAt, [], config);
9767
+ const log = logsById.get(mem.id) ?? emptyAccessLog(mem.id);
9768
+ const salience = computeSalience(mem, log.count);
9769
+ const temporalDecay = computeDecay(mem.createdAt);
9770
+ const reinforcementBoost = computeReinforcementBoost(log.recent, config.sigma);
9771
+ const score = Math.min(1, salience * temporalDecay + reinforcementBoost);
9826
9772
  const entry = {
9827
9773
  memoryId: mem.id,
9828
9774
  score,
9829
9775
  salience,
9830
- temporalDecay: Math.exp(-config.lambda * ((Date.now() - new Date(mem.createdAt).getTime()) / (1e3 * 60 * 60 * 24))),
9831
- reinforcementBoost: 0,
9832
- lastAccessed: mem.updatedAt,
9833
- accessCount: 0
9776
+ temporalDecay,
9777
+ reinforcementBoost,
9778
+ lastAccessed: log.lastAt || mem.updatedAt,
9779
+ accessCount: log.count
9834
9780
  };
9835
9781
  scores.push(entry);
9836
9782
  await kv.set(KV.retentionScores, mem.id, entry);
9837
9783
  }
9838
9784
  for (const sem of semanticMems) {
9839
- const accessTimestamps = sem.lastAccessedAt ? [new Date(sem.lastAccessedAt).getTime()] : [];
9840
- const salience = computeSalience(sem, sem.accessCount);
9841
- const score = computeRetention(salience, sem.createdAt, accessTimestamps, config);
9785
+ const log = logsById.get(sem.id) ?? emptyAccessLog(sem.id);
9786
+ let accessTimestamps;
9787
+ let effectiveCount;
9788
+ if (log.recent.length > 0 || log.count > 0) {
9789
+ accessTimestamps = log.recent;
9790
+ effectiveCount = log.count;
9791
+ } else if (sem.lastAccessedAt) {
9792
+ const legacyTs = Date.parse(sem.lastAccessedAt);
9793
+ accessTimestamps = Number.isFinite(legacyTs) ? [legacyTs] : [];
9794
+ effectiveCount = sem.accessCount;
9795
+ } else {
9796
+ accessTimestamps = [];
9797
+ effectiveCount = sem.accessCount;
9798
+ }
9799
+ const salience = computeSalience(sem, effectiveCount);
9800
+ const temporalDecay = computeDecay(sem.createdAt);
9801
+ const reinforcementBoost = computeReinforcementBoost(accessTimestamps, config.sigma);
9802
+ const score = Math.min(1, salience * temporalDecay + reinforcementBoost);
9842
9803
  const entry = {
9843
9804
  memoryId: sem.id,
9844
9805
  score,
9845
9806
  salience,
9846
- temporalDecay: Math.exp(-config.lambda * ((Date.now() - new Date(sem.createdAt).getTime()) / (1e3 * 60 * 60 * 24))),
9847
- reinforcementBoost: score - salience * Math.exp(-config.lambda * ((Date.now() - new Date(sem.createdAt).getTime()) / (1e3 * 60 * 60 * 24))),
9848
- lastAccessed: sem.lastAccessedAt,
9849
- accessCount: sem.accessCount
9807
+ temporalDecay,
9808
+ reinforcementBoost,
9809
+ lastAccessed: log.lastAt || sem.lastAccessedAt,
9810
+ accessCount: effectiveCount
9850
9811
  };
9851
9812
  scores.push(entry);
9852
9813
  await kv.set(KV.retentionScores, sem.id, entry);
@@ -9890,6 +9851,7 @@ function registerRetentionFunctions(sdk, kv) {
9890
9851
  for (const candidate of candidates) try {
9891
9852
  await kv.delete(KV.memories, candidate.memoryId);
9892
9853
  await kv.delete(KV.retentionScores, candidate.memoryId);
9854
+ await deleteAccessLog(kv, candidate.memoryId);
9893
9855
  evicted++;
9894
9856
  } catch {
9895
9857
  continue;
@@ -10045,14 +10007,57 @@ async function getLatestHealth(kv) {
10045
10007
  //#endregion
10046
10008
  //#region src/auth.ts
10047
10009
  const hmacKey = randomBytes(32);
10010
+ const VIEWER_NONCE_PLACEHOLDER = "__AGENTMEMORY_VIEWER_NONCE__";
10048
10011
  function timingSafeCompare(a, b) {
10049
10012
  return timingSafeEqual(createHmac("sha256", hmacKey).update(a).digest(), createHmac("sha256", hmacKey).update(b).digest());
10050
10013
  }
10051
- const VIEWER_CSP = "default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; connect-src 'self' ws://localhost:* wss://localhost:*; img-src 'self'; font-src 'self'";
10014
+ function createViewerNonce() {
10015
+ return randomBytes(16).toString("base64url");
10016
+ }
10017
+ function buildViewerCsp(nonce) {
10018
+ return [
10019
+ "default-src 'none'",
10020
+ "base-uri 'none'",
10021
+ "frame-ancestors 'none'",
10022
+ "object-src 'none'",
10023
+ "form-action 'none'",
10024
+ `script-src 'nonce-${nonce}'`,
10025
+ "script-src-attr 'none'",
10026
+ "style-src 'unsafe-inline'",
10027
+ "connect-src 'self' http://localhost:* http://127.0.0.1:* ws://localhost:* ws://127.0.0.1:* wss://localhost:* wss://127.0.0.1:*",
10028
+ "img-src 'self'",
10029
+ "font-src 'self'"
10030
+ ].join("; ");
10031
+ }
10032
+
10033
+ //#endregion
10034
+ //#region src/viewer/document.ts
10035
+ function loadViewerTemplate() {
10036
+ const base = dirname(fileURLToPath(import.meta.url));
10037
+ const candidates = [
10038
+ join(base, "..", "src", "viewer", "index.html"),
10039
+ join(base, "..", "viewer", "index.html"),
10040
+ join(base, "viewer", "index.html")
10041
+ ];
10042
+ for (const path of candidates) try {
10043
+ return readFileSync(path, "utf-8");
10044
+ } catch {}
10045
+ return null;
10046
+ }
10047
+ function renderViewerDocument() {
10048
+ const template = loadViewerTemplate();
10049
+ if (!template) return { found: false };
10050
+ const nonce = createViewerNonce();
10051
+ return {
10052
+ found: true,
10053
+ html: template.replaceAll(VIEWER_NONCE_PLACEHOLDER, nonce),
10054
+ csp: buildViewerCsp(nonce)
10055
+ };
10056
+ }
10052
10057
 
10053
10058
  //#endregion
10054
10059
  //#region src/triggers/api.ts
10055
- function checkAuth$1(req, secret) {
10060
+ function checkAuth(req, secret) {
10056
10061
  if (!secret) return null;
10057
10062
  const auth = req.headers?.["authorization"] || req.headers?.["Authorization"];
10058
10063
  if (typeof auth !== "string" || !timingSafeCompare(auth, `Bearer ${secret}`)) return {
@@ -10061,6 +10066,13 @@ function checkAuth$1(req, secret) {
10061
10066
  };
10062
10067
  return null;
10063
10068
  }
10069
+ function requireConfiguredSecret(secret, feature) {
10070
+ if (secret) return null;
10071
+ return {
10072
+ status_code: 503,
10073
+ body: { error: `${feature} requires AGENTMEMORY_SECRET` }
10074
+ };
10075
+ }
10064
10076
  function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10065
10077
  sdk.registerFunction({ id: "api::liveness" }, async () => ({
10066
10078
  status_code: 200,
@@ -10078,7 +10090,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10078
10090
  }
10079
10091
  });
10080
10092
  sdk.registerFunction({ id: "api::health" }, async (req) => {
10081
- const authErr = checkAuth$1(req, secret);
10093
+ const authErr = checkAuth(req, secret);
10082
10094
  if (authErr) return authErr;
10083
10095
  const health = await getLatestHealth(kv);
10084
10096
  const functionMetrics = metricsStore ? await metricsStore.getAll() : [];
@@ -10105,7 +10117,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10105
10117
  }
10106
10118
  });
10107
10119
  sdk.registerFunction({ id: "api::observe" }, async (req) => {
10108
- const authErr = checkAuth$1(req, secret);
10120
+ const authErr = checkAuth(req, secret);
10109
10121
  if (authErr) return authErr;
10110
10122
  return {
10111
10123
  status_code: 201,
@@ -10121,7 +10133,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10121
10133
  }
10122
10134
  });
10123
10135
  sdk.registerFunction({ id: "api::context" }, async (req) => {
10124
- const authErr = checkAuth$1(req, secret);
10136
+ const authErr = checkAuth(req, secret);
10125
10137
  if (authErr) return authErr;
10126
10138
  return {
10127
10139
  status_code: 200,
@@ -10137,7 +10149,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10137
10149
  }
10138
10150
  });
10139
10151
  sdk.registerFunction({ id: "api::search" }, async (req) => {
10140
- const authErr = checkAuth$1(req, secret);
10152
+ const authErr = checkAuth(req, secret);
10141
10153
  if (authErr) return authErr;
10142
10154
  const body = req.body ?? {};
10143
10155
  if (typeof body.query !== "string" || !body.query.trim()) return {
@@ -10176,7 +10188,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10176
10188
  }
10177
10189
  });
10178
10190
  sdk.registerFunction({ id: "api::session::start" }, async (req) => {
10179
- const authErr = checkAuth$1(req, secret);
10191
+ const authErr = checkAuth(req, secret);
10180
10192
  if (authErr) return authErr;
10181
10193
  const { sessionId, project, cwd } = req.body;
10182
10194
  const session = {
@@ -10208,7 +10220,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10208
10220
  }
10209
10221
  });
10210
10222
  sdk.registerFunction({ id: "api::session::end" }, async (req) => {
10211
- const authErr = checkAuth$1(req, secret);
10223
+ const authErr = checkAuth(req, secret);
10212
10224
  if (authErr) return authErr;
10213
10225
  const session = await kv.get(KV.sessions, req.body.sessionId);
10214
10226
  if (session) await kv.set(KV.sessions, req.body.sessionId, {
@@ -10230,7 +10242,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10230
10242
  }
10231
10243
  });
10232
10244
  sdk.registerFunction({ id: "api::summarize" }, async (req) => {
10233
- const authErr = checkAuth$1(req, secret);
10245
+ const authErr = checkAuth(req, secret);
10234
10246
  if (authErr) return authErr;
10235
10247
  return {
10236
10248
  status_code: 200,
@@ -10246,7 +10258,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10246
10258
  }
10247
10259
  });
10248
10260
  sdk.registerFunction({ id: "api::sessions" }, async (req) => {
10249
- const authErr = checkAuth$1(req, secret);
10261
+ const authErr = checkAuth(req, secret);
10250
10262
  if (authErr) return authErr;
10251
10263
  return {
10252
10264
  status_code: 200,
@@ -10262,7 +10274,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10262
10274
  }
10263
10275
  });
10264
10276
  sdk.registerFunction({ id: "api::observations" }, async (req) => {
10265
- const authErr = checkAuth$1(req, secret);
10277
+ const authErr = checkAuth(req, secret);
10266
10278
  if (authErr) return authErr;
10267
10279
  const sessionId = req.query_params["sessionId"];
10268
10280
  if (!sessionId) return {
@@ -10283,7 +10295,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10283
10295
  }
10284
10296
  });
10285
10297
  sdk.registerFunction({ id: "api::file-context" }, async (req) => {
10286
- const authErr = checkAuth$1(req, secret);
10298
+ const authErr = checkAuth(req, secret);
10287
10299
  if (authErr) return authErr;
10288
10300
  return {
10289
10301
  status_code: 200,
@@ -10299,7 +10311,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10299
10311
  }
10300
10312
  });
10301
10313
  sdk.registerFunction({ id: "api::enrich" }, async (req) => {
10302
- const authErr = checkAuth$1(req, secret);
10314
+ const authErr = checkAuth(req, secret);
10303
10315
  if (authErr) return authErr;
10304
10316
  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 {
10305
10317
  status_code: 400,
@@ -10323,7 +10335,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10323
10335
  }
10324
10336
  });
10325
10337
  sdk.registerFunction({ id: "api::remember" }, async (req) => {
10326
- const authErr = checkAuth$1(req, secret);
10338
+ const authErr = checkAuth(req, secret);
10327
10339
  if (authErr) return authErr;
10328
10340
  if (!req.body?.content || typeof req.body.content !== "string" || !req.body.content.trim()) return {
10329
10341
  status_code: 400,
@@ -10343,7 +10355,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10343
10355
  }
10344
10356
  });
10345
10357
  sdk.registerFunction({ id: "api::forget" }, async (req) => {
10346
- const authErr = checkAuth$1(req, secret);
10358
+ const authErr = checkAuth(req, secret);
10347
10359
  if (authErr) return authErr;
10348
10360
  if (!req.body?.sessionId && !req.body?.memoryId) return {
10349
10361
  status_code: 400,
@@ -10363,7 +10375,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10363
10375
  }
10364
10376
  });
10365
10377
  sdk.registerFunction({ id: "api::consolidate" }, async (req) => {
10366
- const authErr = checkAuth$1(req, secret);
10378
+ const authErr = checkAuth(req, secret);
10367
10379
  if (authErr) return authErr;
10368
10380
  return {
10369
10381
  status_code: 200,
@@ -10379,7 +10391,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10379
10391
  }
10380
10392
  });
10381
10393
  sdk.registerFunction({ id: "api::patterns" }, async (req) => {
10382
- const authErr = checkAuth$1(req, secret);
10394
+ const authErr = checkAuth(req, secret);
10383
10395
  if (authErr) return authErr;
10384
10396
  return {
10385
10397
  status_code: 200,
@@ -10395,7 +10407,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10395
10407
  }
10396
10408
  });
10397
10409
  sdk.registerFunction({ id: "api::generate-rules" }, async (req) => {
10398
- const authErr = checkAuth$1(req, secret);
10410
+ const authErr = checkAuth(req, secret);
10399
10411
  if (authErr) return authErr;
10400
10412
  return {
10401
10413
  status_code: 200,
@@ -10411,7 +10423,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10411
10423
  }
10412
10424
  });
10413
10425
  sdk.registerFunction({ id: "api::migrate" }, async (req) => {
10414
- const authErr = checkAuth$1(req, secret);
10426
+ const authErr = checkAuth(req, secret);
10415
10427
  if (authErr) return authErr;
10416
10428
  if (!req.body?.dbPath || typeof req.body.dbPath !== "string") return {
10417
10429
  status_code: 400,
@@ -10431,7 +10443,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10431
10443
  }
10432
10444
  });
10433
10445
  sdk.registerFunction({ id: "api::evict" }, async (req) => {
10434
- const authErr = checkAuth$1(req, secret);
10446
+ const authErr = checkAuth(req, secret);
10435
10447
  if (authErr) return authErr;
10436
10448
  const dryRun = req.query_params?.["dryRun"] === "true" || req.body?.dryRun === true;
10437
10449
  return {
@@ -10448,7 +10460,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10448
10460
  }
10449
10461
  });
10450
10462
  sdk.registerFunction({ id: "api::smart-search" }, async (req) => {
10451
- const authErr = checkAuth$1(req, secret);
10463
+ const authErr = checkAuth(req, secret);
10452
10464
  if (authErr) return authErr;
10453
10465
  if (!req.body?.query && (!req.body?.expandIds || req.body.expandIds.length === 0)) return {
10454
10466
  status_code: 400,
@@ -10468,7 +10480,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10468
10480
  }
10469
10481
  });
10470
10482
  sdk.registerFunction({ id: "api::timeline" }, async (req) => {
10471
- const authErr = checkAuth$1(req, secret);
10483
+ const authErr = checkAuth(req, secret);
10472
10484
  if (authErr) return authErr;
10473
10485
  if (!req.body?.anchor) return {
10474
10486
  status_code: 400,
@@ -10488,7 +10500,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10488
10500
  }
10489
10501
  });
10490
10502
  sdk.registerFunction({ id: "api::profile" }, async (req) => {
10491
- const authErr = checkAuth$1(req, secret);
10503
+ const authErr = checkAuth(req, secret);
10492
10504
  if (authErr) return authErr;
10493
10505
  const project = req.query_params["project"];
10494
10506
  if (!project) return {
@@ -10509,7 +10521,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10509
10521
  }
10510
10522
  });
10511
10523
  sdk.registerFunction({ id: "api::export" }, async (req) => {
10512
- const authErr = checkAuth$1(req, secret);
10524
+ const authErr = checkAuth(req, secret);
10513
10525
  if (authErr) return authErr;
10514
10526
  return {
10515
10527
  status_code: 200,
@@ -10525,7 +10537,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10525
10537
  }
10526
10538
  });
10527
10539
  sdk.registerFunction({ id: "api::import" }, async (req) => {
10528
- const authErr = checkAuth$1(req, secret);
10540
+ const authErr = checkAuth(req, secret);
10529
10541
  if (authErr) return authErr;
10530
10542
  if (!req.body?.exportData) return {
10531
10543
  status_code: 400,
@@ -10545,7 +10557,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10545
10557
  }
10546
10558
  });
10547
10559
  sdk.registerFunction({ id: "api::relations" }, async (req) => {
10548
- const authErr = checkAuth$1(req, secret);
10560
+ const authErr = checkAuth(req, secret);
10549
10561
  if (authErr) return authErr;
10550
10562
  if (!req.body?.sourceId || !req.body?.targetId || !req.body?.type) return {
10551
10563
  status_code: 400,
@@ -10565,7 +10577,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10565
10577
  }
10566
10578
  });
10567
10579
  sdk.registerFunction({ id: "api::evolve" }, async (req) => {
10568
- const authErr = checkAuth$1(req, secret);
10580
+ const authErr = checkAuth(req, secret);
10569
10581
  if (authErr) return authErr;
10570
10582
  if (!req.body?.memoryId || !req.body?.newContent) return {
10571
10583
  status_code: 400,
@@ -10585,7 +10597,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10585
10597
  }
10586
10598
  });
10587
10599
  sdk.registerFunction({ id: "api::auto-forget" }, async (req) => {
10588
- const authErr = checkAuth$1(req, secret);
10600
+ const authErr = checkAuth(req, secret);
10589
10601
  if (authErr) return authErr;
10590
10602
  const dryRun = req.query_params?.["dryRun"] === "true" || req.body?.dryRun === true;
10591
10603
  return {
@@ -10602,7 +10614,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10602
10614
  }
10603
10615
  });
10604
10616
  sdk.registerFunction({ id: "api::claude-bridge-read" }, async (req) => {
10605
- const authErr = checkAuth$1(req, secret);
10617
+ const authErr = checkAuth(req, secret);
10606
10618
  if (authErr) return authErr;
10607
10619
  try {
10608
10620
  return {
@@ -10625,7 +10637,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10625
10637
  }
10626
10638
  });
10627
10639
  sdk.registerFunction({ id: "api::claude-bridge-sync" }, async (req) => {
10628
- const authErr = checkAuth$1(req, secret);
10640
+ const authErr = checkAuth(req, secret);
10629
10641
  if (authErr) return authErr;
10630
10642
  try {
10631
10643
  return {
@@ -10648,7 +10660,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10648
10660
  }
10649
10661
  });
10650
10662
  sdk.registerFunction({ id: "api::graph-query" }, async (req) => {
10651
- const authErr = checkAuth$1(req, secret);
10663
+ const authErr = checkAuth(req, secret);
10652
10664
  if (authErr) return authErr;
10653
10665
  try {
10654
10666
  return {
@@ -10671,7 +10683,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10671
10683
  }
10672
10684
  });
10673
10685
  sdk.registerFunction({ id: "api::graph-stats" }, async (req) => {
10674
- const authErr = checkAuth$1(req, secret);
10686
+ const authErr = checkAuth(req, secret);
10675
10687
  if (authErr) return authErr;
10676
10688
  try {
10677
10689
  return {
@@ -10694,7 +10706,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10694
10706
  }
10695
10707
  });
10696
10708
  sdk.registerFunction({ id: "api::graph-extract" }, async (req) => {
10697
- const authErr = checkAuth$1(req, secret);
10709
+ const authErr = checkAuth(req, secret);
10698
10710
  if (authErr) return authErr;
10699
10711
  if (!Array.isArray(req.body?.observations) || req.body.observations.length === 0) return {
10700
10712
  status_code: 400,
@@ -10721,7 +10733,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10721
10733
  }
10722
10734
  });
10723
10735
  sdk.registerFunction({ id: "api::consolidate-pipeline" }, async (req) => {
10724
- const authErr = checkAuth$1(req, secret);
10736
+ const authErr = checkAuth(req, secret);
10725
10737
  if (authErr) return authErr;
10726
10738
  try {
10727
10739
  return {
@@ -10744,7 +10756,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10744
10756
  }
10745
10757
  });
10746
10758
  sdk.registerFunction({ id: "api::team-share" }, async (req) => {
10747
- const authErr = checkAuth$1(req, secret);
10759
+ const authErr = checkAuth(req, secret);
10748
10760
  if (authErr) return authErr;
10749
10761
  if (!req.body?.itemId || !req.body?.itemType) return {
10750
10762
  status_code: 400,
@@ -10771,7 +10783,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10771
10783
  }
10772
10784
  });
10773
10785
  sdk.registerFunction({ id: "api::team-feed" }, async (req) => {
10774
- const authErr = checkAuth$1(req, secret);
10786
+ const authErr = checkAuth(req, secret);
10775
10787
  if (authErr) return authErr;
10776
10788
  try {
10777
10789
  const limit = parseInt(req.query_params?.["limit"]) || 20;
@@ -10795,7 +10807,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10795
10807
  }
10796
10808
  });
10797
10809
  sdk.registerFunction({ id: "api::team-profile" }, async (req) => {
10798
- const authErr = checkAuth$1(req, secret);
10810
+ const authErr = checkAuth(req, secret);
10799
10811
  if (authErr) return authErr;
10800
10812
  try {
10801
10813
  return {
@@ -10818,7 +10830,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10818
10830
  }
10819
10831
  });
10820
10832
  sdk.registerFunction({ id: "api::audit" }, async (req) => {
10821
- const authErr = checkAuth$1(req, secret);
10833
+ const authErr = checkAuth(req, secret);
10822
10834
  if (authErr) return authErr;
10823
10835
  return {
10824
10836
  status_code: 200,
@@ -10837,7 +10849,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10837
10849
  }
10838
10850
  });
10839
10851
  sdk.registerFunction({ id: "api::governance-delete" }, async (req) => {
10840
- const authErr = checkAuth$1(req, secret);
10852
+ const authErr = checkAuth(req, secret);
10841
10853
  if (authErr) return authErr;
10842
10854
  if (!req.body?.memoryIds || !Array.isArray(req.body.memoryIds)) return {
10843
10855
  status_code: 400,
@@ -10857,7 +10869,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10857
10869
  }
10858
10870
  });
10859
10871
  sdk.registerFunction({ id: "api::governance-bulk" }, async (req) => {
10860
- const authErr = checkAuth$1(req, secret);
10872
+ const authErr = checkAuth(req, secret);
10861
10873
  if (authErr) return authErr;
10862
10874
  return {
10863
10875
  status_code: 200,
@@ -10873,7 +10885,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10873
10885
  }
10874
10886
  });
10875
10887
  sdk.registerFunction({ id: "api::snapshots" }, async (req) => {
10876
- const authErr = checkAuth$1(req, secret);
10888
+ const authErr = checkAuth(req, secret);
10877
10889
  if (authErr) return authErr;
10878
10890
  try {
10879
10891
  return {
@@ -10896,7 +10908,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10896
10908
  }
10897
10909
  });
10898
10910
  sdk.registerFunction({ id: "api::snapshot-create" }, async (req) => {
10899
- const authErr = checkAuth$1(req, secret);
10911
+ const authErr = checkAuth(req, secret);
10900
10912
  if (authErr) return authErr;
10901
10913
  try {
10902
10914
  return {
@@ -10919,7 +10931,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10919
10931
  }
10920
10932
  });
10921
10933
  sdk.registerFunction({ id: "api::snapshot-restore" }, async (req) => {
10922
- const authErr = checkAuth$1(req, secret);
10934
+ const authErr = checkAuth(req, secret);
10923
10935
  if (authErr) return authErr;
10924
10936
  if (!req.body?.commitHash) return {
10925
10937
  status_code: 400,
@@ -10946,7 +10958,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10946
10958
  }
10947
10959
  });
10948
10960
  sdk.registerFunction({ id: "api::memories" }, async (req) => {
10949
- const authErr = checkAuth$1(req, secret);
10961
+ const authErr = checkAuth(req, secret);
10950
10962
  if (authErr) return authErr;
10951
10963
  const memories = await kv.list(KV.memories);
10952
10964
  return {
@@ -10963,7 +10975,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10963
10975
  }
10964
10976
  });
10965
10977
  sdk.registerFunction({ id: "api::action-create" }, async (req) => {
10966
- const authErr = checkAuth$1(req, secret);
10978
+ const authErr = checkAuth(req, secret);
10967
10979
  if (authErr) return authErr;
10968
10980
  if (!req.body?.title) return {
10969
10981
  status_code: 400,
@@ -10983,7 +10995,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
10983
10995
  }
10984
10996
  });
10985
10997
  sdk.registerFunction({ id: "api::action-update" }, async (req) => {
10986
- const authErr = checkAuth$1(req, secret);
10998
+ const authErr = checkAuth(req, secret);
10987
10999
  if (authErr) return authErr;
10988
11000
  if (!req.body?.actionId) return {
10989
11001
  status_code: 400,
@@ -11003,7 +11015,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11003
11015
  }
11004
11016
  });
11005
11017
  sdk.registerFunction({ id: "api::action-list" }, async (req) => {
11006
- const authErr = checkAuth$1(req, secret);
11018
+ const authErr = checkAuth(req, secret);
11007
11019
  if (authErr) return authErr;
11008
11020
  return {
11009
11021
  status_code: 200,
@@ -11023,7 +11035,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11023
11035
  }
11024
11036
  });
11025
11037
  sdk.registerFunction({ id: "api::action-get" }, async (req) => {
11026
- const authErr = checkAuth$1(req, secret);
11038
+ const authErr = checkAuth(req, secret);
11027
11039
  if (authErr) return authErr;
11028
11040
  const actionId = req.query_params?.["actionId"];
11029
11041
  if (!actionId) return {
@@ -11044,7 +11056,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11044
11056
  }
11045
11057
  });
11046
11058
  sdk.registerFunction({ id: "api::action-edge" }, async (req) => {
11047
- const authErr = checkAuth$1(req, secret);
11059
+ const authErr = checkAuth(req, secret);
11048
11060
  if (authErr) return authErr;
11049
11061
  if (!req.body?.sourceActionId || !req.body?.targetActionId || !req.body?.type) return {
11050
11062
  status_code: 400,
@@ -11064,7 +11076,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11064
11076
  }
11065
11077
  });
11066
11078
  sdk.registerFunction({ id: "api::frontier" }, async (req) => {
11067
- const authErr = checkAuth$1(req, secret);
11079
+ const authErr = checkAuth(req, secret);
11068
11080
  if (authErr) return authErr;
11069
11081
  return {
11070
11082
  status_code: 200,
@@ -11084,7 +11096,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11084
11096
  }
11085
11097
  });
11086
11098
  sdk.registerFunction({ id: "api::next" }, async (req) => {
11087
- const authErr = checkAuth$1(req, secret);
11099
+ const authErr = checkAuth(req, secret);
11088
11100
  if (authErr) return authErr;
11089
11101
  return {
11090
11102
  status_code: 200,
@@ -11103,7 +11115,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11103
11115
  }
11104
11116
  });
11105
11117
  sdk.registerFunction({ id: "api::lease-acquire" }, async (req) => {
11106
- const authErr = checkAuth$1(req, secret);
11118
+ const authErr = checkAuth(req, secret);
11107
11119
  if (authErr) return authErr;
11108
11120
  if (!req.body?.actionId || !req.body?.agentId) return {
11109
11121
  status_code: 400,
@@ -11123,7 +11135,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11123
11135
  }
11124
11136
  });
11125
11137
  sdk.registerFunction({ id: "api::lease-release" }, async (req) => {
11126
- const authErr = checkAuth$1(req, secret);
11138
+ const authErr = checkAuth(req, secret);
11127
11139
  if (authErr) return authErr;
11128
11140
  if (!req.body?.actionId || !req.body?.agentId) return {
11129
11141
  status_code: 400,
@@ -11143,7 +11155,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11143
11155
  }
11144
11156
  });
11145
11157
  sdk.registerFunction({ id: "api::lease-renew" }, async (req) => {
11146
- const authErr = checkAuth$1(req, secret);
11158
+ const authErr = checkAuth(req, secret);
11147
11159
  if (authErr) return authErr;
11148
11160
  if (!req.body?.actionId || !req.body?.agentId) return {
11149
11161
  status_code: 400,
@@ -11163,7 +11175,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11163
11175
  }
11164
11176
  });
11165
11177
  sdk.registerFunction({ id: "api::routine-create" }, async (req) => {
11166
- const authErr = checkAuth$1(req, secret);
11178
+ const authErr = checkAuth(req, secret);
11167
11179
  if (authErr) return authErr;
11168
11180
  if (!req.body?.name) return {
11169
11181
  status_code: 400,
@@ -11183,7 +11195,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11183
11195
  }
11184
11196
  });
11185
11197
  sdk.registerFunction({ id: "api::routine-list" }, async (req) => {
11186
- const authErr = checkAuth$1(req, secret);
11198
+ const authErr = checkAuth(req, secret);
11187
11199
  if (authErr) return authErr;
11188
11200
  return {
11189
11201
  status_code: 200,
@@ -11199,7 +11211,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11199
11211
  }
11200
11212
  });
11201
11213
  sdk.registerFunction({ id: "api::routine-run" }, async (req) => {
11202
- const authErr = checkAuth$1(req, secret);
11214
+ const authErr = checkAuth(req, secret);
11203
11215
  if (authErr) return authErr;
11204
11216
  if (!req.body?.routineId) return {
11205
11217
  status_code: 400,
@@ -11219,7 +11231,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11219
11231
  }
11220
11232
  });
11221
11233
  sdk.registerFunction({ id: "api::routine-status" }, async (req) => {
11222
- const authErr = checkAuth$1(req, secret);
11234
+ const authErr = checkAuth(req, secret);
11223
11235
  if (authErr) return authErr;
11224
11236
  const runId = req.query_params?.["runId"];
11225
11237
  if (!runId) return {
@@ -11240,7 +11252,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11240
11252
  }
11241
11253
  });
11242
11254
  sdk.registerFunction({ id: "api::signal-send" }, async (req) => {
11243
- const authErr = checkAuth$1(req, secret);
11255
+ const authErr = checkAuth(req, secret);
11244
11256
  if (authErr) return authErr;
11245
11257
  if (!req.body?.from || !req.body?.content) return {
11246
11258
  status_code: 400,
@@ -11260,7 +11272,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11260
11272
  }
11261
11273
  });
11262
11274
  sdk.registerFunction({ id: "api::signal-read" }, async (req) => {
11263
- const authErr = checkAuth$1(req, secret);
11275
+ const authErr = checkAuth(req, secret);
11264
11276
  if (authErr) return authErr;
11265
11277
  const agentId = req.query_params?.["agentId"];
11266
11278
  if (!agentId) return {
@@ -11286,7 +11298,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11286
11298
  }
11287
11299
  });
11288
11300
  sdk.registerFunction({ id: "api::checkpoint-create" }, async (req) => {
11289
- const authErr = checkAuth$1(req, secret);
11301
+ const authErr = checkAuth(req, secret);
11290
11302
  if (authErr) return authErr;
11291
11303
  if (!req.body?.name) return {
11292
11304
  status_code: 400,
@@ -11306,7 +11318,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11306
11318
  }
11307
11319
  });
11308
11320
  sdk.registerFunction({ id: "api::checkpoint-resolve" }, async (req) => {
11309
- const authErr = checkAuth$1(req, secret);
11321
+ const authErr = checkAuth(req, secret);
11310
11322
  if (authErr) return authErr;
11311
11323
  if (!req.body?.checkpointId || !req.body?.status) return {
11312
11324
  status_code: 400,
@@ -11326,7 +11338,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11326
11338
  }
11327
11339
  });
11328
11340
  sdk.registerFunction({ id: "api::checkpoint-list" }, async (req) => {
11329
- const authErr = checkAuth$1(req, secret);
11341
+ const authErr = checkAuth(req, secret);
11330
11342
  if (authErr) return authErr;
11331
11343
  return {
11332
11344
  status_code: 200,
@@ -11345,7 +11357,9 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11345
11357
  }
11346
11358
  });
11347
11359
  sdk.registerFunction({ id: "api::mesh-register" }, async (req) => {
11348
- const authErr = checkAuth$1(req, secret);
11360
+ const secretErr = requireConfiguredSecret(secret, "mesh");
11361
+ if (secretErr) return secretErr;
11362
+ const authErr = checkAuth(req, secret);
11349
11363
  if (authErr) return authErr;
11350
11364
  if (!req.body?.url || !req.body?.name) return {
11351
11365
  status_code: 400,
@@ -11365,7 +11379,9 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11365
11379
  }
11366
11380
  });
11367
11381
  sdk.registerFunction({ id: "api::mesh-list" }, async (req) => {
11368
- const authErr = checkAuth$1(req, secret);
11382
+ const secretErr = requireConfiguredSecret(secret, "mesh");
11383
+ if (secretErr) return secretErr;
11384
+ const authErr = checkAuth(req, secret);
11369
11385
  if (authErr) return authErr;
11370
11386
  return {
11371
11387
  status_code: 200,
@@ -11381,7 +11397,9 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11381
11397
  }
11382
11398
  });
11383
11399
  sdk.registerFunction({ id: "api::mesh-sync" }, async (req) => {
11384
- const authErr = checkAuth$1(req, secret);
11400
+ const secretErr = requireConfiguredSecret(secret, "mesh");
11401
+ if (secretErr) return secretErr;
11402
+ const authErr = checkAuth(req, secret);
11385
11403
  if (authErr) return authErr;
11386
11404
  return {
11387
11405
  status_code: 200,
@@ -11397,7 +11415,9 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11397
11415
  }
11398
11416
  });
11399
11417
  sdk.registerFunction({ id: "api::mesh-receive" }, async (req) => {
11400
- const authErr = checkAuth$1(req, secret);
11418
+ const secretErr = requireConfiguredSecret(secret, "mesh");
11419
+ if (secretErr) return secretErr;
11420
+ const authErr = checkAuth(req, secret);
11401
11421
  if (authErr) return authErr;
11402
11422
  return {
11403
11423
  status_code: 200,
@@ -11413,7 +11433,9 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11413
11433
  }
11414
11434
  });
11415
11435
  sdk.registerFunction({ id: "api::mesh-export" }, async (req) => {
11416
- const authErr = checkAuth$1(req, secret);
11436
+ const secretErr = requireConfiguredSecret(secret, "mesh");
11437
+ if (secretErr) return secretErr;
11438
+ const authErr = checkAuth(req, secret);
11417
11439
  if (authErr) return authErr;
11418
11440
  const since = req.query_params?.["since"];
11419
11441
  if (since) {
@@ -11459,7 +11481,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11459
11481
  }
11460
11482
  });
11461
11483
  sdk.registerFunction({ id: "api::flow-compress" }, async (req) => {
11462
- const authErr = checkAuth$1(req, secret);
11484
+ const authErr = checkAuth(req, secret);
11463
11485
  if (authErr) return authErr;
11464
11486
  try {
11465
11487
  return {
@@ -11482,7 +11504,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11482
11504
  }
11483
11505
  });
11484
11506
  sdk.registerFunction({ id: "api::branch-detect" }, async (req) => {
11485
- const authErr = checkAuth$1(req, secret);
11507
+ const authErr = checkAuth(req, secret);
11486
11508
  if (authErr) return authErr;
11487
11509
  const cwd = req.query_params?.["cwd"] || process.cwd();
11488
11510
  return {
@@ -11499,7 +11521,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11499
11521
  }
11500
11522
  });
11501
11523
  sdk.registerFunction({ id: "api::branch-worktrees" }, async (req) => {
11502
- const authErr = checkAuth$1(req, secret);
11524
+ const authErr = checkAuth(req, secret);
11503
11525
  if (authErr) return authErr;
11504
11526
  const cwd = req.query_params?.["cwd"] || process.cwd();
11505
11527
  return {
@@ -11516,7 +11538,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11516
11538
  }
11517
11539
  });
11518
11540
  sdk.registerFunction({ id: "api::branch-sessions" }, async (req) => {
11519
- const authErr = checkAuth$1(req, secret);
11541
+ const authErr = checkAuth(req, secret);
11520
11542
  if (authErr) return authErr;
11521
11543
  const cwd = req.query_params?.["cwd"] || process.cwd();
11522
11544
  return {
@@ -11532,27 +11554,21 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11532
11554
  http_method: "GET"
11533
11555
  }
11534
11556
  });
11535
- sdk.registerFunction({ id: "api::viewer" }, async () => {
11536
- const headers = {
11537
- "Content-Type": "text/html",
11538
- "Content-Security-Policy": VIEWER_CSP
11557
+ sdk.registerFunction({ id: "api::viewer" }, async (req) => {
11558
+ const denied = checkAuth(req, secret);
11559
+ if (denied) return denied;
11560
+ const rendered = renderViewerDocument();
11561
+ if (rendered.found) return {
11562
+ status_code: 200,
11563
+ headers: {
11564
+ "Content-Type": "text/html",
11565
+ "Content-Security-Policy": rendered.csp
11566
+ },
11567
+ body: rendered.html
11539
11568
  };
11540
- const base = dirname(fileURLToPath(import.meta.url));
11541
- const candidates = [
11542
- join(base, "..", "viewer", "index.html"),
11543
- join(base, "..", "src", "viewer", "index.html"),
11544
- join(base, "viewer", "index.html")
11545
- ];
11546
- for (const p of candidates) try {
11547
- return {
11548
- status_code: 200,
11549
- headers,
11550
- body: readFileSync(p, "utf-8")
11551
- };
11552
- } catch {}
11553
11569
  return {
11554
11570
  status_code: 404,
11555
- headers,
11571
+ headers: { "Content-Type": "text/html" },
11556
11572
  body: "<!DOCTYPE html><html><body><h1>agentmemory</h1><p>viewer not found</p></body></html>"
11557
11573
  };
11558
11574
  });
@@ -11565,7 +11581,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11565
11581
  }
11566
11582
  });
11567
11583
  sdk.registerFunction({ id: "api::sentinel-create" }, async (req) => {
11568
- const denied = checkAuth$1(req, secret);
11584
+ const denied = checkAuth(req, secret);
11569
11585
  if (denied) return denied;
11570
11586
  const body = req.body;
11571
11587
  if (!body?.name) return {
@@ -11586,7 +11602,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11586
11602
  }
11587
11603
  });
11588
11604
  sdk.registerFunction({ id: "api::sentinel-trigger" }, async (req) => {
11589
- const denied = checkAuth$1(req, secret);
11605
+ const denied = checkAuth(req, secret);
11590
11606
  if (denied) return denied;
11591
11607
  const body = req.body;
11592
11608
  if (!body?.sentinelId) return {
@@ -11607,7 +11623,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11607
11623
  }
11608
11624
  });
11609
11625
  sdk.registerFunction({ id: "api::sentinel-check" }, async (req) => {
11610
- const denied = checkAuth$1(req, secret);
11626
+ const denied = checkAuth(req, secret);
11611
11627
  if (denied) return denied;
11612
11628
  return {
11613
11629
  status_code: 200,
@@ -11623,7 +11639,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11623
11639
  }
11624
11640
  });
11625
11641
  sdk.registerFunction({ id: "api::sentinel-cancel" }, async (req) => {
11626
- const denied = checkAuth$1(req, secret);
11642
+ const denied = checkAuth(req, secret);
11627
11643
  if (denied) return denied;
11628
11644
  const body = req.body;
11629
11645
  if (!body?.sentinelId) return {
@@ -11644,7 +11660,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11644
11660
  }
11645
11661
  });
11646
11662
  sdk.registerFunction({ id: "api::sentinel-list" }, async (req) => {
11647
- const denied = checkAuth$1(req, secret);
11663
+ const denied = checkAuth(req, secret);
11648
11664
  if (denied) return denied;
11649
11665
  const params = req.query_params || {};
11650
11666
  return {
@@ -11664,7 +11680,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11664
11680
  }
11665
11681
  });
11666
11682
  sdk.registerFunction({ id: "api::sketch-create" }, async (req) => {
11667
- const denied = checkAuth$1(req, secret);
11683
+ const denied = checkAuth(req, secret);
11668
11684
  if (denied) return denied;
11669
11685
  const body = req.body;
11670
11686
  if (!body?.title) return {
@@ -11685,7 +11701,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11685
11701
  }
11686
11702
  });
11687
11703
  sdk.registerFunction({ id: "api::sketch-add" }, async (req) => {
11688
- const denied = checkAuth$1(req, secret);
11704
+ const denied = checkAuth(req, secret);
11689
11705
  if (denied) return denied;
11690
11706
  const body = req.body;
11691
11707
  if (!body?.sketchId || !body?.title) return {
@@ -11706,7 +11722,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11706
11722
  }
11707
11723
  });
11708
11724
  sdk.registerFunction({ id: "api::sketch-promote" }, async (req) => {
11709
- const denied = checkAuth$1(req, secret);
11725
+ const denied = checkAuth(req, secret);
11710
11726
  if (denied) return denied;
11711
11727
  const body = req.body;
11712
11728
  if (!body?.sketchId) return {
@@ -11727,7 +11743,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11727
11743
  }
11728
11744
  });
11729
11745
  sdk.registerFunction({ id: "api::sketch-discard" }, async (req) => {
11730
- const denied = checkAuth$1(req, secret);
11746
+ const denied = checkAuth(req, secret);
11731
11747
  if (denied) return denied;
11732
11748
  const body = req.body;
11733
11749
  if (!body?.sketchId) return {
@@ -11748,7 +11764,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11748
11764
  }
11749
11765
  });
11750
11766
  sdk.registerFunction({ id: "api::sketch-list" }, async (req) => {
11751
- const denied = checkAuth$1(req, secret);
11767
+ const denied = checkAuth(req, secret);
11752
11768
  if (denied) return denied;
11753
11769
  const params = req.query_params || {};
11754
11770
  return {
@@ -11768,7 +11784,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11768
11784
  }
11769
11785
  });
11770
11786
  sdk.registerFunction({ id: "api::sketch-gc" }, async (req) => {
11771
- const denied = checkAuth$1(req, secret);
11787
+ const denied = checkAuth(req, secret);
11772
11788
  if (denied) return denied;
11773
11789
  return {
11774
11790
  status_code: 200,
@@ -11784,7 +11800,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11784
11800
  }
11785
11801
  });
11786
11802
  sdk.registerFunction({ id: "api::crystallize" }, async (req) => {
11787
- const denied = checkAuth$1(req, secret);
11803
+ const denied = checkAuth(req, secret);
11788
11804
  if (denied) return denied;
11789
11805
  const body = req.body;
11790
11806
  if (!body?.actionIds) return {
@@ -11805,7 +11821,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11805
11821
  }
11806
11822
  });
11807
11823
  sdk.registerFunction({ id: "api::crystal-list" }, async (req) => {
11808
- const denied = checkAuth$1(req, secret);
11824
+ const denied = checkAuth(req, secret);
11809
11825
  if (denied) return denied;
11810
11826
  const params = req.query_params || {};
11811
11827
  return {
@@ -11826,7 +11842,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11826
11842
  }
11827
11843
  });
11828
11844
  sdk.registerFunction({ id: "api::auto-crystallize" }, async (req) => {
11829
- const denied = checkAuth$1(req, secret);
11845
+ const denied = checkAuth(req, secret);
11830
11846
  if (denied) return denied;
11831
11847
  const body = req.body;
11832
11848
  return {
@@ -11843,7 +11859,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11843
11859
  }
11844
11860
  });
11845
11861
  sdk.registerFunction({ id: "api::diagnose" }, async (req) => {
11846
- const denied = checkAuth$1(req, secret);
11862
+ const denied = checkAuth(req, secret);
11847
11863
  if (denied) return denied;
11848
11864
  const body = req.body;
11849
11865
  return {
@@ -11860,7 +11876,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11860
11876
  }
11861
11877
  });
11862
11878
  sdk.registerFunction({ id: "api::heal" }, async (req) => {
11863
- const denied = checkAuth$1(req, secret);
11879
+ const denied = checkAuth(req, secret);
11864
11880
  if (denied) return denied;
11865
11881
  const body = req.body;
11866
11882
  return {
@@ -11877,7 +11893,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11877
11893
  }
11878
11894
  });
11879
11895
  sdk.registerFunction({ id: "api::facet-tag" }, async (req) => {
11880
- const denied = checkAuth$1(req, secret);
11896
+ const denied = checkAuth(req, secret);
11881
11897
  if (denied) return denied;
11882
11898
  const body = req.body;
11883
11899
  if (!body?.targetId || !body?.dimension || !body?.value) return {
@@ -11898,7 +11914,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11898
11914
  }
11899
11915
  });
11900
11916
  sdk.registerFunction({ id: "api::facet-untag" }, async (req) => {
11901
- const denied = checkAuth$1(req, secret);
11917
+ const denied = checkAuth(req, secret);
11902
11918
  if (denied) return denied;
11903
11919
  const body = req.body;
11904
11920
  if (!body?.targetId || !body?.dimension) return {
@@ -11919,7 +11935,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11919
11935
  }
11920
11936
  });
11921
11937
  sdk.registerFunction({ id: "api::facet-query" }, async (req) => {
11922
- const denied = checkAuth$1(req, secret);
11938
+ const denied = checkAuth(req, secret);
11923
11939
  if (denied) return denied;
11924
11940
  const body = req.body;
11925
11941
  return {
@@ -11936,7 +11952,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11936
11952
  }
11937
11953
  });
11938
11954
  sdk.registerFunction({ id: "api::facet-get" }, async (req) => {
11939
- const denied = checkAuth$1(req, secret);
11955
+ const denied = checkAuth(req, secret);
11940
11956
  if (denied) return denied;
11941
11957
  const params = req.query_params || {};
11942
11958
  if (!params.targetId) return {
@@ -11957,7 +11973,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11957
11973
  }
11958
11974
  });
11959
11975
  sdk.registerFunction({ id: "api::facet-stats" }, async (req) => {
11960
- const denied = checkAuth$1(req, secret);
11976
+ const denied = checkAuth(req, secret);
11961
11977
  if (denied) return denied;
11962
11978
  const params = req.query_params || {};
11963
11979
  return {
@@ -11974,7 +11990,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11974
11990
  }
11975
11991
  });
11976
11992
  sdk.registerFunction({ id: "api::verify" }, async (req) => {
11977
- const denied = checkAuth$1(req, secret);
11993
+ const denied = checkAuth(req, secret);
11978
11994
  if (denied) return denied;
11979
11995
  const body = req.body;
11980
11996
  if (!body?.id || typeof body.id !== "string") return {
@@ -11995,7 +12011,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
11995
12011
  }
11996
12012
  });
11997
12013
  sdk.registerFunction({ id: "api::cascade-update" }, async (req) => {
11998
- const denied = checkAuth$1(req, secret);
12014
+ const denied = checkAuth(req, secret);
11999
12015
  if (denied) return denied;
12000
12016
  const body = req.body;
12001
12017
  if (!body?.supersededMemoryId || typeof body.supersededMemoryId !== "string") return {
@@ -12016,7 +12032,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
12016
12032
  }
12017
12033
  });
12018
12034
  sdk.registerFunction({ id: "api::lesson-save" }, async (req) => {
12019
- const denied = checkAuth$1(req, secret);
12035
+ const denied = checkAuth(req, secret);
12020
12036
  if (denied) return denied;
12021
12037
  const body = req.body;
12022
12038
  if (!body?.content || typeof body.content !== "string") return {
@@ -12046,7 +12062,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
12046
12062
  }
12047
12063
  });
12048
12064
  sdk.registerFunction({ id: "api::lesson-list" }, async (req) => {
12049
- const denied = checkAuth$1(req, secret);
12065
+ const denied = checkAuth(req, secret);
12050
12066
  if (denied) return denied;
12051
12067
  const params = req.query_params || {};
12052
12068
  return {
@@ -12068,7 +12084,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
12068
12084
  }
12069
12085
  });
12070
12086
  sdk.registerFunction({ id: "api::lesson-search" }, async (req) => {
12071
- const denied = checkAuth$1(req, secret);
12087
+ const denied = checkAuth(req, secret);
12072
12088
  if (denied) return denied;
12073
12089
  const body = req.body;
12074
12090
  if (!body?.query || typeof body.query !== "string") return {
@@ -12089,7 +12105,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
12089
12105
  }
12090
12106
  });
12091
12107
  sdk.registerFunction({ id: "api::lesson-strengthen" }, async (req) => {
12092
- const denied = checkAuth$1(req, secret);
12108
+ const denied = checkAuth(req, secret);
12093
12109
  if (denied) return denied;
12094
12110
  const body = req.body;
12095
12111
  if (!body?.lessonId || typeof body.lessonId !== "string") return {
@@ -12110,7 +12126,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
12110
12126
  }
12111
12127
  });
12112
12128
  sdk.registerFunction({ id: "api::obsidian-export" }, async (req) => {
12113
- const denied = checkAuth$1(req, secret);
12129
+ const denied = checkAuth(req, secret);
12114
12130
  if (denied) return denied;
12115
12131
  const body = req.body || {};
12116
12132
  const types = typeof body.types === "string" ? body.types.split(",").map((t) => t.trim()).filter(Boolean) : void 0;
@@ -12131,7 +12147,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
12131
12147
  }
12132
12148
  });
12133
12149
  sdk.registerFunction({ id: "api::reflect" }, async (req) => {
12134
- const denied = checkAuth$1(req, secret);
12150
+ const denied = checkAuth(req, secret);
12135
12151
  if (denied) return denied;
12136
12152
  const body = req.body || {};
12137
12153
  return {
@@ -12151,7 +12167,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
12151
12167
  }
12152
12168
  });
12153
12169
  sdk.registerFunction({ id: "api::insight-list" }, async (req) => {
12154
- const denied = checkAuth$1(req, secret);
12170
+ const denied = checkAuth(req, secret);
12155
12171
  if (denied) return denied;
12156
12172
  const params = req.query_params || {};
12157
12173
  return {
@@ -12172,7 +12188,7 @@ function registerApiTriggers(sdk, kv, secret, metricsStore, provider) {
12172
12188
  }
12173
12189
  });
12174
12190
  sdk.registerFunction({ id: "api::insight-search" }, async (req) => {
12175
- const denied = checkAuth$1(req, secret);
12191
+ const denied = checkAuth(req, secret);
12176
12192
  if (denied) return denied;
12177
12193
  const body = req.body;
12178
12194
  if (!body?.query || typeof body.query !== "string") return {
@@ -12253,925 +12269,6 @@ function registerEventTriggers(sdk, kv) {
12253
12269
  });
12254
12270
  }
12255
12271
 
12256
- //#endregion
12257
- //#region src/mcp/tools-registry.ts
12258
- const CORE_TOOLS = [
12259
- {
12260
- name: "memory_recall",
12261
- 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.",
12262
- inputSchema: {
12263
- type: "object",
12264
- properties: {
12265
- query: {
12266
- type: "string",
12267
- description: "Search query (keywords, file names, concepts)"
12268
- },
12269
- limit: {
12270
- type: "number",
12271
- description: "Max results to return (default 10)"
12272
- }
12273
- },
12274
- required: ["query"]
12275
- }
12276
- },
12277
- {
12278
- name: "memory_save",
12279
- description: "Explicitly save an important insight, decision, or pattern to long-term memory.",
12280
- inputSchema: {
12281
- type: "object",
12282
- properties: {
12283
- content: {
12284
- type: "string",
12285
- description: "The insight or decision to remember"
12286
- },
12287
- type: {
12288
- type: "string",
12289
- description: "Memory type: pattern, preference, architecture, bug, workflow, or fact"
12290
- },
12291
- concepts: {
12292
- type: "string",
12293
- description: "Comma-separated key concepts"
12294
- },
12295
- files: {
12296
- type: "string",
12297
- description: "Comma-separated relevant file paths"
12298
- }
12299
- },
12300
- required: ["content"]
12301
- }
12302
- },
12303
- {
12304
- name: "memory_file_history",
12305
- description: "Get past observations about specific files.",
12306
- inputSchema: {
12307
- type: "object",
12308
- properties: {
12309
- files: {
12310
- type: "string",
12311
- description: "Comma-separated file paths"
12312
- },
12313
- sessionId: {
12314
- type: "string",
12315
- description: "Current session ID to exclude"
12316
- }
12317
- },
12318
- required: ["files"]
12319
- }
12320
- },
12321
- {
12322
- name: "memory_patterns",
12323
- description: "Detect recurring patterns across sessions.",
12324
- inputSchema: {
12325
- type: "object",
12326
- properties: { project: {
12327
- type: "string",
12328
- description: "Project path to analyze"
12329
- } }
12330
- }
12331
- },
12332
- {
12333
- name: "memory_sessions",
12334
- description: "List recent sessions with their status and observation counts.",
12335
- inputSchema: {
12336
- type: "object",
12337
- properties: {}
12338
- }
12339
- },
12340
- {
12341
- name: "memory_smart_search",
12342
- description: "Hybrid semantic+keyword search with progressive disclosure.",
12343
- inputSchema: {
12344
- type: "object",
12345
- properties: {
12346
- query: {
12347
- type: "string",
12348
- description: "Search query"
12349
- },
12350
- expandIds: {
12351
- type: "string",
12352
- description: "Comma-separated observation IDs to expand"
12353
- },
12354
- limit: {
12355
- type: "number",
12356
- description: "Max results (default 10)"
12357
- }
12358
- },
12359
- required: ["query"]
12360
- }
12361
- },
12362
- {
12363
- name: "memory_timeline",
12364
- description: "Chronological observations around an anchor point.",
12365
- inputSchema: {
12366
- type: "object",
12367
- properties: {
12368
- anchor: {
12369
- type: "string",
12370
- description: "Anchor point: ISO date or keyword"
12371
- },
12372
- project: {
12373
- type: "string",
12374
- description: "Filter by project path"
12375
- },
12376
- before: {
12377
- type: "number",
12378
- description: "Observations before anchor (default 5)"
12379
- },
12380
- after: {
12381
- type: "number",
12382
- description: "Observations after anchor (default 5)"
12383
- }
12384
- },
12385
- required: ["anchor"]
12386
- }
12387
- },
12388
- {
12389
- name: "memory_profile",
12390
- description: "User/project profile with top concepts and file patterns.",
12391
- inputSchema: {
12392
- type: "object",
12393
- properties: {
12394
- project: {
12395
- type: "string",
12396
- description: "Project path"
12397
- },
12398
- refresh: {
12399
- type: "string",
12400
- description: "Set to 'true' to force rebuild"
12401
- }
12402
- },
12403
- required: ["project"]
12404
- }
12405
- },
12406
- {
12407
- name: "memory_export",
12408
- description: "Export all memory data as JSON.",
12409
- inputSchema: {
12410
- type: "object",
12411
- properties: {}
12412
- }
12413
- },
12414
- {
12415
- name: "memory_relations",
12416
- description: "Query the memory relationship graph.",
12417
- inputSchema: {
12418
- type: "object",
12419
- properties: {
12420
- memoryId: {
12421
- type: "string",
12422
- description: "Memory ID to find relations for"
12423
- },
12424
- maxHops: {
12425
- type: "number",
12426
- description: "Max traversal depth (default 2)"
12427
- },
12428
- minConfidence: {
12429
- type: "number",
12430
- description: "Min confidence (0-1, default 0)"
12431
- }
12432
- },
12433
- required: ["memoryId"]
12434
- }
12435
- }
12436
- ];
12437
- const V040_TOOLS = [
12438
- {
12439
- name: "memory_claude_bridge_sync",
12440
- description: "Sync memory state to/from Claude Code's native MEMORY.md file.",
12441
- inputSchema: {
12442
- type: "object",
12443
- properties: { direction: {
12444
- type: "string",
12445
- description: "'read' to import from MEMORY.md, 'write' to export to MEMORY.md"
12446
- } },
12447
- required: ["direction"]
12448
- }
12449
- },
12450
- {
12451
- name: "memory_graph_query",
12452
- description: "Query the knowledge graph for entities and relationships.",
12453
- inputSchema: {
12454
- type: "object",
12455
- properties: {
12456
- startNodeId: {
12457
- type: "string",
12458
- description: "Starting node ID for traversal"
12459
- },
12460
- nodeType: {
12461
- type: "string",
12462
- description: "Filter by node type"
12463
- },
12464
- maxDepth: {
12465
- type: "number",
12466
- description: "Max BFS depth (default 3, max 5)"
12467
- },
12468
- query: {
12469
- type: "string",
12470
- description: "Search nodes by name"
12471
- }
12472
- }
12473
- }
12474
- },
12475
- {
12476
- name: "memory_consolidate",
12477
- description: "Run the 4-tier memory consolidation pipeline (working -> episodic -> semantic -> procedural).",
12478
- inputSchema: {
12479
- type: "object",
12480
- properties: { tier: {
12481
- type: "string",
12482
- description: "Target tier: episodic, semantic, or procedural"
12483
- } }
12484
- }
12485
- },
12486
- {
12487
- name: "memory_team_share",
12488
- description: "Share a memory or observation with team members.",
12489
- inputSchema: {
12490
- type: "object",
12491
- properties: {
12492
- itemId: {
12493
- type: "string",
12494
- description: "ID of memory or observation to share"
12495
- },
12496
- itemType: {
12497
- type: "string",
12498
- description: "Type: observation, memory, or pattern"
12499
- }
12500
- },
12501
- required: ["itemId", "itemType"]
12502
- }
12503
- },
12504
- {
12505
- name: "memory_team_feed",
12506
- description: "Get recent shared items from all team members.",
12507
- inputSchema: {
12508
- type: "object",
12509
- properties: { limit: {
12510
- type: "number",
12511
- description: "Max items (default 20)"
12512
- } }
12513
- }
12514
- },
12515
- {
12516
- name: "memory_audit",
12517
- description: "View the audit trail of memory operations.",
12518
- inputSchema: {
12519
- type: "object",
12520
- properties: {
12521
- operation: {
12522
- type: "string",
12523
- description: "Filter by operation type"
12524
- },
12525
- limit: {
12526
- type: "number",
12527
- description: "Max entries (default 50)"
12528
- }
12529
- }
12530
- }
12531
- },
12532
- {
12533
- name: "memory_governance_delete",
12534
- description: "Delete specific memories with audit trail.",
12535
- inputSchema: {
12536
- type: "object",
12537
- properties: {
12538
- memoryIds: {
12539
- type: "string",
12540
- description: "Comma-separated memory IDs to delete"
12541
- },
12542
- reason: {
12543
- type: "string",
12544
- description: "Reason for deletion"
12545
- }
12546
- },
12547
- required: ["memoryIds"]
12548
- }
12549
- },
12550
- {
12551
- name: "memory_snapshot_create",
12552
- description: "Create a git-versioned snapshot of current memory state.",
12553
- inputSchema: {
12554
- type: "object",
12555
- properties: { message: {
12556
- type: "string",
12557
- description: "Snapshot description"
12558
- } }
12559
- }
12560
- }
12561
- ];
12562
- const V050_TOOLS = [
12563
- {
12564
- name: "memory_action_create",
12565
- description: "Create an actionable work item with typed dependencies. Actions track what agents need to do and how work items relate to each other.",
12566
- inputSchema: {
12567
- type: "object",
12568
- properties: {
12569
- title: {
12570
- type: "string",
12571
- description: "Action title"
12572
- },
12573
- description: {
12574
- type: "string",
12575
- description: "Detailed description of the work"
12576
- },
12577
- priority: {
12578
- type: "number",
12579
- description: "Priority 1-10 (10 highest)"
12580
- },
12581
- project: {
12582
- type: "string",
12583
- description: "Project path"
12584
- },
12585
- tags: {
12586
- type: "string",
12587
- description: "Comma-separated tags"
12588
- },
12589
- parentId: {
12590
- type: "string",
12591
- description: "Parent action ID for hierarchical actions"
12592
- },
12593
- requires: {
12594
- type: "string",
12595
- description: "Comma-separated action IDs that must complete before this"
12596
- }
12597
- },
12598
- required: ["title"]
12599
- }
12600
- },
12601
- {
12602
- name: "memory_action_update",
12603
- description: "Update an action's status, priority, or details. Set status to 'done' to complete it and unblock dependent actions.",
12604
- inputSchema: {
12605
- type: "object",
12606
- properties: {
12607
- actionId: {
12608
- type: "string",
12609
- description: "Action ID to update"
12610
- },
12611
- status: {
12612
- type: "string",
12613
- description: "New status: pending, active, done, blocked, cancelled"
12614
- },
12615
- result: {
12616
- type: "string",
12617
- description: "Outcome description (when completing)"
12618
- },
12619
- priority: {
12620
- type: "number",
12621
- description: "New priority 1-10"
12622
- }
12623
- },
12624
- required: ["actionId"]
12625
- }
12626
- },
12627
- {
12628
- name: "memory_frontier",
12629
- description: "Get all unblocked actions ranked by priority and urgency. Returns the frontier of actionable work with no unsatisfied dependencies.",
12630
- inputSchema: {
12631
- type: "object",
12632
- properties: {
12633
- project: {
12634
- type: "string",
12635
- description: "Filter by project"
12636
- },
12637
- agentId: {
12638
- type: "string",
12639
- description: "Agent ID to check lease conflicts"
12640
- },
12641
- limit: {
12642
- type: "number",
12643
- description: "Max results (default 20)"
12644
- }
12645
- }
12646
- }
12647
- },
12648
- {
12649
- name: "memory_next",
12650
- description: "Get the single most important next action to work on. Combines dependency resolution, priority, and recency into a score.",
12651
- inputSchema: {
12652
- type: "object",
12653
- properties: {
12654
- project: {
12655
- type: "string",
12656
- description: "Filter by project"
12657
- },
12658
- agentId: {
12659
- type: "string",
12660
- description: "Current agent ID"
12661
- }
12662
- }
12663
- }
12664
- },
12665
- {
12666
- name: "memory_lease",
12667
- description: "Acquire, release, or renew an exclusive lease on an action. Prevents multiple agents from working on the same thing.",
12668
- inputSchema: {
12669
- type: "object",
12670
- properties: {
12671
- actionId: {
12672
- type: "string",
12673
- description: "Action ID"
12674
- },
12675
- agentId: {
12676
- type: "string",
12677
- description: "Agent claiming the action"
12678
- },
12679
- operation: {
12680
- type: "string",
12681
- description: "acquire, release, or renew"
12682
- },
12683
- result: {
12684
- type: "string",
12685
- description: "Result when releasing (marks action done)"
12686
- },
12687
- ttlMs: {
12688
- type: "number",
12689
- description: "Lease duration in ms (default 10min, max 1hr)"
12690
- }
12691
- },
12692
- required: [
12693
- "actionId",
12694
- "agentId",
12695
- "operation"
12696
- ]
12697
- }
12698
- },
12699
- {
12700
- name: "memory_routine_run",
12701
- description: "Instantiate a frozen workflow routine, creating actions for each step with proper dependencies.",
12702
- inputSchema: {
12703
- type: "object",
12704
- properties: {
12705
- routineId: {
12706
- type: "string",
12707
- description: "Routine template ID"
12708
- },
12709
- project: {
12710
- type: "string",
12711
- description: "Project context"
12712
- },
12713
- initiatedBy: {
12714
- type: "string",
12715
- description: "Agent starting the run"
12716
- }
12717
- },
12718
- required: ["routineId"]
12719
- }
12720
- },
12721
- {
12722
- name: "memory_signal_send",
12723
- description: "Send a message to another agent or broadcast. Supports threading, typed messages, and TTL expiration.",
12724
- inputSchema: {
12725
- type: "object",
12726
- properties: {
12727
- from: {
12728
- type: "string",
12729
- description: "Sender agent ID"
12730
- },
12731
- to: {
12732
- type: "string",
12733
- description: "Recipient agent ID (omit for broadcast)"
12734
- },
12735
- content: {
12736
- type: "string",
12737
- description: "Message content"
12738
- },
12739
- type: {
12740
- type: "string",
12741
- description: "Message type: info, request, response, alert, handoff"
12742
- },
12743
- replyTo: {
12744
- type: "string",
12745
- description: "Signal ID to reply to (auto-threads)"
12746
- }
12747
- },
12748
- required: ["from", "content"]
12749
- }
12750
- },
12751
- {
12752
- name: "memory_signal_read",
12753
- description: "Read messages for an agent. Marks delivered messages as read.",
12754
- inputSchema: {
12755
- type: "object",
12756
- properties: {
12757
- agentId: {
12758
- type: "string",
12759
- description: "Agent to read messages for"
12760
- },
12761
- unreadOnly: {
12762
- type: "string",
12763
- description: "Set to 'true' for unread only"
12764
- },
12765
- threadId: {
12766
- type: "string",
12767
- description: "Filter by conversation thread"
12768
- },
12769
- limit: {
12770
- type: "number",
12771
- description: "Max messages (default 50)"
12772
- }
12773
- },
12774
- required: ["agentId"]
12775
- }
12776
- },
12777
- {
12778
- name: "memory_checkpoint",
12779
- description: "Create or resolve an external checkpoint (CI result, approval, deploy status) that gates action progress.",
12780
- inputSchema: {
12781
- type: "object",
12782
- properties: {
12783
- operation: {
12784
- type: "string",
12785
- description: "create, resolve, or list"
12786
- },
12787
- name: {
12788
- type: "string",
12789
- description: "Checkpoint name (for create)"
12790
- },
12791
- checkpointId: {
12792
- type: "string",
12793
- description: "Checkpoint ID (for resolve)"
12794
- },
12795
- status: {
12796
- type: "string",
12797
- description: "passed or failed (for resolve)"
12798
- },
12799
- type: {
12800
- type: "string",
12801
- description: "Checkpoint type: ci, approval, deploy, external, timer"
12802
- },
12803
- linkedActionIds: {
12804
- type: "string",
12805
- description: "Comma-separated action IDs this checkpoint gates (for create)"
12806
- }
12807
- },
12808
- required: ["operation"]
12809
- }
12810
- },
12811
- {
12812
- name: "memory_mesh_sync",
12813
- description: "Sync memories and actions with peer agentmemory instances for multi-agent collaboration.",
12814
- inputSchema: {
12815
- type: "object",
12816
- properties: {
12817
- peerId: {
12818
- type: "string",
12819
- description: "Specific peer ID (omit for all)"
12820
- },
12821
- direction: {
12822
- type: "string",
12823
- description: "push, pull, or both (default both)"
12824
- }
12825
- }
12826
- }
12827
- }
12828
- ];
12829
- const V051_TOOLS = [
12830
- {
12831
- name: "memory_sentinel_create",
12832
- description: "Create an event-driven sentinel that watches for conditions (webhook, timer, threshold, pattern, approval) and auto-unblocks gated actions when triggered.",
12833
- inputSchema: {
12834
- type: "object",
12835
- properties: {
12836
- name: {
12837
- type: "string",
12838
- description: "Sentinel name"
12839
- },
12840
- type: {
12841
- type: "string",
12842
- description: "Type: webhook, timer, threshold, pattern, approval, custom"
12843
- },
12844
- config: {
12845
- type: "string",
12846
- description: "JSON config (timer: {durationMs}, threshold: {metric,operator,value}, pattern: {pattern}, webhook: {path})"
12847
- },
12848
- linkedActionIds: {
12849
- type: "string",
12850
- description: "Comma-separated action IDs to gate"
12851
- },
12852
- expiresInMs: {
12853
- type: "number",
12854
- description: "Auto-expire after ms"
12855
- }
12856
- },
12857
- required: ["name", "type"]
12858
- }
12859
- },
12860
- {
12861
- name: "memory_sentinel_trigger",
12862
- description: "Externally fire a sentinel, providing an optional result payload. Unblocks any gated actions.",
12863
- inputSchema: {
12864
- type: "object",
12865
- properties: {
12866
- sentinelId: {
12867
- type: "string",
12868
- description: "Sentinel ID to trigger"
12869
- },
12870
- result: {
12871
- type: "string",
12872
- description: "JSON result payload"
12873
- }
12874
- },
12875
- required: ["sentinelId"]
12876
- }
12877
- },
12878
- {
12879
- name: "memory_sketch_create",
12880
- description: "Create an ephemeral action graph for exploratory work. Auto-expires after TTL. Can be promoted to permanent actions or discarded.",
12881
- inputSchema: {
12882
- type: "object",
12883
- properties: {
12884
- title: {
12885
- type: "string",
12886
- description: "Sketch title"
12887
- },
12888
- description: {
12889
- type: "string",
12890
- description: "What this sketch explores"
12891
- },
12892
- expiresInMs: {
12893
- type: "number",
12894
- description: "TTL in ms (default 1 hour)"
12895
- },
12896
- project: {
12897
- type: "string",
12898
- description: "Project context"
12899
- }
12900
- },
12901
- required: ["title"]
12902
- }
12903
- },
12904
- {
12905
- name: "memory_sketch_promote",
12906
- description: "Promote a sketch's ephemeral actions to permanent actions. Makes the exploratory work official.",
12907
- inputSchema: {
12908
- type: "object",
12909
- properties: {
12910
- sketchId: {
12911
- type: "string",
12912
- description: "Sketch ID to promote"
12913
- },
12914
- project: {
12915
- type: "string",
12916
- description: "Override project for promoted actions"
12917
- }
12918
- },
12919
- required: ["sketchId"]
12920
- }
12921
- },
12922
- {
12923
- name: "memory_crystallize",
12924
- description: "Compress completed action chains into compact crystal digests using LLM summarization. Extracts narrative, key outcomes, files affected, and lessons.",
12925
- inputSchema: {
12926
- type: "object",
12927
- properties: {
12928
- actionIds: {
12929
- type: "string",
12930
- description: "Comma-separated completed action IDs to crystallize"
12931
- },
12932
- project: {
12933
- type: "string",
12934
- description: "Project context"
12935
- },
12936
- sessionId: {
12937
- type: "string",
12938
- description: "Session context"
12939
- }
12940
- },
12941
- required: ["actionIds"]
12942
- }
12943
- },
12944
- {
12945
- name: "memory_diagnose",
12946
- description: "Run health checks across all subsystems (actions, leases, sentinels, sketches, signals, sessions, memories, mesh). Identifies stuck, orphaned, and inconsistent state.",
12947
- inputSchema: {
12948
- type: "object",
12949
- properties: { categories: {
12950
- type: "string",
12951
- description: "Comma-separated categories to check (default all)"
12952
- } }
12953
- }
12954
- },
12955
- {
12956
- name: "memory_heal",
12957
- description: "Auto-fix all fixable issues found by diagnostics. Unblocks stuck actions, expires stale leases, cleans up orphaned data.",
12958
- inputSchema: {
12959
- type: "object",
12960
- properties: {
12961
- categories: {
12962
- type: "string",
12963
- description: "Comma-separated categories to heal (default all)"
12964
- },
12965
- dryRun: {
12966
- type: "string",
12967
- description: "Set to 'true' for dry run (report but don't fix)"
12968
- }
12969
- }
12970
- }
12971
- },
12972
- {
12973
- name: "memory_facet_tag",
12974
- description: "Attach a structured tag (dimension:value) to an action, memory, or observation for multi-dimensional categorization.",
12975
- inputSchema: {
12976
- type: "object",
12977
- properties: {
12978
- targetId: {
12979
- type: "string",
12980
- description: "ID of the target to tag"
12981
- },
12982
- targetType: {
12983
- type: "string",
12984
- description: "Type: action, memory, or observation"
12985
- },
12986
- dimension: {
12987
- type: "string",
12988
- description: "Tag dimension (e.g., priority, team, status)"
12989
- },
12990
- value: {
12991
- type: "string",
12992
- description: "Tag value (e.g., urgent, backend, reviewed)"
12993
- }
12994
- },
12995
- required: [
12996
- "targetId",
12997
- "targetType",
12998
- "dimension",
12999
- "value"
13000
- ]
13001
- }
13002
- },
13003
- {
13004
- name: "memory_facet_query",
13005
- description: "Query targets by facet tags with AND/OR logic. Find all actions tagged priority:urgent AND team:backend.",
13006
- inputSchema: {
13007
- type: "object",
13008
- properties: {
13009
- matchAll: {
13010
- type: "string",
13011
- description: "Comma-separated dimension:value pairs (AND logic)"
13012
- },
13013
- matchAny: {
13014
- type: "string",
13015
- description: "Comma-separated dimension:value pairs (OR logic)"
13016
- },
13017
- targetType: {
13018
- type: "string",
13019
- description: "Filter by type: action, memory, or observation"
13020
- }
13021
- }
13022
- }
13023
- }
13024
- ];
13025
- const V061_TOOLS = [{
13026
- name: "memory_verify",
13027
- description: "Verify a memory or observation by tracing its citation chain back to source observations and session context. Returns provenance information including confidence scores.",
13028
- inputSchema: {
13029
- type: "object",
13030
- properties: { id: {
13031
- type: "string",
13032
- description: "Memory ID or observation ID to verify"
13033
- } },
13034
- required: ["id"]
13035
- }
13036
- }];
13037
- const V070_TOOLS = [
13038
- {
13039
- name: "memory_lesson_save",
13040
- 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.",
13041
- inputSchema: {
13042
- type: "object",
13043
- properties: {
13044
- content: {
13045
- type: "string",
13046
- description: "The lesson learned (what worked, what to avoid, when to use X approach)"
13047
- },
13048
- context: {
13049
- type: "string",
13050
- description: "When/where this lesson applies"
13051
- },
13052
- confidence: {
13053
- type: "number",
13054
- description: "Initial confidence 0.0-1.0 (default 0.5)"
13055
- },
13056
- project: {
13057
- type: "string",
13058
- description: "Project this lesson is about"
13059
- },
13060
- tags: {
13061
- type: "string",
13062
- description: "Comma-separated tags"
13063
- }
13064
- },
13065
- required: ["content"]
13066
- }
13067
- },
13068
- {
13069
- name: "memory_lesson_recall",
13070
- description: "Search lessons by query. Returns lessons sorted by confidence and recency. Use to check what the agent has learned before making decisions.",
13071
- inputSchema: {
13072
- type: "object",
13073
- properties: {
13074
- query: {
13075
- type: "string",
13076
- description: "Search query"
13077
- },
13078
- project: {
13079
- type: "string",
13080
- description: "Filter by project"
13081
- },
13082
- minConfidence: {
13083
- type: "number",
13084
- description: "Minimum confidence threshold (default 0.1)"
13085
- },
13086
- limit: {
13087
- type: "number",
13088
- description: "Max results (default 10)"
13089
- }
13090
- },
13091
- required: ["query"]
13092
- }
13093
- },
13094
- {
13095
- name: "memory_obsidian_export",
13096
- description: "Export memories, lessons, and crystals as Obsidian-compatible Markdown files with YAML frontmatter and wikilinks for graph view.",
13097
- inputSchema: {
13098
- type: "object",
13099
- properties: {
13100
- vaultDir: {
13101
- type: "string",
13102
- description: "Output directory (default ~/.agentmemory/vault/)"
13103
- },
13104
- types: {
13105
- type: "string",
13106
- description: "Comma-separated types to export: memories,lessons,crystals,sessions (default all)"
13107
- }
13108
- }
13109
- }
13110
- }
13111
- ];
13112
- const V073_TOOLS = [{
13113
- name: "memory_reflect",
13114
- description: "Traverse the knowledge graph, group related memories by concept clusters, and synthesize higher-order insights via LLM. Returns new and reinforced insights.",
13115
- inputSchema: {
13116
- type: "object",
13117
- properties: {
13118
- project: {
13119
- type: "string",
13120
- description: "Filter by project"
13121
- },
13122
- maxClusters: {
13123
- type: "number",
13124
- description: "Max concept clusters to process (default 10, max 20)"
13125
- }
13126
- }
13127
- }
13128
- }, {
13129
- name: "memory_insight_list",
13130
- description: "List synthesized insights — higher-order observations derived from patterns across memories, lessons, and crystals.",
13131
- inputSchema: {
13132
- type: "object",
13133
- properties: {
13134
- project: {
13135
- type: "string",
13136
- description: "Filter by project"
13137
- },
13138
- minConfidence: {
13139
- type: "number",
13140
- description: "Minimum confidence threshold (default 0)"
13141
- },
13142
- limit: {
13143
- type: "number",
13144
- description: "Max results (default 50)"
13145
- }
13146
- }
13147
- }
13148
- }];
13149
- const ESSENTIAL_TOOLS = new Set([
13150
- "memory_save",
13151
- "memory_recall",
13152
- "memory_consolidate",
13153
- "memory_smart_search",
13154
- "memory_sessions",
13155
- "memory_diagnose",
13156
- "memory_lesson_save",
13157
- "memory_reflect"
13158
- ]);
13159
- function getAllTools() {
13160
- return [
13161
- ...CORE_TOOLS,
13162
- ...V040_TOOLS,
13163
- ...V050_TOOLS,
13164
- ...V051_TOOLS,
13165
- ...V061_TOOLS,
13166
- ...V070_TOOLS,
13167
- ...V073_TOOLS
13168
- ];
13169
- }
13170
- function getVisibleTools() {
13171
- if ((process.env["AGENTMEMORY_TOOLS"] || "core") === "all") return getAllTools();
13172
- return getAllTools().filter((t) => ESSENTIAL_TOOLS.has(t.name));
13173
- }
13174
-
13175
12272
  //#endregion
13176
12273
  //#region src/mcp/server.ts
13177
12274
  function registerMcpEndpoints(sdk, kv, secret) {
@@ -14441,11 +13538,6 @@ function readBody(req) {
14441
13538
  req.on("error", reject);
14442
13539
  });
14443
13540
  }
14444
- function checkAuth(req, secret) {
14445
- if (!secret) return true;
14446
- const auth = req.headers["authorization"] || "";
14447
- return typeof auth === "string" && timingSafeCompare(auth, `Bearer ${secret}`);
14448
- }
14449
13541
  function startViewerServer(port, _kv, _sdk, secret, restPort) {
14450
13542
  const resolvedRestPort = restPort ?? port - 2;
14451
13543
  const server = createServer(async (req, res) => {
@@ -14463,32 +13555,20 @@ function startViewerServer(port, _kv, _sdk, secret, restPort) {
14463
13555
  return;
14464
13556
  }
14465
13557
  if (method === "GET" && (pathname === "/" || pathname === "/viewer" || pathname === "/agentmemory/viewer")) {
14466
- const base = dirname(fileURLToPath(import.meta.url));
14467
- const candidates = [
14468
- join(base, "index.html"),
14469
- join(base, "viewer", "index.html"),
14470
- join(base, "..", "viewer", "index.html"),
14471
- join(base, "..", "src", "viewer", "index.html"),
14472
- join(base, "..", "dist", "viewer", "index.html")
14473
- ];
14474
- for (const p of candidates) try {
14475
- const html = readFileSync(p, "utf-8");
13558
+ const rendered = renderViewerDocument();
13559
+ if (rendered.found) {
14476
13560
  res.writeHead(200, {
14477
13561
  "Content-Type": "text/html; charset=utf-8",
14478
- "Content-Security-Policy": VIEWER_CSP,
13562
+ "Content-Security-Policy": rendered.csp,
14479
13563
  "Cache-Control": "no-cache"
14480
13564
  });
14481
- res.end(html);
13565
+ res.end(rendered.html);
14482
13566
  return;
14483
- } catch {}
13567
+ }
14484
13568
  res.writeHead(404, { "Content-Type": "text/plain" });
14485
13569
  res.end("viewer not found");
14486
13570
  return;
14487
13571
  }
14488
- if (!checkAuth(req, secret)) {
14489
- json(res, 401, { error: "unauthorized" }, req);
14490
- return;
14491
- }
14492
13572
  try {
14493
13573
  await proxyToRestApi(resolvedRestPort, pathname, qs, method, req, res, secret);
14494
13574
  } catch (err) {
@@ -14746,7 +13826,7 @@ async function main() {
14746
13826
  registerRoutinesFunction(sdk, kv);
14747
13827
  registerSignalsFunction(sdk, kv);
14748
13828
  registerCheckpointsFunction(sdk, kv);
14749
- registerMeshFunction(sdk, kv);
13829
+ registerMeshFunction(sdk, kv, secret);
14750
13830
  registerBranchAwareFunction(sdk, kv);
14751
13831
  registerFlowCompressFunction(sdk, kv, provider);
14752
13832
  registerSentinelsFunction(sdk, kv);
@@ -14859,4 +13939,4 @@ main().catch((err) => {
14859
13939
 
14860
13940
  //#endregion
14861
13941
  export { };
14862
- //# sourceMappingURL=src-Df36IFVL.mjs.map
13942
+ //# sourceMappingURL=src-DjVaT_sI.mjs.map