@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
package/src/sdk/index.ts
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supermemory SDK
|
|
3
|
+
* A drop-in replacement for the official supermemory npm package
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import Supermemory from './sdk';
|
|
10
|
+
*
|
|
11
|
+
* const client = new Supermemory({
|
|
12
|
+
* apiKey: process.env.SUPERMEMORY_API_KEY,
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* // Add content
|
|
16
|
+
* const doc = await client.add({ content: 'Hello, world!' });
|
|
17
|
+
*
|
|
18
|
+
* // Search documents
|
|
19
|
+
* const results = await client.search.documents({ q: 'hello' });
|
|
20
|
+
*
|
|
21
|
+
* // Upload files
|
|
22
|
+
* await client.documents.uploadFile({ file: myFile });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
// Main client export
|
|
27
|
+
export { Supermemory, toFile } from './client.js'
|
|
28
|
+
export { Supermemory as default } from './client.js'
|
|
29
|
+
|
|
30
|
+
// HTTP utilities
|
|
31
|
+
export { APIPromise } from './http.js'
|
|
32
|
+
|
|
33
|
+
// Error classes
|
|
34
|
+
export {
|
|
35
|
+
SupermemoryError,
|
|
36
|
+
APIError,
|
|
37
|
+
APIUserAbortError,
|
|
38
|
+
APIConnectionError,
|
|
39
|
+
APIConnectionTimeoutError,
|
|
40
|
+
BadRequestError,
|
|
41
|
+
AuthenticationError,
|
|
42
|
+
PermissionDeniedError,
|
|
43
|
+
NotFoundError,
|
|
44
|
+
ConflictError,
|
|
45
|
+
UnprocessableEntityError,
|
|
46
|
+
RateLimitError,
|
|
47
|
+
InternalServerError,
|
|
48
|
+
isAPIError,
|
|
49
|
+
isRateLimitError,
|
|
50
|
+
isRetryableError,
|
|
51
|
+
} from './errors.js'
|
|
52
|
+
|
|
53
|
+
// Type exports
|
|
54
|
+
export type {
|
|
55
|
+
// Client types
|
|
56
|
+
ClientOptions,
|
|
57
|
+
RequestOptions,
|
|
58
|
+
LogLevel,
|
|
59
|
+
Logger,
|
|
60
|
+
Uploadable,
|
|
61
|
+
ToFileOptions,
|
|
62
|
+
|
|
63
|
+
// Common types
|
|
64
|
+
Metadata,
|
|
65
|
+
Pagination,
|
|
66
|
+
Chunk,
|
|
67
|
+
Filter,
|
|
68
|
+
OrFilter,
|
|
69
|
+
AndFilter,
|
|
70
|
+
FilterCondition,
|
|
71
|
+
|
|
72
|
+
// Add types
|
|
73
|
+
AddParams,
|
|
74
|
+
AddResponse,
|
|
75
|
+
|
|
76
|
+
// Profile types
|
|
77
|
+
ProfileParams,
|
|
78
|
+
ProfileResponse,
|
|
79
|
+
Profile,
|
|
80
|
+
ProfileMemory,
|
|
81
|
+
|
|
82
|
+
// Search types
|
|
83
|
+
SearchDocumentsParams,
|
|
84
|
+
SearchDocumentsResponse,
|
|
85
|
+
SearchMemoriesParams,
|
|
86
|
+
SearchMemoriesResponse,
|
|
87
|
+
SearchExecuteParams,
|
|
88
|
+
SearchExecuteResponse,
|
|
89
|
+
SearchResultItem,
|
|
90
|
+
SearchResults,
|
|
91
|
+
MemoryResult,
|
|
92
|
+
|
|
93
|
+
// Document types
|
|
94
|
+
Document,
|
|
95
|
+
DocumentListParams,
|
|
96
|
+
DocumentListResponse,
|
|
97
|
+
DocumentUpdateParams,
|
|
98
|
+
DocumentUpdateResponse,
|
|
99
|
+
DocumentAddParams,
|
|
100
|
+
DocumentAddResponse,
|
|
101
|
+
DocumentBatchAddParams,
|
|
102
|
+
DocumentBatchAddResponse,
|
|
103
|
+
DocumentDeleteBulkParams,
|
|
104
|
+
DocumentDeleteBulkResponse,
|
|
105
|
+
DocumentGetResponse,
|
|
106
|
+
DocumentListProcessingResponse,
|
|
107
|
+
DocumentUploadFileParams,
|
|
108
|
+
DocumentUploadFileResponse,
|
|
109
|
+
|
|
110
|
+
// Memory types
|
|
111
|
+
Memory,
|
|
112
|
+
MemoryListParams,
|
|
113
|
+
MemoryListResponse,
|
|
114
|
+
MemoryAddParams,
|
|
115
|
+
MemoryAddResponse,
|
|
116
|
+
MemoryUpdateParams,
|
|
117
|
+
MemoryUpdateResponse,
|
|
118
|
+
MemoryForgetParams,
|
|
119
|
+
MemoryForgetResponse,
|
|
120
|
+
MemoryGetResponse,
|
|
121
|
+
MemoryUpdateMemoryParams,
|
|
122
|
+
MemoryUpdateMemoryResponse,
|
|
123
|
+
MemoryUploadFileParams,
|
|
124
|
+
MemoryUploadFileResponse,
|
|
125
|
+
|
|
126
|
+
// Connection types
|
|
127
|
+
Connection,
|
|
128
|
+
ConnectionProvider,
|
|
129
|
+
ConnectionCreateParams,
|
|
130
|
+
ConnectionCreateResponse,
|
|
131
|
+
ConnectionListParams,
|
|
132
|
+
ConnectionListResponse,
|
|
133
|
+
ConnectionConfigureParams,
|
|
134
|
+
ConnectionConfigureResponse,
|
|
135
|
+
ConnectionDeleteByIDResponse,
|
|
136
|
+
ConnectionDeleteByProviderParams,
|
|
137
|
+
ConnectionDeleteByProviderResponse,
|
|
138
|
+
ConnectionGetByIDResponse,
|
|
139
|
+
ConnectionGetByTagParams,
|
|
140
|
+
ConnectionGetByTagResponse,
|
|
141
|
+
ConnectionImportParams,
|
|
142
|
+
ConnectionImportResponse,
|
|
143
|
+
ConnectionListDocumentsParams,
|
|
144
|
+
ConnectionListDocumentsResponse,
|
|
145
|
+
ConnectionResourcesParams,
|
|
146
|
+
ConnectionResource,
|
|
147
|
+
ConnectionResourcesResponse,
|
|
148
|
+
|
|
149
|
+
// Settings types
|
|
150
|
+
Settings,
|
|
151
|
+
SettingUpdateParams,
|
|
152
|
+
SettingUpdateResponse,
|
|
153
|
+
SettingGetResponse,
|
|
154
|
+
} from './types.js'
|
|
155
|
+
|
|
156
|
+
// Namespace for type convenience (matches official SDK pattern)
|
|
157
|
+
// Types are available both at module level and under Supermemory namespace
|
|
158
|
+
import type * as Types from './types.js'
|
|
159
|
+
|
|
160
|
+
export namespace Supermemory {
|
|
161
|
+
// Re-export all types under the Supermemory namespace
|
|
162
|
+
export type ClientOptions = Types.ClientOptions
|
|
163
|
+
export type RequestOptions = Types.RequestOptions
|
|
164
|
+
export type LogLevel = Types.LogLevel
|
|
165
|
+
export type Logger = Types.Logger
|
|
166
|
+
export type Uploadable = Types.Uploadable
|
|
167
|
+
export type ToFileOptions = Types.ToFileOptions
|
|
168
|
+
export type Metadata = Types.Metadata
|
|
169
|
+
export type Pagination = Types.Pagination
|
|
170
|
+
export type Chunk = Types.Chunk
|
|
171
|
+
export type Filter = Types.Filter
|
|
172
|
+
export type OrFilter = Types.OrFilter
|
|
173
|
+
export type AndFilter = Types.AndFilter
|
|
174
|
+
export type FilterCondition = Types.FilterCondition
|
|
175
|
+
export type AddParams = Types.AddParams
|
|
176
|
+
export type AddResponse = Types.AddResponse
|
|
177
|
+
export type ProfileParams = Types.ProfileParams
|
|
178
|
+
export type ProfileResponse = Types.ProfileResponse
|
|
179
|
+
export type Profile = Types.Profile
|
|
180
|
+
export type ProfileMemory = Types.ProfileMemory
|
|
181
|
+
export type SearchDocumentsParams = Types.SearchDocumentsParams
|
|
182
|
+
export type SearchDocumentsResponse = Types.SearchDocumentsResponse
|
|
183
|
+
export type SearchMemoriesParams = Types.SearchMemoriesParams
|
|
184
|
+
export type SearchMemoriesResponse = Types.SearchMemoriesResponse
|
|
185
|
+
export type SearchExecuteParams = Types.SearchExecuteParams
|
|
186
|
+
export type SearchExecuteResponse = Types.SearchExecuteResponse
|
|
187
|
+
export type SearchResultItem = Types.SearchResultItem
|
|
188
|
+
export type SearchResults = Types.SearchResults
|
|
189
|
+
export type MemoryResult = Types.MemoryResult
|
|
190
|
+
export type Document = Types.Document
|
|
191
|
+
export type DocumentListParams = Types.DocumentListParams
|
|
192
|
+
export type DocumentListResponse = Types.DocumentListResponse
|
|
193
|
+
export type DocumentUpdateParams = Types.DocumentUpdateParams
|
|
194
|
+
export type DocumentUpdateResponse = Types.DocumentUpdateResponse
|
|
195
|
+
export type DocumentAddParams = Types.DocumentAddParams
|
|
196
|
+
export type DocumentAddResponse = Types.DocumentAddResponse
|
|
197
|
+
export type DocumentBatchAddParams = Types.DocumentBatchAddParams
|
|
198
|
+
export type DocumentBatchAddResponse = Types.DocumentBatchAddResponse
|
|
199
|
+
export type DocumentDeleteBulkParams = Types.DocumentDeleteBulkParams
|
|
200
|
+
export type DocumentDeleteBulkResponse = Types.DocumentDeleteBulkResponse
|
|
201
|
+
export type DocumentGetResponse = Types.DocumentGetResponse
|
|
202
|
+
export type DocumentListProcessingResponse = Types.DocumentListProcessingResponse
|
|
203
|
+
export type DocumentUploadFileParams = Types.DocumentUploadFileParams
|
|
204
|
+
export type DocumentUploadFileResponse = Types.DocumentUploadFileResponse
|
|
205
|
+
export type Memory = Types.Memory
|
|
206
|
+
export type MemoryListParams = Types.MemoryListParams
|
|
207
|
+
export type MemoryListResponse = Types.MemoryListResponse
|
|
208
|
+
export type MemoryAddParams = Types.MemoryAddParams
|
|
209
|
+
export type MemoryAddResponse = Types.MemoryAddResponse
|
|
210
|
+
export type MemoryUpdateParams = Types.MemoryUpdateParams
|
|
211
|
+
export type MemoryUpdateResponse = Types.MemoryUpdateResponse
|
|
212
|
+
export type MemoryForgetParams = Types.MemoryForgetParams
|
|
213
|
+
export type MemoryForgetResponse = Types.MemoryForgetResponse
|
|
214
|
+
export type MemoryGetResponse = Types.MemoryGetResponse
|
|
215
|
+
export type MemoryUpdateMemoryParams = Types.MemoryUpdateMemoryParams
|
|
216
|
+
export type MemoryUpdateMemoryResponse = Types.MemoryUpdateMemoryResponse
|
|
217
|
+
export type MemoryUploadFileParams = Types.MemoryUploadFileParams
|
|
218
|
+
export type MemoryUploadFileResponse = Types.MemoryUploadFileResponse
|
|
219
|
+
export type Connection = Types.Connection
|
|
220
|
+
export type ConnectionProvider = Types.ConnectionProvider
|
|
221
|
+
export type ConnectionCreateParams = Types.ConnectionCreateParams
|
|
222
|
+
export type ConnectionCreateResponse = Types.ConnectionCreateResponse
|
|
223
|
+
export type ConnectionListParams = Types.ConnectionListParams
|
|
224
|
+
export type ConnectionListResponse = Types.ConnectionListResponse
|
|
225
|
+
export type ConnectionConfigureParams = Types.ConnectionConfigureParams
|
|
226
|
+
export type ConnectionConfigureResponse = Types.ConnectionConfigureResponse
|
|
227
|
+
export type ConnectionDeleteByIDResponse = Types.ConnectionDeleteByIDResponse
|
|
228
|
+
export type ConnectionDeleteByProviderParams = Types.ConnectionDeleteByProviderParams
|
|
229
|
+
export type ConnectionDeleteByProviderResponse = Types.ConnectionDeleteByProviderResponse
|
|
230
|
+
export type ConnectionGetByIDResponse = Types.ConnectionGetByIDResponse
|
|
231
|
+
export type ConnectionGetByTagParams = Types.ConnectionGetByTagParams
|
|
232
|
+
export type ConnectionGetByTagResponse = Types.ConnectionGetByTagResponse
|
|
233
|
+
export type ConnectionImportParams = Types.ConnectionImportParams
|
|
234
|
+
export type ConnectionImportResponse = Types.ConnectionImportResponse
|
|
235
|
+
export type ConnectionListDocumentsParams = Types.ConnectionListDocumentsParams
|
|
236
|
+
export type ConnectionListDocumentsResponse = Types.ConnectionListDocumentsResponse
|
|
237
|
+
export type ConnectionResourcesParams = Types.ConnectionResourcesParams
|
|
238
|
+
export type ConnectionResource = Types.ConnectionResource
|
|
239
|
+
export type ConnectionResourcesResponse = Types.ConnectionResourcesResponse
|
|
240
|
+
export type Settings = Types.Settings
|
|
241
|
+
export type SettingUpdateParams = Types.SettingUpdateParams
|
|
242
|
+
export type SettingUpdateResponse = Types.SettingUpdateResponse
|
|
243
|
+
export type SettingGetResponse = Types.SettingGetResponse
|
|
244
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base resource class for API resources
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { HTTPClient, APIPromise } from '../http.js'
|
|
6
|
+
import type { RequestOptions } from '../types.js'
|
|
7
|
+
|
|
8
|
+
export abstract class APIResource {
|
|
9
|
+
protected client: HTTPClient
|
|
10
|
+
|
|
11
|
+
constructor(client: HTTPClient) {
|
|
12
|
+
this.client = client
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
protected _get<T>(
|
|
16
|
+
path: string,
|
|
17
|
+
options?: { query?: Record<string, unknown>; requestOptions?: RequestOptions }
|
|
18
|
+
): APIPromise<T> {
|
|
19
|
+
return this.client.get<T>(path, options)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
protected _post<T>(
|
|
23
|
+
path: string,
|
|
24
|
+
options?: {
|
|
25
|
+
body?: unknown
|
|
26
|
+
query?: Record<string, unknown>
|
|
27
|
+
requestOptions?: RequestOptions
|
|
28
|
+
}
|
|
29
|
+
): APIPromise<T> {
|
|
30
|
+
return this.client.post<T>(path, options)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
protected _put<T>(
|
|
34
|
+
path: string,
|
|
35
|
+
options?: {
|
|
36
|
+
body?: unknown
|
|
37
|
+
query?: Record<string, unknown>
|
|
38
|
+
requestOptions?: RequestOptions
|
|
39
|
+
}
|
|
40
|
+
): APIPromise<T> {
|
|
41
|
+
return this.client.put<T>(path, options)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
protected _patch<T>(
|
|
45
|
+
path: string,
|
|
46
|
+
options?: {
|
|
47
|
+
body?: unknown
|
|
48
|
+
query?: Record<string, unknown>
|
|
49
|
+
requestOptions?: RequestOptions
|
|
50
|
+
}
|
|
51
|
+
): APIPromise<T> {
|
|
52
|
+
return this.client.patch<T>(path, options)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
protected _delete<T>(
|
|
56
|
+
path: string,
|
|
57
|
+
options?: {
|
|
58
|
+
body?: unknown
|
|
59
|
+
query?: Record<string, unknown>
|
|
60
|
+
requestOptions?: RequestOptions
|
|
61
|
+
}
|
|
62
|
+
): APIPromise<T> {
|
|
63
|
+
return this.client.delete<T>(path, options)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connections Resource
|
|
3
|
+
* Manages external provider connections (GitHub, Gmail, Google Drive, etc.)
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { APIResource } from './base.js'
|
|
7
|
+
import { APIPromise } from '../http.js'
|
|
8
|
+
import type {
|
|
9
|
+
RequestOptions,
|
|
10
|
+
ConnectionProvider,
|
|
11
|
+
ConnectionCreateParams,
|
|
12
|
+
ConnectionCreateResponse,
|
|
13
|
+
ConnectionListParams,
|
|
14
|
+
ConnectionListResponse,
|
|
15
|
+
ConnectionConfigureParams,
|
|
16
|
+
ConnectionConfigureResponse,
|
|
17
|
+
ConnectionDeleteByIDResponse,
|
|
18
|
+
ConnectionDeleteByProviderParams,
|
|
19
|
+
ConnectionDeleteByProviderResponse,
|
|
20
|
+
ConnectionGetByIDResponse,
|
|
21
|
+
ConnectionGetByTagParams,
|
|
22
|
+
ConnectionGetByTagResponse,
|
|
23
|
+
ConnectionImportParams,
|
|
24
|
+
ConnectionImportResponse,
|
|
25
|
+
ConnectionListDocumentsParams,
|
|
26
|
+
ConnectionListDocumentsResponse,
|
|
27
|
+
ConnectionResourcesParams,
|
|
28
|
+
ConnectionResourcesResponse,
|
|
29
|
+
} from '../types.js'
|
|
30
|
+
|
|
31
|
+
export class Connections extends APIResource {
|
|
32
|
+
/**
|
|
33
|
+
* Create a new connection to an external provider
|
|
34
|
+
*
|
|
35
|
+
* @param provider - Provider type (github, gmail, google-drive, notion, etc.)
|
|
36
|
+
* @param body - Connection configuration
|
|
37
|
+
* @param options - Request options
|
|
38
|
+
* @returns Authorization link and connection details
|
|
39
|
+
*/
|
|
40
|
+
create(
|
|
41
|
+
provider: ConnectionProvider | string,
|
|
42
|
+
body?: ConnectionCreateParams | null,
|
|
43
|
+
options?: RequestOptions
|
|
44
|
+
): APIPromise<ConnectionCreateResponse> {
|
|
45
|
+
return this._post<ConnectionCreateResponse>(`/v3/connections/${encodeURIComponent(provider)}`, {
|
|
46
|
+
body: body || {},
|
|
47
|
+
requestOptions: options,
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* List all connections
|
|
53
|
+
*
|
|
54
|
+
* @param body - List parameters including filters
|
|
55
|
+
* @param options - Request options
|
|
56
|
+
* @returns Array of connections
|
|
57
|
+
*/
|
|
58
|
+
list(body?: ConnectionListParams | null, options?: RequestOptions): APIPromise<ConnectionListResponse> {
|
|
59
|
+
return this._post<ConnectionListResponse>('/v3/connections/list', {
|
|
60
|
+
body: body || {},
|
|
61
|
+
requestOptions: options,
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Get connection details by ID
|
|
67
|
+
*
|
|
68
|
+
* @param id - Connection ID
|
|
69
|
+
* @param options - Request options
|
|
70
|
+
* @returns Connection details
|
|
71
|
+
*/
|
|
72
|
+
getByID(id: string, options?: RequestOptions): APIPromise<ConnectionGetByIDResponse> {
|
|
73
|
+
return this.client.get<ConnectionGetByIDResponse>(`/v3/connections/${encodeURIComponent(id)}`, {
|
|
74
|
+
requestOptions: options,
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Get connections by container tag
|
|
80
|
+
*
|
|
81
|
+
* @param provider - Provider type
|
|
82
|
+
* @param body - Container tags to filter by
|
|
83
|
+
* @param options - Request options
|
|
84
|
+
* @returns Connection details
|
|
85
|
+
*/
|
|
86
|
+
getByTag(
|
|
87
|
+
provider: ConnectionProvider | string,
|
|
88
|
+
body: ConnectionGetByTagParams,
|
|
89
|
+
options?: RequestOptions
|
|
90
|
+
): APIPromise<ConnectionGetByTagResponse> {
|
|
91
|
+
return this._post<ConnectionGetByTagResponse>(`/v3/connections/${encodeURIComponent(provider)}/by-tag`, {
|
|
92
|
+
body,
|
|
93
|
+
requestOptions: options,
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Configure resources for a connection
|
|
99
|
+
*
|
|
100
|
+
* @param id - Connection ID
|
|
101
|
+
* @param body - Resources to configure
|
|
102
|
+
* @param options - Request options
|
|
103
|
+
* @returns Configuration result
|
|
104
|
+
*/
|
|
105
|
+
configure(
|
|
106
|
+
id: string,
|
|
107
|
+
body: ConnectionConfigureParams,
|
|
108
|
+
options?: RequestOptions
|
|
109
|
+
): APIPromise<ConnectionConfigureResponse> {
|
|
110
|
+
return this._post<ConnectionConfigureResponse>(`/v3/connections/${encodeURIComponent(id)}/configure`, {
|
|
111
|
+
body,
|
|
112
|
+
requestOptions: options,
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Delete a connection by ID
|
|
118
|
+
*
|
|
119
|
+
* @param id - Connection ID
|
|
120
|
+
* @param options - Request options
|
|
121
|
+
* @returns Deleted connection details
|
|
122
|
+
*/
|
|
123
|
+
deleteByID(id: string, options?: RequestOptions): APIPromise<ConnectionDeleteByIDResponse> {
|
|
124
|
+
return this.client.delete<ConnectionDeleteByIDResponse>(`/v3/connections/${encodeURIComponent(id)}`, {
|
|
125
|
+
requestOptions: options,
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Delete connections by provider and container tags
|
|
131
|
+
*
|
|
132
|
+
* @param provider - Provider type
|
|
133
|
+
* @param body - Container tags to filter which connections to delete
|
|
134
|
+
* @param options - Request options
|
|
135
|
+
* @returns Deleted connection details
|
|
136
|
+
*/
|
|
137
|
+
deleteByProvider(
|
|
138
|
+
provider: ConnectionProvider | string,
|
|
139
|
+
body: ConnectionDeleteByProviderParams,
|
|
140
|
+
options?: RequestOptions
|
|
141
|
+
): APIPromise<ConnectionDeleteByProviderResponse> {
|
|
142
|
+
return this.client.delete<ConnectionDeleteByProviderResponse>(`/v3/connections/${encodeURIComponent(provider)}`, {
|
|
143
|
+
body,
|
|
144
|
+
requestOptions: options,
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Import resources from a connection
|
|
150
|
+
*
|
|
151
|
+
* @param id - Connection ID
|
|
152
|
+
* @param body - Import parameters
|
|
153
|
+
* @param options - Request options
|
|
154
|
+
* @returns Import results
|
|
155
|
+
*/
|
|
156
|
+
import(
|
|
157
|
+
id: string,
|
|
158
|
+
body?: ConnectionImportParams | null,
|
|
159
|
+
options?: RequestOptions
|
|
160
|
+
): APIPromise<ConnectionImportResponse> {
|
|
161
|
+
return this._post<ConnectionImportResponse>(`/v3/connections/${encodeURIComponent(id)}/import`, {
|
|
162
|
+
body: body || {},
|
|
163
|
+
requestOptions: options,
|
|
164
|
+
})
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* List documents from a connection
|
|
169
|
+
*
|
|
170
|
+
* @param id - Connection ID
|
|
171
|
+
* @param body - List parameters
|
|
172
|
+
* @param options - Request options
|
|
173
|
+
* @returns Documents from the connection
|
|
174
|
+
*/
|
|
175
|
+
listDocuments(
|
|
176
|
+
id: string,
|
|
177
|
+
body?: ConnectionListDocumentsParams | null,
|
|
178
|
+
options?: RequestOptions
|
|
179
|
+
): APIPromise<ConnectionListDocumentsResponse> {
|
|
180
|
+
return this._post<ConnectionListDocumentsResponse>(`/v3/connections/${encodeURIComponent(id)}/documents`, {
|
|
181
|
+
body: body || {},
|
|
182
|
+
requestOptions: options,
|
|
183
|
+
})
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Get available resources from a connection
|
|
188
|
+
*
|
|
189
|
+
* @param id - Connection ID
|
|
190
|
+
* @param body - Pagination parameters
|
|
191
|
+
* @param options - Request options
|
|
192
|
+
* @returns Available resources
|
|
193
|
+
*/
|
|
194
|
+
resources(
|
|
195
|
+
id: string,
|
|
196
|
+
body?: ConnectionResourcesParams | null,
|
|
197
|
+
options?: RequestOptions
|
|
198
|
+
): APIPromise<ConnectionResourcesResponse> {
|
|
199
|
+
return this.client.get<ConnectionResourcesResponse>(`/v3/connections/${encodeURIComponent(id)}/resources`, {
|
|
200
|
+
query: body as Record<string, unknown> | undefined,
|
|
201
|
+
requestOptions: options,
|
|
202
|
+
})
|
|
203
|
+
}
|
|
204
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Documents Resource
|
|
3
|
+
* Provides CRUD operations for documents
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { APIResource } from './base.js'
|
|
7
|
+
import { APIPromise } from '../http.js'
|
|
8
|
+
import type {
|
|
9
|
+
RequestOptions,
|
|
10
|
+
DocumentListParams,
|
|
11
|
+
DocumentListResponse,
|
|
12
|
+
DocumentUpdateParams,
|
|
13
|
+
DocumentUpdateResponse,
|
|
14
|
+
DocumentAddParams,
|
|
15
|
+
DocumentAddResponse,
|
|
16
|
+
DocumentBatchAddParams,
|
|
17
|
+
DocumentBatchAddResponse,
|
|
18
|
+
DocumentDeleteBulkParams,
|
|
19
|
+
DocumentDeleteBulkResponse,
|
|
20
|
+
DocumentGetResponse,
|
|
21
|
+
DocumentListProcessingResponse,
|
|
22
|
+
DocumentUploadFileParams,
|
|
23
|
+
DocumentUploadFileResponse,
|
|
24
|
+
} from '../types.js'
|
|
25
|
+
|
|
26
|
+
export class Documents extends APIResource {
|
|
27
|
+
/**
|
|
28
|
+
* Retrieve a specific document by ID
|
|
29
|
+
*
|
|
30
|
+
* @param id - Document ID or customId
|
|
31
|
+
* @param options - Request options
|
|
32
|
+
* @returns The document with full details
|
|
33
|
+
*/
|
|
34
|
+
get(id: string, options?: RequestOptions): APIPromise<DocumentGetResponse> {
|
|
35
|
+
return this.client.get<DocumentGetResponse>(`/v3/documents/${encodeURIComponent(id)}`, {
|
|
36
|
+
requestOptions: options,
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Retrieve a paginated collection of documents
|
|
42
|
+
*
|
|
43
|
+
* @param body - List parameters including filters and pagination
|
|
44
|
+
* @param options - Request options
|
|
45
|
+
* @returns Paginated list of documents
|
|
46
|
+
*/
|
|
47
|
+
list(body?: DocumentListParams | null, options?: RequestOptions): APIPromise<DocumentListResponse> {
|
|
48
|
+
return this._post<DocumentListResponse>('/v3/documents/list', {
|
|
49
|
+
body: body || {},
|
|
50
|
+
requestOptions: options,
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Insert a new document
|
|
56
|
+
*
|
|
57
|
+
* @param body - Document content and metadata
|
|
58
|
+
* @param options - Request options
|
|
59
|
+
* @returns Created document ID and status
|
|
60
|
+
*/
|
|
61
|
+
add(body: DocumentAddParams, options?: RequestOptions): APIPromise<DocumentAddResponse> {
|
|
62
|
+
return this._post<DocumentAddResponse>('/v3/add', {
|
|
63
|
+
body,
|
|
64
|
+
requestOptions: options,
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Insert multiple documents in one request
|
|
70
|
+
*
|
|
71
|
+
* @param body - Array of documents to add
|
|
72
|
+
* @param options - Request options
|
|
73
|
+
* @returns Results for each document including any failures
|
|
74
|
+
*/
|
|
75
|
+
batchAdd(body: DocumentBatchAddParams, options?: RequestOptions): APIPromise<DocumentBatchAddResponse> {
|
|
76
|
+
return this._post<DocumentBatchAddResponse>('/v3/documents/batch', {
|
|
77
|
+
body,
|
|
78
|
+
requestOptions: options,
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Update a document's content or metadata
|
|
84
|
+
*
|
|
85
|
+
* @param id - Document ID or customId
|
|
86
|
+
* @param body - Updated content and/or metadata
|
|
87
|
+
* @param options - Request options
|
|
88
|
+
* @returns Updated document status
|
|
89
|
+
*/
|
|
90
|
+
update(id: string, body?: DocumentUpdateParams | null, options?: RequestOptions): APIPromise<DocumentUpdateResponse> {
|
|
91
|
+
return this._patch<DocumentUpdateResponse>(`/v3/documents/${encodeURIComponent(id)}`, {
|
|
92
|
+
body: body || {},
|
|
93
|
+
requestOptions: options,
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Delete a document by ID
|
|
99
|
+
*
|
|
100
|
+
* @param id - Document ID or customId
|
|
101
|
+
* @param options - Request options
|
|
102
|
+
*/
|
|
103
|
+
delete(id: string, options?: RequestOptions): APIPromise<void> {
|
|
104
|
+
return this.client.delete<void>(`/v3/documents/${encodeURIComponent(id)}`, {
|
|
105
|
+
requestOptions: options,
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Delete multiple documents by IDs or container tags
|
|
111
|
+
*
|
|
112
|
+
* @param body - IDs or container tags to delete
|
|
113
|
+
* @param options - Request options
|
|
114
|
+
* @returns Count and IDs of deleted documents
|
|
115
|
+
*/
|
|
116
|
+
deleteBulk(body?: DocumentDeleteBulkParams | null, options?: RequestOptions): APIPromise<DocumentDeleteBulkResponse> {
|
|
117
|
+
return this._post<DocumentDeleteBulkResponse>('/v3/documents/delete', {
|
|
118
|
+
body: body || {},
|
|
119
|
+
requestOptions: options,
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Get documents currently being processed
|
|
125
|
+
*
|
|
126
|
+
* @param options - Request options
|
|
127
|
+
* @returns List of documents in processing state
|
|
128
|
+
*/
|
|
129
|
+
listProcessing(options?: RequestOptions): APIPromise<DocumentListProcessingResponse> {
|
|
130
|
+
return this.client.get<DocumentListProcessingResponse>('/v3/documents/processing', {
|
|
131
|
+
requestOptions: options,
|
|
132
|
+
})
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Upload a file for processing
|
|
137
|
+
*
|
|
138
|
+
* @param body - File and metadata for upload
|
|
139
|
+
* @param options - Request options
|
|
140
|
+
* @returns Created document ID and status
|
|
141
|
+
*/
|
|
142
|
+
uploadFile(body: DocumentUploadFileParams, options?: RequestOptions): APIPromise<DocumentUploadFileResponse> {
|
|
143
|
+
const { file, containerTag, customId, metadata } = body
|
|
144
|
+
|
|
145
|
+
// Build additional form fields
|
|
146
|
+
const additionalFields: Record<string, string> = {}
|
|
147
|
+
if (containerTag) {
|
|
148
|
+
additionalFields.containerTag = containerTag
|
|
149
|
+
}
|
|
150
|
+
if (customId) {
|
|
151
|
+
additionalFields.customId = customId
|
|
152
|
+
}
|
|
153
|
+
if (metadata) {
|
|
154
|
+
additionalFields.metadata = JSON.stringify(metadata)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return this.client.uploadFile<DocumentUploadFileResponse>('/v3/documents/upload', file, {
|
|
158
|
+
fieldName: 'file',
|
|
159
|
+
additionalFields,
|
|
160
|
+
requestOptions: options,
|
|
161
|
+
})
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resource exports
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export { APIResource } from './base.js'
|
|
6
|
+
export { Search } from './search.js'
|
|
7
|
+
export { Documents } from './documents.js'
|
|
8
|
+
export { Memories } from './memories.js'
|
|
9
|
+
export { Connections } from './connections.js'
|
|
10
|
+
export { Settings } from './settings.js'
|