@twelvehart/supermemory-runtime 1.0.0-next.0

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 (156) hide show
  1. package/.env.example +57 -0
  2. package/README.md +374 -0
  3. package/dist/index.js +189 -0
  4. package/dist/mcp/index.js +1132 -0
  5. package/docker-compose.prod.yml +91 -0
  6. package/docker-compose.yml +358 -0
  7. package/drizzle/0000_dapper_the_professor.sql +159 -0
  8. package/drizzle/0001_api_keys.sql +51 -0
  9. package/drizzle/meta/0000_snapshot.json +1532 -0
  10. package/drizzle/meta/_journal.json +13 -0
  11. package/drizzle.config.ts +20 -0
  12. package/package.json +114 -0
  13. package/scripts/add-extraction-job.ts +122 -0
  14. package/scripts/benchmark-pgvector.ts +122 -0
  15. package/scripts/bootstrap.sh +209 -0
  16. package/scripts/check-runtime-pack.ts +111 -0
  17. package/scripts/claude-mcp-config.ts +336 -0
  18. package/scripts/docker-entrypoint.sh +183 -0
  19. package/scripts/doctor.ts +377 -0
  20. package/scripts/init-db.sql +33 -0
  21. package/scripts/install.sh +1110 -0
  22. package/scripts/mcp-setup.ts +271 -0
  23. package/scripts/migrations/001_create_pgvector_extension.sql +31 -0
  24. package/scripts/migrations/002_create_memory_embeddings_table.sql +75 -0
  25. package/scripts/migrations/003_create_hnsw_index.sql +94 -0
  26. package/scripts/migrations/004_create_memory_embeddings_standalone.sql +70 -0
  27. package/scripts/migrations/005_create_chunks_table.sql +95 -0
  28. package/scripts/migrations/006_create_processing_queue.sql +45 -0
  29. package/scripts/migrations/generate_test_data.sql +42 -0
  30. package/scripts/migrations/phase1_comprehensive_test.sql +204 -0
  31. package/scripts/migrations/run_migrations.sh +286 -0
  32. package/scripts/migrations/test_hnsw_index.sql +255 -0
  33. package/scripts/pre-commit-secrets +282 -0
  34. package/scripts/run-extraction-worker.ts +46 -0
  35. package/scripts/run-phase1-tests.sh +291 -0
  36. package/scripts/setup.ts +222 -0
  37. package/scripts/smoke-install.sh +12 -0
  38. package/scripts/test-health-endpoint.sh +328 -0
  39. package/src/api/index.ts +2 -0
  40. package/src/api/middleware/auth.ts +80 -0
  41. package/src/api/middleware/csrf.ts +308 -0
  42. package/src/api/middleware/errorHandler.ts +166 -0
  43. package/src/api/middleware/rateLimit.ts +360 -0
  44. package/src/api/middleware/validation.ts +514 -0
  45. package/src/api/routes/documents.ts +286 -0
  46. package/src/api/routes/profiles.ts +237 -0
  47. package/src/api/routes/search.ts +71 -0
  48. package/src/api/stores/index.ts +58 -0
  49. package/src/config/bootstrap-env.ts +3 -0
  50. package/src/config/env.ts +71 -0
  51. package/src/config/feature-flags.ts +25 -0
  52. package/src/config/index.ts +140 -0
  53. package/src/config/secrets.config.ts +291 -0
  54. package/src/db/client.ts +92 -0
  55. package/src/db/index.ts +73 -0
  56. package/src/db/postgres.ts +72 -0
  57. package/src/db/schema/chunks.schema.ts +31 -0
  58. package/src/db/schema/containers.schema.ts +46 -0
  59. package/src/db/schema/documents.schema.ts +49 -0
  60. package/src/db/schema/embeddings.schema.ts +32 -0
  61. package/src/db/schema/index.ts +11 -0
  62. package/src/db/schema/memories.schema.ts +72 -0
  63. package/src/db/schema/profiles.schema.ts +34 -0
  64. package/src/db/schema/queue.schema.ts +59 -0
  65. package/src/db/schema/relationships.schema.ts +42 -0
  66. package/src/db/schema.ts +223 -0
  67. package/src/db/worker-connection.ts +47 -0
  68. package/src/index.ts +235 -0
  69. package/src/mcp/CLAUDE.md +1 -0
  70. package/src/mcp/index.ts +1380 -0
  71. package/src/mcp/legacyState.ts +22 -0
  72. package/src/mcp/rateLimit.ts +358 -0
  73. package/src/mcp/resources.ts +309 -0
  74. package/src/mcp/results.ts +104 -0
  75. package/src/mcp/tools.ts +401 -0
  76. package/src/queues/config.ts +119 -0
  77. package/src/queues/index.ts +289 -0
  78. package/src/sdk/client.ts +225 -0
  79. package/src/sdk/errors.ts +266 -0
  80. package/src/sdk/http.ts +560 -0
  81. package/src/sdk/index.ts +244 -0
  82. package/src/sdk/resources/base.ts +65 -0
  83. package/src/sdk/resources/connections.ts +204 -0
  84. package/src/sdk/resources/documents.ts +163 -0
  85. package/src/sdk/resources/index.ts +10 -0
  86. package/src/sdk/resources/memories.ts +150 -0
  87. package/src/sdk/resources/search.ts +60 -0
  88. package/src/sdk/resources/settings.ts +36 -0
  89. package/src/sdk/types.ts +674 -0
  90. package/src/services/chunking/index.ts +451 -0
  91. package/src/services/chunking.service.ts +650 -0
  92. package/src/services/csrf.service.ts +252 -0
  93. package/src/services/documents.repository.ts +219 -0
  94. package/src/services/documents.service.ts +191 -0
  95. package/src/services/embedding.service.ts +404 -0
  96. package/src/services/extraction.service.ts +300 -0
  97. package/src/services/extractors/code.extractor.ts +451 -0
  98. package/src/services/extractors/index.ts +9 -0
  99. package/src/services/extractors/markdown.extractor.ts +461 -0
  100. package/src/services/extractors/pdf.extractor.ts +315 -0
  101. package/src/services/extractors/text.extractor.ts +118 -0
  102. package/src/services/extractors/url.extractor.ts +243 -0
  103. package/src/services/index.ts +235 -0
  104. package/src/services/ingestion.service.ts +177 -0
  105. package/src/services/llm/anthropic.ts +400 -0
  106. package/src/services/llm/base.ts +460 -0
  107. package/src/services/llm/contradiction-detector.service.ts +526 -0
  108. package/src/services/llm/heuristics.ts +148 -0
  109. package/src/services/llm/index.ts +309 -0
  110. package/src/services/llm/memory-classifier.service.ts +383 -0
  111. package/src/services/llm/memory-extension-detector.service.ts +523 -0
  112. package/src/services/llm/mock.ts +470 -0
  113. package/src/services/llm/openai.ts +398 -0
  114. package/src/services/llm/prompts.ts +438 -0
  115. package/src/services/llm/types.ts +373 -0
  116. package/src/services/memory.repository.ts +1769 -0
  117. package/src/services/memory.service.ts +1338 -0
  118. package/src/services/memory.types.ts +234 -0
  119. package/src/services/persistence/index.ts +295 -0
  120. package/src/services/pipeline.service.ts +509 -0
  121. package/src/services/profile.repository.ts +436 -0
  122. package/src/services/profile.service.ts +560 -0
  123. package/src/services/profile.types.ts +270 -0
  124. package/src/services/relationships/detector.ts +1128 -0
  125. package/src/services/relationships/index.ts +268 -0
  126. package/src/services/relationships/memory-integration.ts +459 -0
  127. package/src/services/relationships/strategies.ts +132 -0
  128. package/src/services/relationships/types.ts +370 -0
  129. package/src/services/search.service.ts +761 -0
  130. package/src/services/search.types.ts +220 -0
  131. package/src/services/secrets.service.ts +384 -0
  132. package/src/services/vectorstore/base.ts +327 -0
  133. package/src/services/vectorstore/index.ts +444 -0
  134. package/src/services/vectorstore/memory.ts +286 -0
  135. package/src/services/vectorstore/migration.ts +295 -0
  136. package/src/services/vectorstore/mock.ts +403 -0
  137. package/src/services/vectorstore/pgvector.ts +695 -0
  138. package/src/services/vectorstore/types.ts +247 -0
  139. package/src/startup.ts +389 -0
  140. package/src/types/api.types.ts +193 -0
  141. package/src/types/document.types.ts +103 -0
  142. package/src/types/index.ts +241 -0
  143. package/src/types/profile.base.ts +133 -0
  144. package/src/utils/errors.ts +447 -0
  145. package/src/utils/id.ts +15 -0
  146. package/src/utils/index.ts +101 -0
  147. package/src/utils/logger.ts +313 -0
  148. package/src/utils/sanitization.ts +501 -0
  149. package/src/utils/secret-validation.ts +273 -0
  150. package/src/utils/synonyms.ts +188 -0
  151. package/src/utils/validation.ts +581 -0
  152. package/src/workers/chunking.worker.ts +242 -0
  153. package/src/workers/embedding.worker.ts +358 -0
  154. package/src/workers/extraction.worker.ts +346 -0
  155. package/src/workers/indexing.worker.ts +505 -0
  156. package/tsconfig.json +38 -0
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Memories Resource
3
+ * Provides CRUD operations for memories (conversation-oriented storage)
4
+ */
5
+
6
+ import { APIResource } from './base.js'
7
+ import { APIPromise } from '../http.js'
8
+ import type {
9
+ RequestOptions,
10
+ MemoryListParams,
11
+ MemoryListResponse,
12
+ MemoryAddParams,
13
+ MemoryAddResponse,
14
+ MemoryUpdateParams,
15
+ MemoryUpdateResponse,
16
+ MemoryForgetParams,
17
+ MemoryForgetResponse,
18
+ MemoryGetResponse,
19
+ MemoryUpdateMemoryParams,
20
+ MemoryUpdateMemoryResponse,
21
+ MemoryUploadFileParams,
22
+ MemoryUploadFileResponse,
23
+ } from '../types.js'
24
+
25
+ export class Memories extends APIResource {
26
+ /**
27
+ * Retrieve a specific memory by ID
28
+ *
29
+ * @param id - Memory ID
30
+ * @param options - Request options
31
+ * @returns The memory with full details
32
+ */
33
+ get(id: string, options?: RequestOptions): APIPromise<MemoryGetResponse> {
34
+ return this.client.get<MemoryGetResponse>(`/v4/memories/${encodeURIComponent(id)}`, {
35
+ requestOptions: options,
36
+ })
37
+ }
38
+
39
+ /**
40
+ * Retrieve a paginated collection of memories
41
+ *
42
+ * @param body - List parameters including filters and pagination
43
+ * @param options - Request options
44
+ * @returns Paginated list of memories
45
+ */
46
+ list(body?: MemoryListParams | null, options?: RequestOptions): APIPromise<MemoryListResponse> {
47
+ return this._post<MemoryListResponse>('/v4/memories/list', {
48
+ body: body || {},
49
+ requestOptions: options,
50
+ })
51
+ }
52
+
53
+ /**
54
+ * Add a new memory
55
+ *
56
+ * @param body - Memory content and metadata
57
+ * @param options - Request options
58
+ * @returns Created memory ID and status
59
+ */
60
+ add(body: MemoryAddParams, options?: RequestOptions): APIPromise<MemoryAddResponse> {
61
+ return this._post<MemoryAddResponse>('/v4/memories', {
62
+ body,
63
+ requestOptions: options,
64
+ })
65
+ }
66
+
67
+ /**
68
+ * Update a memory's content or metadata
69
+ *
70
+ * @param id - Memory ID
71
+ * @param body - Updated content and/or metadata
72
+ * @param options - Request options
73
+ * @returns Updated memory status
74
+ */
75
+ update(id: string, body?: MemoryUpdateParams | null, options?: RequestOptions): APIPromise<MemoryUpdateResponse> {
76
+ return this._patch<MemoryUpdateResponse>(`/v4/memories/${encodeURIComponent(id)}`, {
77
+ body: body || {},
78
+ requestOptions: options,
79
+ })
80
+ }
81
+
82
+ /**
83
+ * Delete a memory by ID
84
+ *
85
+ * @param id - Memory ID
86
+ * @param options - Request options
87
+ */
88
+ delete(id: string, options?: RequestOptions): APIPromise<void> {
89
+ return this.client.delete<void>(`/v4/memories/${encodeURIComponent(id)}`, {
90
+ requestOptions: options,
91
+ })
92
+ }
93
+
94
+ /**
95
+ * Soft delete (forget) a memory
96
+ *
97
+ * @param body - Memory ID and optional reason
98
+ * @param options - Request options
99
+ * @returns Confirmation of forgotten memory
100
+ */
101
+ forget(body: MemoryForgetParams, options?: RequestOptions): APIPromise<MemoryForgetResponse> {
102
+ return this._post<MemoryForgetResponse>('/v4/memories/forget', {
103
+ body,
104
+ requestOptions: options,
105
+ })
106
+ }
107
+
108
+ /**
109
+ * Create a new version of a memory while preserving the original
110
+ *
111
+ * @param body - Memory update with versioning
112
+ * @param options - Request options
113
+ * @returns New memory version details
114
+ */
115
+ updateMemory(body: MemoryUpdateMemoryParams, options?: RequestOptions): APIPromise<MemoryUpdateMemoryResponse> {
116
+ return this._post<MemoryUpdateMemoryResponse>('/v4/memories/update', {
117
+ body,
118
+ requestOptions: options,
119
+ })
120
+ }
121
+
122
+ /**
123
+ * Upload a file as a memory
124
+ *
125
+ * @param body - File and metadata for upload
126
+ * @param options - Request options
127
+ * @returns Created memory ID and status
128
+ */
129
+ uploadFile(body: MemoryUploadFileParams, options?: RequestOptions): APIPromise<MemoryUploadFileResponse> {
130
+ const { file, containerTag, customId, metadata } = body
131
+
132
+ // Build additional form fields
133
+ const additionalFields: Record<string, string> = {}
134
+ if (containerTag) {
135
+ additionalFields.containerTag = containerTag
136
+ }
137
+ if (customId) {
138
+ additionalFields.customId = customId
139
+ }
140
+ if (metadata) {
141
+ additionalFields.metadata = JSON.stringify(metadata)
142
+ }
143
+
144
+ return this.client.uploadFile<MemoryUploadFileResponse>('/v4/memories/upload', file, {
145
+ fieldName: 'file',
146
+ additionalFields,
147
+ requestOptions: options,
148
+ })
149
+ }
150
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Search Resource
3
+ * Provides search functionality for documents and memories
4
+ */
5
+
6
+ import { APIResource } from './base.js'
7
+ import { APIPromise } from '../http.js'
8
+ import type {
9
+ RequestOptions,
10
+ SearchDocumentsParams,
11
+ SearchDocumentsResponse,
12
+ SearchMemoriesParams,
13
+ SearchMemoriesResponse,
14
+ SearchExecuteParams,
15
+ SearchExecuteResponse,
16
+ } from '../types.js'
17
+
18
+ export class Search extends APIResource {
19
+ /**
20
+ * Search documents with advanced filtering
21
+ *
22
+ * @param body - Search parameters including query and filters
23
+ * @param options - Request options
24
+ * @returns Search results with documents and metadata
25
+ */
26
+ documents(body: SearchDocumentsParams, options?: RequestOptions): APIPromise<SearchDocumentsResponse> {
27
+ return this._post<SearchDocumentsResponse>('/v3/search', {
28
+ body,
29
+ requestOptions: options,
30
+ })
31
+ }
32
+
33
+ /**
34
+ * Execute a search query (alias for documents)
35
+ *
36
+ * @param body - Search parameters including query and filters
37
+ * @param options - Request options
38
+ * @returns Search results with documents and metadata
39
+ */
40
+ execute(body: SearchExecuteParams, options?: RequestOptions): APIPromise<SearchExecuteResponse> {
41
+ return this._post<SearchExecuteResponse>('/v3/search', {
42
+ body,
43
+ requestOptions: options,
44
+ })
45
+ }
46
+
47
+ /**
48
+ * Search memories with advanced filtering
49
+ *
50
+ * @param body - Search parameters for memories
51
+ * @param options - Request options
52
+ * @returns Search results with memories and metadata
53
+ */
54
+ memories(body: SearchMemoriesParams, options?: RequestOptions): APIPromise<SearchMemoriesResponse> {
55
+ return this._post<SearchMemoriesResponse>('/v4/memories/search', {
56
+ body,
57
+ requestOptions: options,
58
+ })
59
+ }
60
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Settings Resource
3
+ * Manages organization settings
4
+ */
5
+
6
+ import { APIResource } from './base.js'
7
+ import { APIPromise } from '../http.js'
8
+ import type { RequestOptions, SettingUpdateParams, SettingUpdateResponse, SettingGetResponse } from '../types.js'
9
+
10
+ export class Settings extends APIResource {
11
+ /**
12
+ * Get organization settings
13
+ *
14
+ * @param options - Request options
15
+ * @returns Current settings
16
+ */
17
+ get(options?: RequestOptions): APIPromise<SettingGetResponse> {
18
+ return this.client.get<SettingGetResponse>('/v3/settings', {
19
+ requestOptions: options,
20
+ })
21
+ }
22
+
23
+ /**
24
+ * Update organization settings
25
+ *
26
+ * @param body - Settings to update
27
+ * @param options - Request options
28
+ * @returns Updated settings
29
+ */
30
+ update(body: SettingUpdateParams, options?: RequestOptions): APIPromise<SettingUpdateResponse> {
31
+ return this._patch<SettingUpdateResponse>('/v3/settings', {
32
+ body,
33
+ requestOptions: options,
34
+ })
35
+ }
36
+ }