@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.
- package/.env.example +57 -0
- package/README.md +374 -0
- package/dist/index.js +189 -0
- package/dist/mcp/index.js +1132 -0
- package/docker-compose.prod.yml +91 -0
- package/docker-compose.yml +358 -0
- package/drizzle/0000_dapper_the_professor.sql +159 -0
- package/drizzle/0001_api_keys.sql +51 -0
- package/drizzle/meta/0000_snapshot.json +1532 -0
- package/drizzle/meta/_journal.json +13 -0
- package/drizzle.config.ts +20 -0
- package/package.json +114 -0
- package/scripts/add-extraction-job.ts +122 -0
- package/scripts/benchmark-pgvector.ts +122 -0
- package/scripts/bootstrap.sh +209 -0
- package/scripts/check-runtime-pack.ts +111 -0
- package/scripts/claude-mcp-config.ts +336 -0
- package/scripts/docker-entrypoint.sh +183 -0
- package/scripts/doctor.ts +377 -0
- package/scripts/init-db.sql +33 -0
- package/scripts/install.sh +1110 -0
- package/scripts/mcp-setup.ts +271 -0
- package/scripts/migrations/001_create_pgvector_extension.sql +31 -0
- package/scripts/migrations/002_create_memory_embeddings_table.sql +75 -0
- package/scripts/migrations/003_create_hnsw_index.sql +94 -0
- package/scripts/migrations/004_create_memory_embeddings_standalone.sql +70 -0
- package/scripts/migrations/005_create_chunks_table.sql +95 -0
- package/scripts/migrations/006_create_processing_queue.sql +45 -0
- package/scripts/migrations/generate_test_data.sql +42 -0
- package/scripts/migrations/phase1_comprehensive_test.sql +204 -0
- package/scripts/migrations/run_migrations.sh +286 -0
- package/scripts/migrations/test_hnsw_index.sql +255 -0
- package/scripts/pre-commit-secrets +282 -0
- package/scripts/run-extraction-worker.ts +46 -0
- package/scripts/run-phase1-tests.sh +291 -0
- package/scripts/setup.ts +222 -0
- package/scripts/smoke-install.sh +12 -0
- package/scripts/test-health-endpoint.sh +328 -0
- package/src/api/index.ts +2 -0
- package/src/api/middleware/auth.ts +80 -0
- package/src/api/middleware/csrf.ts +308 -0
- package/src/api/middleware/errorHandler.ts +166 -0
- package/src/api/middleware/rateLimit.ts +360 -0
- package/src/api/middleware/validation.ts +514 -0
- package/src/api/routes/documents.ts +286 -0
- package/src/api/routes/profiles.ts +237 -0
- package/src/api/routes/search.ts +71 -0
- package/src/api/stores/index.ts +58 -0
- package/src/config/bootstrap-env.ts +3 -0
- package/src/config/env.ts +71 -0
- package/src/config/feature-flags.ts +25 -0
- package/src/config/index.ts +140 -0
- package/src/config/secrets.config.ts +291 -0
- package/src/db/client.ts +92 -0
- package/src/db/index.ts +73 -0
- package/src/db/postgres.ts +72 -0
- package/src/db/schema/chunks.schema.ts +31 -0
- package/src/db/schema/containers.schema.ts +46 -0
- package/src/db/schema/documents.schema.ts +49 -0
- package/src/db/schema/embeddings.schema.ts +32 -0
- package/src/db/schema/index.ts +11 -0
- package/src/db/schema/memories.schema.ts +72 -0
- package/src/db/schema/profiles.schema.ts +34 -0
- package/src/db/schema/queue.schema.ts +59 -0
- package/src/db/schema/relationships.schema.ts +42 -0
- package/src/db/schema.ts +223 -0
- package/src/db/worker-connection.ts +47 -0
- package/src/index.ts +235 -0
- package/src/mcp/CLAUDE.md +1 -0
- package/src/mcp/index.ts +1380 -0
- package/src/mcp/legacyState.ts +22 -0
- package/src/mcp/rateLimit.ts +358 -0
- package/src/mcp/resources.ts +309 -0
- package/src/mcp/results.ts +104 -0
- package/src/mcp/tools.ts +401 -0
- package/src/queues/config.ts +119 -0
- package/src/queues/index.ts +289 -0
- package/src/sdk/client.ts +225 -0
- package/src/sdk/errors.ts +266 -0
- package/src/sdk/http.ts +560 -0
- package/src/sdk/index.ts +244 -0
- package/src/sdk/resources/base.ts +65 -0
- package/src/sdk/resources/connections.ts +204 -0
- package/src/sdk/resources/documents.ts +163 -0
- package/src/sdk/resources/index.ts +10 -0
- package/src/sdk/resources/memories.ts +150 -0
- package/src/sdk/resources/search.ts +60 -0
- package/src/sdk/resources/settings.ts +36 -0
- package/src/sdk/types.ts +674 -0
- package/src/services/chunking/index.ts +451 -0
- package/src/services/chunking.service.ts +650 -0
- package/src/services/csrf.service.ts +252 -0
- package/src/services/documents.repository.ts +219 -0
- package/src/services/documents.service.ts +191 -0
- package/src/services/embedding.service.ts +404 -0
- package/src/services/extraction.service.ts +300 -0
- package/src/services/extractors/code.extractor.ts +451 -0
- package/src/services/extractors/index.ts +9 -0
- package/src/services/extractors/markdown.extractor.ts +461 -0
- package/src/services/extractors/pdf.extractor.ts +315 -0
- package/src/services/extractors/text.extractor.ts +118 -0
- package/src/services/extractors/url.extractor.ts +243 -0
- package/src/services/index.ts +235 -0
- package/src/services/ingestion.service.ts +177 -0
- package/src/services/llm/anthropic.ts +400 -0
- package/src/services/llm/base.ts +460 -0
- package/src/services/llm/contradiction-detector.service.ts +526 -0
- package/src/services/llm/heuristics.ts +148 -0
- package/src/services/llm/index.ts +309 -0
- package/src/services/llm/memory-classifier.service.ts +383 -0
- package/src/services/llm/memory-extension-detector.service.ts +523 -0
- package/src/services/llm/mock.ts +470 -0
- package/src/services/llm/openai.ts +398 -0
- package/src/services/llm/prompts.ts +438 -0
- package/src/services/llm/types.ts +373 -0
- package/src/services/memory.repository.ts +1769 -0
- package/src/services/memory.service.ts +1338 -0
- package/src/services/memory.types.ts +234 -0
- package/src/services/persistence/index.ts +295 -0
- package/src/services/pipeline.service.ts +509 -0
- package/src/services/profile.repository.ts +436 -0
- package/src/services/profile.service.ts +560 -0
- package/src/services/profile.types.ts +270 -0
- package/src/services/relationships/detector.ts +1128 -0
- package/src/services/relationships/index.ts +268 -0
- package/src/services/relationships/memory-integration.ts +459 -0
- package/src/services/relationships/strategies.ts +132 -0
- package/src/services/relationships/types.ts +370 -0
- package/src/services/search.service.ts +761 -0
- package/src/services/search.types.ts +220 -0
- package/src/services/secrets.service.ts +384 -0
- package/src/services/vectorstore/base.ts +327 -0
- package/src/services/vectorstore/index.ts +444 -0
- package/src/services/vectorstore/memory.ts +286 -0
- package/src/services/vectorstore/migration.ts +295 -0
- package/src/services/vectorstore/mock.ts +403 -0
- package/src/services/vectorstore/pgvector.ts +695 -0
- package/src/services/vectorstore/types.ts +247 -0
- package/src/startup.ts +389 -0
- package/src/types/api.types.ts +193 -0
- package/src/types/document.types.ts +103 -0
- package/src/types/index.ts +241 -0
- package/src/types/profile.base.ts +133 -0
- package/src/utils/errors.ts +447 -0
- package/src/utils/id.ts +15 -0
- package/src/utils/index.ts +101 -0
- package/src/utils/logger.ts +313 -0
- package/src/utils/sanitization.ts +501 -0
- package/src/utils/secret-validation.ts +273 -0
- package/src/utils/synonyms.ts +188 -0
- package/src/utils/validation.ts +581 -0
- package/src/workers/chunking.worker.ts +242 -0
- package/src/workers/embedding.worker.ts +358 -0
- package/src/workers/extraction.worker.ts +346 -0
- package/src/workers/indexing.worker.ts +505 -0
- 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
|
+
}
|