convex-supermemory 0.0.1
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/LICENSE +201 -0
- package/README.md +306 -0
- package/dist/client/_generated/_ignore.d.ts +1 -0
- package/dist/client/_generated/_ignore.d.ts.map +1 -0
- package/dist/client/_generated/_ignore.js +3 -0
- package/dist/client/_generated/_ignore.js.map +1 -0
- package/dist/client/index.d.ts +188 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +177 -0
- package/dist/client/index.js.map +1 -0
- package/dist/component/_generated/api.d.ts +34 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +31 -0
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/component.d.ts +152 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +46 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +133 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +80 -0
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/convex.config.d.ts +3 -0
- package/dist/component/convex.config.d.ts.map +1 -0
- package/dist/component/convex.config.js +4 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/lib.d.ts +128 -0
- package/dist/component/lib.d.ts.map +1 -0
- package/dist/component/lib.js +196 -0
- package/dist/component/lib.js.map +1 -0
- package/dist/component/schema.d.ts +56 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +33 -0
- package/dist/component/schema.js.map +1 -0
- package/package.json +106 -0
- package/src/client/_generated/_ignore.ts +1 -0
- package/src/client/index.ts +289 -0
- package/src/client/setup.test.ts +26 -0
- package/src/component/_generated/api.ts +50 -0
- package/src/component/_generated/component.ts +232 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +169 -0
- package/src/component/convex.config.ts +5 -0
- package/src/component/lib.test.ts +127 -0
- package/src/component/lib.ts +224 -0
- package/src/component/schema.ts +43 -0
- package/src/component/setup.test.ts +11 -0
- package/src/test.ts +18 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
import { mutation, query } from "./_generated/server.js";
|
|
3
|
+
|
|
4
|
+
const documentStatusValidator = v.union(
|
|
5
|
+
v.literal("unknown"),
|
|
6
|
+
v.literal("queued"),
|
|
7
|
+
v.literal("extracting"),
|
|
8
|
+
v.literal("chunking"),
|
|
9
|
+
v.literal("embedding"),
|
|
10
|
+
v.literal("indexing"),
|
|
11
|
+
v.literal("done"),
|
|
12
|
+
v.literal("failed"),
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
const memoryValidator = v.object({
|
|
16
|
+
_id: v.id("memories"),
|
|
17
|
+
_creationTime: v.number(),
|
|
18
|
+
memoryId: v.string(),
|
|
19
|
+
containerTag: v.string(),
|
|
20
|
+
content: v.string(),
|
|
21
|
+
isStatic: v.boolean(),
|
|
22
|
+
metadata: v.optional(v.string()),
|
|
23
|
+
forgetAfter: v.optional(v.number()),
|
|
24
|
+
forgetReason: v.optional(v.string()),
|
|
25
|
+
forgotten: v.boolean(),
|
|
26
|
+
createdAt: v.number(),
|
|
27
|
+
updatedAt: v.number(),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const documentValidator = v.object({
|
|
31
|
+
_id: v.id("documents"),
|
|
32
|
+
_creationTime: v.number(),
|
|
33
|
+
documentId: v.string(),
|
|
34
|
+
containerTag: v.string(),
|
|
35
|
+
content: v.optional(v.string()),
|
|
36
|
+
customId: v.optional(v.string()),
|
|
37
|
+
metadata: v.optional(v.string()),
|
|
38
|
+
status: documentStatusValidator,
|
|
39
|
+
title: v.optional(v.string()),
|
|
40
|
+
summary: v.optional(v.string()),
|
|
41
|
+
createdAt: v.number(),
|
|
42
|
+
updatedAt: v.number(),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// ─── Queries ────────────────────────────────────────────────────────────────
|
|
46
|
+
|
|
47
|
+
export const getMemory = query({
|
|
48
|
+
args: { memoryId: v.string() },
|
|
49
|
+
returns: v.union(v.null(), memoryValidator),
|
|
50
|
+
handler: async (ctx, args) => {
|
|
51
|
+
return await ctx.db
|
|
52
|
+
.query("memories")
|
|
53
|
+
.withIndex("by_memoryId", (q) => q.eq("memoryId", args.memoryId))
|
|
54
|
+
.first();
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export const listMemories = query({
|
|
59
|
+
args: { containerTag: v.string(), limit: v.optional(v.number()) },
|
|
60
|
+
returns: v.array(memoryValidator),
|
|
61
|
+
handler: async (ctx, args) => {
|
|
62
|
+
return await ctx.db
|
|
63
|
+
.query("memories")
|
|
64
|
+
.withIndex("by_containerTag", (q) => q.eq("containerTag", args.containerTag))
|
|
65
|
+
.order("desc")
|
|
66
|
+
.take(args.limit ?? 100);
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
export const getDocument = query({
|
|
71
|
+
args: { documentId: v.string() },
|
|
72
|
+
returns: v.union(v.null(), documentValidator),
|
|
73
|
+
handler: async (ctx, args) => {
|
|
74
|
+
return await ctx.db
|
|
75
|
+
.query("documents")
|
|
76
|
+
.withIndex("by_documentId", (q) => q.eq("documentId", args.documentId))
|
|
77
|
+
.first();
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
export const listDocuments = query({
|
|
82
|
+
args: { containerTag: v.string(), limit: v.optional(v.number()) },
|
|
83
|
+
returns: v.array(documentValidator),
|
|
84
|
+
handler: async (ctx, args) => {
|
|
85
|
+
return await ctx.db
|
|
86
|
+
.query("documents")
|
|
87
|
+
.withIndex("by_containerTag", (q) => q.eq("containerTag", args.containerTag))
|
|
88
|
+
.order("desc")
|
|
89
|
+
.take(args.limit ?? 50);
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// ─── Mutations ──────────────────────────────────────────────────────────────
|
|
94
|
+
|
|
95
|
+
export const recordMemory = mutation({
|
|
96
|
+
args: {
|
|
97
|
+
memoryId: v.string(),
|
|
98
|
+
containerTag: v.string(),
|
|
99
|
+
content: v.string(),
|
|
100
|
+
isStatic: v.boolean(),
|
|
101
|
+
metadata: v.optional(v.string()),
|
|
102
|
+
forgetAfter: v.optional(v.number()),
|
|
103
|
+
forgetReason: v.optional(v.string()),
|
|
104
|
+
},
|
|
105
|
+
returns: v.id("memories"),
|
|
106
|
+
handler: async (ctx, args) => {
|
|
107
|
+
const now = Date.now();
|
|
108
|
+
const existing = await ctx.db
|
|
109
|
+
.query("memories")
|
|
110
|
+
.withIndex("by_memoryId", (q) => q.eq("memoryId", args.memoryId))
|
|
111
|
+
.first();
|
|
112
|
+
|
|
113
|
+
if (existing) {
|
|
114
|
+
await ctx.db.patch(existing._id, { ...args, updatedAt: now });
|
|
115
|
+
return existing._id;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return await ctx.db.insert("memories", {
|
|
119
|
+
...args,
|
|
120
|
+
forgotten: false,
|
|
121
|
+
createdAt: now,
|
|
122
|
+
updatedAt: now,
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
export const markMemoryForgotten = mutation({
|
|
128
|
+
args: { memoryId: v.string() },
|
|
129
|
+
returns: v.null(),
|
|
130
|
+
handler: async (ctx, args) => {
|
|
131
|
+
const existing = await ctx.db
|
|
132
|
+
.query("memories")
|
|
133
|
+
.withIndex("by_memoryId", (q) => q.eq("memoryId", args.memoryId))
|
|
134
|
+
.first();
|
|
135
|
+
if (!existing) return null;
|
|
136
|
+
await ctx.db.patch(existing._id, { forgotten: true, updatedAt: Date.now() });
|
|
137
|
+
return null;
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
export const recordDocument = mutation({
|
|
142
|
+
args: {
|
|
143
|
+
documentId: v.string(),
|
|
144
|
+
containerTag: v.string(),
|
|
145
|
+
content: v.optional(v.string()),
|
|
146
|
+
customId: v.optional(v.string()),
|
|
147
|
+
metadata: v.optional(v.string()),
|
|
148
|
+
status: documentStatusValidator,
|
|
149
|
+
title: v.optional(v.string()),
|
|
150
|
+
summary: v.optional(v.string()),
|
|
151
|
+
},
|
|
152
|
+
returns: v.id("documents"),
|
|
153
|
+
handler: async (ctx, args) => {
|
|
154
|
+
const now = Date.now();
|
|
155
|
+
const existing = await ctx.db
|
|
156
|
+
.query("documents")
|
|
157
|
+
.withIndex("by_documentId", (q) => q.eq("documentId", args.documentId))
|
|
158
|
+
.first();
|
|
159
|
+
|
|
160
|
+
if (existing) {
|
|
161
|
+
await ctx.db.patch(existing._id, { ...args, updatedAt: now });
|
|
162
|
+
return existing._id;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return await ctx.db.insert("documents", {
|
|
166
|
+
...args,
|
|
167
|
+
createdAt: now,
|
|
168
|
+
updatedAt: now,
|
|
169
|
+
});
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
export const deleteDocument = mutation({
|
|
174
|
+
args: { documentId: v.string() },
|
|
175
|
+
returns: v.null(),
|
|
176
|
+
handler: async (ctx, args) => {
|
|
177
|
+
const existing = await ctx.db
|
|
178
|
+
.query("documents")
|
|
179
|
+
.withIndex("by_documentId", (q) => q.eq("documentId", args.documentId))
|
|
180
|
+
.first();
|
|
181
|
+
if (existing) {
|
|
182
|
+
await ctx.db.delete(existing._id);
|
|
183
|
+
}
|
|
184
|
+
return null;
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// ─── Dashboard / history ────────────────────────────────────────────────────
|
|
189
|
+
|
|
190
|
+
export const getStats = query({
|
|
191
|
+
args: {},
|
|
192
|
+
returns: v.object({ memories: v.number(), documents: v.number() }),
|
|
193
|
+
handler: async (ctx) => {
|
|
194
|
+
const [memories, documents] = await Promise.all([
|
|
195
|
+
ctx.db.query("memories").collect(),
|
|
196
|
+
ctx.db.query("documents").collect(),
|
|
197
|
+
]);
|
|
198
|
+
return { memories: memories.length, documents: documents.length };
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// Every memory, newest first, regardless of containerTag — for a history view
|
|
203
|
+
// that doesn't require already knowing which container to look under.
|
|
204
|
+
export const listRecentMemories = query({
|
|
205
|
+
args: { limit: v.optional(v.number()) },
|
|
206
|
+
returns: v.array(memoryValidator),
|
|
207
|
+
handler: async (ctx, args) => {
|
|
208
|
+
return await ctx.db
|
|
209
|
+
.query("memories")
|
|
210
|
+
.order("desc")
|
|
211
|
+
.take(args.limit ?? 30);
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
export const listRecentDocuments = query({
|
|
216
|
+
args: { limit: v.optional(v.number()) },
|
|
217
|
+
returns: v.array(documentValidator),
|
|
218
|
+
handler: async (ctx, args) => {
|
|
219
|
+
return await ctx.db
|
|
220
|
+
.query("documents")
|
|
221
|
+
.order("desc")
|
|
222
|
+
.take(args.limit ?? 30);
|
|
223
|
+
},
|
|
224
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { defineSchema, defineTable } from "convex/server";
|
|
2
|
+
import { v } from "convex/values";
|
|
3
|
+
|
|
4
|
+
export default defineSchema({
|
|
5
|
+
memories: defineTable({
|
|
6
|
+
memoryId: v.string(),
|
|
7
|
+
containerTag: v.string(),
|
|
8
|
+
content: v.string(),
|
|
9
|
+
isStatic: v.boolean(),
|
|
10
|
+
metadata: v.optional(v.string()),
|
|
11
|
+
forgetAfter: v.optional(v.number()),
|
|
12
|
+
forgetReason: v.optional(v.string()),
|
|
13
|
+
forgotten: v.boolean(),
|
|
14
|
+
createdAt: v.number(),
|
|
15
|
+
updatedAt: v.number(),
|
|
16
|
+
})
|
|
17
|
+
.index("by_memoryId", ["memoryId"])
|
|
18
|
+
.index("by_containerTag", ["containerTag"]),
|
|
19
|
+
|
|
20
|
+
documents: defineTable({
|
|
21
|
+
documentId: v.string(),
|
|
22
|
+
containerTag: v.string(),
|
|
23
|
+
content: v.optional(v.string()),
|
|
24
|
+
customId: v.optional(v.string()),
|
|
25
|
+
metadata: v.optional(v.string()),
|
|
26
|
+
status: v.union(
|
|
27
|
+
v.literal("unknown"),
|
|
28
|
+
v.literal("queued"),
|
|
29
|
+
v.literal("extracting"),
|
|
30
|
+
v.literal("chunking"),
|
|
31
|
+
v.literal("embedding"),
|
|
32
|
+
v.literal("indexing"),
|
|
33
|
+
v.literal("done"),
|
|
34
|
+
v.literal("failed"),
|
|
35
|
+
),
|
|
36
|
+
title: v.optional(v.string()),
|
|
37
|
+
summary: v.optional(v.string()),
|
|
38
|
+
createdAt: v.number(),
|
|
39
|
+
updatedAt: v.number(),
|
|
40
|
+
})
|
|
41
|
+
.index("by_documentId", ["documentId"])
|
|
42
|
+
.index("by_containerTag", ["containerTag"]),
|
|
43
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
import { test } from "vitest";
|
|
3
|
+
import schema from "./schema.js";
|
|
4
|
+
import { convexTest } from "convex-test";
|
|
5
|
+
export const modules = import.meta.glob("./**/*.*s");
|
|
6
|
+
|
|
7
|
+
export function initConvexTest() {
|
|
8
|
+
const t = convexTest(schema, modules);
|
|
9
|
+
return t;
|
|
10
|
+
}
|
|
11
|
+
test("setup", () => {});
|
package/src/test.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
import type { TestConvex } from "convex-test";
|
|
3
|
+
import type { GenericSchema, SchemaDefinition } from "convex/server";
|
|
4
|
+
import schema from "./component/schema.js";
|
|
5
|
+
const modules = import.meta.glob("./component/**/*.ts");
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Register the component with the test convex instance.
|
|
9
|
+
* @param t - The test convex instance, e.g. from calling `convexTest`.
|
|
10
|
+
* @param name - The name of the component, as registered in convex.config.ts.
|
|
11
|
+
*/
|
|
12
|
+
export function register(
|
|
13
|
+
t: TestConvex<SchemaDefinition<GenericSchema, boolean>>,
|
|
14
|
+
name: string = "convexSupermemory",
|
|
15
|
+
) {
|
|
16
|
+
t.registerComponent(name, schema, modules);
|
|
17
|
+
}
|
|
18
|
+
export default { register, schema, modules };
|