@waynesutton/agent-memory 0.0.1-alpha.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.
Files changed (200) hide show
  1. package/.claude/settings.json +9 -0
  2. package/.claude/settings.local.json +7 -0
  3. package/AGENTS.md +113 -0
  4. package/CLAUDE.md +79 -0
  5. package/README.md +1003 -0
  6. package/dist/cli/index.d.ts +3 -0
  7. package/dist/cli/index.d.ts.map +1 -0
  8. package/dist/cli/index.js +192 -0
  9. package/dist/cli/index.js.map +1 -0
  10. package/dist/cli/parsers/claude-code.d.ts +3 -0
  11. package/dist/cli/parsers/claude-code.d.ts.map +1 -0
  12. package/dist/cli/parsers/claude-code.js +75 -0
  13. package/dist/cli/parsers/claude-code.js.map +1 -0
  14. package/dist/cli/parsers/codex.d.ts +3 -0
  15. package/dist/cli/parsers/codex.d.ts.map +1 -0
  16. package/dist/cli/parsers/codex.js +42 -0
  17. package/dist/cli/parsers/codex.js.map +1 -0
  18. package/dist/cli/parsers/conductor.d.ts +3 -0
  19. package/dist/cli/parsers/conductor.d.ts.map +1 -0
  20. package/dist/cli/parsers/conductor.js +43 -0
  21. package/dist/cli/parsers/conductor.js.map +1 -0
  22. package/dist/cli/parsers/cursor.d.ts +3 -0
  23. package/dist/cli/parsers/cursor.d.ts.map +1 -0
  24. package/dist/cli/parsers/cursor.js +50 -0
  25. package/dist/cli/parsers/cursor.js.map +1 -0
  26. package/dist/cli/parsers/index.d.ts +12 -0
  27. package/dist/cli/parsers/index.d.ts.map +1 -0
  28. package/dist/cli/parsers/index.js +27 -0
  29. package/dist/cli/parsers/index.js.map +1 -0
  30. package/dist/cli/parsers/opencode.d.ts +3 -0
  31. package/dist/cli/parsers/opencode.d.ts.map +1 -0
  32. package/dist/cli/parsers/opencode.js +72 -0
  33. package/dist/cli/parsers/opencode.js.map +1 -0
  34. package/dist/cli/parsers/parsers.test.d.ts +2 -0
  35. package/dist/cli/parsers/parsers.test.d.ts.map +1 -0
  36. package/dist/cli/parsers/parsers.test.js +151 -0
  37. package/dist/cli/parsers/parsers.test.js.map +1 -0
  38. package/dist/cli/parsers/pi.d.ts +3 -0
  39. package/dist/cli/parsers/pi.d.ts.map +1 -0
  40. package/dist/cli/parsers/pi.js +43 -0
  41. package/dist/cli/parsers/pi.js.map +1 -0
  42. package/dist/cli/parsers/types.d.ts +25 -0
  43. package/dist/cli/parsers/types.d.ts.map +1 -0
  44. package/dist/cli/parsers/types.js +2 -0
  45. package/dist/cli/parsers/types.js.map +1 -0
  46. package/dist/cli/parsers/vscode-copilot.d.ts +3 -0
  47. package/dist/cli/parsers/vscode-copilot.d.ts.map +1 -0
  48. package/dist/cli/parsers/vscode-copilot.js +69 -0
  49. package/dist/cli/parsers/vscode-copilot.js.map +1 -0
  50. package/dist/cli/parsers/zed.d.ts +3 -0
  51. package/dist/cli/parsers/zed.d.ts.map +1 -0
  52. package/dist/cli/parsers/zed.js +43 -0
  53. package/dist/cli/parsers/zed.js.map +1 -0
  54. package/dist/cli/sync.d.ts +21 -0
  55. package/dist/cli/sync.d.ts.map +1 -0
  56. package/dist/cli/sync.js +78 -0
  57. package/dist/cli/sync.js.map +1 -0
  58. package/dist/cli/type-extractor.d.ts +25 -0
  59. package/dist/cli/type-extractor.d.ts.map +1 -0
  60. package/dist/cli/type-extractor.js +254 -0
  61. package/dist/cli/type-extractor.js.map +1 -0
  62. package/dist/cli/type-extractor.test.d.ts +2 -0
  63. package/dist/cli/type-extractor.test.d.ts.map +1 -0
  64. package/dist/cli/type-extractor.test.js +173 -0
  65. package/dist/cli/type-extractor.test.js.map +1 -0
  66. package/dist/client/http.d.ts +44 -0
  67. package/dist/client/http.d.ts.map +1 -0
  68. package/dist/client/http.js +311 -0
  69. package/dist/client/http.js.map +1 -0
  70. package/dist/client/index.d.ts +158 -0
  71. package/dist/client/index.d.ts.map +1 -0
  72. package/dist/client/index.js +256 -0
  73. package/dist/client/index.js.map +1 -0
  74. package/dist/component/_generated/api.d.ts +12 -0
  75. package/dist/component/_generated/api.d.ts.map +1 -0
  76. package/dist/component/_generated/api.js +13 -0
  77. package/dist/component/_generated/api.js.map +1 -0
  78. package/dist/component/_generated/dataModel.d.ts +18 -0
  79. package/dist/component/_generated/dataModel.d.ts.map +1 -0
  80. package/dist/component/_generated/dataModel.js +11 -0
  81. package/dist/component/_generated/dataModel.js.map +1 -0
  82. package/dist/component/_generated/server.d.ts +42 -0
  83. package/dist/component/_generated/server.d.ts.map +1 -0
  84. package/dist/component/_generated/server.js +39 -0
  85. package/dist/component/_generated/server.js.map +1 -0
  86. package/dist/component/actions.d.ts +42 -0
  87. package/dist/component/actions.d.ts.map +1 -0
  88. package/dist/component/actions.js +405 -0
  89. package/dist/component/actions.js.map +1 -0
  90. package/dist/component/apiKeyMutations.d.ts +29 -0
  91. package/dist/component/apiKeyMutations.d.ts.map +1 -0
  92. package/dist/component/apiKeyMutations.js +149 -0
  93. package/dist/component/apiKeyMutations.js.map +1 -0
  94. package/dist/component/apiKeyQueries.d.ts +37 -0
  95. package/dist/component/apiKeyQueries.d.ts.map +1 -0
  96. package/dist/component/apiKeyQueries.js +127 -0
  97. package/dist/component/apiKeyQueries.js.map +1 -0
  98. package/dist/component/checksum.d.ts +6 -0
  99. package/dist/component/checksum.d.ts.map +1 -0
  100. package/dist/component/checksum.js +14 -0
  101. package/dist/component/checksum.js.map +1 -0
  102. package/dist/component/checksum.test.d.ts +2 -0
  103. package/dist/component/checksum.test.d.ts.map +1 -0
  104. package/dist/component/checksum.test.js +27 -0
  105. package/dist/component/checksum.test.js.map +1 -0
  106. package/dist/component/convex.config.d.ts +3 -0
  107. package/dist/component/convex.config.d.ts.map +1 -0
  108. package/dist/component/convex.config.js +4 -0
  109. package/dist/component/convex.config.js.map +1 -0
  110. package/dist/component/cronActions.d.ts +3 -0
  111. package/dist/component/cronActions.d.ts.map +1 -0
  112. package/dist/component/cronActions.js +38 -0
  113. package/dist/component/cronActions.js.map +1 -0
  114. package/dist/component/cronQueries.d.ts +6 -0
  115. package/dist/component/cronQueries.d.ts.map +1 -0
  116. package/dist/component/cronQueries.js +38 -0
  117. package/dist/component/cronQueries.js.map +1 -0
  118. package/dist/component/crons.d.ts +3 -0
  119. package/dist/component/crons.d.ts.map +1 -0
  120. package/dist/component/crons.js +18 -0
  121. package/dist/component/crons.js.map +1 -0
  122. package/dist/component/format.d.ts +11 -0
  123. package/dist/component/format.d.ts.map +1 -0
  124. package/dist/component/format.js +175 -0
  125. package/dist/component/format.js.map +1 -0
  126. package/dist/component/format.test.d.ts +2 -0
  127. package/dist/component/format.test.d.ts.map +1 -0
  128. package/dist/component/format.test.js +118 -0
  129. package/dist/component/format.test.js.map +1 -0
  130. package/dist/component/mutations.d.ts +158 -0
  131. package/dist/component/mutations.d.ts.map +1 -0
  132. package/dist/component/mutations.js +745 -0
  133. package/dist/component/mutations.js.map +1 -0
  134. package/dist/component/queries.d.ts +94 -0
  135. package/dist/component/queries.d.ts.map +1 -0
  136. package/dist/component/queries.js +574 -0
  137. package/dist/component/queries.js.map +1 -0
  138. package/dist/component/schema.d.ts +278 -0
  139. package/dist/component/schema.d.ts.map +1 -0
  140. package/dist/component/schema.js +161 -0
  141. package/dist/component/schema.js.map +1 -0
  142. package/dist/mcp/server.d.ts +11 -0
  143. package/dist/mcp/server.d.ts.map +1 -0
  144. package/dist/mcp/server.js +571 -0
  145. package/dist/mcp/server.js.map +1 -0
  146. package/dist/shared.d.ts +126 -0
  147. package/dist/shared.d.ts.map +1 -0
  148. package/dist/shared.js +67 -0
  149. package/dist/shared.js.map +1 -0
  150. package/dist/test.d.ts +23 -0
  151. package/dist/test.d.ts.map +1 -0
  152. package/dist/test.js +21 -0
  153. package/dist/test.js.map +1 -0
  154. package/eslint.config.js +15 -0
  155. package/example/convex/convex.config.ts +7 -0
  156. package/example/convex/memory.ts +129 -0
  157. package/llms.md +175 -0
  158. package/llms.txt +126 -0
  159. package/package.json +80 -0
  160. package/prds/API-REFERENCE.md +935 -0
  161. package/prds/SETUP.md +682 -0
  162. package/src/cli/index.ts +254 -0
  163. package/src/cli/parsers/claude-code.ts +80 -0
  164. package/src/cli/parsers/codex.ts +45 -0
  165. package/src/cli/parsers/conductor.ts +47 -0
  166. package/src/cli/parsers/cursor.ts +55 -0
  167. package/src/cli/parsers/index.ts +30 -0
  168. package/src/cli/parsers/opencode.ts +84 -0
  169. package/src/cli/parsers/parsers.test.ts +201 -0
  170. package/src/cli/parsers/pi.ts +47 -0
  171. package/src/cli/parsers/types.ts +26 -0
  172. package/src/cli/parsers/vscode-copilot.ts +78 -0
  173. package/src/cli/parsers/zed.ts +47 -0
  174. package/src/cli/sync.ts +110 -0
  175. package/src/cli/type-extractor.test.ts +241 -0
  176. package/src/cli/type-extractor.ts +331 -0
  177. package/src/client/http.ts +415 -0
  178. package/src/client/index.ts +519 -0
  179. package/src/component/_generated/api.ts +14 -0
  180. package/src/component/_generated/dataModel.ts +20 -0
  181. package/src/component/_generated/server.ts +64 -0
  182. package/src/component/actions.ts +558 -0
  183. package/src/component/apiKeyMutations.ts +175 -0
  184. package/src/component/apiKeyQueries.ts +156 -0
  185. package/src/component/checksum.test.ts +31 -0
  186. package/src/component/checksum.ts +13 -0
  187. package/src/component/convex.config.ts +5 -0
  188. package/src/component/cronActions.ts +52 -0
  189. package/src/component/cronQueries.ts +42 -0
  190. package/src/component/crons.ts +34 -0
  191. package/src/component/format.test.ts +133 -0
  192. package/src/component/format.ts +232 -0
  193. package/src/component/mutations.ts +824 -0
  194. package/src/component/queries.ts +684 -0
  195. package/src/component/schema.ts +207 -0
  196. package/src/mcp/server.ts +695 -0
  197. package/src/shared.ts +251 -0
  198. package/src/test.ts +32 -0
  199. package/tsconfig.json +21 -0
  200. package/vitest.config.ts +8 -0
@@ -0,0 +1,519 @@
1
+ import type {
2
+ GenericActionCtx,
3
+ GenericDataModel,
4
+ GenericMutationCtx,
5
+ GenericQueryCtx,
6
+ } from "convex/server";
7
+ import type { api } from "../component/_generated/api.js";
8
+
9
+ import { computeChecksum } from "../component/checksum.js";
10
+ import type {
11
+ Memory,
12
+ MemoryType,
13
+ Scope,
14
+ ToolFormat,
15
+ ContextBundle,
16
+ ExportedFile,
17
+ ImportResult,
18
+ MemoryHistoryEntry,
19
+ MemoryFeedbackEntry,
20
+ MemoryRelation,
21
+ FeedbackSentiment,
22
+ IngestResult,
23
+ ApiKeyInfo,
24
+ ApiKeyCreateResult,
25
+ } from "../shared.js";
26
+
27
+ export type {
28
+ Memory,
29
+ MemoryType,
30
+ Scope,
31
+ ToolFormat,
32
+ ContextBundle,
33
+ ExportedFile,
34
+ ImportResult,
35
+ MemoryHistoryEntry,
36
+ MemoryFeedbackEntry,
37
+ MemoryRelation,
38
+ FeedbackSentiment,
39
+ IngestResult,
40
+ ApiKeyInfo,
41
+ ApiKeyCreateResult,
42
+ };
43
+
44
+ // ── Types ───────────────────────────────────────────────────────────
45
+
46
+ type QueryCtx = GenericQueryCtx<GenericDataModel>;
47
+ type MutationCtx = GenericMutationCtx<GenericDataModel>;
48
+ type ActionCtx = GenericActionCtx<GenericDataModel>;
49
+
50
+ type ComponentApi = typeof api;
51
+
52
+ export interface AgentMemoryConfig {
53
+ projectId: string;
54
+ defaultScope?: Scope;
55
+ userId?: string;
56
+ agentId?: string;
57
+ sessionId?: string;
58
+ embeddingApiKey?: string;
59
+ embeddingModel?: string;
60
+ llmApiKey?: string;
61
+ llmModel?: string;
62
+ llmBaseUrl?: string;
63
+ }
64
+
65
+ // ── Client class ────────────────────────────────────────────────────
66
+
67
+ export class AgentMemory {
68
+ public component: ComponentApi;
69
+ public config: AgentMemoryConfig;
70
+
71
+ constructor(component: ComponentApi, config: AgentMemoryConfig) {
72
+ this.component = component;
73
+ this.config = config;
74
+ }
75
+
76
+ // ── Read operations (query context) ─────────────────────────────
77
+
78
+ async list(
79
+ ctx: QueryCtx,
80
+ opts?: {
81
+ memoryType?: MemoryType;
82
+ scope?: Scope;
83
+ agentId?: string;
84
+ sessionId?: string;
85
+ source?: string;
86
+ tags?: string[];
87
+ minPriority?: number;
88
+ archived?: boolean;
89
+ createdAfter?: number;
90
+ createdBefore?: number;
91
+ limit?: number;
92
+ },
93
+ ): Promise<Memory[]> {
94
+ return (await ctx.runQuery(this.component.queries.list, {
95
+ projectId: this.config.projectId,
96
+ scope: opts?.scope ?? this.config.defaultScope,
97
+ userId: this.config.userId,
98
+ agentId: opts?.agentId ?? this.config.agentId,
99
+ sessionId: opts?.sessionId ?? this.config.sessionId,
100
+ memoryType: opts?.memoryType,
101
+ source: opts?.source,
102
+ tags: opts?.tags,
103
+ archived: opts?.archived,
104
+ minPriority: opts?.minPriority,
105
+ createdAfter: opts?.createdAfter,
106
+ createdBefore: opts?.createdBefore,
107
+ limit: opts?.limit,
108
+ })) as Memory[];
109
+ }
110
+
111
+ async get(ctx: QueryCtx, memoryId: string): Promise<Memory | null> {
112
+ return (await ctx.runQuery(this.component.queries.get, {
113
+ memoryId,
114
+ })) as Memory | null;
115
+ }
116
+
117
+ async search(
118
+ ctx: QueryCtx,
119
+ query: string,
120
+ opts?: {
121
+ memoryType?: MemoryType;
122
+ scope?: Scope;
123
+ limit?: number;
124
+ },
125
+ ): Promise<Memory[]> {
126
+ return (await ctx.runQuery(this.component.queries.search, {
127
+ projectId: this.config.projectId,
128
+ query,
129
+ memoryType: opts?.memoryType,
130
+ scope: opts?.scope,
131
+ limit: opts?.limit,
132
+ })) as Memory[];
133
+ }
134
+
135
+ async getContextBundle(
136
+ ctx: QueryCtx,
137
+ opts?: {
138
+ activePaths?: string[];
139
+ maxTokens?: number;
140
+ agentId?: string;
141
+ },
142
+ ): Promise<ContextBundle> {
143
+ return (await ctx.runQuery(this.component.queries.getContextBundle, {
144
+ projectId: this.config.projectId,
145
+ scope: this.config.defaultScope ?? "project",
146
+ userId: this.config.userId,
147
+ agentId: opts?.agentId ?? this.config.agentId,
148
+ activePaths: opts?.activePaths,
149
+ maxTokens: opts?.maxTokens,
150
+ })) as ContextBundle;
151
+ }
152
+
153
+ async exportForTool(
154
+ ctx: QueryCtx,
155
+ format: ToolFormat,
156
+ opts?: {
157
+ since?: number;
158
+ },
159
+ ): Promise<ExportedFile[]> {
160
+ return (await ctx.runQuery(this.component.queries.exportForTool, {
161
+ projectId: this.config.projectId,
162
+ format,
163
+ scope: this.config.defaultScope,
164
+ userId: this.config.userId,
165
+ since: opts?.since,
166
+ })) as ExportedFile[];
167
+ }
168
+
169
+ // ── History & audit trail (query context) ──────────────────────
170
+
171
+ async history(
172
+ ctx: QueryCtx,
173
+ memoryId: string,
174
+ opts?: { limit?: number },
175
+ ): Promise<MemoryHistoryEntry[]> {
176
+ return (await ctx.runQuery(this.component.queries.history, {
177
+ memoryId,
178
+ limit: opts?.limit,
179
+ })) as MemoryHistoryEntry[];
180
+ }
181
+
182
+ async projectHistory(
183
+ ctx: QueryCtx,
184
+ opts?: { limit?: number },
185
+ ): Promise<MemoryHistoryEntry[]> {
186
+ return (await ctx.runQuery(this.component.queries.projectHistory, {
187
+ projectId: this.config.projectId,
188
+ limit: opts?.limit,
189
+ })) as MemoryHistoryEntry[];
190
+ }
191
+
192
+ // ── Feedback (query + mutation context) ────────────────────────
193
+
194
+ async getFeedback(
195
+ ctx: QueryCtx,
196
+ memoryId: string,
197
+ opts?: { limit?: number },
198
+ ): Promise<MemoryFeedbackEntry[]> {
199
+ return (await ctx.runQuery(this.component.queries.getFeedback, {
200
+ memoryId,
201
+ limit: opts?.limit,
202
+ })) as MemoryFeedbackEntry[];
203
+ }
204
+
205
+ async addFeedback(
206
+ ctx: MutationCtx,
207
+ memoryId: string,
208
+ sentiment: FeedbackSentiment,
209
+ opts?: { comment?: string; actor?: string },
210
+ ): Promise<void> {
211
+ await ctx.runMutation(this.component.mutations.addFeedback, {
212
+ memoryId,
213
+ sentiment,
214
+ comment: opts?.comment,
215
+ actor: opts?.actor ?? this.config.agentId ?? this.config.userId ?? "unknown",
216
+ });
217
+ }
218
+
219
+ // ── Relations / graph (query + mutation context) ───────────────
220
+
221
+ async getRelations(
222
+ ctx: QueryCtx,
223
+ memoryId: string,
224
+ opts?: {
225
+ direction?: "from" | "to" | "both";
226
+ relationship?: string;
227
+ limit?: number;
228
+ },
229
+ ): Promise<MemoryRelation[]> {
230
+ return (await ctx.runQuery(this.component.queries.getRelations, {
231
+ memoryId,
232
+ direction: opts?.direction,
233
+ relationship: opts?.relationship,
234
+ limit: opts?.limit,
235
+ })) as MemoryRelation[];
236
+ }
237
+
238
+ async addRelation(
239
+ ctx: MutationCtx,
240
+ fromMemoryId: string,
241
+ toMemoryId: string,
242
+ relationship: string,
243
+ opts?: { confidence?: number; createdBy?: string },
244
+ ): Promise<string> {
245
+ return await ctx.runMutation(this.component.mutations.addRelation, {
246
+ projectId: this.config.projectId,
247
+ fromMemoryId,
248
+ toMemoryId,
249
+ relationship,
250
+ metadata: opts
251
+ ? { confidence: opts.confidence, createdBy: opts.createdBy }
252
+ : undefined,
253
+ });
254
+ }
255
+
256
+ async removeRelation(ctx: MutationCtx, relationId: string): Promise<void> {
257
+ await ctx.runMutation(this.component.mutations.removeRelation, {
258
+ relationId,
259
+ });
260
+ }
261
+
262
+ // ── Write operations (mutation context) ─────────────────────────
263
+
264
+ async remember(
265
+ ctx: MutationCtx,
266
+ memory: {
267
+ title: string;
268
+ content: string;
269
+ memoryType: MemoryType;
270
+ tags?: string[];
271
+ paths?: string[];
272
+ priority?: number;
273
+ source?: string;
274
+ agentId?: string;
275
+ sessionId?: string;
276
+ },
277
+ ): Promise<string> {
278
+ return await ctx.runMutation(this.component.mutations.create, {
279
+ projectId: this.config.projectId,
280
+ scope: this.config.defaultScope ?? "project",
281
+ userId: this.config.userId,
282
+ agentId: memory.agentId ?? this.config.agentId,
283
+ sessionId: memory.sessionId ?? this.config.sessionId,
284
+ ...memory,
285
+ });
286
+ }
287
+
288
+ async update(
289
+ ctx: MutationCtx,
290
+ memoryId: string,
291
+ updates: {
292
+ content?: string;
293
+ title?: string;
294
+ tags?: string[];
295
+ paths?: string[];
296
+ priority?: number;
297
+ memoryType?: MemoryType;
298
+ },
299
+ ): Promise<void> {
300
+ await ctx.runMutation(this.component.mutations.update, {
301
+ memoryId,
302
+ actor: this.config.agentId ?? this.config.userId,
303
+ ...updates,
304
+ });
305
+ }
306
+
307
+ async forget(ctx: MutationCtx, memoryId: string): Promise<void> {
308
+ await ctx.runMutation(this.component.mutations.archive, {
309
+ memoryId,
310
+ actor: this.config.agentId ?? this.config.userId,
311
+ });
312
+ }
313
+
314
+ async restore(ctx: MutationCtx, memoryId: string): Promise<void> {
315
+ await ctx.runMutation(this.component.mutations.restore, {
316
+ memoryId,
317
+ actor: this.config.agentId ?? this.config.userId,
318
+ });
319
+ }
320
+
321
+ // ── Batch operations (mutation context) ────────────────────────
322
+
323
+ async batchArchive(
324
+ ctx: MutationCtx,
325
+ memoryIds: string[],
326
+ ): Promise<{ archived: number; failed: number }> {
327
+ return await ctx.runMutation(this.component.mutations.batchArchive, {
328
+ memoryIds,
329
+ actor: this.config.agentId ?? this.config.userId,
330
+ });
331
+ }
332
+
333
+ async batchUpdate(
334
+ ctx: MutationCtx,
335
+ updates: Array<{
336
+ memoryId: string;
337
+ content?: string;
338
+ title?: string;
339
+ tags?: string[];
340
+ paths?: string[];
341
+ priority?: number;
342
+ memoryType?: MemoryType;
343
+ }>,
344
+ ): Promise<{ updated: number; failed: number }> {
345
+ return await ctx.runMutation(this.component.mutations.batchUpdate, {
346
+ updates,
347
+ actor: this.config.agentId ?? this.config.userId,
348
+ });
349
+ }
350
+
351
+ // ── Access tracking (mutation context) ─────────────────────────
352
+
353
+ async recordAccess(
354
+ ctx: MutationCtx,
355
+ memoryIds: string[],
356
+ ): Promise<void> {
357
+ await ctx.runMutation(this.component.mutations.recordAccess, {
358
+ memoryIds,
359
+ });
360
+ }
361
+
362
+ // ── Import operations (mutation context) ───────────────────────
363
+
364
+ async importLocal(
365
+ ctx: MutationCtx,
366
+ memories: Array<{
367
+ title: string;
368
+ content: string;
369
+ memoryType: MemoryType;
370
+ scope: Scope;
371
+ tags: string[];
372
+ paths?: string[];
373
+ priority?: number;
374
+ source: string;
375
+ checksum: string;
376
+ }>,
377
+ ): Promise<ImportResult> {
378
+ return (await ctx.runMutation(this.component.mutations.importFromLocal, {
379
+ projectId: this.config.projectId,
380
+ userId: this.config.userId,
381
+ memories,
382
+ })) as ImportResult;
383
+ }
384
+
385
+ // ── Type ingestion (mutation context) ──────────────────────────
386
+
387
+ async ingestTypes(
388
+ ctx: MutationCtx,
389
+ typeMemories: Array<{
390
+ title: string;
391
+ content: string;
392
+ tags?: string[];
393
+ paths?: string[];
394
+ priority?: number;
395
+ }>,
396
+ ): Promise<ImportResult> {
397
+ const memories = typeMemories.map((m) => ({
398
+ title: m.title.startsWith("types/") ? m.title : `types/${m.title}`,
399
+ content: m.content,
400
+ memoryType: "reference" as const,
401
+ scope: (this.config.defaultScope ?? "project") as Scope,
402
+ tags: ["typescript", "types", "auto-generated", ...(m.tags ?? [])],
403
+ paths: m.paths,
404
+ priority: m.priority ?? 0.6,
405
+ source: "ingest-types",
406
+ checksum: computeChecksum(m.content),
407
+ }));
408
+ return this.importLocal(ctx, memories);
409
+ }
410
+
411
+ // ── Embedding operations (action context) ─────────────────────
412
+
413
+ async embed(ctx: ActionCtx, memoryId: string): Promise<void> {
414
+ const apiKey = this.config.embeddingApiKey;
415
+ if (!apiKey) throw new Error("embeddingApiKey is required for embed()");
416
+
417
+ await ctx.runAction(this.component.actions.generateEmbedding, {
418
+ memoryId,
419
+ embeddingApiKey: apiKey,
420
+ model: this.config.embeddingModel,
421
+ });
422
+ }
423
+
424
+ async embedAll(
425
+ ctx: ActionCtx,
426
+ ): Promise<{ embedded: number; skipped: number }> {
427
+ const apiKey = this.config.embeddingApiKey;
428
+ if (!apiKey) throw new Error("embeddingApiKey is required for embedAll()");
429
+
430
+ return await ctx.runAction(this.component.actions.embedAll, {
431
+ projectId: this.config.projectId,
432
+ embeddingApiKey: apiKey,
433
+ model: this.config.embeddingModel,
434
+ });
435
+ }
436
+
437
+ async semanticSearch(
438
+ ctx: ActionCtx,
439
+ query: string,
440
+ opts?: { limit?: number },
441
+ ): Promise<Memory[]> {
442
+ return (await ctx.runAction(this.component.actions.semanticSearch, {
443
+ projectId: this.config.projectId,
444
+ query,
445
+ embeddingApiKey: this.config.embeddingApiKey,
446
+ limit: opts?.limit,
447
+ })) as Memory[];
448
+ }
449
+
450
+ // ── Intelligent ingest (action context) ───────────────────────
451
+
452
+ async ingest(
453
+ ctx: ActionCtx,
454
+ content: string,
455
+ opts?: {
456
+ scope?: Scope;
457
+ agentId?: string;
458
+ sessionId?: string;
459
+ customExtractionPrompt?: string;
460
+ customUpdatePrompt?: string;
461
+ },
462
+ ): Promise<IngestResult> {
463
+ const llmApiKey = this.config.llmApiKey;
464
+ if (!llmApiKey) throw new Error("llmApiKey is required for ingest()");
465
+
466
+ return (await ctx.runAction(this.component.actions.ingest, {
467
+ projectId: this.config.projectId,
468
+ content,
469
+ scope: opts?.scope ?? this.config.defaultScope,
470
+ userId: this.config.userId,
471
+ agentId: opts?.agentId ?? this.config.agentId,
472
+ sessionId: opts?.sessionId ?? this.config.sessionId,
473
+ llmApiKey,
474
+ llmModel: this.config.llmModel,
475
+ llmBaseUrl: this.config.llmBaseUrl,
476
+ embeddingApiKey: this.config.embeddingApiKey,
477
+ customExtractionPrompt: opts?.customExtractionPrompt,
478
+ customUpdatePrompt: opts?.customUpdatePrompt,
479
+ })) as IngestResult;
480
+ }
481
+
482
+ // ── API key management (mutation/query context) ──────────────────
483
+
484
+ async createApiKey(
485
+ ctx: MutationCtx,
486
+ opts: {
487
+ name: string;
488
+ permissions: string[];
489
+ rateLimitOverride?: {
490
+ requestsPerWindow: number;
491
+ windowMs: number;
492
+ };
493
+ expiresAt?: number;
494
+ },
495
+ ): Promise<ApiKeyCreateResult> {
496
+ return (await ctx.runMutation(
497
+ this.component.apiKeyMutations.createApiKey,
498
+ {
499
+ projectId: this.config.projectId,
500
+ name: opts.name,
501
+ permissions: opts.permissions,
502
+ rateLimitOverride: opts.rateLimitOverride,
503
+ expiresAt: opts.expiresAt,
504
+ },
505
+ )) as ApiKeyCreateResult;
506
+ }
507
+
508
+ async revokeApiKey(ctx: MutationCtx, keyHash: string): Promise<void> {
509
+ await ctx.runMutation(this.component.apiKeyMutations.revokeApiKey, {
510
+ keyHash,
511
+ });
512
+ }
513
+
514
+ async listApiKeys(ctx: QueryCtx): Promise<ApiKeyInfo[]> {
515
+ return (await ctx.runQuery(this.component.apiKeyQueries.listApiKeys, {
516
+ projectId: this.config.projectId,
517
+ })) as ApiKeyInfo[];
518
+ }
519
+ }
@@ -0,0 +1,14 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated API types for the component.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import { anyApi } from "convex/server";
12
+
13
+ export const api: typeof anyApi = anyApi;
14
+ export const internal: typeof anyApi = anyApi;
@@ -0,0 +1,20 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated data model types for the component.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import type { AnyDataModel } from "convex/server";
12
+
13
+ export type DataModel = AnyDataModel;
14
+
15
+ export type Doc<TableName extends string> = Record<string, any> & {
16
+ _id: string;
17
+ _creationTime: number;
18
+ };
19
+
20
+ export type Id<TableName extends string> = string & { __tableName: TableName };
@@ -0,0 +1,64 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated utilities for the component server.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import {
12
+ actionGeneric,
13
+ queryGeneric,
14
+ mutationGeneric,
15
+ internalActionGeneric,
16
+ internalQueryGeneric,
17
+ internalMutationGeneric,
18
+ componentsGeneric,
19
+ type GenericQueryCtx,
20
+ type GenericMutationCtx,
21
+ type GenericActionCtx,
22
+ } from "convex/server";
23
+ import type { DataModel } from "./dataModel.js";
24
+
25
+ /**
26
+ * Define a query in this Convex component.
27
+ */
28
+ export const query = queryGeneric as typeof queryGeneric;
29
+
30
+ /**
31
+ * Define a mutation in this Convex component.
32
+ */
33
+ export const mutation = mutationGeneric as typeof mutationGeneric;
34
+
35
+ /**
36
+ * Define an action in this Convex component.
37
+ */
38
+ export const action = actionGeneric as typeof actionGeneric;
39
+
40
+ /**
41
+ * Define an internal query in this Convex component.
42
+ */
43
+ export const internalQuery = internalQueryGeneric as typeof internalQueryGeneric;
44
+
45
+ /**
46
+ * Define an internal mutation in this Convex component.
47
+ */
48
+ export const internalMutation =
49
+ internalMutationGeneric as typeof internalMutationGeneric;
50
+
51
+ /**
52
+ * Define an internal action in this Convex component.
53
+ */
54
+ export const internalAction =
55
+ internalActionGeneric as typeof internalActionGeneric;
56
+
57
+ /**
58
+ * Access component APIs.
59
+ */
60
+ export const components = componentsGeneric();
61
+
62
+ export type QueryCtx = GenericQueryCtx<DataModel>;
63
+ export type MutationCtx = GenericMutationCtx<DataModel>;
64
+ export type ActionCtx = GenericActionCtx<DataModel>;