@vpxa/aikit 0.1.299 → 0.1.301
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/package.json +1 -1
- package/packages/core/dist/index.d.ts +16 -5
- package/packages/core/dist/index.js +1 -1
- package/packages/embeddings/dist/embedder-worker.js +1 -1
- package/packages/embeddings/dist/index.d.ts +3 -0
- package/packages/embeddings/dist/index.js +1 -1
- package/packages/present/dist/index.html +357 -20
- package/packages/server/dist/bin.js +1 -1
- package/packages/server/dist/config-B5gyZrbp.js +2 -0
- package/packages/server/dist/config-CcbU0fiV.js +1 -0
- package/packages/server/dist/index.js +1 -1
- package/packages/server/dist/{server-BRsZ1W2n.js → server-CDWtY-Sp.js} +153 -152
- package/packages/server/dist/{server-DDs9k_Pg.js → server-DSRcQgsx.js} +154 -151
- package/packages/store/dist/index.d.ts +18 -0
- package/packages/store/dist/index.js +9 -9
- package/packages/server/dist/config-BkWFC9ah.js +0 -1
- package/packages/server/dist/config-DK_lqZRv.js +0 -2
|
@@ -402,6 +402,10 @@ interface EmbeddingProfile$1 {
|
|
|
402
402
|
nativeDim: number;
|
|
403
403
|
dimensions: number;
|
|
404
404
|
queryPrefix: string;
|
|
405
|
+
/** Pooling strategy ('mean' for xsmall, 'cls' for large). Used for migration detection. */
|
|
406
|
+
pooling?: 'mean' | 'cls';
|
|
407
|
+
/** Whether embeddings are L2-normalized. */
|
|
408
|
+
normalize?: boolean;
|
|
405
409
|
}
|
|
406
410
|
interface SqliteVecStoreOptions {
|
|
407
411
|
/** Path to the .db file (file is created if missing) */
|
|
@@ -414,6 +418,8 @@ interface SqliteVecStoreOptions {
|
|
|
414
418
|
adapter?: ISqliteAdapter;
|
|
415
419
|
/** Optional state-partition config for future split-db deployments. */
|
|
416
420
|
partition?: StatePartitionConfig;
|
|
421
|
+
/** Profile name for scoped vector table naming (e.g., vec_knowledge_<profileName>) */
|
|
422
|
+
profileName?: string;
|
|
417
423
|
}
|
|
418
424
|
declare class SqliteVecStore implements IKnowledgeStore {
|
|
419
425
|
private adapter;
|
|
@@ -423,6 +429,10 @@ declare class SqliteVecStore implements IKnowledgeStore {
|
|
|
423
429
|
private readonly embeddingProfile;
|
|
424
430
|
/** Coarse embedding dimension for multi-resolution search (matryoshka). */
|
|
425
431
|
private readonly coarseDim;
|
|
432
|
+
/** Vector table name (scoped by profileName if configured). */
|
|
433
|
+
private readonly vecTableName;
|
|
434
|
+
/** Coarse vector table name (scoped by profileName if configured). */
|
|
435
|
+
private readonly vecTableCoarseName;
|
|
426
436
|
private vectorEnabled;
|
|
427
437
|
private ftsEnabled;
|
|
428
438
|
private warnedVectorDisabled;
|
|
@@ -642,6 +652,10 @@ interface EmbeddingProfile {
|
|
|
642
652
|
nativeDim: number;
|
|
643
653
|
dimensions: number;
|
|
644
654
|
queryPrefix: string;
|
|
655
|
+
/** Pooling strategy used by the embedding model. 'mean' averages token embeddings, 'cls' uses the [CLS] token. */
|
|
656
|
+
pooling?: 'mean' | 'cls';
|
|
657
|
+
/** Whether embeddings are L2-normalized. */
|
|
658
|
+
normalize?: boolean;
|
|
645
659
|
}
|
|
646
660
|
interface StoreConfig {
|
|
647
661
|
backend: StoreBackend;
|
|
@@ -653,6 +667,10 @@ interface StoreConfig {
|
|
|
653
667
|
embeddingDim?: number;
|
|
654
668
|
/** Full embedding profile (only used by the sqlite-vec backend). */
|
|
655
669
|
embeddingProfile?: EmbeddingProfile;
|
|
670
|
+
/** Profile name for scoped vector table naming (e.g., "quality", "lightweight").
|
|
671
|
+
* When set, vector tables use `vec_knowledge_<profileName>` instead of the default.
|
|
672
|
+
* When unset, the default table name is used for backward compatibility. */
|
|
673
|
+
profileName?: string;
|
|
656
674
|
/** Optional control/content partition config for sqlite-backed stores. */
|
|
657
675
|
partition?: StatePartitionConfig;
|
|
658
676
|
/**
|
|
@@ -210,7 +210,7 @@ import{createRequire as e}from"node:module";import{AIKIT_PATHS as t,EMBEDDING_DE
|
|
|
210
210
|
VALUES (?, ?, ?, '{}', ?)`,[a,e,t,o]);for(let e=0;e<n.length;e++)this.run(`INSERT INTO process_steps (process_id, node_id, step_order) VALUES (?, ?, ?)`,[a,n[e],e]);s.exec(`COMMIT`),s.flush()}catch(e){throw s.exec(`ROLLBACK`),e}return{id:a,entryNodeId:e,label:t,properties:{},steps:n,createdAt:o}}async getProcesses(e){await this.ensureOpen();let t;t=e?this.query(`SELECT DISTINCT p.id, p.entry_node_id, p.label, p.properties, p.created_at
|
|
211
211
|
FROM processes p
|
|
212
212
|
JOIN process_steps ps ON p.id = ps.process_id
|
|
213
|
-
WHERE ps.node_id = ?`,[e]):this.query(`SELECT * FROM processes`);let n=[];for(let e of t){let t=this.query(`SELECT node_id FROM process_steps WHERE process_id = ? ORDER BY step_order`,[e.id]);n.push({id:e.id,entryNodeId:e.entry_node_id,label:e.label,properties:G(e.properties),steps:t.map(e=>e.node_id),createdAt:e.created_at})}return n}async deleteProcess(e){await this.ensureOpen();let t=this.getAdapter();t.exec(`BEGIN TRANSACTION`);try{this.run(`DELETE FROM process_steps WHERE process_id = ?`,[e]),this.run(`DELETE FROM processes WHERE id = ?`,[e]),t.exec(`COMMIT`),t.flush()}catch(e){throw t.exec(`ROLLBACK`),e}}async depthGroupedTraversal(e,t=3,n){await this.ensureOpen();let r=n?.direction??`both`,i=n?.edgeType,a=n?.limit??100,o={},s=new Set;s.add(e);let c=[e];for(let e=1;e<=t;e++){let t=[],n=[];for(let e of c){let o=await this.getNeighbors(e,{direction:r,edgeType:i,limit:a});for(let e of o.nodes)s.has(e.id)||(s.add(e.id),t.push(e.id),n.push(e))}if(n.length>0&&(o[e]=n),c=t,c.length===0||s.size>=a)break}return o}async getCohesionScore(e){await this.ensureOpen();let t=this.query(`SELECT id FROM nodes WHERE community = ?`,[e]);if(t.length===0)return 0;let n=new Set(t.map(e=>e.id)),r=t.map(()=>`?`).join(`,`),i=t.map(e=>e.id),a=this.query(`SELECT from_id, to_id FROM edges WHERE from_id IN (${r}) OR to_id IN (${r})`,[...i,...i]);if(a.length===0)return 0;let o=0;for(let e of a)n.has(e.from_id)&&n.has(e.to_id)&&o++;return o/a.length}async getSymbol360(e){let t=await this.getNode(e);if(!t)throw Error(`Node '${e}' not found`);let n=await this.findEdges({toId:e}),r=await this.findEdges({fromId:e}),i=await this.getProcesses(e);return{node:t,incoming:n,outgoing:r,community:t.community??null,processes:i}}releaseMemory(){if(this.adapter)try{this.adapter.exec(`PRAGMA shrink_memory`),this.adapter.exec(`PRAGMA wal_checkpoint(TRUNCATE)`)}catch{}}async close(){this.adapter&&=(this.externalAdapter||this.adapter.close(),null)}};function G(e){if(!e)return{};try{return JSON.parse(e)}catch{return{}}}function Ue(e){return{id:e.id,type:e.type,name:e.name,properties:G(e.properties),sourceRecordId:e.source_record_id??void 0,sourcePath:e.source_path??void 0,createdAt:e.created_at,community:e.community??void 0}}function We(e){return{id:e.id,fromId:e.from_id,toId:e.to_id,type:e.type,weight:e.weight??1,confidence:e.confidence??1,properties:G(e.properties)}}function Ge(e){return{id:e.edge_id,fromId:e.from_id,toId:e.to_id,type:e.edge_type,weight:e.weight??1,confidence:e.edge_confidence??1,properties:G(e.edge_props??`{}`)}}function Ke(e){return{id:e.node_id,type:e.node_type,name:e.node_name,properties:G(e.node_props??`{}`),sourceRecordId:e.node_src_rec??void 0,sourcePath:e.node_src_path??void 0,createdAt:e.node_created,community:e.node_community??void 0}}function K(e){let t=0;for(let n=0;n<e.length;n++){let r=e[n]<0?-e[n]:e[n];r>t&&(t=r)}let n=new Int8Array(e.length);if(t===0)return Buffer.from(n.buffer,n.byteOffset,n.byteLength);let r=127/t;for(let t=0;t<e.length;t++){let i=Math.round(e[t]*r);n[t]=i<-127?-127:i>127?127:i}return Buffer.from(n.buffer,n.byteOffset,n.byteLength)}const q=a(`sqlite-vec-store`);function qe(e){if(!e)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}function Je(e){return!e||e.length===0?[]:[...new Set(e.filter(e=>typeof e==`string`&&e.length>0))]}const J=`knowledge_meta`,Y=`embedding_profile`,X=Object.freeze({additionalFilterMultiplier:4,baseOverfetchMultiplier:4,filteredOverfetchMultiplier:8,filteredRetryMultiplier:2,maxCandidateLimit:512,maxExpansionFactor:4,minFilteredCandidateLimit:16,tagFilterMultiplier:4});function Ye(e){return{model:e.model,nativeDim:e.nativeDim,dimensions:e.dimensions,queryPrefix:e.queryPrefix}}function Xe(e){return JSON.stringify(Ye(e))}function Ze(e){return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}var Qe=class{adapter=null;externalAdapter;dbPath;embeddingDim;embeddingProfile;coarseDim;vectorEnabled=!1;ftsEnabled=!1;warnedVectorDisabled=!1;_draining=!1;_priorityQueue=[];_normalQueue=[];_closeWaiter=null;_onCloseHooks=[];constructor(e={}){let t=e.embeddingProfile?.dimensions??e.embeddingDim??n.dimensions;
|
|
213
|
+
WHERE ps.node_id = ?`,[e]):this.query(`SELECT * FROM processes`);let n=[];for(let e of t){let t=this.query(`SELECT node_id FROM process_steps WHERE process_id = ? ORDER BY step_order`,[e.id]);n.push({id:e.id,entryNodeId:e.entry_node_id,label:e.label,properties:G(e.properties),steps:t.map(e=>e.node_id),createdAt:e.created_at})}return n}async deleteProcess(e){await this.ensureOpen();let t=this.getAdapter();t.exec(`BEGIN TRANSACTION`);try{this.run(`DELETE FROM process_steps WHERE process_id = ?`,[e]),this.run(`DELETE FROM processes WHERE id = ?`,[e]),t.exec(`COMMIT`),t.flush()}catch(e){throw t.exec(`ROLLBACK`),e}}async depthGroupedTraversal(e,t=3,n){await this.ensureOpen();let r=n?.direction??`both`,i=n?.edgeType,a=n?.limit??100,o={},s=new Set;s.add(e);let c=[e];for(let e=1;e<=t;e++){let t=[],n=[];for(let e of c){let o=await this.getNeighbors(e,{direction:r,edgeType:i,limit:a});for(let e of o.nodes)s.has(e.id)||(s.add(e.id),t.push(e.id),n.push(e))}if(n.length>0&&(o[e]=n),c=t,c.length===0||s.size>=a)break}return o}async getCohesionScore(e){await this.ensureOpen();let t=this.query(`SELECT id FROM nodes WHERE community = ?`,[e]);if(t.length===0)return 0;let n=new Set(t.map(e=>e.id)),r=t.map(()=>`?`).join(`,`),i=t.map(e=>e.id),a=this.query(`SELECT from_id, to_id FROM edges WHERE from_id IN (${r}) OR to_id IN (${r})`,[...i,...i]);if(a.length===0)return 0;let o=0;for(let e of a)n.has(e.from_id)&&n.has(e.to_id)&&o++;return o/a.length}async getSymbol360(e){let t=await this.getNode(e);if(!t)throw Error(`Node '${e}' not found`);let n=await this.findEdges({toId:e}),r=await this.findEdges({fromId:e}),i=await this.getProcesses(e);return{node:t,incoming:n,outgoing:r,community:t.community??null,processes:i}}releaseMemory(){if(this.adapter)try{this.adapter.exec(`PRAGMA shrink_memory`),this.adapter.exec(`PRAGMA wal_checkpoint(TRUNCATE)`)}catch{}}async close(){this.adapter&&=(this.externalAdapter||this.adapter.close(),null)}};function G(e){if(!e)return{};try{return JSON.parse(e)}catch{return{}}}function Ue(e){return{id:e.id,type:e.type,name:e.name,properties:G(e.properties),sourceRecordId:e.source_record_id??void 0,sourcePath:e.source_path??void 0,createdAt:e.created_at,community:e.community??void 0}}function We(e){return{id:e.id,fromId:e.from_id,toId:e.to_id,type:e.type,weight:e.weight??1,confidence:e.confidence??1,properties:G(e.properties)}}function Ge(e){return{id:e.edge_id,fromId:e.from_id,toId:e.to_id,type:e.edge_type,weight:e.weight??1,confidence:e.edge_confidence??1,properties:G(e.edge_props??`{}`)}}function Ke(e){return{id:e.node_id,type:e.node_type,name:e.node_name,properties:G(e.node_props??`{}`),sourceRecordId:e.node_src_rec??void 0,sourcePath:e.node_src_path??void 0,createdAt:e.node_created,community:e.node_community??void 0}}function K(e){let t=0;for(let n=0;n<e.length;n++){let r=e[n]<0?-e[n]:e[n];r>t&&(t=r)}let n=new Int8Array(e.length);if(t===0)return Buffer.from(n.buffer,n.byteOffset,n.byteLength);let r=127/t;for(let t=0;t<e.length;t++){let i=Math.round(e[t]*r);n[t]=i<-127?-127:i>127?127:i}return Buffer.from(n.buffer,n.byteOffset,n.byteLength)}const q=a(`sqlite-vec-store`);function qe(e){if(!e)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}function Je(e){return!e||e.length===0?[]:[...new Set(e.filter(e=>typeof e==`string`&&e.length>0))]}const J=`knowledge_meta`,Y=`embedding_profile`,X=Object.freeze({additionalFilterMultiplier:4,baseOverfetchMultiplier:4,filteredOverfetchMultiplier:8,filteredRetryMultiplier:2,maxCandidateLimit:512,maxExpansionFactor:4,minFilteredCandidateLimit:16,tagFilterMultiplier:4});function Ye(e){return{model:e.model,nativeDim:e.nativeDim,dimensions:e.dimensions,queryPrefix:e.queryPrefix,pooling:e.pooling,normalize:e.normalize}}function Xe(e){return JSON.stringify(Ye(e))}function Ze(e){return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}var Qe=class{adapter=null;externalAdapter;dbPath;embeddingDim;embeddingProfile;coarseDim;vecTableName;vecTableCoarseName;vectorEnabled=!1;ftsEnabled=!1;warnedVectorDisabled=!1;_draining=!1;_priorityQueue=[];_normalQueue=[];_closeWaiter=null;_onCloseHooks=[];constructor(e={}){let t=e.embeddingProfile?.dimensions??e.embeddingDim??n.dimensions;this.embeddingDim=t,this.embeddingProfile=Ye(e.embeddingProfile??{model:n.model,nativeDim:n.nativeDim,dimensions:t,queryPrefix:n.queryPrefix}),this.coarseDim=Math.min(128,this.embeddingDim);let r=e.profileName?`_${e.profileName}`:``;if(this.vecTableName=`vec_knowledge${r}`,this.vecTableCoarseName=`vec_knowledge${r}_coarse`,e.adapter)this.adapter=e.adapter,this.externalAdapter=!0,this.dbPath=``;else{let t=z(e.path??`${i.path}/aikit.db`,e.partition);this.dbPath=t.contentDbPath,this.externalAdapter=!1}}async initialize(){if(!this.adapter){let e=m(this.dbPath);c(e)||l(e,{recursive:!0}),this.adapter=await I(this.dbPath)}this.configureConnectionPragmas(),this.vectorEnabled=this.adapter.vectorCapable,g(this.adapter,_),this.createKnowledgeTable(),this.createKnowledgeTagsTable(),this.createFtsTable(),this.vectorEnabled?(this.ensureVecTable(),this.backfillCanonicalEmbeddingsIfNeeded()):this.warnedVectorDisabled||(this.warnedVectorDisabled=!0,q.warn(`SqliteVecStore: vector search disabled (sqlite-vec extension not loaded). Hybrid search will return FTS-only results.`))}configureConnectionPragmas(){let e=this.getAdapter();e.pragma(`journal_mode = WAL`),e.pragma(`busy_timeout = 5000`)}getDiagnostics(){let e=this.adapter,t=e?e.constructor.name:`unknown`,n=null,r=this.externalAdapter?``:this.dbPath;if(r)try{let{statSync:e}=ae(`node:fs`);n=e(r).size}catch{n=null}return{adapterType:t,vectorSearchEnabled:this.vectorEnabled,ftsEnabled:this.ftsEnabled,degradedMode:!this.vectorEnabled,dbPath:r,dbSizeBytes:n,embeddingDim:this.embeddingDim,vectorDtype:`int8`,embeddingModel:this.embeddingProfile.model,embeddingProfile:this.embeddingProfile}}createKnowledgeTable(){let e=this.getAdapter();e.exec(`
|
|
214
214
|
CREATE TABLE IF NOT EXISTS knowledge (
|
|
215
215
|
id TEXT PRIMARY KEY,
|
|
216
216
|
content TEXT NOT NULL,
|
|
@@ -248,13 +248,13 @@ import{createRequire as e}from"node:module";import{AIKIT_PATHS as t,EMBEDDING_DE
|
|
|
248
248
|
)
|
|
249
249
|
`)}getStoredEmbeddingProfile(){return this.getAdapter().queryAll(`SELECT value FROM ${J} WHERE key = ? LIMIT 1`,[Y])[0]?.value??null}saveEmbeddingProfile(){this.getAdapter().run(`INSERT INTO ${J} (key, value)
|
|
250
250
|
VALUES (?, ?)
|
|
251
|
-
ON CONFLICT(key) DO UPDATE SET value = excluded.value`,[Y,Xe(this.embeddingProfile)])}dropVectorTables(){let e=this.getAdapter();e.exec(`DROP TABLE IF EXISTS
|
|
252
|
-
CREATE VIRTUAL TABLE IF NOT EXISTS
|
|
251
|
+
ON CONFLICT(key) DO UPDATE SET value = excluded.value`,[Y,Xe(this.embeddingProfile)])}dropVectorTables(){let e=this.getAdapter();e.exec(`DROP TABLE IF EXISTS ${this.vecTableCoarseName}`),e.exec(`DROP TABLE IF EXISTS ${this.vecTableName}`)}ensureVecTable(){let e=this.getAdapter();this.createEmbeddingProfileTable();let t=Xe(this.embeddingProfile),n=this.getStoredEmbeddingProfile(),r=!1;n!==null&&n!==t&&(r=!0,q.warn(`Vec profile mismatch — dropping vector tables for recreation`,{storedProfile:n,activeProfile:t}));let i=e.queryAll(`SELECT name, sql FROM sqlite_master WHERE type='table' AND name='${this.vecTableName}'`);if(!r&&i.length>0){let e=i[0].sql??``,t=e.match(/(?:float|int8)\[(\d+)\]/i),n=t?Number(t[1]):null,a=/int8\[/i.test(e);(n!==null&&n!==this.embeddingDim||!a)&&(r=!0,q.warn(`Vec table schema mismatch — dropping for recreation`,{existingDim:n,newDim:this.embeddingDim,wasInt8:a}))}r&&this.dropVectorTables(),e.exec(`
|
|
252
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS ${this.vecTableName} USING vec0(
|
|
253
253
|
embedding int8[${this.embeddingDim}] distance_metric=cosine,
|
|
254
254
|
+knowledge_id TEXT
|
|
255
255
|
)
|
|
256
256
|
`),this.coarseDim<this.embeddingDim&&e.exec(`
|
|
257
|
-
CREATE VIRTUAL TABLE IF NOT EXISTS
|
|
257
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS ${this.vecTableCoarseName} USING vec0(
|
|
258
258
|
embedding int8[${this.coarseDim}] distance_metric=cosine,
|
|
259
259
|
+knowledge_id TEXT
|
|
260
260
|
)
|
|
@@ -262,10 +262,10 @@ import{createRequire as e}from"node:module";import{AIKIT_PATHS as t,EMBEDDING_DE
|
|
|
262
262
|
(memory_id, embedding_model, embedding_version, dimensions, element_type, embedding, created_at)
|
|
263
263
|
SELECT knowledge_id, 'default', '1', ?, 'float32', embedding, ?
|
|
264
264
|
FROM ${i.name}`,[a,n])}catch(e){q.warn(`backfillCanonicalEmbeddings: failed for vec0 table`,{table:i.name,error:o(e)});continue}let c=e.queryAll(`SELECT COUNT(*) AS cnt FROM memory_embeddings`)[0]?.cnt??0;r+=c-s}if(r>0){q.info(`backfilled canonical embeddings from vec0`,{count:r});try{let t=this.embeddingProfile?.model??`default`,i=this.embeddingProfile?.version??`1`;e.run(`INSERT INTO vector_index_metadata (index_name, generation, embedding_model, embedding_version, dimensions, canonical_count, indexed_count, built_at)
|
|
265
|
-
|
|
265
|
+
VALUES ('${this.vecTableName}', 0, ?, ?, ?, ?, 0, ?)
|
|
266
266
|
ON CONFLICT(index_name) DO UPDATE SET
|
|
267
267
|
canonical_count = excluded.canonical_count,
|
|
268
|
-
generation = excluded.generation`,[t,i,this.embeddingDim,r,n])}catch(e){q.warn(`backfillCanonicalEmbeddings: failed to update vector_index_metadata`,{error:o(e)})}}}enqueueWrite(e,t=!1){return new Promise((n,r)=>{let i=async()=>{try{n(await e())}catch(e){r(e)}};t?this._priorityQueue.push(i):this._normalQueue.push(i),this._drain()})}async _drain(){if(!this._draining){this._draining=!0;try{for(;this._priorityQueue.length>0||this._normalQueue.length>0;){let e=this._priorityQueue.shift()??this._normalQueue.shift();e&&await e()}}finally{if(this._draining=!1,this._closeWaiter){let e=this._closeWaiter;this._closeWaiter=null,e.resolve()}}}}async upsert(e,t){if(e.length!==0){if(e.length!==t.length)throw Error(`Record count (${e.length}) does not match vector count (${t.length})`);for(let n=0;n<t.length;n++)if(t[n].length===0)throw Error(`Zero-length vector at index ${n} for record ${e[n].sourcePath}`);return this.enqueueWrite(()=>this._upsertImpl(e,t))}}async upsertInteractive(e,t){if(e.length!==0){if(e.length!==t.length)throw Error(`Record count (${e.length}) does not match vector count (${t.length})`);for(let n=0;n<t.length;n++)if(t[n].length===0)throw Error(`Zero-length vector at index ${n} for record ${e[n].sourcePath}`);return this.enqueueWrite(()=>this._upsertImpl(e,t),!0)}}async upsertWithoutVector(e,t){return this.enqueueWrite(async()=>{let n=this.getAdapter(),r=e;n.exec(`BEGIN`);try{if(this.upsertKnowledgeRow(r),this.ftsEnabled&&(n.run(`DELETE FROM knowledge_fts WHERE id = ?`,[r.id]),n.run(`INSERT INTO knowledge_fts (id, content) VALUES (?, ?)`,[r.id,r.content])),this.vectorEnabled){let e=n.queryAll(`SELECT embedding FROM
|
|
268
|
+
generation = excluded.generation`,[t,i,this.embeddingDim,r,n])}catch(e){q.warn(`backfillCanonicalEmbeddings: failed to update vector_index_metadata`,{error:o(e)})}}}enqueueWrite(e,t=!1){return new Promise((n,r)=>{let i=async()=>{try{n(await e())}catch(e){r(e)}};t?this._priorityQueue.push(i):this._normalQueue.push(i),this._drain()})}async _drain(){if(!this._draining){this._draining=!0;try{for(;this._priorityQueue.length>0||this._normalQueue.length>0;){let e=this._priorityQueue.shift()??this._normalQueue.shift();e&&await e()}}finally{if(this._draining=!1,this._closeWaiter){let e=this._closeWaiter;this._closeWaiter=null,e.resolve()}}}}async upsert(e,t){if(e.length!==0){if(e.length!==t.length)throw Error(`Record count (${e.length}) does not match vector count (${t.length})`);for(let n=0;n<t.length;n++)if(t[n].length===0)throw Error(`Zero-length vector at index ${n} for record ${e[n].sourcePath}`);return this.enqueueWrite(()=>this._upsertImpl(e,t))}}async upsertInteractive(e,t){if(e.length!==0){if(e.length!==t.length)throw Error(`Record count (${e.length}) does not match vector count (${t.length})`);for(let n=0;n<t.length;n++)if(t[n].length===0)throw Error(`Zero-length vector at index ${n} for record ${e[n].sourcePath}`);return this.enqueueWrite(()=>this._upsertImpl(e,t),!0)}}async upsertWithoutVector(e,t){return this.enqueueWrite(async()=>{let n=this.getAdapter(),r=e;n.exec(`BEGIN`);try{if(this.upsertKnowledgeRow(r),this.ftsEnabled&&(n.run(`DELETE FROM knowledge_fts WHERE id = ?`,[r.id]),n.run(`INSERT INTO knowledge_fts (id, content) VALUES (?, ?)`,[r.id,r.content])),this.vectorEnabled){let e=n.queryAll(`SELECT embedding FROM ${this.vecTableName} WHERE knowledge_id = ?`,[t]);if(e.length>0){if(n.run(`DELETE FROM ${this.vecTableName} WHERE knowledge_id = ?`,[r.id]),n.run(`INSERT INTO ${this.vecTableName} (embedding, knowledge_id) VALUES (vec_int8(?), ?)`,[e[0].embedding,r.id]),this.coarseDim<this.embeddingDim){let e=n.queryAll(`SELECT embedding FROM ${this.vecTableCoarseName} WHERE knowledge_id = ?`,[t]);e.length>0&&(n.run(`DELETE FROM ${this.vecTableCoarseName} WHERE knowledge_id = ?`,[r.id]),n.run(`INSERT INTO ${this.vecTableCoarseName} (embedding, knowledge_id) VALUES (vec_int8(?), ?)`,[e[0].embedding,r.id]))}}else q.warn(`upsertWithoutVector: source vector not found, record will lack vector`,{recordId:r.id,sourceRecordId:t})}n.exec(`COMMIT`)}catch(e){try{n.exec(`ROLLBACK`)}catch{}throw e}n.flush()})}upsertKnowledgeRow(e){this.getAdapter().run(`INSERT INTO knowledge (id, content, sourcePath, contentType, headingPath, chunkIndex,
|
|
269
269
|
totalChunks, startLine, endLine, fileHash, content_hash, indexedAt, origin, tags, category, version)
|
|
270
270
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
271
271
|
ON CONFLICT(id) DO UPDATE SET
|
|
@@ -283,9 +283,9 @@ import{createRequire as e}from"node:module";import{AIKIT_PATHS as t,EMBEDDING_DE
|
|
|
283
283
|
origin = excluded.origin,
|
|
284
284
|
tags = excluded.tags,
|
|
285
285
|
category = excluded.category,
|
|
286
|
-
version = excluded.version`,[e.id,e.content,e.sourcePath,e.contentType,e.headingPath??``,e.chunkIndex,e.totalChunks,e.startLine,e.endLine,e.fileHash,e.contentHash??``,e.indexedAt,e.origin,JSON.stringify(Je(e.tags)),e.category??``,e.version])}replaceKnowledgeTags(e,t){let n=this.getAdapter(),r=Je(t);if(n.run(`DELETE FROM knowledge_tags WHERE knowledge_id = ?`,[e]),r.length===0)return;let i=r.map(()=>`(?, ?)`).join(`, `),a=[];for(let t of r)a.push(e,t);n.run(`INSERT INTO knowledge_tags (knowledge_id, tag) VALUES ${i}`,a)}async _upsertImpl(e,t){let n=this.getAdapter();n.transaction(()=>{for(let r=0;r<e.length;r++){let i=e[r];if(this.upsertKnowledgeRow(i),this.replaceKnowledgeTags(i.id,i.tags),this.ftsEnabled&&(n.run(`DELETE FROM knowledge_fts WHERE id = ?`,[i.id]),n.run(`INSERT INTO knowledge_fts (id, content) VALUES (?, ?)`,[i.id,i.content])),this.vectorEnabled){if(n.run(`DELETE FROM
|
|
286
|
+
version = excluded.version`,[e.id,e.content,e.sourcePath,e.contentType,e.headingPath??``,e.chunkIndex,e.totalChunks,e.startLine,e.endLine,e.fileHash,e.contentHash??``,e.indexedAt,e.origin,JSON.stringify(Je(e.tags)),e.category??``,e.version])}replaceKnowledgeTags(e,t){let n=this.getAdapter(),r=Je(t);if(n.run(`DELETE FROM knowledge_tags WHERE knowledge_id = ?`,[e]),r.length===0)return;let i=r.map(()=>`(?, ?)`).join(`, `),a=[];for(let t of r)a.push(e,t);n.run(`INSERT INTO knowledge_tags (knowledge_id, tag) VALUES ${i}`,a)}async _upsertImpl(e,t){let n=this.getAdapter();n.transaction(()=>{for(let r=0;r<e.length;r++){let i=e[r];if(this.upsertKnowledgeRow(i),this.replaceKnowledgeTags(i.id,i.tags),this.ftsEnabled&&(n.run(`DELETE FROM knowledge_fts WHERE id = ?`,[i.id]),n.run(`INSERT INTO knowledge_fts (id, content) VALUES (?, ?)`,[i.id,i.content])),this.vectorEnabled){if(n.run(`DELETE FROM ${this.vecTableName} WHERE knowledge_id = ?`,[i.id]),n.run(`INSERT INTO ${this.vecTableName} (embedding, knowledge_id) VALUES (vec_int8(?), ?)`,[K(t[r]),i.id]),this.coarseDim<this.embeddingDim){let e=t[r].subarray(0,this.coarseDim);n.run(`DELETE FROM ${this.vecTableCoarseName} WHERE knowledge_id = ?`,[i.id]),n.run(`INSERT INTO ${this.vecTableCoarseName} (embedding, knowledge_id) VALUES (vec_int8(?), ?)`,[K(e),i.id])}let e=Ze(t[r]);n.run(`INSERT OR REPLACE INTO memory_embeddings
|
|
287
287
|
(memory_id, embedding_model, embedding_version, dimensions, element_type, embedding, created_at)
|
|
288
|
-
VALUES (?, ?, ?, ?, ?, ?, ?)`,[i.id,this.embeddingProfile?.model??`default`,this.embeddingProfile?.version??`1`,t[r].length,`float32`,e,Date.now()])}}}),n.flush()}async search(e,t){if(e.length===0)return[];if(!this.vectorEnabled)return this.warnedVectorDisabled||(this.warnedVectorDisabled=!0,q.warn(`search() called but vector backend is disabled — returning []`)),[];let n=t?.limit??r.maxResults,i=t?.minScore??r.minScore,a;try{a=this.runAdaptiveVectorSearch(
|
|
288
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)`,[i.id,this.embeddingProfile?.model??`default`,this.embeddingProfile?.version??`1`,t[r].length,`float32`,e,Date.now()])}}}),n.flush()}async search(e,t){if(e.length===0)return[];if(!this.vectorEnabled)return this.warnedVectorDisabled||(this.warnedVectorDisabled=!0,q.warn(`search() called but vector backend is disabled — returning []`)),[];let n=t?.limit??r.maxResults,i=t?.minScore??r.minScore,a;try{a=this.runAdaptiveVectorSearch(this.vecTableName,K(e),t)}catch(e){return q.warn(`vector search failed`,o(e)),[]}return this.rowsToSearchResults(a,i,n)}async coarseSearch(e,t){if(!this.vectorEnabled||this.coarseDim>=this.embeddingDim)return this.search(e,t);let n=t?.limit??r.maxResults,i=t?.minScore??r.minScore,a=e.subarray(0,this.coarseDim),s;try{s=this.runAdaptiveVectorSearch(this.vecTableCoarseName,K(a),t)}catch(n){return q.warn(`coarse vector search failed, falling back to full search`,o(n)),this.search(e,t)}return s.length===0?this.search(e,t):this.rowsToSearchResults(s,i,n)}async ftsSearch(e,t){if(!e||e.trim().length===0||!this.ftsEnabled)return[];let n=this.getAdapter(),i=t?.limit??r.maxResults,a=this.buildFilterSqlSuffix(t,!0),s=`
|
|
289
289
|
SELECT k.*, bm25(knowledge_fts) AS _bm25
|
|
290
290
|
FROM knowledge_fts
|
|
291
291
|
JOIN knowledge k ON k.id = knowledge_fts.id
|
|
@@ -293,7 +293,7 @@ import{createRequire as e}from"node:module";import{AIKIT_PATHS as t,EMBEDDING_DE
|
|
|
293
293
|
${a.sql}
|
|
294
294
|
ORDER BY _bm25 ASC
|
|
295
295
|
LIMIT ?
|
|
296
|
-
`,c;try{let t=$e(e);c=n.queryAll(s,[t,...a.params,i])}catch(e){return q.warn(`fts search failed`,o(e)),[]}return c.map(e=>({record:this.fromRow(e),score:et(e._bm25)}))}async getById(e){let t=this.getAdapter().queryAll(`SELECT * FROM knowledge WHERE id = ? LIMIT 1`,[e]);return t.length===0?null:this.fromRow(t[0])}async deleteBySourcePath(e){return this.enqueueWrite(()=>this._deleteBySourcePathImpl(e))}async _deleteBySourcePathImpl(e){let t=this.getAdapter(),n=t.queryAll(`SELECT id FROM knowledge WHERE sourcePath = ?`,[e]);if(n.length===0)return 0;t.exec(`BEGIN`);try{for(let{id:e}of n)this.vectorEnabled&&(t.run(`DELETE FROM
|
|
296
|
+
`,c;try{let t=$e(e);c=n.queryAll(s,[t,...a.params,i])}catch(e){return q.warn(`fts search failed`,o(e)),[]}return c.map(e=>({record:this.fromRow(e),score:et(e._bm25)}))}async getById(e){let t=this.getAdapter().queryAll(`SELECT * FROM knowledge WHERE id = ? LIMIT 1`,[e]);return t.length===0?null:this.fromRow(t[0])}async deleteBySourcePath(e){return this.enqueueWrite(()=>this._deleteBySourcePathImpl(e))}async _deleteBySourcePathImpl(e){let t=this.getAdapter(),n=t.queryAll(`SELECT id FROM knowledge WHERE sourcePath = ?`,[e]);if(n.length===0)return 0;t.exec(`BEGIN`);try{for(let{id:e}of n)this.vectorEnabled&&(t.run(`DELETE FROM ${this.vecTableName} WHERE knowledge_id = ?`,[e]),this.coarseDim<this.embeddingDim&&t.run(`DELETE FROM ${this.vecTableCoarseName} WHERE knowledge_id = ?`,[e])),t.run(`DELETE FROM memory_embeddings WHERE memory_id = ?`,[e]),t.run(`DELETE FROM knowledge_tags WHERE knowledge_id = ?`,[e]),this.ftsEnabled&&t.run(`DELETE FROM knowledge_fts WHERE id = ?`,[e]);t.run(`DELETE FROM knowledge WHERE sourcePath = ?`,[e]),t.exec(`COMMIT`)}catch(e){try{t.exec(`ROLLBACK`)}catch{}throw e}return t.flush(),n.length}async deleteById(e){return this.enqueueWrite(()=>this._deleteByIdImpl(e))}async deleteByIdInteractive(e){return this.enqueueWrite(()=>this._deleteByIdImpl(e),!0)}async _deleteByIdImpl(e){let t=this.getAdapter();if(t.queryAll(`SELECT id FROM knowledge WHERE id = ? LIMIT 1`,[e]).length===0)return!1;t.exec(`BEGIN`);try{this.vectorEnabled&&(t.run(`DELETE FROM ${this.vecTableName} WHERE knowledge_id = ?`,[e]),this.coarseDim<this.embeddingDim&&t.run(`DELETE FROM ${this.vecTableCoarseName} WHERE knowledge_id = ?`,[e])),t.run(`DELETE FROM memory_embeddings WHERE memory_id = ?`,[e]),t.run(`DELETE FROM knowledge_tags WHERE knowledge_id = ?`,[e]),this.ftsEnabled&&t.run(`DELETE FROM knowledge_fts WHERE id = ?`,[e]),t.run(`DELETE FROM knowledge WHERE id = ?`,[e]),t.exec(`COMMIT`)}catch(e){try{t.exec(`ROLLBACK`)}catch{}throw e}return t.flush(),!0}async getBySourcePath(e){return this.getAdapter().queryAll(`SELECT * FROM knowledge WHERE sourcePath = ? ORDER BY chunkIndex ASC`,[e]).map(e=>this.fromRow(e))}async getStats(){let e=this.getAdapter(),t=e.queryAll(`SELECT COUNT(*) AS n FROM knowledge`)[0]?.n??0;if(t===0)return{totalRecords:0,totalFiles:0,contentTypeBreakdown:{},lastIndexedAt:null,storeBackend:`sqlite-vec`,embeddingModel:this.embeddingProfile.model};let n=e.queryAll(`SELECT COUNT(DISTINCT sourcePath) AS n FROM knowledge`),r=e.queryAll(`SELECT contentType, COUNT(*) AS n FROM knowledge GROUP BY contentType`),i=e.queryAll(`SELECT MAX(indexedAt) AS ts FROM knowledge`),a={};for(let e of r)a[e.contentType]=e.n;return{totalRecords:t,totalFiles:n[0]?.n??0,contentTypeBreakdown:a,lastIndexedAt:i[0]?.ts??null,storeBackend:`sqlite-vec`,embeddingModel:this.embeddingProfile.model}}async listSourcePaths(){return this.getAdapter().queryAll(`SELECT DISTINCT sourcePath FROM knowledge ORDER BY sourcePath`).map(e=>e.sourcePath)}async createFtsIndex(){this.createFtsTable()}async dropTable(){return this.enqueueWrite(()=>this._dropTableImpl())}async _dropTableImpl(){let e=this.getAdapter();this.ftsEnabled&&e.exec(`DROP TABLE IF EXISTS knowledge_fts`),this.vectorEnabled&&this.dropVectorTables(),e.exec(`DROP TABLE IF EXISTS ${J}`),e.exec(`DROP TABLE IF EXISTS knowledge_tags`),e.exec(`DROP TABLE IF EXISTS knowledge`),e.flush(),this.createKnowledgeTable(),this.createKnowledgeTagsTable(),this.createFtsTable(),this.vectorEnabled&&this.ensureVecTable()}releaseMemory(){if(this.adapter)try{this.adapter.exec(`PRAGMA shrink_memory`),this.adapter.exec(`PRAGMA wal_checkpoint(TRUNCATE)`)}catch{}}onBeforeClose(e){this._onCloseHooks.push(e)}async close(e=5e3){for(let e of this._onCloseHooks)try{e()}catch{}this._onCloseHooks.length=0,(this._priorityQueue.length>0||this._normalQueue.length>0||this._draining)&&(this._drain(),await new Promise(t=>{let n=setTimeout(()=>{q.warn(`SqliteVecStore.close() timed out waiting for queue drain — force closing`),t(!0)},e);this._closeWaiter={resolve:()=>{clearTimeout(n),t(!1)},reject:()=>{clearTimeout(n),t(!1)}}})&&(this._priorityQueue.length=0,this._normalQueue.length=0)),this.adapter&&!this.externalAdapter&&this.adapter.close(),this.adapter=null}getAdapter(){if(!this.adapter)throw Error(`SqliteVecStore: not initialized — call initialize() first`);return this.adapter}runAdaptiveVectorSearch(e,t,n){let i=n?.limit??r.maxResults;if(i<=0)return[];let a=this.buildFilterSqlSuffix(n),o=this.buildVectorSearchPlan(i,a.profile),s=o.initialCandidateLimit,c=this.queryVectorRows(e,t,a,s,i);for(;o.hasFilters&&c.length<i&&s<o.maxCandidateLimit;)s=Math.min(o.maxCandidateLimit,Math.max(s+i,s*X.filteredRetryMultiplier)),c=this.queryVectorRows(e,t,a,s,i);return c}queryVectorRows(e,t,n,r,i){let a=this.getAdapter(),o=`
|
|
297
297
|
SELECT k.*, v.distance AS _distance
|
|
298
298
|
FROM (
|
|
299
299
|
SELECT knowledge_id, distance
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e,t}from"./supersession-CWEne3av.js";import{existsSync as n,mkdirSync as r,readFileSync as i,writeFileSync as a}from"node:fs";import{dirname as o,isAbsolute as s,relative as c,resolve as l}from"node:path";import{fileURLToPath as u}from"node:url";import{AIKIT_RUNTIME_PATHS as d,EMBEDDING_DEFAULTS as f,computePartitionKey as p,createLogger as m,getPartitionDir as h,migrateLegacyWorkspaceLayout as g,serializeError as _}from"../../core/dist/index.js";const v={workingToEpisodicAccesses:2,episodicToSemanticReferences:3,semanticToProceduralVerifications:5},y={working:1,episodic:2,semantic:4,procedural:12};function b(e,t=v){switch(e.tier){case`working`:if(e.accessCount>=t.workingToEpisodicAccesses)return`episodic`;break;case`episodic`:if(e.accessCount>=t.workingToEpisodicAccesses+t.episodicToSemanticReferences)return`semantic`;break;case`semantic`:if(e.accessCount>=t.workingToEpisodicAccesses+t.episodicToSemanticReferences+t.semanticToProceduralVerifications)return`procedural`;break;case`procedural`:break;default:break}}function x(e,t,n){e.memoryMetaUpdateTier(t,n)}const S={stabilityHours:168,accessMultiplier:1.5,flagThreshold:.1,maxStabilityHours:8760};function C(e){return{...S,...e}}function w(e,t){if(!e)return t;let n=Date.parse(e);return Number.isNaN(n)?t:n}function T(e){return e&&e in y?e:`working`}function E(e,t,n,r=S,i){let a=typeof r==`string`?T(r):`working`,o=C(typeof r==`string`?i:r),s=w(e,w(n,Date.now())),c=Math.max(0,Date.now()-s)/(1e3*60*60),l=Math.min(o.stabilityHours*y[a]*o.accessMultiplier**Math.max(0,t),o.maxStabilityHours);return Math.exp(-c/l)}function D(e,t,n){let r=e.memoryMetaGet(t);if(!r)return;let i=E(r.lastAccessedAt,r.accessCount,r.createdAt,r.tier,n);return r.retentionScore!==i&&e.memoryMetaUpdateScore(t,i),e.memoryMetaGet(t)??{...r,retentionScore:i}}function O(e,t,n){e.memoryMetaGet(t)||e.memoryMetaCreate(t),e.memoryMetaTouch(t);let r=e.memoryMetaGet(t);if(!r)return 1;let i=E(r.lastAccessedAt,r.accessCount,r.createdAt,r.tier,n);return e.memoryMetaUpdateScore(t,i),i}function k(e,t){let n=C(t);return e.memoryMetaList().map(t=>D(e,t.entryId,n)??t).filter(e=>e.retentionScore<n.flagThreshold).sort((e,t)=>e.retentionScore-t.retentionScore)}const A=o(u(import.meta.url)),j=m(`server`),M=[`auto`,`manual`,`smart`],N={model:f.model,nativeDim:f.nativeDim,dimensions:f.dimensions,queryPrefix:f.queryPrefix,childProcess:!0,idleTimeoutMs:6e4};function P(e){return typeof e==`string`&&M.includes(e)}function F(e,t,n){let r=l(e),i=c(l(t),r);if(i.startsWith(`..`)||s(i))throw Error(`Config ${n} path escapes allowed root: ${e} is not under ${t}`);return r}function I(e,t){let n=l(e),r=c(l(t),n);return!(r.startsWith(`..`)||s(r))}function L(e){return h(p(e))}function R(e,t,n,r,i){let a=r?l(t,r):t;if(!n)return F(a,t,i);let o=l(e,n);return I(o,t)?r&&l(o)===l(t)?F(a,t,i):F(o,t,i):F(a,t,i)}function z(e){let t=[e.store?.path,e.curated?.path,e.onboardDir,e.stateDir];for(let e of t)e&&r(e,{recursive:!0})}function B(e,t){g(t);let n=L(t);e.store={...e.store,path:R(t,n,e.store?.path,d.data,`store`)},e.curated={...e.curated,path:R(t,n,e.curated?.path,d.curated,`curated`)},e.onboardDir=R(t,n,e.onboardDir,d.onboard,`onboard`),e.stateDir=R(t,n,e.stateDir,d.state,`state`)}function V(e){let t=process.env.AIKIT_INDEX_MODE;if(P(t))return t;if(e.indexMode)return e.indexMode;let n=process.env.AIKIT_AUTO_INDEX;return n===void 0?e.autoIndex===void 0?`smart`:e.autoIndex?`auto`:`manual`:n===`true`?`auto`:`manual`}function H(){let r=process.env.AIKIT_CONFIG_PATH??(n(l(process.cwd(),`aikit.config.json`))?l(process.cwd(),`aikit.config.json`):l(A,`..`,`..`,`..`,`aikit.config.json`));try{if(!n(r))return j.info(`No config file found, using defaults`,{configPath:r}),W();let a=i(r,`utf-8`),s=JSON.parse(a),c={...N,...s.embedding};if(s.embedding=c,s.memory={retention:{...S,...s.memory?.retention},lessons:{...e,...s.memory?.lessons},consolidation:{...v,...s.memory?.consolidation},supersession:{...t,...s.memory?.supersession}},s.logging?.errorDetails!==void 0&&typeof s.logging.errorDetails!=`boolean`)throw Error(`Config logging.errorDetails must be a boolean`);if(s.logging={errorDetails:s.logging?.errorDetails===!0},!s.sources||!Array.isArray(s.sources)||s.sources.length===0)throw Error(`Config must have at least one source`);if(!s.store?.path)throw Error(`Config must specify store.path`);if(s.autoIndex!==void 0&&typeof s.autoIndex!=`boolean`)throw Error(`Config autoIndex must be a boolean`);if(s.indexMode!==void 0&&!P(s.indexMode))throw Error(`Config indexMode must be one of: ${M.join(`, `)}`);if(typeof c.model!=`string`||c.model.trim()===``)throw Error(`Config embedding.model must be a non-empty string`);if(!Number.isInteger(c.nativeDim)||c.nativeDim<=0)throw Error(`Config embedding.nativeDim must be a positive integer`);if(!Number.isInteger(c.dimensions)||c.dimensions<=0)throw Error(`Config embedding.dimensions must be a positive integer`);if(c.dimensions>c.nativeDim)throw Error(`Config embedding.dimensions must not exceed embedding.nativeDim`);if(typeof c.queryPrefix!=`string`)throw Error(`Config embedding.queryPrefix must be a string`);let u=o(r);return s.sources=s.sources.map(e=>({...e,path:F(l(u,e.path),u,`source`)})),G(s,r),B(s,u),s.indexMode=V(s),s}catch(e){let t=`Failed to load config from ${r}. ${e instanceof Error?e.message:String(e)}`;console.error(`\n ⚠ CONFIG ERROR — ${t}\n Check that the file exists, is valid JSON, and all required fields are present.\n`),j.error(`Failed to load config`,{configPath:r,..._(e)}),j.warn(`Falling back to default configuration`,{configPath:r});let n=W();return n.configError=t,n}}const U=[`.git/**`,`**/node_modules/**`,`*.lock`,`pnpm-lock.yaml`,`package-lock.json`,`**/dist/**`,`**/build/**`,`**/out/**`,`**/.output/**`,`**/cdk.out/**`,`**/.next/**`,`**/.nuxt/**`,`**/.vercel/**`,`**/.serverless/**`,`**/.turbo/**`,`**/.cache/**`,`**/.parcel-cache/**`,`**/coverage/**`,`**/.terraform/**`,`**/__pycache__/**`,`**/.venv/**`,`**/.docusaurus/**`,`**/.temp/**`,`**/tmp/**`];function W(){let n=process.env.AIKIT_WORKSPACE_ROOT??process.cwd(),r=L(n),i={sources:[{path:n,excludePatterns:[...U]}],serverName:`aikit`,indexing:{chunkSize:1500,chunkOverlap:200,minChunkSize:100},embedding:{...N},store:{backend:`sqlite-vec`,path:l(r,d.data)},curated:{path:l(r,d.curated)},memory:{retention:{...S},lessons:{...e},consolidation:{...v},supersession:{...t}},logging:{errorDetails:!1},onboardDir:l(r,d.onboard),stateDir:l(r,d.state)};return i.indexMode=V(i),i}function G(e,t){let n=e.configVersion??0;if(n>=1)return e;if(n<1)for(let t of e.sources){t.excludePatterns=t.excludePatterns??[];let e=new Set(t.excludePatterns);for(let n of U)e.has(n)||t.excludePatterns.push(n)}e.configVersion=1;try{a(t,`${JSON.stringify(e,null,2)}\n`,`utf-8`),j.info(`Config auto-upgraded`,{from:n,to:1,configPath:t})}catch(e){j.warn(`Failed to write upgraded config`,{configPath:t,..._(e)})}return e}function K(e,t){if(!n(t))throw Error(`Workspace root does not exist: ${t}`);g(t),j.debug(`Reconfiguring for workspace root`,{workspaceRoot:t});try{process.chdir(t),j.debug(`Changed process cwd to workspace root`,{cwd:process.cwd()})}catch(e){j.warn(`Failed to chdir to workspace root`,{workspaceRoot:t,..._(e)})}e.sources=[{path:t,excludePatterns:e.sources[0]?.excludePatterns??[`node_modules/**`,`dist/**`,`.git/**`,`coverage/**`,`*.lock`,`pnpm-lock.yaml`]}],B(e,t),z(e)}export{U as DEFAULT_EXCLUDE_PATTERNS,b as a,v as i,H as loadConfig,D as n,x as o,O as r,K as reconfigureForWorkspace,V as resolveIndexMode,k as t};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import{o as e,t}from"./supersession-DO_ZROFl.js";import{existsSync as n,mkdirSync as r,readFileSync as i,writeFileSync as a}from"node:fs";import{dirname as o,isAbsolute as s,relative as c,resolve as l}from"node:path";import{fileURLToPath as u}from"node:url";import{AIKIT_RUNTIME_PATHS as d,EMBEDDING_DEFAULTS as f,computePartitionKey as p,createLogger as m,getPartitionDir as h,migrateLegacyWorkspaceLayout as g,serializeError as _}from"../../core/dist/index.js";const v={workingToEpisodicAccesses:2,episodicToSemanticReferences:3,semanticToProceduralVerifications:5},y={working:1,episodic:2,semantic:4,procedural:12};function b(e,t=v){switch(e.tier){case`working`:if(e.accessCount>=t.workingToEpisodicAccesses)return`episodic`;break;case`episodic`:if(e.accessCount>=t.workingToEpisodicAccesses+t.episodicToSemanticReferences)return`semantic`;break;case`semantic`:if(e.accessCount>=t.workingToEpisodicAccesses+t.episodicToSemanticReferences+t.semanticToProceduralVerifications)return`procedural`;break;case`procedural`:break;default:break}}function x(e,t,n){e.memoryMetaUpdateTier(t,n)}const S={stabilityHours:168,accessMultiplier:1.5,flagThreshold:.1,maxStabilityHours:8760};function C(e){return{...S,...e}}function w(e,t){if(!e)return t;let n=Date.parse(e);return Number.isNaN(n)?t:n}function T(e){return e&&e in y?e:`working`}function E(e,t,n,r=S,i){let a=typeof r==`string`?T(r):`working`,o=C(typeof r==`string`?i:r),s=w(e,w(n,Date.now())),c=Math.max(0,Date.now()-s)/(1e3*60*60),l=Math.min(o.stabilityHours*y[a]*o.accessMultiplier**Math.max(0,t),o.maxStabilityHours);return Math.exp(-c/l)}function D(e,t,n){let r=e.memoryMetaGet(t);if(!r)return;let i=E(r.lastAccessedAt,r.accessCount,r.createdAt,r.tier,n);return r.retentionScore!==i&&e.memoryMetaUpdateScore(t,i),e.memoryMetaGet(t)??{...r,retentionScore:i}}function O(e,t,n){e.memoryMetaGet(t)||e.memoryMetaCreate(t),e.memoryMetaTouch(t);let r=e.memoryMetaGet(t);if(!r)return 1;let i=E(r.lastAccessedAt,r.accessCount,r.createdAt,r.tier,n);return e.memoryMetaUpdateScore(t,i),i}function k(e,t){let n=C(t);return e.memoryMetaList().map(t=>D(e,t.entryId,n)??t).filter(e=>e.retentionScore<n.flagThreshold).sort((e,t)=>e.retentionScore-t.retentionScore)}const A=o(u(import.meta.url)),j=m(`server`),M=[`auto`,`manual`,`smart`],N={model:f.model,nativeDim:f.nativeDim,dimensions:f.dimensions,queryPrefix:f.queryPrefix,childProcess:!0,idleTimeoutMs:6e4};function P(e){return typeof e==`string`&&M.includes(e)}function F(e,t,n){let r=l(e),i=c(l(t),r);if(i.startsWith(`..`)||s(i))throw Error(`Config ${n} path escapes allowed root: ${e} is not under ${t}`);return r}function I(e,t){let n=l(e),r=c(l(t),n);return!(r.startsWith(`..`)||s(r))}function L(e){return h(p(e))}function R(e,t,n,r,i){let a=r?l(t,r):t;if(!n)return F(a,t,i);let o=l(e,n);return I(o,t)?r&&l(o)===l(t)?F(a,t,i):F(o,t,i):F(a,t,i)}function z(e){let t=[e.store?.path,e.curated?.path,e.onboardDir,e.stateDir];for(let e of t)e&&r(e,{recursive:!0})}function B(e,t){g(t);let n=L(t);e.store={...e.store,path:R(t,n,e.store?.path,d.data,`store`)},e.curated={...e.curated,path:R(t,n,e.curated?.path,d.curated,`curated`)},e.onboardDir=R(t,n,e.onboardDir,d.onboard,`onboard`),e.stateDir=R(t,n,e.stateDir,d.state,`state`)}function V(e){let t=process.env.AIKIT_INDEX_MODE;if(P(t))return t;if(e.indexMode)return e.indexMode;let n=process.env.AIKIT_AUTO_INDEX;return n===void 0?e.autoIndex===void 0?`smart`:e.autoIndex?`auto`:`manual`:n===`true`?`auto`:`manual`}function H(){let r=process.env.AIKIT_CONFIG_PATH??(n(l(process.cwd(),`aikit.config.json`))?l(process.cwd(),`aikit.config.json`):l(A,`..`,`..`,`..`,`aikit.config.json`));try{if(!n(r))return j.info(`No config file found, using defaults`,{configPath:r}),W();let a=i(r,`utf-8`),s=JSON.parse(a),c={...N,...s.embedding};if(s.embedding=c,s.memory={retention:{...S,...s.memory?.retention},lessons:{...e,...s.memory?.lessons},consolidation:{...v,...s.memory?.consolidation},supersession:{...t,...s.memory?.supersession}},s.logging?.errorDetails!==void 0&&typeof s.logging.errorDetails!=`boolean`)throw Error(`Config logging.errorDetails must be a boolean`);if(s.logging={errorDetails:s.logging?.errorDetails===!0},!s.sources||!Array.isArray(s.sources)||s.sources.length===0)throw Error(`Config must have at least one source`);if(!s.store?.path)throw Error(`Config must specify store.path`);if(s.autoIndex!==void 0&&typeof s.autoIndex!=`boolean`)throw Error(`Config autoIndex must be a boolean`);if(s.indexMode!==void 0&&!P(s.indexMode))throw Error(`Config indexMode must be one of: ${M.join(`, `)}`);if(typeof c.model!=`string`||c.model.trim()===``)throw Error(`Config embedding.model must be a non-empty string`);if(!Number.isInteger(c.nativeDim)||c.nativeDim<=0)throw Error(`Config embedding.nativeDim must be a positive integer`);if(!Number.isInteger(c.dimensions)||c.dimensions<=0)throw Error(`Config embedding.dimensions must be a positive integer`);if(c.dimensions>c.nativeDim)throw Error(`Config embedding.dimensions must not exceed embedding.nativeDim`);if(typeof c.queryPrefix!=`string`)throw Error(`Config embedding.queryPrefix must be a string`);let u=o(r);return s.sources=s.sources.map(e=>({...e,path:F(l(u,e.path),u,`source`)})),G(s,r),B(s,u),s.indexMode=V(s),s}catch(e){let t=`Failed to load config from ${r}. ${e instanceof Error?e.message:String(e)}`;console.error(`\n ⚠ CONFIG ERROR — ${t}\n Check that the file exists, is valid JSON, and all required fields are present.\n`),j.error(`Failed to load config`,{configPath:r,..._(e)}),j.warn(`Falling back to default configuration`,{configPath:r});let n=W();return n.configError=t,n}}const U=[`.git/**`,`**/node_modules/**`,`*.lock`,`pnpm-lock.yaml`,`package-lock.json`,`**/dist/**`,`**/build/**`,`**/out/**`,`**/.output/**`,`**/cdk.out/**`,`**/.next/**`,`**/.nuxt/**`,`**/.vercel/**`,`**/.serverless/**`,`**/.turbo/**`,`**/.cache/**`,`**/.parcel-cache/**`,`**/coverage/**`,`**/.terraform/**`,`**/__pycache__/**`,`**/.venv/**`,`**/.docusaurus/**`,`**/.temp/**`,`**/tmp/**`];function W(){let n=process.env.AIKIT_WORKSPACE_ROOT??process.cwd(),r=L(n),i={sources:[{path:n,excludePatterns:[...U]}],serverName:`aikit`,indexing:{chunkSize:1500,chunkOverlap:200,minChunkSize:100},embedding:{...N},store:{backend:`sqlite-vec`,path:l(r,d.data)},curated:{path:l(r,d.curated)},memory:{retention:{...S},lessons:{...e},consolidation:{...v},supersession:{...t}},logging:{errorDetails:!1},onboardDir:l(r,d.onboard),stateDir:l(r,d.state)};return i.indexMode=V(i),i}function G(e,t){let n=e.configVersion??0;if(n>=1)return e;if(n<1)for(let t of e.sources){t.excludePatterns=t.excludePatterns??[];let e=new Set(t.excludePatterns);for(let n of U)e.has(n)||t.excludePatterns.push(n)}e.configVersion=1;try{a(t,`${JSON.stringify(e,null,2)}\n`,`utf-8`),j.info(`Config auto-upgraded`,{from:n,to:1,configPath:t})}catch(e){j.warn(`Failed to write upgraded config`,{configPath:t,..._(e)})}return e}function K(e,t){if(!n(t))throw Error(`Workspace root does not exist: ${t}`);g(t),j.debug(`Reconfiguring for workspace root`,{workspaceRoot:t});try{process.chdir(t),j.debug(`Changed process cwd to workspace root`,{cwd:process.cwd()})}catch(e){j.warn(`Failed to chdir to workspace root`,{workspaceRoot:t,..._(e)})}e.sources=[{path:t,excludePatterns:e.sources[0]?.excludePatterns??[`node_modules/**`,`dist/**`,`.git/**`,`coverage/**`,`*.lock`,`pnpm-lock.yaml`]}],B(e,t),z(e)}export{U as DEFAULT_EXCLUDE_PATTERNS,b as a,v as i,H as loadConfig,D as n,x as o,O as r,K as reconfigureForWorkspace,V as resolveIndexMode,k as t};
|