mem-os-python 1.6.27__py3-none-any.whl

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 (253) hide show
  1. mem_os_python-1.6.27.dist-info/METADATA +1032 -0
  2. mem_os_python-1.6.27.dist-info/RECORD +253 -0
  3. mem_os_python-1.6.27.dist-info/WHEEL +4 -0
  4. mem_os_python-1.6.27.dist-info/entry_points.txt +2 -0
  5. mem_os_python-1.6.27.dist-info/licenses/LICENSE +21 -0
  6. memos/__init__.py +16 -0
  7. memos/_js/adapters/anthropic.d.ts +279 -0
  8. memos/_js/adapters/anthropic.d.ts.map +1 -0
  9. memos/_js/adapters/anthropic.js +348 -0
  10. memos/_js/adapters/anthropic.js.map +1 -0
  11. memos/_js/adapters/base.d.ts +10 -0
  12. memos/_js/adapters/base.d.ts.map +1 -0
  13. memos/_js/adapters/base.js +2 -0
  14. memos/_js/adapters/base.js.map +1 -0
  15. memos/_js/adapters/openai.d.ts +264 -0
  16. memos/_js/adapters/openai.d.ts.map +1 -0
  17. memos/_js/adapters/openai.js +342 -0
  18. memos/_js/adapters/openai.js.map +1 -0
  19. memos/_js/apps/explorer.d.ts +244 -0
  20. memos/_js/apps/explorer.d.ts.map +1 -0
  21. memos/_js/apps/explorer.js +738 -0
  22. memos/_js/apps/explorer.js.map +1 -0
  23. memos/_js/citations.d.ts +65 -0
  24. memos/_js/citations.d.ts.map +1 -0
  25. memos/_js/citations.js +143 -0
  26. memos/_js/citations.js.map +1 -0
  27. memos/_js/cli-browse.d.ts +3 -0
  28. memos/_js/cli-browse.d.ts.map +1 -0
  29. memos/_js/cli-browse.js +129 -0
  30. memos/_js/cli-browse.js.map +1 -0
  31. memos/_js/cli-completion.d.ts +31 -0
  32. memos/_js/cli-completion.d.ts.map +1 -0
  33. memos/_js/cli-completion.js +340 -0
  34. memos/_js/cli-completion.js.map +1 -0
  35. memos/_js/cli-help.d.ts +18 -0
  36. memos/_js/cli-help.d.ts.map +1 -0
  37. memos/_js/cli-help.js +357 -0
  38. memos/_js/cli-help.js.map +1 -0
  39. memos/_js/cli.d.ts +28 -0
  40. memos/_js/cli.d.ts.map +1 -0
  41. memos/_js/cli.js +2880 -0
  42. memos/_js/cli.js.map +1 -0
  43. memos/_js/compression.d.ts +25 -0
  44. memos/_js/compression.d.ts.map +1 -0
  45. memos/_js/compression.js +319 -0
  46. memos/_js/compression.js.map +1 -0
  47. memos/_js/confidence-machine.d.ts +99 -0
  48. memos/_js/confidence-machine.d.ts.map +1 -0
  49. memos/_js/confidence-machine.js +222 -0
  50. memos/_js/confidence-machine.js.map +1 -0
  51. memos/_js/context-pack.d.ts +506 -0
  52. memos/_js/context-pack.d.ts.map +1 -0
  53. memos/_js/context-pack.js +1435 -0
  54. memos/_js/context-pack.js.map +1 -0
  55. memos/_js/contradictions.d.ts +160 -0
  56. memos/_js/contradictions.d.ts.map +1 -0
  57. memos/_js/contradictions.js +255 -0
  58. memos/_js/contradictions.js.map +1 -0
  59. memos/_js/dashboard.d.ts +30 -0
  60. memos/_js/dashboard.d.ts.map +1 -0
  61. memos/_js/dashboard.js +302 -0
  62. memos/_js/dashboard.js.map +1 -0
  63. memos/_js/ebbinghaus.d.ts +29 -0
  64. memos/_js/ebbinghaus.d.ts.map +1 -0
  65. memos/_js/ebbinghaus.js +32 -0
  66. memos/_js/ebbinghaus.js.map +1 -0
  67. memos/_js/embedding-queue.d.ts +190 -0
  68. memos/_js/embedding-queue.d.ts.map +1 -0
  69. memos/_js/embedding-queue.js +316 -0
  70. memos/_js/embedding-queue.js.map +1 -0
  71. memos/_js/embeddings.d.ts +187 -0
  72. memos/_js/embeddings.d.ts.map +1 -0
  73. memos/_js/embeddings.js +633 -0
  74. memos/_js/embeddings.js.map +1 -0
  75. memos/_js/entity-extraction.d.ts +54 -0
  76. memos/_js/entity-extraction.d.ts.map +1 -0
  77. memos/_js/entity-extraction.js +325 -0
  78. memos/_js/entity-extraction.js.map +1 -0
  79. memos/_js/entity-index.d.ts +93 -0
  80. memos/_js/entity-index.d.ts.map +1 -0
  81. memos/_js/entity-index.js +165 -0
  82. memos/_js/entity-index.js.map +1 -0
  83. memos/_js/event-memory.d.ts +147 -0
  84. memos/_js/event-memory.d.ts.map +1 -0
  85. memos/_js/event-memory.js +290 -0
  86. memos/_js/event-memory.js.map +1 -0
  87. memos/_js/external-import.d.ts +98 -0
  88. memos/_js/external-import.d.ts.map +1 -0
  89. memos/_js/external-import.js +669 -0
  90. memos/_js/external-import.js.map +1 -0
  91. memos/_js/fidelity.d.ts +367 -0
  92. memos/_js/fidelity.d.ts.map +1 -0
  93. memos/_js/fidelity.js +911 -0
  94. memos/_js/fidelity.js.map +1 -0
  95. memos/_js/graph-expansion.d.ts +119 -0
  96. memos/_js/graph-expansion.d.ts.map +1 -0
  97. memos/_js/graph-expansion.js +213 -0
  98. memos/_js/graph-expansion.js.map +1 -0
  99. memos/_js/graph-mermaid.d.ts +13 -0
  100. memos/_js/graph-mermaid.d.ts.map +1 -0
  101. memos/_js/graph-mermaid.js +32 -0
  102. memos/_js/graph-mermaid.js.map +1 -0
  103. memos/_js/graph.d.ts +170 -0
  104. memos/_js/graph.d.ts.map +1 -0
  105. memos/_js/graph.js +482 -0
  106. memos/_js/graph.js.map +1 -0
  107. memos/_js/harness.d.ts +63 -0
  108. memos/_js/harness.d.ts.map +1 -0
  109. memos/_js/harness.js +93 -0
  110. memos/_js/harness.js.map +1 -0
  111. memos/_js/importance.d.ts +118 -0
  112. memos/_js/importance.d.ts.map +1 -0
  113. memos/_js/importance.js +144 -0
  114. memos/_js/importance.js.map +1 -0
  115. memos/_js/index.d.ts +51 -0
  116. memos/_js/index.d.ts.map +1 -0
  117. memos/_js/index.js +53 -0
  118. memos/_js/index.js.map +1 -0
  119. memos/_js/mcp.d.ts +58 -0
  120. memos/_js/mcp.d.ts.map +1 -0
  121. memos/_js/mcp.js +1853 -0
  122. memos/_js/mcp.js.map +1 -0
  123. memos/_js/memory.d.ts +1762 -0
  124. memos/_js/memory.d.ts.map +1 -0
  125. memos/_js/memory.js +6283 -0
  126. memos/_js/memory.js.map +1 -0
  127. memos/_js/procedural.d.ts +74 -0
  128. memos/_js/procedural.d.ts.map +1 -0
  129. memos/_js/procedural.js +125 -0
  130. memos/_js/procedural.js.map +1 -0
  131. memos/_js/project-config.d.ts +68 -0
  132. memos/_js/project-config.d.ts.map +1 -0
  133. memos/_js/project-config.js +59 -0
  134. memos/_js/project-config.js.map +1 -0
  135. memos/_js/proof-of-forgetting.d.ts +57 -0
  136. memos/_js/proof-of-forgetting.d.ts.map +1 -0
  137. memos/_js/proof-of-forgetting.js +80 -0
  138. memos/_js/proof-of-forgetting.js.map +1 -0
  139. memos/_js/provenance.d.ts +122 -0
  140. memos/_js/provenance.d.ts.map +1 -0
  141. memos/_js/provenance.js +182 -0
  142. memos/_js/provenance.js.map +1 -0
  143. memos/_js/quarantine-commands.d.ts +23 -0
  144. memos/_js/quarantine-commands.d.ts.map +1 -0
  145. memos/_js/quarantine-commands.js +42 -0
  146. memos/_js/quarantine-commands.js.map +1 -0
  147. memos/_js/quarantine.d.ts +120 -0
  148. memos/_js/quarantine.d.ts.map +1 -0
  149. memos/_js/quarantine.js +873 -0
  150. memos/_js/quarantine.js.map +1 -0
  151. memos/_js/redact.d.ts +12 -0
  152. memos/_js/redact.d.ts.map +1 -0
  153. memos/_js/redact.js +26 -0
  154. memos/_js/redact.js.map +1 -0
  155. memos/_js/repl.d.ts +57 -0
  156. memos/_js/repl.d.ts.map +1 -0
  157. memos/_js/repl.js +295 -0
  158. memos/_js/repl.js.map +1 -0
  159. memos/_js/rerank-local.d.ts +61 -0
  160. memos/_js/rerank-local.d.ts.map +1 -0
  161. memos/_js/rerank-local.js +210 -0
  162. memos/_js/rerank-local.js.map +1 -0
  163. memos/_js/retain-filter.d.ts +98 -0
  164. memos/_js/retain-filter.d.ts.map +1 -0
  165. memos/_js/retain-filter.js +232 -0
  166. memos/_js/retain-filter.js.map +1 -0
  167. memos/_js/retrieval.d.ts +265 -0
  168. memos/_js/retrieval.d.ts.map +1 -0
  169. memos/_js/retrieval.js +1018 -0
  170. memos/_js/retrieval.js.map +1 -0
  171. memos/_js/revert.d.ts +77 -0
  172. memos/_js/revert.d.ts.map +1 -0
  173. memos/_js/revert.js +252 -0
  174. memos/_js/revert.js.map +1 -0
  175. memos/_js/scope.d.ts +30 -0
  176. memos/_js/scope.d.ts.map +1 -0
  177. memos/_js/scope.js +71 -0
  178. memos/_js/scope.js.map +1 -0
  179. memos/_js/semantic-screen.d.ts +152 -0
  180. memos/_js/semantic-screen.d.ts.map +1 -0
  181. memos/_js/semantic-screen.js +290 -0
  182. memos/_js/semantic-screen.js.map +1 -0
  183. memos/_js/session-hooks.d.ts +127 -0
  184. memos/_js/session-hooks.d.ts.map +1 -0
  185. memos/_js/session-hooks.js +482 -0
  186. memos/_js/session-hooks.js.map +1 -0
  187. memos/_js/storage/sqlite.d.ts +427 -0
  188. memos/_js/storage/sqlite.d.ts.map +1 -0
  189. memos/_js/storage/sqlite.js +2428 -0
  190. memos/_js/storage/sqlite.js.map +1 -0
  191. memos/_js/sync.d.ts +213 -0
  192. memos/_js/sync.d.ts.map +1 -0
  193. memos/_js/sync.js +389 -0
  194. memos/_js/sync.js.map +1 -0
  195. memos/_js/tamper-log.d.ts +98 -0
  196. memos/_js/tamper-log.d.ts.map +1 -0
  197. memos/_js/tamper-log.js +327 -0
  198. memos/_js/tamper-log.js.map +1 -0
  199. memos/_js/temporal.d.ts +92 -0
  200. memos/_js/temporal.d.ts.map +1 -0
  201. memos/_js/temporal.js +536 -0
  202. memos/_js/temporal.js.map +1 -0
  203. memos/_js/time-travel.d.ts +38 -0
  204. memos/_js/time-travel.d.ts.map +1 -0
  205. memos/_js/time-travel.js +46 -0
  206. memos/_js/time-travel.js.map +1 -0
  207. memos/_js/timestamp-format.d.ts +18 -0
  208. memos/_js/timestamp-format.d.ts.map +1 -0
  209. memos/_js/timestamp-format.js +52 -0
  210. memos/_js/timestamp-format.js.map +1 -0
  211. memos/_js/triple-extraction.d.ts +31 -0
  212. memos/_js/triple-extraction.d.ts.map +1 -0
  213. memos/_js/triple-extraction.js +116 -0
  214. memos/_js/triple-extraction.js.map +1 -0
  215. memos/_js/types.d.ts +2474 -0
  216. memos/_js/types.d.ts.map +1 -0
  217. memos/_js/types.js +20 -0
  218. memos/_js/types.js.map +1 -0
  219. memos/_js/updater.d.ts +95 -0
  220. memos/_js/updater.d.ts.map +1 -0
  221. memos/_js/updater.js +268 -0
  222. memos/_js/updater.js.map +1 -0
  223. memos/_js/version.d.ts +17 -0
  224. memos/_js/version.d.ts.map +1 -0
  225. memos/_js/version.js +34 -0
  226. memos/_js/version.js.map +1 -0
  227. memos/_js/vision/clip-query-cache.d.ts +58 -0
  228. memos/_js/vision/clip-query-cache.d.ts.map +1 -0
  229. memos/_js/vision/clip-query-cache.js +79 -0
  230. memos/_js/vision/clip-query-cache.js.map +1 -0
  231. memos/_js/vision/clip.d.ts +113 -0
  232. memos/_js/vision/clip.d.ts.map +1 -0
  233. memos/_js/vision/clip.js +224 -0
  234. memos/_js/vision/clip.js.map +1 -0
  235. memos/_js/vision/fake-clip.d.ts +55 -0
  236. memos/_js/vision/fake-clip.d.ts.map +1 -0
  237. memos/_js/vision/fake-clip.js +122 -0
  238. memos/_js/vision/fake-clip.js.map +1 -0
  239. memos/_js/vision/index.d.ts +15 -0
  240. memos/_js/vision/index.d.ts.map +1 -0
  241. memos/_js/vision/index.js +13 -0
  242. memos/_js/vision/index.js.map +1 -0
  243. memos/_js/vision/store.d.ts +137 -0
  244. memos/_js/vision/store.d.ts.map +1 -0
  245. memos/_js/vision/store.js +383 -0
  246. memos/_js/vision/store.js.map +1 -0
  247. memos/adapters/__init__.py +0 -0
  248. memos/adapters/crewai.py +385 -0
  249. memos/adapters/langchain.py +301 -0
  250. memos/adapters/ollama.py +396 -0
  251. memos/server/__init__.py +0 -0
  252. memos/server/main.py +547 -0
  253. memos/server/routes.py +360 -0
@@ -0,0 +1,342 @@
1
+ /**
2
+ * MemOS OpenAI Adapter — first-class memory integration for the OpenAI SDK.
3
+ *
4
+ * Wraps a MemOS instance and exposes helpers that map cleanly onto the
5
+ * OpenAI Chat Completions API: a memory-backed function tool, system-prompt
6
+ * context injection, automatic fact extraction from conversations, and
7
+ * simple store/forget helpers.
8
+ *
9
+ * The adapter has **zero hard dependencies** on the `openai` package. Every
10
+ * exported message/tool shape is structurally compatible with the
11
+ * corresponding `openai` types (`ChatCompletionMessageParam`,
12
+ * `ChatCompletionTool`, `ChatCompletionToolMessageParam`), so they can be
13
+ * passed straight into `openai.chat.completions.create(...)` with no glue
14
+ * layer. Install `openai` only if you want to call the model; the adapter
15
+ * itself only needs MemOS.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import OpenAI from "openai";
20
+ * import { createOpenAIMemory } from "@mem-os/sdk/openai";
21
+ *
22
+ * const { plugin } = await createOpenAIMemory({ dbPath: "./my-app.db" });
23
+ * const openai = new OpenAI();
24
+ *
25
+ * const completion = await openai.chat.completions.create({
26
+ * model: "gpt-4o",
27
+ * messages: [{ role: "user", content: "What theme do I like?" }],
28
+ * tools: [plugin.memoryTool],
29
+ * });
30
+ * ```
31
+ *
32
+ * @module @memos/adapters/openai
33
+ */
34
+ import { MemOS } from "../index.js";
35
+ // ---------------------------------------------------------------------------
36
+ // Plugin
37
+ // ---------------------------------------------------------------------------
38
+ /**
39
+ * OpenAI SDK memory plugin backed by MemOS.
40
+ *
41
+ * Wrap an existing MemOS instance, or use {@link createOpenAIMemory} to
42
+ * construct both in one call. The plugin does not call the OpenAI API
43
+ * itself — it prepares memories (as tools, tool messages, and system-prompt
44
+ * strings) for you to feed into your own `openai.chat.completions` calls.
45
+ */
46
+ export class MemOSOpenAIPlugin {
47
+ /** The wrapped MemOS instance. */
48
+ memos;
49
+ opts;
50
+ /**
51
+ * Create a new OpenAI memory plugin.
52
+ *
53
+ * @param memos - An initialised MemOS instance.
54
+ * @param opts - Plugin options. All fields optional with sensible defaults.
55
+ */
56
+ constructor(memos, opts = {}) {
57
+ this.memos = memos;
58
+ this.opts = {
59
+ maxContextMemories: opts.maxContextMemories ?? 5,
60
+ autoExtractFacts: opts.autoExtractFacts ?? true,
61
+ minMessageLength: opts.minMessageLength ?? 15,
62
+ source: opts.source ?? "user_input",
63
+ minConfidence: opts.minConfidence ?? 0.6,
64
+ namespace: opts.namespace ?? "default",
65
+ };
66
+ }
67
+ /**
68
+ * OpenAI function-tool definition that lets the model search the user's
69
+ * memory. Pass it via the `tools` parameter of
70
+ * `openai.chat.completions.create`.
71
+ *
72
+ * When the model invokes it, call {@link searchMemories} and return the
73
+ * `toolMessage` field (after setting `tool_call_id`) as a tool message.
74
+ */
75
+ get memoryTool() {
76
+ return {
77
+ type: "function",
78
+ function: {
79
+ name: "search_memories",
80
+ description: "Search the user's persistent MemOS memory for relevant facts, " +
81
+ "preferences, and context. Call this before answering personal or " +
82
+ "preference questions, or when prior context seems relevant.",
83
+ parameters: {
84
+ type: "object",
85
+ properties: {
86
+ query: {
87
+ type: "string",
88
+ description: "Natural-language search query.",
89
+ },
90
+ limit: {
91
+ type: "number",
92
+ description: "Maximum number of memories to return.",
93
+ default: 5,
94
+ },
95
+ },
96
+ required: ["query"],
97
+ },
98
+ },
99
+ };
100
+ }
101
+ /**
102
+ * Extract facts from a conversation and store them in MemOS.
103
+ *
104
+ * Runs MemOS' local rule-based fact extractor over the conversation,
105
+ * persisting any candidate facts whose confidence meets the configured
106
+ * `minConfidence` threshold. Near-duplicates are skipped automatically
107
+ * when embeddings are available.
108
+ *
109
+ * @param conversation - The messages to extract facts from.
110
+ * @returns The extraction result (candidate facts, stored ids, dup count).
111
+ */
112
+ async addMessages(conversation) {
113
+ const candidates = conversation.filter((m) => m.content.trim().length >= this.opts.minMessageLength);
114
+ if (candidates.length === 0) {
115
+ return { facts: [], storedIds: [], duplicates: 0 };
116
+ }
117
+ return this.memos.extractFacts(candidates, {
118
+ autoStore: true,
119
+ minConfidence: this.opts.minConfidence,
120
+ namespace: this.opts.namespace,
121
+ dedupe: true,
122
+ });
123
+ }
124
+ /**
125
+ * Search memories and format the results for OpenAI tool use.
126
+ *
127
+ * @param query - Natural-language search query.
128
+ * @param opts - Search options (limit, type, namespace).
129
+ * @returns An object containing the ranked memory entries and a
130
+ * ready-to-send `tool` message (JSON-encoded memories). Set
131
+ * `toolMessage.tool_call_id` to the model's `tool_call` id before
132
+ * returning it.
133
+ */
134
+ async searchMemories(query, opts = {}) {
135
+ const filter = {
136
+ query,
137
+ limit: opts.limit ?? this.opts.maxContextMemories,
138
+ };
139
+ if (opts.type)
140
+ filter.type = opts.type;
141
+ if (opts.namespace)
142
+ filter.namespace = opts.namespace;
143
+ const results = await this.memos.search(filter);
144
+ const memories = results.map((r) => this.toEntry(r));
145
+ const content = memories.length > 0
146
+ ? JSON.stringify(memories, null, 2)
147
+ : "No relevant memories found.";
148
+ return {
149
+ query,
150
+ memories,
151
+ toolMessage: { role: "tool", content },
152
+ };
153
+ }
154
+ /**
155
+ * Build a system-prompt string of relevant memories for injection.
156
+ *
157
+ * Optionally extracts & stores facts from the recent `messages` first,
158
+ * then searches MemOS using the most recent user message and returns the
159
+ * matches as a formatted block ready to prepend to the `system` prompt.
160
+ *
161
+ * @param messages - Recent conversation messages.
162
+ * @param opts - Context options (limit, whether to extract).
163
+ * @returns A memory-context string, or `""` if nothing relevant was found.
164
+ */
165
+ async getMemoryContext(messages, opts = {}) {
166
+ const shouldExtract = opts.extract ?? this.opts.autoExtractFacts;
167
+ if (shouldExtract && messages.length > 0) {
168
+ await this.addMessages(messages);
169
+ }
170
+ const lastUser = [...messages].reverse().find((m) => m.role === "user");
171
+ const query = lastUser?.content.trim() ?? "";
172
+ if (!query)
173
+ return "";
174
+ const results = await this.memos.search({
175
+ query,
176
+ limit: opts.limit ?? this.opts.maxContextMemories,
177
+ });
178
+ if (results.length === 0)
179
+ return "";
180
+ const lines = ["Relevant memories from prior conversations:"];
181
+ results.forEach((m, i) => {
182
+ lines.push(` ${i + 1}. [${m.node.type}] ${m.node.content}`);
183
+ });
184
+ return lines.join("\n");
185
+ }
186
+ /**
187
+ * Manually store a memory.
188
+ *
189
+ * @param content - Text to remember.
190
+ * @param opts - Additional memory parameters (type, tags, importance…).
191
+ * @returns The created memory node.
192
+ */
193
+ async remember(content, opts = {}) {
194
+ const { node } = await this.memos.store(content, {
195
+ ...opts,
196
+ source: opts.source ?? this.opts.source,
197
+ namespace: opts.namespace ?? this.opts.namespace,
198
+ });
199
+ return node;
200
+ }
201
+ /**
202
+ * Search for relevant memories.
203
+ *
204
+ * @param query - Search query.
205
+ * @param limit - Maximum number of results. @default 5
206
+ * @returns Scored memory nodes.
207
+ */
208
+ async recall(query, limit = 5) {
209
+ return this.memos.search({ query, limit });
210
+ }
211
+ /**
212
+ * Permanently forget a memory.
213
+ *
214
+ * @param memoryId - ID of the memory to delete.
215
+ * @returns `true` if the memory existed and was deleted.
216
+ */
217
+ async forget(memoryId) {
218
+ return this.memos.forget(memoryId);
219
+ }
220
+ /**
221
+ * Remove all memories and edges from the underlying MemOS instance.
222
+ *
223
+ * This is destructive and cannot be undone.
224
+ */
225
+ async clearMemories() {
226
+ await this.memos.clear();
227
+ }
228
+ /**
229
+ * Return the total number of stored memories.
230
+ *
231
+ * @returns The current memory count.
232
+ */
233
+ getMemoryCount() {
234
+ return this.memos.count;
235
+ }
236
+ /** Convert a scored memory into a JSON-friendly entry. */
237
+ toEntry(scored) {
238
+ return {
239
+ id: scored.node.id,
240
+ content: scored.node.content,
241
+ summary: scored.node.summary,
242
+ type: scored.node.type,
243
+ score: scored.score,
244
+ tags: scored.node.tags,
245
+ trustScore: scored.node.trustScore,
246
+ };
247
+ }
248
+ }
249
+ // ---------------------------------------------------------------------------
250
+ // Convenience constructor
251
+ // ---------------------------------------------------------------------------
252
+ /**
253
+ * Create a MemOS instance and an OpenAI memory plugin in one call.
254
+ *
255
+ * The MemOS instance is created with `config`, initialised, and wrapped in a
256
+ * {@link MemOSOpenAIPlugin}. Plugin-level options go under `config.plugin`.
257
+ *
258
+ * @param config - MemOS config plus optional `plugin` options.
259
+ * @returns The initialised `memos` instance and bound `plugin`.
260
+ *
261
+ * @example
262
+ * ```ts
263
+ * const { memos, plugin } = await createOpenAIMemory({
264
+ * dbPath: "./my-app.db",
265
+ * plugin: { maxContextMemories: 8 },
266
+ * });
267
+ * ```
268
+ */
269
+ export async function createOpenAIMemory(config = {}) {
270
+ const { plugin: pluginOpts, ...memosConfig } = config;
271
+ const memos = new MemOS(memosConfig);
272
+ await memos.init();
273
+ const plugin = new MemOSOpenAIPlugin(memos, pluginOpts);
274
+ return { memos, plugin };
275
+ }
276
+ // ---------------------------------------------------------------------------
277
+ // Usage example
278
+ // ---------------------------------------------------------------------------
279
+ /*
280
+ * End-to-end example using the official `openai` SDK.
281
+ *
282
+ * npm install openai
283
+ *
284
+ * import OpenAI from "openai";
285
+ * import { createOpenAIMemory } from "@mem-os/sdk/openai";
286
+ *
287
+ * // 1. Boot MemOS + the plugin.
288
+ * const { memos, plugin } = await createOpenAIMemory({
289
+ * dbPath: "./my-app.db",
290
+ * plugin: { maxContextMemories: 6 },
291
+ * });
292
+ *
293
+ * const openai = new OpenAI();
294
+ *
295
+ * // 2. Teach it something. addMessages() extracts & stores facts.
296
+ * await plugin.addMessages([
297
+ * { role: "user", content: "I prefer dark mode in all my apps." },
298
+ * { role: "assistant", content: "Got it — dark mode it is." },
299
+ * ]);
300
+ *
301
+ * // 3a. Context-injection style: fold memories into the system prompt.
302
+ * const systemCtx = await plugin.getMemoryContext([
303
+ * { role: "user", content: "What theme do I like?" },
304
+ * ]);
305
+ * const a = await openai.chat.completions.create({
306
+ * model: "gpt-4o",
307
+ * messages: [
308
+ * { role: "system", content: `You are a helpful assistant.\n\n${systemCtx}` },
309
+ * { role: "user", content: "What theme do I like?" },
310
+ * ],
311
+ * });
312
+ * console.log(a.choices[0].message.content); // → "dark mode"
313
+ *
314
+ * // 3b. Tool style: let the model call search_memories itself.
315
+ * const tools = [plugin.memoryTool];
316
+ * const res = await openai.chat.completions.create({
317
+ * model: "gpt-4o",
318
+ * messages: [{ role: "user", content: "What theme do I like?" }],
319
+ * tools,
320
+ * });
321
+ * const call = res.choices[0].message.tool_calls?.[0];
322
+ * if (call && call.function.name === "search_memories") {
323
+ * const { query } = JSON.parse(call.function.arguments);
324
+ * const { toolMessage } = await plugin.searchMemories(query);
325
+ * toolMessage.tool_call_id = call.id;
326
+ * const followUp = await openai.chat.completions.create({
327
+ * model: "gpt-4o",
328
+ * messages: [
329
+ * { role: "user", content: "What theme do I like?" },
330
+ * res.choices[0].message,
331
+ * toolMessage,
332
+ * ],
333
+ * tools,
334
+ * });
335
+ * console.log(followUp.choices[0].message.content); // → "dark mode"
336
+ * }
337
+ *
338
+ * // 4. Housekeeping helpers.
339
+ * console.log(plugin.getMemoryCount()); // number of stored memories
340
+ * await plugin.clearMemories(); // wipe everything
341
+ */
342
+ //# sourceMappingURL=openai.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.js","sourceRoot":"","sources":["../../src/adapters/openai.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AA6IpC,8EAA8E;AAC9E,SAAS;AACT,8EAA8E;AAE9E;;;;;;;GAOG;AACH,MAAM,OAAO,iBAAiB;IAC5B,kCAAkC;IACzB,KAAK,CAAQ;IAEL,IAAI,CAOnB;IAEF;;;;;OAKG;IACH,YAAY,KAAY,EAAE,IAAI,GAA6B,EAAE;QAC3D,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG;YACV,kBAAkB,EAAE,IAAI,CAAC,kBAAkB,IAAI,CAAC;YAChD,gBAAgB,EAAE,IAAI,CAAC,gBAAgB,IAAI,IAAI;YAC/C,gBAAgB,EAAE,IAAI,CAAC,gBAAgB,IAAI,EAAE;YAC7C,MAAM,EAAE,I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EAAE,CAAC;IACnB,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IACxD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAC3B,CAAC;AAED,8EAA8E;AAC9E,gBAAgB;AAChB,8EAA8E;AAC9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG"}
@@ -0,0 +1,244 @@
1
+ /**
2
+ * MCP Apps memory explorer — an interactive graph UI served as a `ui://`
3
+ * resource (MCP Apps, ratified Jan 2026).
4
+ *
5
+ * The explorer renders the MemOS entity/memory graph as a self-contained,
6
+ * CSP-locked HTML payload: no external network fetches, no CDN scripts —
7
+ * the SVG renderer, pan/zoom, and filters are all hand-rolled in the
8
+ * payload. The bitemporal "as-of" scrubber re-queries the graph at any past
9
+ * timestamp through the host: each scrub position sends a structured `read`
10
+ * request over the `postMessage` bridge, the host performs a server-side
11
+ * `resources/read` at that timestamp (the existing as-of read path), and the
12
+ * app swaps in the returned snapshot. Nodes are colored by provenance
13
+ * tier, edges labeled by relation type.
14
+ *
15
+ * Consent model (the important part): the app itself is UNPRIVILEGED. It
16
+ * cannot touch the database. Mutating actions (forget, link, release from
17
+ * quarantine) are expressed as structured *intents* posted to the host via
18
+ * `postMessage`; the host translates each intent into a normal MCP
19
+ * `tools/call` (see {@link intentToToolCall}) so the HOST's consent UI
20
+ * applies exactly as if the agent had called the tool itself. Read-path
21
+ * interactions (pan/zoom/filter/scrub) need no consent.
22
+ *
23
+ * Where the host has no MCP Apps support the same resource serves a
24
+ * text/markdown fallback (mermaid diagram + summary) instead of the HTML
25
+ * app — see {@link resolveExplorerMode}.
26
+ *
27
+ * Everything here is deterministic and LLM-free.
28
+ *
29
+ * @module @mem-os/apps-explorer
30
+ */
31
+ import { UriTemplate, type Variables } from "@modelcontextprotocol/server";
32
+ import type { GraphSnapshot, MemoryEdge, MemoryNode, ProvenanceTier } from "../types.js";
33
+ /** Canonical resource URI for the explorer app. */
34
+ export declare const EXPLORER_APP_URI = "ui://memos/explorer";
35
+ /**
36
+ * URI template registered on the MCP server. Query variables:
37
+ * - `asOf` — unix ms; render the graph as of a past timestamp
38
+ * (bitemporal time-travel) instead of live.
39
+ * - `mode` — `app` forces the HTML app, `text` forces the markdown
40
+ * fallback. Unset: auto-detect from the host signal,
41
+ * defaulting to the safe `text` fallback.
42
+ * - `nodeLimit` — override the node cap (clamped to 1..1000).
43
+ * - `edgeLimit` — override the edge cap (clamped to 1..2000).
44
+ */
45
+ export declare const EXPLORER_URI_TEMPLATE = "ui://memos/explorer{?asOf,mode,nodeLimit,edgeLimit}";
46
+ /**
47
+ * URI template for the explorer resource with correct optional-query
48
+ * matching.
49
+ *
50
+ * The SDK's built-in `UriTemplate.match()` compiles `{?a,b,...}` into a
51
+ * regex that requires *every* variable to be present, in declaration order —
52
+ * so `ui://memos/explorer?mode=app` would never match
53
+ * `ui://memos/explorer{?asOf,mode,nodeLimit,edgeLimit}`. This subclass keeps
54
+ * the standard template string (so `resources/templates/list` advertises the
55
+ * documented template) but overrides matching: the path must be exactly
56
+ * `ui://memos/explorer`, and any subset of the documented query parameters
57
+ * may be present, in any order. Unknown query parameters are ignored.
58
+ */
59
+ export declare class ExplorerUriTemplate extends UriTemplate {
60
+ constructor();
61
+ match(uri: string): Variables | null;
62
+ }
63
+ /** Default cap on nodes embedded in one payload (keeps it small). */
64
+ export declare const EXPLORER_NODE_CAP = 150;
65
+ /** Default cap on edges embedded in one payload. */
66
+ export declare const EXPLORER_EDGE_CAP = 400;
67
+ /** Hard ceiling for client-overridden caps. */
68
+ export declare const EXPLORER_NODE_CAP_MAX = 1000;
69
+ export declare const EXPLORER_EDGE_CAP_MAX = 2000;
70
+ /** Characters of node content embedded per node. */
71
+ export declare const EXPLORER_CONTENT_CHARS = 280;
72
+ /**
73
+ * postMessage protocol identifier. The app posts
74
+ * `{ protocol: "memos-explorer/1", kind: "intent", intent, params, requestId }`
75
+ * to `window.parent`; hosts translate intents via {@link intentToToolCall}
76
+ * and reply with `{ protocol: "memos-explorer/1", kind: "intent-result", ... }`.
77
+ *
78
+ * Read-path time travel uses a second message pair so scrubbing the as-of
79
+ * slider re-queries the server instead of filtering the embedded snapshot
80
+ * client-side: the app posts
81
+ * `{ protocol: "memos-explorer/1", kind: "read", requestId, asOf: number|null }`
82
+ * (`asOf: null` = live graph) and the host performs an MCP `resources/read`
83
+ * of `ui://memos/explorer?mode=app` (plus `&asOf=<ms>` when set) and replies
84
+ * with `{ protocol: "memos-explorer/1", kind: "snapshot", requestId, ok, html?, error? }`
85
+ * where `html` is the raw resource text — the app extracts the new snapshot
86
+ * from its `<script id="memos-snapshot">` tag and re-renders. Reads need no
87
+ * consent. If the host never answers (no bridge support) the app falls back
88
+ * to filtering its embedded snapshot locally.
89
+ */
90
+ export declare const EXPLORER_PROTOCOL = "memos-explorer/1";
91
+ /** Node fill color per provenance tier (highest trust → greenest). */
92
+ export declare const PROVENANCE_TIER_COLORS: Record<ProvenanceTier, string>;
93
+ /** Edge stroke color per relation type. */
94
+ export declare const EDGE_RELATION_COLORS: Record<string, string>;
95
+ /** Intents the app may emit (all go through host consent). */
96
+ export declare const SUPPORTED_INTENTS: readonly ["forget", "link", "release-quarantine"];
97
+ export type ExplorerIntentName = (typeof SUPPORTED_INTENTS)[number];
98
+ /** Compact, JSON-safe node projection embedded in the app payload. */
99
+ export interface ExplorerNode {
100
+ id: string;
101
+ content: string;
102
+ contentTruncated: boolean;
103
+ type: string;
104
+ importance: number;
105
+ trustScore: number;
106
+ /** Provenance tier string; "unknown" when the row predates the column. */
107
+ provenance: string;
108
+ quarantined: boolean;
109
+ quarantineReason: string | null;
110
+ validFrom: number | null;
111
+ validTo: number | null;
112
+ createdAt: number;
113
+ /** Citable `[mem:hex]` token for this memory. */
114
+ citation: string;
115
+ }
116
+ /** Compact, JSON-safe edge projection embedded in the app payload. */
117
+ export interface ExplorerEdge {
118
+ id: string;
119
+ sourceId: string;
120
+ targetId: string;
121
+ relation: string;
122
+ weight: number;
123
+ validFrom: number | null;
124
+ validTo: number | null;
125
+ }
126
+ /** Everything the app needs, in one JSON blob. */
127
+ export interface ExplorerSnapshot {
128
+ nodes: ExplorerNode[];
129
+ edges: ExplorerEdge[];
130
+ /** Pre-cap totals, so the UI can say "showing 150 of 1,204". */
131
+ totalNodes: number;
132
+ totalEdges: number;
133
+ truncated: boolean;
134
+ /** When the snapshot was generated (unix ms). */
135
+ generatedAt: number;
136
+ /** As-of timestamp when rendered for a past moment, else null (live). */
137
+ asOf: number | null;
138
+ }
139
+ export interface SnapshotOptions {
140
+ nodeCap?: number;
141
+ edgeCap?: number;
142
+ /** Pre-filter to this bitemporal timestamp (unix ms). */
143
+ asOf?: number;
144
+ }
145
+ /**
146
+ * Build the capped, JSON-safe snapshot the app embeds. Nodes are taken in
147
+ * importance order (most important first); edges are kept only when both
148
+ * endpoints survived the node cap, in weight order. Pass `asOf` to
149
+ * pre-filter to a bitemporal timestamp (same predicates as the server
150
+ * as-of read path).
151
+ */
152
+ export declare function buildExplorerSnapshot(graph: GraphSnapshot, opts?: SnapshotOptions): ExplorerSnapshot;
153
+ /**
154
+ * Node as-of predicate — identical to the SQLite as-of read path
155
+ * (`valid_from <= t AND (valid_to IS NULL OR valid_to >= t)`).
156
+ */
157
+ export declare function isNodeValidAt(node: Pick<MemoryNode, "validFrom" | "validTo"> | Pick<ExplorerNode, "validFrom" | "validTo">, atTime: number): boolean;
158
+ /**
159
+ * Edge as-of predicate — identical to the SQLite edge as-of read path,
160
+ * which uses strict `valid_to > t` (see `queryEdges({ validAt })`): an
161
+ * edge closed in the same millisecond as the query is already historical.
162
+ */
163
+ export declare function isEdgeValidAt(edge: Pick<MemoryEdge, "validFrom" | "validTo"> | Pick<ExplorerEdge, "validFrom" | "validTo">, atTime: number): boolean;
164
+ /**
165
+ * The as-of scrubber's filter: re-evaluate a snapshot at a past timestamp.
166
+ * This is the graceful-degradation path for the time slider — the same
167
+ * predicates the server uses, applied client-side to the embedded
168
+ * snapshot — used only when the host does not implement the `read` bridge
169
+ * (see {@link EXPLORER_PROTOCOL}). With a supporting host, every scrub
170
+ * position re-queries the server via `resources/read?asOf=` instead.
171
+ */
172
+ export declare function filterSnapshotAsOf(snapshot: ExplorerSnapshot, atTime: number): ExplorerSnapshot;
173
+ export type ExplorerMode = "app" | "text";
174
+ /**
175
+ * Probe a `resources/read` request `_meta` for host MCP Apps support.
176
+ * Returns true/false on an explicit signal, null when the host says
177
+ * nothing (the common case for older clients).
178
+ */
179
+ export declare function probeHostAppsSupport(meta: unknown): boolean | null;
180
+ export interface ResolveModeOptions {
181
+ /** Raw `mode` URI-template variable (`app` | `text`), if given. */
182
+ modeParam?: string | null;
183
+ /** The `resources/read` request `_meta` (host signal probe). */
184
+ meta?: unknown;
185
+ }
186
+ /**
187
+ * Decide whether to serve the HTML app or the markdown fallback.
188
+ *
189
+ * 1. An explicit `?mode=app|text` always wins.
190
+ * 2. Otherwise an explicit host Apps signal in `_meta` wins.
191
+ * 3. Otherwise fail closed to the `text` fallback: a host that cannot
192
+ * render the app must never receive a raw HTML blob it would dump as
193
+ * markup into the conversation.
194
+ */
195
+ export declare function resolveExplorerMode(opts: ResolveModeOptions): ExplorerMode;
196
+ export interface IntentToolCall {
197
+ /** MCP tool name — the host calls this via the standard tools/call path. */
198
+ tool: string;
199
+ args: Record<string, unknown>;
200
+ }
201
+ export type IntentTranslation = {
202
+ ok: true;
203
+ intent: ExplorerIntentName;
204
+ call: IntentToolCall;
205
+ } | {
206
+ ok: false;
207
+ error: string;
208
+ };
209
+ /**
210
+ * Translate a UI intent (posted by the app via `postMessage`) into the MCP
211
+ * tool call the host must issue. Pure and zod-validated: unknown intents
212
+ * and malformed params are rejected here, before any host consent UI.
213
+ *
214
+ * The host — never this module, never the app — performs the actual
215
+ * `tools/call`, so the host's consent model applies to every mutation.
216
+ * The app itself has no credentials and no database access.
217
+ */
218
+ export declare function intentToToolCall(raw: unknown): IntentTranslation;
219
+ export interface FallbackOptions {
220
+ asOf?: number | null;
221
+ }
222
+ /**
223
+ * Build the graceful-degradation payload: the mermaid diagram (reusing
224
+ * `graphToMermaid`, the same renderer as `memos://graph`) plus a summary.
225
+ * Served when {@link resolveExplorerMode} picks `"text"`.
226
+ */
227
+ export declare function buildExplorerFallbackMarkdown(snapshot: ExplorerSnapshot, opts?: FallbackOptions): string;
228
+ export interface HtmlOptions {
229
+ asOf?: number | null;
230
+ }
231
+ /**
232
+ * Build the single-file HTML app payload.
233
+ *
234
+ * Security properties (asserted by tests):
235
+ * - `<meta http-equiv="Content-Security-Policy">` locks the document down:
236
+ * no network, no plugins, inline scripts/styles only.
237
+ * - No external URLs anywhere in the payload (no CDNs, fonts, images).
238
+ * - An HTML comment states the host-side requirement:
239
+ * `<iframe sandbox="allow-scripts">` (no `allow-same-origin`).
240
+ * - The app is unprivileged: the only outbound channel is `postMessage`
241
+ * intents to the host; there is no database access from this layer.
242
+ */
243
+ export declare function buildExplorerHtml(snapshot: ExplorerSnapshot, opts?: HtmlOptions): string;
244
+ //# sourceMappingURL=explorer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"explorer.d.ts","sourceRoot":"","sources":["../../src/apps/explorer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAIH,OAAO,EAAE,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAK3E,OAAO,KAAK,EACV,aAAa,EACb,UAAU,EACV,UAAU,EACV,cAAc,EACf,MAAM,aAAa,CAAC;AAMrB,mDAAmD;AACnD,eAAO,MAAM,gBAAgB,wBAAwB,CAAC;AAEtD;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,wDACqB,CAAC;AAExD;;;;;;;;;;;;GAYG;AACH,qBAAa,mBAAoB,SAAQ,WAAW;IAClD,cAEC;IAEQ,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG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