@vellumai/assistant 0.10.10-dev.202607201810.d417cba → 0.10.10-dev.202607201843.29886ee
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/openapi.yaml
CHANGED
|
@@ -17421,6 +17421,65 @@ paths:
|
|
|
17421
17421
|
- confident
|
|
17422
17422
|
- notes
|
|
17423
17423
|
additionalProperties: false
|
|
17424
|
+
/v1/memory/remember:
|
|
17425
|
+
post:
|
|
17426
|
+
operationId: memory_remember_post
|
|
17427
|
+
summary: Create a memory by remembering a fact
|
|
17428
|
+
description:
|
|
17429
|
+
Append a user-authored fact to the memory buffer via handleRemember; it is materialized into a graph node
|
|
17430
|
+
later by consolidation.
|
|
17431
|
+
tags:
|
|
17432
|
+
- memory
|
|
17433
|
+
requestBody:
|
|
17434
|
+
required: true
|
|
17435
|
+
content:
|
|
17436
|
+
application/json:
|
|
17437
|
+
schema:
|
|
17438
|
+
type: object
|
|
17439
|
+
properties:
|
|
17440
|
+
content:
|
|
17441
|
+
type: string
|
|
17442
|
+
required:
|
|
17443
|
+
- content
|
|
17444
|
+
responses:
|
|
17445
|
+
"200":
|
|
17446
|
+
description: Successful response
|
|
17447
|
+
content:
|
|
17448
|
+
application/json:
|
|
17449
|
+
schema:
|
|
17450
|
+
type: object
|
|
17451
|
+
properties:
|
|
17452
|
+
message:
|
|
17453
|
+
type: string
|
|
17454
|
+
success:
|
|
17455
|
+
type: boolean
|
|
17456
|
+
required:
|
|
17457
|
+
- message
|
|
17458
|
+
- success
|
|
17459
|
+
additionalProperties: false
|
|
17460
|
+
/v1/memory/stats:
|
|
17461
|
+
get:
|
|
17462
|
+
operationId: memory_stats_get
|
|
17463
|
+
summary: Get lightweight memory stats
|
|
17464
|
+
description:
|
|
17465
|
+
Return a cheap count of concept pages from the cached memory page index, for glanceable surfaces like the
|
|
17466
|
+
identity Memory card. Counts concept pages only and never builds the memory-concept graph.
|
|
17467
|
+
tags:
|
|
17468
|
+
- memory
|
|
17469
|
+
responses:
|
|
17470
|
+
"200":
|
|
17471
|
+
description: Successful response
|
|
17472
|
+
content:
|
|
17473
|
+
application/json:
|
|
17474
|
+
schema:
|
|
17475
|
+
type: object
|
|
17476
|
+
properties:
|
|
17477
|
+
concepts:
|
|
17478
|
+
type: number
|
|
17479
|
+
description: Number of concept pages in memory
|
|
17480
|
+
required:
|
|
17481
|
+
- concepts
|
|
17482
|
+
additionalProperties: false
|
|
17424
17483
|
/v1/memory/v2/backfill:
|
|
17425
17484
|
post:
|
|
17426
17485
|
operationId: memory_v2_backfill_post
|
package/package.json
CHANGED
|
@@ -4,7 +4,11 @@
|
|
|
4
4
|
* Covers: list with filters, get by ID, create + duplicate rejection,
|
|
5
5
|
* update + fingerprint collision, delete + 404.
|
|
6
6
|
*/
|
|
7
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
8
|
+
import { tmpdir } from "node:os";
|
|
9
|
+
import { join } from "node:path";
|
|
7
10
|
import {
|
|
11
|
+
afterAll,
|
|
8
12
|
afterEach,
|
|
9
13
|
beforeAll,
|
|
10
14
|
beforeEach,
|
|
@@ -59,6 +63,16 @@ mock.module(
|
|
|
59
63
|
}),
|
|
60
64
|
);
|
|
61
65
|
|
|
66
|
+
// Programmable synthetic skill list for the memory-stats page-index count.
|
|
67
|
+
// `getPageIndex` dynamically imports skill-store, so mocking it here lets the
|
|
68
|
+
// stats test seed synthetic (modifiedAt: 0) rows and assert they're excluded.
|
|
69
|
+
let mockSkillEntries: Array<{ id: string; content: string }> = [];
|
|
70
|
+
|
|
71
|
+
mock.module("../v2/skill-store.js", () => ({
|
|
72
|
+
SKILL_SLUG_PREFIX: "skills/",
|
|
73
|
+
listSkillEntries: () => mockSkillEntries,
|
|
74
|
+
}));
|
|
75
|
+
|
|
62
76
|
import { eq } from "drizzle-orm";
|
|
63
77
|
|
|
64
78
|
import { setConfig } from "../../../../__tests__/helpers/set-config.js";
|
|
@@ -78,6 +92,9 @@ import {
|
|
|
78
92
|
NotFoundError,
|
|
79
93
|
} from "../../../../runtime/routes/errors.js";
|
|
80
94
|
import type { RouteDefinition } from "../../../../runtime/routes/types.js";
|
|
95
|
+
import { invalidatePageIndex } from "../v2/page-index.js";
|
|
96
|
+
import { writePage } from "../v2/page-store.js";
|
|
97
|
+
import type { ConceptPage } from "../v2/types.js";
|
|
81
98
|
import { ROUTES } from "./memory-item-routes.js";
|
|
82
99
|
|
|
83
100
|
// ---------------------------------------------------------------------------
|
|
@@ -1052,4 +1069,155 @@ describe("Memory Item Routes", () => {
|
|
|
1052
1069
|
);
|
|
1053
1070
|
});
|
|
1054
1071
|
});
|
|
1072
|
+
|
|
1073
|
+
// ── Create memory (remember) ──────────────────────────────────────────────
|
|
1074
|
+
|
|
1075
|
+
describe("POST /v1/memory/remember (createMemory)", () => {
|
|
1076
|
+
// handleRemember writes to getWorkspaceDir(); point it at a throwaway
|
|
1077
|
+
// tmpdir so the buffer/archive writes stay isolated. Enable memory v2 so
|
|
1078
|
+
// writes take the memory/ path and skip PKB re-index jobs.
|
|
1079
|
+
let tmpWorkspace: string;
|
|
1080
|
+
let previousWorkspaceEnv: string | undefined;
|
|
1081
|
+
|
|
1082
|
+
beforeAll(() => {
|
|
1083
|
+
tmpWorkspace = mkdtempSync(join(tmpdir(), "create-memory-route-test-"));
|
|
1084
|
+
previousWorkspaceEnv = process.env.VELLUM_WORKSPACE_DIR;
|
|
1085
|
+
process.env.VELLUM_WORKSPACE_DIR = tmpWorkspace;
|
|
1086
|
+
});
|
|
1087
|
+
|
|
1088
|
+
afterAll(() => {
|
|
1089
|
+
if (previousWorkspaceEnv === undefined) {
|
|
1090
|
+
delete process.env.VELLUM_WORKSPACE_DIR;
|
|
1091
|
+
} else {
|
|
1092
|
+
process.env.VELLUM_WORKSPACE_DIR = previousWorkspaceEnv;
|
|
1093
|
+
}
|
|
1094
|
+
rmSync(tmpWorkspace, { recursive: true, force: true });
|
|
1095
|
+
});
|
|
1096
|
+
|
|
1097
|
+
beforeEach(() => {
|
|
1098
|
+
setConfig("memory", { v2: { enabled: true } });
|
|
1099
|
+
});
|
|
1100
|
+
|
|
1101
|
+
afterEach(() => {
|
|
1102
|
+
setConfig("memory", { v2: { enabled: false } });
|
|
1103
|
+
});
|
|
1104
|
+
|
|
1105
|
+
interface RememberBody {
|
|
1106
|
+
success: boolean;
|
|
1107
|
+
message: string;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
test("appends a valid fact and returns { success, message }", async () => {
|
|
1111
|
+
const res = await callHandler(getRoute("memory/remember", "POST"), {
|
|
1112
|
+
body: { content: "User prefers dark mode" },
|
|
1113
|
+
});
|
|
1114
|
+
expect(res.status).toBe(200);
|
|
1115
|
+
const body = (await res.json()) as RememberBody;
|
|
1116
|
+
expect(body.success).toBe(true);
|
|
1117
|
+
expect(body.message.length).toBeGreaterThan(0);
|
|
1118
|
+
});
|
|
1119
|
+
|
|
1120
|
+
test("rejects a missing content body as 400", async () => {
|
|
1121
|
+
const res = await callHandler(getRoute("memory/remember", "POST"), {
|
|
1122
|
+
body: {},
|
|
1123
|
+
});
|
|
1124
|
+
expect(res.status).toBe(400);
|
|
1125
|
+
});
|
|
1126
|
+
|
|
1127
|
+
test("rejects a non-string content field as 400", async () => {
|
|
1128
|
+
const res = await callHandler(getRoute("memory/remember", "POST"), {
|
|
1129
|
+
body: { content: 42 },
|
|
1130
|
+
});
|
|
1131
|
+
expect(res.status).toBe(400);
|
|
1132
|
+
});
|
|
1133
|
+
|
|
1134
|
+
test("rejects empty content as 400", async () => {
|
|
1135
|
+
const res = await callHandler(getRoute("memory/remember", "POST"), {
|
|
1136
|
+
body: { content: "" },
|
|
1137
|
+
});
|
|
1138
|
+
expect(res.status).toBe(400);
|
|
1139
|
+
});
|
|
1140
|
+
|
|
1141
|
+
test("rejects whitespace-only content as 400", async () => {
|
|
1142
|
+
const res = await callHandler(getRoute("memory/remember", "POST"), {
|
|
1143
|
+
body: { content: " " },
|
|
1144
|
+
});
|
|
1145
|
+
expect(res.status).toBe(400);
|
|
1146
|
+
});
|
|
1147
|
+
});
|
|
1148
|
+
|
|
1149
|
+
// ── Memory stats (page-index concept count) ───────────────────────────────
|
|
1150
|
+
|
|
1151
|
+
describe("GET /v1/memory/stats (getMemoryStats)", () => {
|
|
1152
|
+
// handleGetMemoryStats reads concept pages from getWorkspaceDir(); point
|
|
1153
|
+
// it at a throwaway tmpdir so the page scan stays isolated from ~/.vellum.
|
|
1154
|
+
// A fresh workspace per test keeps each concept count independent.
|
|
1155
|
+
let tmpWorkspace: string;
|
|
1156
|
+
let previousWorkspaceEnv: string | undefined;
|
|
1157
|
+
|
|
1158
|
+
beforeEach(() => {
|
|
1159
|
+
tmpWorkspace = mkdtempSync(join(tmpdir(), "memory-stats-route-test-"));
|
|
1160
|
+
previousWorkspaceEnv = process.env.VELLUM_WORKSPACE_DIR;
|
|
1161
|
+
process.env.VELLUM_WORKSPACE_DIR = tmpWorkspace;
|
|
1162
|
+
// A no-skill baseline; the exclusion test seeds synthetic rows itself.
|
|
1163
|
+
mockSkillEntries = [];
|
|
1164
|
+
// Drop any cached index so each run re-scans this fresh workspace.
|
|
1165
|
+
invalidatePageIndex();
|
|
1166
|
+
});
|
|
1167
|
+
|
|
1168
|
+
afterEach(() => {
|
|
1169
|
+
if (previousWorkspaceEnv === undefined) {
|
|
1170
|
+
delete process.env.VELLUM_WORKSPACE_DIR;
|
|
1171
|
+
} else {
|
|
1172
|
+
process.env.VELLUM_WORKSPACE_DIR = previousWorkspaceEnv;
|
|
1173
|
+
}
|
|
1174
|
+
rmSync(tmpWorkspace, { recursive: true, force: true });
|
|
1175
|
+
invalidatePageIndex();
|
|
1176
|
+
});
|
|
1177
|
+
|
|
1178
|
+
const route = getRoute("memory/stats", "GET");
|
|
1179
|
+
|
|
1180
|
+
function makeConceptPage(slug: string): ConceptPage {
|
|
1181
|
+
return {
|
|
1182
|
+
slug,
|
|
1183
|
+
frontmatter: { edges: [], ref_files: [], ref_urls: [] },
|
|
1184
|
+
body: `Body for ${slug}`,
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
test("counts concept pages in the workspace", async () => {
|
|
1189
|
+
await writePage(tmpWorkspace, makeConceptPage("alice"));
|
|
1190
|
+
await writePage(tmpWorkspace, makeConceptPage("bob"));
|
|
1191
|
+
await writePage(tmpWorkspace, makeConceptPage("carol"));
|
|
1192
|
+
|
|
1193
|
+
const res = await callHandler(route);
|
|
1194
|
+
expect(res.status).toBe(200);
|
|
1195
|
+
const body = (await res.json()) as { concepts: number };
|
|
1196
|
+
expect(body.concepts).toBe(3);
|
|
1197
|
+
});
|
|
1198
|
+
|
|
1199
|
+
test("returns zero for an empty workspace", async () => {
|
|
1200
|
+
const res = await callHandler(route);
|
|
1201
|
+
expect(res.status).toBe(200);
|
|
1202
|
+
const body = (await res.json()) as { concepts: number };
|
|
1203
|
+
expect(body.concepts).toBe(0);
|
|
1204
|
+
});
|
|
1205
|
+
|
|
1206
|
+
test("excludes synthetic (modifiedAt <= 0) skill entries", async () => {
|
|
1207
|
+
// Synthetic skill rows (seeded skills / CLI commands) carry
|
|
1208
|
+
// modifiedAt: 0 and must not inflate the concept count.
|
|
1209
|
+
mockSkillEntries = [
|
|
1210
|
+
{ id: "agent-mail", content: "Send and read email" },
|
|
1211
|
+
{ id: "calendar", content: "Manage the calendar" },
|
|
1212
|
+
];
|
|
1213
|
+
await writePage(tmpWorkspace, makeConceptPage("alice"));
|
|
1214
|
+
await writePage(tmpWorkspace, makeConceptPage("bob"));
|
|
1215
|
+
|
|
1216
|
+
const res = await callHandler(route);
|
|
1217
|
+
expect(res.status).toBe(200);
|
|
1218
|
+
const body = (await res.json()) as { concepts: number };
|
|
1219
|
+
// Two real concept pages; the two synthetic skill rows are excluded.
|
|
1220
|
+
expect(body.concepts).toBe(2);
|
|
1221
|
+
});
|
|
1222
|
+
});
|
|
1055
1223
|
});
|
|
@@ -56,6 +56,7 @@ import { createNode, deleteNode, getNode, updateNode } from "../graph/store.js";
|
|
|
56
56
|
import {
|
|
57
57
|
handleDeleteMemory,
|
|
58
58
|
handleListMemory,
|
|
59
|
+
handleRemember,
|
|
59
60
|
handleUpdateMemory,
|
|
60
61
|
} from "../graph/tool-handlers.js";
|
|
61
62
|
import type {
|
|
@@ -66,6 +67,8 @@ import type {
|
|
|
66
67
|
NewNode,
|
|
67
68
|
} from "../graph/types.js";
|
|
68
69
|
import { getLogger } from "../logging.js";
|
|
70
|
+
import { getWorkspaceDir } from "../paths.js";
|
|
71
|
+
import { getPageIndex } from "../v2/page-index.js";
|
|
69
72
|
|
|
70
73
|
const log = getLogger("memory-item-routes");
|
|
71
74
|
|
|
@@ -462,6 +465,22 @@ function handleGetMemoryItem(id: string) {
|
|
|
462
465
|
return { item: nodeToPayload(node) };
|
|
463
466
|
}
|
|
464
467
|
|
|
468
|
+
/**
|
|
469
|
+
* Cheap concept count for glanceable surfaces (the identity Memory card).
|
|
470
|
+
*
|
|
471
|
+
* Read straight from the CACHED page index and count only real concept pages:
|
|
472
|
+
* those carry a real file mtime (`modifiedAt > 0`), while synthetic rows
|
|
473
|
+
* (seeded skills and CLI commands) carry `modifiedAt: 0`. This mirrors the
|
|
474
|
+
* concepts-only filter in `build-memory-graph.ts`, but never triggers the
|
|
475
|
+
* expensive `getMemoryGraph` build (edge / learned / cluster graph) — the
|
|
476
|
+
* concept graph is deliberately kept off identity-page load.
|
|
477
|
+
*/
|
|
478
|
+
async function handleGetMemoryStats(): Promise<{ concepts: number }> {
|
|
479
|
+
const pageIndex = await getPageIndex(getWorkspaceDir());
|
|
480
|
+
const concepts = pageIndex.entries.filter((e) => e.modifiedAt > 0).length;
|
|
481
|
+
return { concepts };
|
|
482
|
+
}
|
|
483
|
+
|
|
465
484
|
async function handleCreateMemoryItem(body: Record<string, unknown>) {
|
|
466
485
|
const { kind, subject, statement, importance } = body as {
|
|
467
486
|
kind?: string;
|
|
@@ -736,6 +755,26 @@ export const ROUTES: RouteDefinition[] = [
|
|
|
736
755
|
handler: ({ pathParams }) => handleGetMemoryItem(pathParams!.id),
|
|
737
756
|
},
|
|
738
757
|
|
|
758
|
+
{
|
|
759
|
+
operationId: "getMemoryStats",
|
|
760
|
+
endpoint: "memory/stats",
|
|
761
|
+
method: "GET",
|
|
762
|
+
policy: {
|
|
763
|
+
requiredScopes: ["settings.read"],
|
|
764
|
+
allowedPrincipalTypes: ACTOR_PRINCIPALS,
|
|
765
|
+
},
|
|
766
|
+
summary: "Get lightweight memory stats",
|
|
767
|
+
description:
|
|
768
|
+
"Return a cheap count of concept pages from the cached memory page " +
|
|
769
|
+
"index, for glanceable surfaces like the identity Memory card. Counts " +
|
|
770
|
+
"concept pages only and never builds the memory-concept graph.",
|
|
771
|
+
tags: ["memory"],
|
|
772
|
+
responseBody: z.object({
|
|
773
|
+
concepts: z.number().describe("Number of concept pages in memory"),
|
|
774
|
+
}),
|
|
775
|
+
handler: () => handleGetMemoryStats(),
|
|
776
|
+
},
|
|
777
|
+
|
|
739
778
|
{
|
|
740
779
|
operationId: "createMemoryItem",
|
|
741
780
|
endpoint: "memory-items",
|
|
@@ -946,4 +985,34 @@ export const ROUTES: RouteDefinition[] = [
|
|
|
946
985
|
);
|
|
947
986
|
},
|
|
948
987
|
},
|
|
988
|
+
|
|
989
|
+
{
|
|
990
|
+
operationId: "createMemory",
|
|
991
|
+
endpoint: "memory/remember",
|
|
992
|
+
method: "POST",
|
|
993
|
+
policy: {
|
|
994
|
+
requiredScopes: ["settings.write"],
|
|
995
|
+
allowedPrincipalTypes: ACTOR_PRINCIPALS,
|
|
996
|
+
},
|
|
997
|
+
summary: "Create a memory by remembering a fact",
|
|
998
|
+
description:
|
|
999
|
+
"Append a user-authored fact to the memory buffer via handleRemember; it is materialized into a graph node later by consolidation.",
|
|
1000
|
+
tags: ["memory"],
|
|
1001
|
+
requestBody: z.object({ content: z.string() }),
|
|
1002
|
+
responseBody: z.object({ message: z.string(), success: z.boolean() }),
|
|
1003
|
+
handler: ({ body }) => {
|
|
1004
|
+
const parsed = z.object({ content: z.string() }).safeParse(body ?? {});
|
|
1005
|
+
if (!parsed.success) {
|
|
1006
|
+
throw new BadRequestError("content (string) is required");
|
|
1007
|
+
}
|
|
1008
|
+
if (parsed.data.content.trim().length === 0) {
|
|
1009
|
+
throw new BadRequestError("content (non-empty string) is required");
|
|
1010
|
+
}
|
|
1011
|
+
return handleRemember(
|
|
1012
|
+
{ content: parsed.data.content },
|
|
1013
|
+
"web",
|
|
1014
|
+
getConfig(),
|
|
1015
|
+
);
|
|
1016
|
+
},
|
|
1017
|
+
},
|
|
949
1018
|
];
|