ai-database 0.0.0-development → 0.2.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/.turbo/turbo-build.log +5 -0
- package/.turbo/turbo-test.log +102 -0
- package/README.md +402 -47
- package/TESTING.md +410 -0
- package/TEST_SUMMARY.md +250 -0
- package/TODO.md +128 -0
- package/dist/ai-promise-db.d.ts +370 -0
- package/dist/ai-promise-db.d.ts.map +1 -0
- package/dist/ai-promise-db.js +839 -0
- package/dist/ai-promise-db.js.map +1 -0
- package/dist/authorization.d.ts +531 -0
- package/dist/authorization.d.ts.map +1 -0
- package/dist/authorization.js +632 -0
- package/dist/authorization.js.map +1 -0
- package/dist/durable-clickhouse.d.ts +193 -0
- package/dist/durable-clickhouse.d.ts.map +1 -0
- package/dist/durable-clickhouse.js +422 -0
- package/dist/durable-clickhouse.js.map +1 -0
- package/dist/durable-promise.d.ts +182 -0
- package/dist/durable-promise.d.ts.map +1 -0
- package/dist/durable-promise.js +409 -0
- package/dist/durable-promise.js.map +1 -0
- package/dist/execution-queue.d.ts +239 -0
- package/dist/execution-queue.d.ts.map +1 -0
- package/dist/execution-queue.js +400 -0
- package/dist/execution-queue.js.map +1 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +79 -0
- package/dist/index.js.map +1 -0
- package/dist/linguistic.d.ts +115 -0
- package/dist/linguistic.d.ts.map +1 -0
- package/dist/linguistic.js +379 -0
- package/dist/linguistic.js.map +1 -0
- package/dist/memory-provider.d.ts +304 -0
- package/dist/memory-provider.d.ts.map +1 -0
- package/dist/memory-provider.js +785 -0
- package/dist/memory-provider.js.map +1 -0
- package/dist/schema.d.ts +899 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +1165 -0
- package/dist/schema.js.map +1 -0
- package/dist/tests.d.ts +107 -0
- package/dist/tests.d.ts.map +1 -0
- package/dist/tests.js +568 -0
- package/dist/tests.js.map +1 -0
- package/dist/types.d.ts +972 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +126 -0
- package/dist/types.js.map +1 -0
- package/package.json +37 -23
- package/src/ai-promise-db.ts +1243 -0
- package/src/authorization.ts +1102 -0
- package/src/durable-clickhouse.ts +596 -0
- package/src/durable-promise.ts +582 -0
- package/src/execution-queue.ts +608 -0
- package/src/index.test.ts +868 -0
- package/src/index.ts +337 -0
- package/src/linguistic.ts +404 -0
- package/src/memory-provider.test.ts +1036 -0
- package/src/memory-provider.ts +1119 -0
- package/src/schema.test.ts +1254 -0
- package/src/schema.ts +2296 -0
- package/src/tests.ts +725 -0
- package/src/types.ts +1177 -0
- package/test/README.md +153 -0
- package/test/edge-cases.test.ts +646 -0
- package/test/provider-resolution.test.ts +402 -0
- package/tsconfig.json +9 -0
- package/vitest.config.ts +19 -0
- package/LICENSE +0 -21
- package/dist/types/database.d.ts +0 -46
- package/dist/types/document.d.ts +0 -15
- package/dist/types/index.d.ts +0 -5
- package/dist/types/mdxdb/embedding.d.ts +0 -7
- package/dist/types/mdxdb/types.d.ts +0 -59
- package/dist/types/synthetic.d.ts +0 -9
- package/dist/types/tools.d.ts +0 -10
- package/dist/types/vector.d.ts +0 -16
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for provider resolution from DATABASE_URL
|
|
3
|
+
*
|
|
4
|
+
* Tests how the DB factory resolves different DATABASE_URL formats.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
8
|
+
import { setProvider, createMemoryProvider } from '../src/index.js'
|
|
9
|
+
|
|
10
|
+
describe('DATABASE_URL parsing', () => {
|
|
11
|
+
let originalEnv: NodeJS.ProcessEnv
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
// Save original environment
|
|
15
|
+
originalEnv = { ...process.env }
|
|
16
|
+
// Reset provider
|
|
17
|
+
setProvider(createMemoryProvider())
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
// Restore original environment
|
|
22
|
+
process.env = originalEnv
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
describe('URL format detection', () => {
|
|
26
|
+
it('detects in-memory provider', () => {
|
|
27
|
+
const url = ':memory:'
|
|
28
|
+
|
|
29
|
+
// The parseDatabaseUrl function is internal, but we can test the behavior
|
|
30
|
+
// by checking that it doesn't throw and returns expected structure
|
|
31
|
+
expect(url).toBe(':memory:')
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('detects filesystem provider (default)', () => {
|
|
35
|
+
const urls = [
|
|
36
|
+
'./content',
|
|
37
|
+
'/absolute/path/to/content',
|
|
38
|
+
'relative/path',
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
urls.forEach(url => {
|
|
42
|
+
expect(url).not.toContain('://')
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('detects SQLite provider', () => {
|
|
47
|
+
const urls = [
|
|
48
|
+
'sqlite://./content',
|
|
49
|
+
'sqlite:///absolute/path',
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
urls.forEach(url => {
|
|
53
|
+
expect(url.startsWith('sqlite://')).toBe(true)
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('detects Turso provider', () => {
|
|
58
|
+
const urls = [
|
|
59
|
+
'libsql://my-db.turso.io',
|
|
60
|
+
'libsql://my-db.turso.io/db',
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
urls.forEach(url => {
|
|
64
|
+
expect(
|
|
65
|
+
url.startsWith('libsql://') || url.includes('.turso.io')
|
|
66
|
+
).toBe(true)
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('detects ClickHouse provider (local)', () => {
|
|
71
|
+
const urls = [
|
|
72
|
+
'chdb://./content',
|
|
73
|
+
'chdb:///absolute/path',
|
|
74
|
+
]
|
|
75
|
+
|
|
76
|
+
urls.forEach(url => {
|
|
77
|
+
expect(url.startsWith('chdb://')).toBe(true)
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('detects ClickHouse provider (remote)', () => {
|
|
82
|
+
const urls = [
|
|
83
|
+
'clickhouse://localhost:8123',
|
|
84
|
+
'clickhouse://clickhouse.example.com:8123/db',
|
|
85
|
+
]
|
|
86
|
+
|
|
87
|
+
urls.forEach(url => {
|
|
88
|
+
expect(url.startsWith('clickhouse://') && url.includes(':')).toBe(true)
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
describe('provider selection', () => {
|
|
94
|
+
it('uses default provider when DATABASE_URL not set', () => {
|
|
95
|
+
delete process.env.DATABASE_URL
|
|
96
|
+
|
|
97
|
+
// Should default to filesystem or memory
|
|
98
|
+
expect(process.env.DATABASE_URL).toBeUndefined()
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
it('respects DATABASE_URL environment variable', () => {
|
|
102
|
+
process.env.DATABASE_URL = 'sqlite://./test.db'
|
|
103
|
+
|
|
104
|
+
expect(process.env.DATABASE_URL).toBe('sqlite://./test.db')
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
it('handles empty DATABASE_URL', () => {
|
|
108
|
+
process.env.DATABASE_URL = ''
|
|
109
|
+
|
|
110
|
+
// Should use default
|
|
111
|
+
expect(process.env.DATABASE_URL).toBe('')
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
describe('URL parsing logic', () => {
|
|
116
|
+
it('extracts root path from filesystem URL', () => {
|
|
117
|
+
const url = './content'
|
|
118
|
+
const root = url
|
|
119
|
+
|
|
120
|
+
expect(root).toBe('./content')
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('extracts root path from SQLite URL', () => {
|
|
124
|
+
const url = 'sqlite://./content'
|
|
125
|
+
const root = url.replace('sqlite://', '')
|
|
126
|
+
|
|
127
|
+
expect(root).toBe('./content')
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
it('extracts root path from chDB URL', () => {
|
|
131
|
+
const url = 'chdb://./data'
|
|
132
|
+
const root = url.replace('chdb://', '')
|
|
133
|
+
|
|
134
|
+
expect(root).toBe('./data')
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
it('preserves remote URLs', () => {
|
|
138
|
+
const url = 'libsql://my-db.turso.io'
|
|
139
|
+
|
|
140
|
+
expect(url).toContain('turso.io')
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
it('converts clickhouse:// to https:// for remote', () => {
|
|
144
|
+
const url = 'clickhouse://localhost:8123'
|
|
145
|
+
const httpUrl = url.replace('clickhouse://', 'https://')
|
|
146
|
+
|
|
147
|
+
expect(httpUrl).toBe('https://localhost:8123')
|
|
148
|
+
})
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
describe('provider paths', () => {
|
|
152
|
+
it('generates correct .db folder path for SQLite', () => {
|
|
153
|
+
const root = './content'
|
|
154
|
+
const dbPath = `${root}/.db/index.sqlite`
|
|
155
|
+
|
|
156
|
+
expect(dbPath).toBe('./content/.db/index.sqlite')
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
it('generates correct .db folder path for ClickHouse', () => {
|
|
160
|
+
const root = './content'
|
|
161
|
+
const dbPath = `${root}/.db/clickhouse`
|
|
162
|
+
|
|
163
|
+
expect(dbPath).toBe('./content/.db/clickhouse')
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
it('handles absolute paths', () => {
|
|
167
|
+
const root = '/var/data/content'
|
|
168
|
+
const dbPath = `${root}/.db/index.sqlite`
|
|
169
|
+
|
|
170
|
+
expect(dbPath).toBe('/var/data/content/.db/index.sqlite')
|
|
171
|
+
})
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
describe('special cases', () => {
|
|
175
|
+
it('handles URLs with query parameters', () => {
|
|
176
|
+
const url = 'libsql://my-db.turso.io?auth=token'
|
|
177
|
+
|
|
178
|
+
expect(url).toContain('?auth=token')
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
it('handles URLs with database names', () => {
|
|
182
|
+
const url = 'clickhouse://localhost:8123/mydb'
|
|
183
|
+
|
|
184
|
+
expect(url).toContain('/mydb')
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
it('handles file:// protocol', () => {
|
|
188
|
+
const url = 'sqlite:///absolute/path/to/db.sqlite'
|
|
189
|
+
const path = url.replace('sqlite://', '')
|
|
190
|
+
|
|
191
|
+
expect(path).toBe('/absolute/path/to/db.sqlite')
|
|
192
|
+
})
|
|
193
|
+
})
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
describe('provider initialization', () => {
|
|
197
|
+
beforeEach(() => {
|
|
198
|
+
setProvider(createMemoryProvider())
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
it('initializes memory provider synchronously', () => {
|
|
202
|
+
const provider = createMemoryProvider()
|
|
203
|
+
|
|
204
|
+
expect(provider).toBeDefined()
|
|
205
|
+
expect(typeof provider.get).toBe('function')
|
|
206
|
+
expect(typeof provider.create).toBe('function')
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
it('memory provider is immediately usable', async () => {
|
|
210
|
+
const provider = createMemoryProvider()
|
|
211
|
+
|
|
212
|
+
const result = await provider.create('Test', 'test1', { value: 'test' })
|
|
213
|
+
|
|
214
|
+
expect(result.$id).toBe('test1')
|
|
215
|
+
expect(result.value).toBe('test')
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
it('setProvider allows custom provider', () => {
|
|
219
|
+
const customProvider = createMemoryProvider()
|
|
220
|
+
|
|
221
|
+
// Should not throw
|
|
222
|
+
expect(() => setProvider(customProvider)).not.toThrow()
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
it('multiple setProvider calls replace provider', async () => {
|
|
226
|
+
const provider1 = createMemoryProvider()
|
|
227
|
+
const provider2 = createMemoryProvider()
|
|
228
|
+
|
|
229
|
+
setProvider(provider1)
|
|
230
|
+
await provider1.create('Test', 'test1', { value: 'first' })
|
|
231
|
+
|
|
232
|
+
setProvider(provider2)
|
|
233
|
+
|
|
234
|
+
// provider2 should not have test1
|
|
235
|
+
const result = await provider2.get('Test', 'test1')
|
|
236
|
+
expect(result).toBeNull()
|
|
237
|
+
})
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
describe('provider interface compliance', () => {
|
|
241
|
+
it('memory provider implements all required methods', () => {
|
|
242
|
+
const provider = createMemoryProvider()
|
|
243
|
+
|
|
244
|
+
const requiredMethods = [
|
|
245
|
+
'get',
|
|
246
|
+
'list',
|
|
247
|
+
'search',
|
|
248
|
+
'create',
|
|
249
|
+
'update',
|
|
250
|
+
'delete',
|
|
251
|
+
'related',
|
|
252
|
+
'relate',
|
|
253
|
+
'unrelate',
|
|
254
|
+
]
|
|
255
|
+
|
|
256
|
+
requiredMethods.forEach(method => {
|
|
257
|
+
expect(typeof (provider as any)[method]).toBe('function')
|
|
258
|
+
})
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
it('memory provider has utility methods', () => {
|
|
262
|
+
const provider = createMemoryProvider()
|
|
263
|
+
|
|
264
|
+
expect(typeof provider.clear).toBe('function')
|
|
265
|
+
expect(typeof provider.stats).toBe('function')
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
it('provider methods return expected types', async () => {
|
|
269
|
+
const provider = createMemoryProvider()
|
|
270
|
+
|
|
271
|
+
// get returns Record<string, unknown> | null
|
|
272
|
+
const getResult = await provider.get('Test', 'id1')
|
|
273
|
+
expect(getResult === null || typeof getResult === 'object').toBe(true)
|
|
274
|
+
|
|
275
|
+
// create returns Record<string, unknown>
|
|
276
|
+
const createResult = await provider.create('Test', 'id1', { value: 'test' })
|
|
277
|
+
expect(typeof createResult).toBe('object')
|
|
278
|
+
|
|
279
|
+
// delete returns boolean
|
|
280
|
+
const deleteResult = await provider.delete('Test', 'id1')
|
|
281
|
+
expect(typeof deleteResult).toBe('boolean')
|
|
282
|
+
|
|
283
|
+
// list returns array
|
|
284
|
+
const listResult = await provider.list('Test')
|
|
285
|
+
expect(Array.isArray(listResult)).toBe(true)
|
|
286
|
+
|
|
287
|
+
// search returns array
|
|
288
|
+
const searchResult = await provider.search('Test', 'query')
|
|
289
|
+
expect(Array.isArray(searchResult)).toBe(true)
|
|
290
|
+
|
|
291
|
+
// related returns array
|
|
292
|
+
const relatedResult = await provider.related('Test', 'id1', 'relation')
|
|
293
|
+
expect(Array.isArray(relatedResult)).toBe(true)
|
|
294
|
+
})
|
|
295
|
+
})
|
|
296
|
+
|
|
297
|
+
describe('error handling', () => {
|
|
298
|
+
it('handles invalid DATABASE_URL gracefully', () => {
|
|
299
|
+
const invalidUrls = [
|
|
300
|
+
'invalid://something',
|
|
301
|
+
'ftp://not-supported',
|
|
302
|
+
'://malformed',
|
|
303
|
+
]
|
|
304
|
+
|
|
305
|
+
// These should not crash the parsing logic
|
|
306
|
+
invalidUrls.forEach(url => {
|
|
307
|
+
expect(typeof url).toBe('string')
|
|
308
|
+
})
|
|
309
|
+
})
|
|
310
|
+
|
|
311
|
+
it('handles missing provider dependencies gracefully', async () => {
|
|
312
|
+
// When using a provider that requires external packages,
|
|
313
|
+
// it should fail gracefully if packages aren't installed
|
|
314
|
+
|
|
315
|
+
// This is more of a documentation test - the actual behavior
|
|
316
|
+
// depends on dynamic imports in resolveProvider()
|
|
317
|
+
expect(true).toBe(true)
|
|
318
|
+
})
|
|
319
|
+
})
|
|
320
|
+
|
|
321
|
+
describe('performance considerations', () => {
|
|
322
|
+
it('provider stats track counts correctly', async () => {
|
|
323
|
+
const provider = createMemoryProvider()
|
|
324
|
+
|
|
325
|
+
await provider.create('User', 'user1', { name: 'User 1' })
|
|
326
|
+
await provider.create('User', 'user2', { name: 'User 2' })
|
|
327
|
+
await provider.create('Post', 'post1', { title: 'Post 1' })
|
|
328
|
+
|
|
329
|
+
const stats = provider.stats()
|
|
330
|
+
|
|
331
|
+
expect(stats.entities).toBe(3)
|
|
332
|
+
expect(stats.relations).toBe(0)
|
|
333
|
+
})
|
|
334
|
+
|
|
335
|
+
it('tracks relation counts', async () => {
|
|
336
|
+
const provider = createMemoryProvider()
|
|
337
|
+
|
|
338
|
+
await provider.create('User', 'user1', { name: 'User 1' })
|
|
339
|
+
await provider.create('Post', 'post1', { title: 'Post 1' })
|
|
340
|
+
await provider.create('Post', 'post2', { title: 'Post 2' })
|
|
341
|
+
|
|
342
|
+
await provider.relate('User', 'user1', 'posts', 'Post', 'post1')
|
|
343
|
+
await provider.relate('User', 'user1', 'posts', 'Post', 'post2')
|
|
344
|
+
|
|
345
|
+
const stats = provider.stats()
|
|
346
|
+
|
|
347
|
+
expect(stats.entities).toBe(3)
|
|
348
|
+
expect(stats.relations).toBe(2)
|
|
349
|
+
})
|
|
350
|
+
|
|
351
|
+
it('clear resets all counts', async () => {
|
|
352
|
+
const provider = createMemoryProvider()
|
|
353
|
+
|
|
354
|
+
await provider.create('User', 'user1', { name: 'User 1' })
|
|
355
|
+
await provider.create('Post', 'post1', { title: 'Post 1' })
|
|
356
|
+
await provider.relate('User', 'user1', 'posts', 'Post', 'post1')
|
|
357
|
+
|
|
358
|
+
provider.clear()
|
|
359
|
+
|
|
360
|
+
const stats = provider.stats()
|
|
361
|
+
expect(stats.entities).toBe(0)
|
|
362
|
+
expect(stats.relations).toBe(0)
|
|
363
|
+
})
|
|
364
|
+
})
|
|
365
|
+
|
|
366
|
+
describe('documentation examples', () => {
|
|
367
|
+
it('matches README filesystem example', () => {
|
|
368
|
+
const url = './content'
|
|
369
|
+
|
|
370
|
+
expect(url).toBe('./content')
|
|
371
|
+
})
|
|
372
|
+
|
|
373
|
+
it('matches README SQLite example', () => {
|
|
374
|
+
const url = 'sqlite://./content'
|
|
375
|
+
|
|
376
|
+
expect(url.startsWith('sqlite://')).toBe(true)
|
|
377
|
+
})
|
|
378
|
+
|
|
379
|
+
it('matches README Turso example', () => {
|
|
380
|
+
const url = 'libsql://your-db.turso.io'
|
|
381
|
+
|
|
382
|
+
expect(url.includes('.turso.io')).toBe(true)
|
|
383
|
+
})
|
|
384
|
+
|
|
385
|
+
it('matches README chDB example', () => {
|
|
386
|
+
const url = 'chdb://./content'
|
|
387
|
+
|
|
388
|
+
expect(url.startsWith('chdb://')).toBe(true)
|
|
389
|
+
})
|
|
390
|
+
|
|
391
|
+
it('matches README ClickHouse example', () => {
|
|
392
|
+
const url = 'clickhouse://localhost:8123'
|
|
393
|
+
|
|
394
|
+
expect(url.startsWith('clickhouse://')).toBe(true)
|
|
395
|
+
})
|
|
396
|
+
|
|
397
|
+
it('matches README memory example', () => {
|
|
398
|
+
const url = ':memory:'
|
|
399
|
+
|
|
400
|
+
expect(url).toBe(':memory:')
|
|
401
|
+
})
|
|
402
|
+
})
|
package/tsconfig.json
ADDED
package/vitest.config.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { defineConfig } from 'vitest/config'
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
test: {
|
|
5
|
+
globals: false,
|
|
6
|
+
environment: 'node',
|
|
7
|
+
include: ['src/**/*.test.ts', 'test/**/*.test.ts'],
|
|
8
|
+
exclude: ['node_modules/**', 'dist/**'],
|
|
9
|
+
testTimeout: 30000,
|
|
10
|
+
hookTimeout: 15000,
|
|
11
|
+
// Run tests sequentially for database operations
|
|
12
|
+
pool: 'forks',
|
|
13
|
+
poolOptions: {
|
|
14
|
+
forks: {
|
|
15
|
+
singleFork: true,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
})
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 AI Primitives
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/dist/types/database.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { AIDocument } from './document';
|
|
2
|
-
import { AIVectorSearchOptions } from './vector';
|
|
3
|
-
/**
|
|
4
|
-
* Configuration options for the AI-native database
|
|
5
|
-
*/
|
|
6
|
-
export interface DatabaseConfig {
|
|
7
|
-
/**
|
|
8
|
-
* Database name or identifier
|
|
9
|
-
*/
|
|
10
|
-
name: string;
|
|
11
|
-
/**
|
|
12
|
-
* Optional vector search configuration
|
|
13
|
-
*/
|
|
14
|
-
vectorSearch?: {
|
|
15
|
-
/**
|
|
16
|
-
* Dimensions for vector embeddings
|
|
17
|
-
*/
|
|
18
|
-
dimensions?: number;
|
|
19
|
-
/**
|
|
20
|
-
* Model to use for embeddings
|
|
21
|
-
*/
|
|
22
|
-
model?: string;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Optional synthetic data generation configuration
|
|
26
|
-
*/
|
|
27
|
-
synthetic?: {
|
|
28
|
-
/**
|
|
29
|
-
* Model to use for synthetic data generation
|
|
30
|
-
*/
|
|
31
|
-
model?: string;
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Database provider interface
|
|
36
|
-
*/
|
|
37
|
-
export interface DatabaseProvider {
|
|
38
|
-
/**
|
|
39
|
-
* Query documents using AI-powered vector search
|
|
40
|
-
*/
|
|
41
|
-
query(options: AIVectorSearchOptions): Promise<AIDocument[]>;
|
|
42
|
-
/**
|
|
43
|
-
* Insert a document into the database
|
|
44
|
-
*/
|
|
45
|
-
insert(document: AIDocument): Promise<void>;
|
|
46
|
-
}
|
package/dist/types/document.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Document } from './mdxdb/types';
|
|
2
|
-
export interface AIDocument extends Document {
|
|
3
|
-
metadata?: {
|
|
4
|
-
model?: string;
|
|
5
|
-
temperature?: number;
|
|
6
|
-
tokens?: number;
|
|
7
|
-
provider?: string;
|
|
8
|
-
};
|
|
9
|
-
synthetic?: boolean;
|
|
10
|
-
toolCalls?: Array<{
|
|
11
|
-
name: string;
|
|
12
|
-
arguments: Record<string, unknown>;
|
|
13
|
-
result?: unknown;
|
|
14
|
-
}>;
|
|
15
|
-
}
|
package/dist/types/index.d.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import type { MDXLD } from 'mdxld';
|
|
2
|
-
export interface Document extends MDXLD {
|
|
3
|
-
embeddings?: number[];
|
|
4
|
-
collections?: string[];
|
|
5
|
-
}
|
|
6
|
-
export interface VectorSearchOptions {
|
|
7
|
-
vector?: number[];
|
|
8
|
-
query?: string;
|
|
9
|
-
filter?: Record<string, unknown>;
|
|
10
|
-
k?: number;
|
|
11
|
-
threshold?: number;
|
|
12
|
-
}
|
|
13
|
-
export interface NamespaceOptions {
|
|
14
|
-
defaultNamespace?: string;
|
|
15
|
-
enforceHttps?: boolean;
|
|
16
|
-
maxPathDepth?: number;
|
|
17
|
-
allowSubdomains?: boolean;
|
|
18
|
-
}
|
|
19
|
-
export interface DatabaseOptions {
|
|
20
|
-
namespace: string;
|
|
21
|
-
baseUrl?: string;
|
|
22
|
-
options?: NamespaceOptions;
|
|
23
|
-
}
|
|
24
|
-
export interface CollectionOptions {
|
|
25
|
-
path: string;
|
|
26
|
-
database: DatabaseProvider;
|
|
27
|
-
}
|
|
28
|
-
export interface DatabaseProvider<T extends Document = Document> {
|
|
29
|
-
namespace: string;
|
|
30
|
-
connect(): Promise<void>;
|
|
31
|
-
disconnect(): Promise<void>;
|
|
32
|
-
list(): Promise<string[]>;
|
|
33
|
-
collection(name: string): CollectionProvider<T>;
|
|
34
|
-
[key: string]: DatabaseProvider<T> | CollectionProvider<T> | string | (() => Promise<void>) | (() => Promise<string[]>) | ((name: string) => CollectionProvider<T>);
|
|
35
|
-
}
|
|
36
|
-
export type FilterQuery<T> = {
|
|
37
|
-
[K in keyof T]?: T[K] | {
|
|
38
|
-
$eq?: T[K];
|
|
39
|
-
$gt?: T[K];
|
|
40
|
-
$gte?: T[K];
|
|
41
|
-
$lt?: T[K];
|
|
42
|
-
$lte?: T[K];
|
|
43
|
-
$in?: T[K][];
|
|
44
|
-
$nin?: T[K][];
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
export interface SearchOptions<T extends Document = Document> {
|
|
48
|
-
filter?: FilterQuery<T>;
|
|
49
|
-
threshold?: number;
|
|
50
|
-
limit?: number;
|
|
51
|
-
offset?: number;
|
|
52
|
-
includeVectors?: boolean;
|
|
53
|
-
}
|
|
54
|
-
export interface CollectionProvider<T extends Document = Document> {
|
|
55
|
-
path: string;
|
|
56
|
-
find(filter: FilterQuery<T>, options?: SearchOptions<T>): Promise<T[]>;
|
|
57
|
-
search(query: string, options?: SearchOptions<T>): Promise<T[]>;
|
|
58
|
-
vectorSearch(options: VectorSearchOptions & SearchOptions<T>): Promise<T[]>;
|
|
59
|
-
}
|
package/dist/types/tools.d.ts
DELETED
package/dist/types/vector.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { VectorSearchOptions } from './mdxdb/types';
|
|
2
|
-
import type { EmbeddingOptions, EmbeddingProvider } from './mdxdb/embedding';
|
|
3
|
-
export interface AIVectorSearchOptions extends VectorSearchOptions {
|
|
4
|
-
rerank?: boolean;
|
|
5
|
-
hybridWeight?: number;
|
|
6
|
-
contextWindow?: number;
|
|
7
|
-
}
|
|
8
|
-
export interface AIEmbeddingOptions extends EmbeddingOptions {
|
|
9
|
-
provider?: string;
|
|
10
|
-
batchSize?: number;
|
|
11
|
-
normalize?: boolean;
|
|
12
|
-
}
|
|
13
|
-
export interface AIEmbeddingProvider extends EmbeddingProvider {
|
|
14
|
-
batchEmbed?(texts: string[], options?: AIEmbeddingOptions): Promise<number[][]>;
|
|
15
|
-
normalize?(vector: number[]): number[];
|
|
16
|
-
}
|