@vpxa/aikit 0.1.238 → 0.1.240

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.
@@ -13,7 +13,7 @@
13
13
  color: #c9d1d9;
14
14
  }
15
15
  </style>
16
- <script type="module" crossorigin src="/settings/assets/index-DLcLvASh.js"></script>
16
+ <script type="module" crossorigin src="/settings/assets/index-BSvuHWLA.js"></script>
17
17
  <link rel="stylesheet" crossorigin href="/settings/assets/index-cNrL0PXt.css">
18
18
  </head>
19
19
  <body>
@@ -79,7 +79,7 @@ import{createRequire as e}from"node:module";import{existsSync as t,mkdirSync as
79
79
  FROM leases_legacy;
80
80
 
81
81
  DROP TABLE leases_legacy;
82
- `)}}],b=h(`sqlite-adapter`),x=e(import.meta.url);var S=class{type=`better-sqlite3`;vectorCapable=!1;db=null;stmtCache=new Map;dbPath=``;DatabaseCtor=null;recovering=!1;async open(e){let t;try{t=x(`better-sqlite3`)}catch(e){throw Error(`better-sqlite3 native binding unavailable: ${e instanceof Error?e.message:String(e)}`)}this.db=new t(e),this.dbPath=e,this.DatabaseCtor=t,this.db.pragma(`journal_mode = WAL`),this.db.pragma(`foreign_keys = ON`),this.db.pragma(`synchronous = NORMAL`),this.runIntegrityCheck(e,t)||(this.db?.pragma(`journal_mode = WAL`),this.db?.pragma(`foreign_keys = ON`),this.db?.pragma(`synchronous = NORMAL`));try{x(`sqlite-vec`).load(this.db),this.vectorCapable=!0,b.info(`sqlite-vec extension loaded`)}catch(e){this.vectorCapable=!1,b.warn(`sqlite-vec extension failed to load; vector search disabled`,g(e))}}exec(e){try{this.getDb().exec(e)}catch(t){if(this.isCorruptionError(t)){this.recover(),this.getDb().exec(e);return}throw t}}pragma(e){this.getDb().pragma(e)}queryAll(e,t=[]){try{let n=this.prepareCached(e);return t.length>0?n.all(...t):n.all()}catch(n){if(this.isCorruptionError(n))return this.recover(),this.queryAll(e,t);throw n}}run(e,t=[]){try{let n=this.prepareCached(e);t.length>0?n.run(...t):n.run()}catch(n){if(this.isCorruptionError(n)){this.recover(),this.run(e,t);return}throw n}}flush(){}close(){this.db&&=(this.stmtCache.clear(),this.db.close(),null)}runIntegrityCheck(e,t){try{let t=this.db?.pragma(`integrity_check`);if(t.length===1&&t[0]?.integrity_check===`ok`)return!0;let n=t.map(e=>e.integrity_check).slice(0,5).join(`; `);b.warn(`Database integrity check failed — recreating`,{dbPath:e,issues:n})}catch(t){b.warn(`Integrity check query failed — recreating database`,{dbPath:e,error:g(t)})}try{this.db?.close()}catch{}this.db=null,this.stmtCache.clear();try{a(e)}catch{}try{a(`${e}-wal`)}catch{}try{a(`${e}-shm`)}catch{}return this.db=new t(e),b.info(`Database recreated successfully — full reindex required`,{dbPath:e}),!1}isCorruptionError(e){if(this.recovering)return!1;let t=e instanceof Error?e.message:String(e);return/database disk image is malformed|file is not a database|database or disk is full/.test(t)}recover(){if(this.recovering)throw Error(`BetterSqlite3Adapter: recovery already in progress`);this.recovering=!0;try{b.warn(`Runtime corruption detected — recovering database`,{dbPath:this.dbPath});try{this.db?.close()}catch{}this.db=null,this.stmtCache.clear();try{a(this.dbPath)}catch{}try{a(`${this.dbPath}-wal`)}catch{}try{a(`${this.dbPath}-shm`)}catch{}if(!this.DatabaseCtor)throw Error(`DatabaseCtor is not initialized`);this.db=this.DatabaseCtor(this.dbPath),this.db.pragma(`journal_mode = WAL`),this.db.pragma(`foreign_keys = ON`),this.db.pragma(`synchronous = NORMAL`);try{x(`sqlite-vec`).load(this.db),this.vectorCapable=!0}catch{this.vectorCapable=!1}b.info(`Database recovered — full reindex required`,{dbPath:this.dbPath})}finally{this.recovering=!1}}getDb(){if(!this.db)throw Error(`BetterSqlite3Adapter: database not opened`);return this.db}prepareCached(e){let t=this.stmtCache.get(e);if(t)return t;let n=this.getDb().prepare(e);return this.stmtCache.set(e,n),n}};function ne(e){return x.resolve(`sql.js/dist/${e}`)}function re(e){return e.match(/^\s*(?:INSERT(?:\s+OR\s+\w+)?\s+INTO|UPDATE)\s+([A-Za-z_][A-Za-z0-9_]*)/i)?.[1]??null}var C=class{type=`sql.js`;vectorCapable=!1;db=null;dbPath=``;dirty=!1;inTransaction=!1;foreignKeysEnabled=!1;async open(e){this.dbPath=e;let n=(await import(`sql.js`)).default,i=await n({locateFile:e=>ne(e)});if(t(e)){let t=r(e);this.db=new i.Database(t)}else this.db=new i.Database}exec(e){let t=e.trimStart().toUpperCase();this.getDb().run(e),t.startsWith(`BEGIN`)?this.inTransaction=!0:(t.startsWith(`COMMIT`)||t.startsWith(`ROLLBACK`))&&(this.inTransaction=!1),this.dirty=!0}pragma(e){let t=e.trim().toLowerCase();t===`foreign_keys = on`||t===`foreign_keys=on`?this.foreignKeysEnabled=!0:(t===`foreign_keys = off`||t===`foreign_keys=off`)&&(this.foreignKeysEnabled=!1),this.getDb().exec(`PRAGMA ${e}`)}queryAll(e,t=[]){let n=this.getDb().prepare(e);try{t.length>0&&n.bind(t);let e=[];for(;n.step();)e.push(n.getAsObject());return e}finally{n.free()}}run(e,t=[]){let n=this.getDb(),r=e.trimStart().toUpperCase(),i=re(e),a=this.foreignKeysEnabled&&!this.inTransaction&&i!==null&&(r.startsWith(`INSERT`)||r.startsWith(`UPDATE`));a&&n.run(`SAVEPOINT fk_check`);try{if(t.length>0){let r=n.prepare(e);try{r.bind(t),r.step()}finally{r.free()}}else n.run(e);if(a){if(n.exec(`PRAGMA foreign_key_check(${i})`).length>0)throw n.run(`ROLLBACK TO fk_check`),n.run(`RELEASE fk_check`),Error(`FOREIGN KEY constraint failed`);n.run(`RELEASE fk_check`)}}catch(e){if(a)try{n.run(`ROLLBACK TO fk_check`),n.run(`RELEASE fk_check`)}catch{}throw e}this.dirty=!0}flush(){if(!this.dirty||!this.db)return;let e=this.db.export(),r=`${this.dbPath}.tmp`,a=c(this.dbPath);a&&!t(a)&&n(a,{recursive:!0}),o(r,Buffer.from(e)),i(r,this.dbPath),this.dirty=!1}close(){if(this.db){let e=this.db,t;try{this.flush()}catch(e){t=e;try{a(`${this.dbPath}.tmp`)}catch{}}try{e.close()}finally{this.db=null}if(t)throw t}}getDb(){if(!this.db)throw Error(`SqlJsAdapter: database not opened`);return this.db}};function w(){try{return x.resolve(`better-sqlite3/package.json`).replace(/[\\/]package\.json$/,``)}catch{return null}}function T(){let e=w();if(!e)return null;let n=u(e,`build`,`Release`,`better_sqlite3.node`);return t(n)?n:null}async function ie(){let e=w();if(!e)return`package-missing`;if(!t(u(e,`build`,`Release`,`better_sqlite3.node`)))return`binding-missing`;try{let{execSync:e}=await import(`node:child_process`);return e(`"${process.execPath}" -e "require('better-sqlite3')"`,{stdio:`pipe`,timeout:15e3}),`ok`}catch(e){let t=e instanceof Error&&`stderr`in e?String(e.stderr):``;return/NODE_MODULE_VERSION/.test(t)?`abi-mismatch`:/Could not locate the bindings file|no native build was found/.test(t)?`binding-missing`:`error`}}async function ae(e=!1){let n=w();if(!n)return b.info(`better-sqlite3 package is not installed — skipping native rebuild`),!1;try{let{execSync:r}=await import(`node:child_process`),i=n.replace(/[\\/]node_modules[\\/]better-sqlite3$/,``);if(e){let e=u(n,`build`,`Release`,`better_sqlite3.node`);if(t(e))try{a(e),b.info(`Deleted stale native binding before rebuild`,{path:e})}catch(t){b.warn(`Cannot delete stale native binding — file may be locked by another process`,{path:e,error:t instanceof Error?t.message:String(t)})}}return b.info(`Attempting native module rebuild for better-sqlite3`,{cwd:i}),r(`npm rebuild better-sqlite3`,{cwd:i,stdio:`pipe`,timeout:6e4}),b.info(`Native module rebuild completed successfully`),!0}catch(e){return b.warn(`Native module rebuild failed — continuing with sql.js fallback`,g(e)),!1}}async function oe(){try{let{execSync:e}=await import(`node:child_process`),t=x.resolve(`@vpxa/aikit/package.json`).replace(/[\\/]package\.json$/,``);return b.info(`Attempting to install better-sqlite3 for native adapter recovery`,{cwd:t}),e(`npm install better-sqlite3 --no-save --package-lock=false`,{cwd:t,stdio:`pipe`,timeout:12e4}),b.info(`better-sqlite3 install completed successfully`),!0}catch(e){return b.warn(`better-sqlite3 install failed — continuing with sql.js fallback`,g(e)),!1}}let E=!1;function D(){return!!process.env.VITEST||process.argv.some(e=>e.includes(`vitest`))}async function O(e){if(!k.isVitestRuntime()){let e=await k.probeNativeModuleAbi();e===`abi-mismatch`?(b.info(`Detected NODE_MODULE_VERSION mismatch via pre-flight probe — rebuilding before load`),await k.tryRebuildNativeModule(!0)&&b.info(`Pre-flight rebuild succeeded — proceeding with native adapter`)):e===`binding-missing`?(b.info(`No native binding found — attempting rebuild before load`),await k.tryRebuildNativeModule(!1)):e===`package-missing`&&(b.info(`better-sqlite3 package is not installed — attempting install before load`),await oe())}{let t=k.createNativeAdapter();try{return await t.open(e),t}catch(t){let n=t instanceof Error?t.message:String(t);if(!k.isVitestRuntime()&&/NODE_MODULE_VERSION|Could not locate the bindings file|no native build was found/.test(n)&&await k.tryRebuildNativeModule(!1)){let t=k.createNativeAdapter();try{return await t.open(e),b.info(`better-sqlite3 recovered after native module rebuild`),t}catch{}}E||(E=!0,b.warn(`[aikit] better-sqlite3 unavailable — falling back to sql.js (vector search disabled). Reinstall with prebuild support or rebuild from source to enable vector search.`,g(t)))}}let t=k.createFallbackAdapter();try{return await t.open(e),t}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`[aikit] SQLite adapter "sql.js" failed to load: ${t}`)}}async function se(e){let t=new C;return await t.open(e),t}const k={BetterSqlite3Adapter:S,SqlJsAdapter:C,isVitestRuntime:D,resolveNativeModulePackageDir:w,resolveNativeBindingPath:T,probeNativeModuleAbi:ie,tryRebuildNativeModule:ae,createNativeAdapter:()=>new S,createFallbackAdapter:()=>new C},A=new Set([`sessions`,`stash`,`checkpoints`,`leases`,`signals`,`audit_log`,`replay_entries`,`session_metadata`]);function ce(e){let t=l(e)||`.db`,n=s(e,t);return u(c(e),`${n}-control${t}`)}function le(e){return A.has(e)?`control`:`content`}function j(e,t={}){let n=t.splitEnabled??!1;return{splitEnabled:n,contentDbPath:t.contentDbPath??e,controlDbPath:t.controlDbPath??(n?ce(e):e)}}function ue(e,t=process.env){let n=t.AIKIT_SPLIT_STATE?.trim().toLowerCase();return j(e,{splitEnabled:n===`1`||n===`true`||n===`yes`||n===`on`})}const M=`_state_partition_meta`;function N(e){return`"${e.replaceAll(`"`,`""`)}"`}function P(e){let r=c(e);t(r)||n(r,{recursive:!0})}async function F(e){return P(e),O(e)}function I(e,t){return e.queryAll(`SELECT name FROM sqlite_master WHERE type = 'table' AND name = ?`,[t]).length>0}function L(e,t){return e.queryAll(`SELECT sql FROM sqlite_master WHERE type = 'table' AND name = ?`,[t])[0]?.sql??void 0}function R(e,t){return e.queryAll(`PRAGMA table_info(${N(t)})`).map(e=>e.name)}function z(e,t){return e.queryAll(`SELECT COUNT(*) AS count FROM ${N(t)}`)[0]?.count??0}function B(e,t,n){if(!I(e,n))return;if(!I(t,n)){let r=L(e,n);if(!r)return;t.exec(r)}let r=R(t,n);if(r.length===0)return;let i=r.map(N).join(`, `),a=r.map(()=>`?`).join(`, `),o=e.queryAll(`SELECT ${i} FROM ${N(n)}`);if(o.length===0)return;let s=`INSERT OR REPLACE INTO ${N(n)} (${i}) VALUES (${a})`;for(let e of o)t.run(s,r.map(t=>e[t]??null))}function V(e){e.exec(`
82
+ `)}}],b=h(`sqlite-adapter`),x=e(import.meta.url);var S=class{type=`better-sqlite3`;vectorCapable=!1;db=null;stmtCache=new Map;dbPath=``;DatabaseCtor=null;recovering=!1;async open(e){let t;try{t=x(`better-sqlite3`)}catch(e){throw Error(`better-sqlite3 native binding unavailable: ${e instanceof Error?e.message:String(e)}`)}this.db=new t(e),this.dbPath=e,this.DatabaseCtor=t,this.db.pragma(`journal_mode = WAL`),this.db.pragma(`foreign_keys = ON`),this.db.pragma(`synchronous = NORMAL`),this.runIntegrityCheck(e,t)||(this.db?.pragma(`journal_mode = WAL`),this.db?.pragma(`foreign_keys = ON`),this.db?.pragma(`synchronous = NORMAL`));try{x(`sqlite-vec`).load(this.db),this.vectorCapable=!0,b.debug(`sqlite-vec extension loaded`)}catch(e){this.vectorCapable=!1,b.warn(`sqlite-vec extension failed to load; vector search disabled`,g(e))}}exec(e){try{this.getDb().exec(e)}catch(t){if(this.isCorruptionError(t)){this.recover(),this.getDb().exec(e);return}throw t}}pragma(e){this.getDb().pragma(e)}queryAll(e,t=[]){try{let n=this.prepareCached(e);return t.length>0?n.all(...t):n.all()}catch(n){if(this.isCorruptionError(n))return this.recover(),this.queryAll(e,t);throw n}}run(e,t=[]){try{let n=this.prepareCached(e);t.length>0?n.run(...t):n.run()}catch(n){if(this.isCorruptionError(n)){this.recover(),this.run(e,t);return}throw n}}flush(){}close(){this.db&&=(this.stmtCache.clear(),this.db.close(),null)}runIntegrityCheck(e,t){try{let t=this.db?.pragma(`integrity_check`);if(t.length===1&&t[0]?.integrity_check===`ok`)return!0;let n=t.map(e=>e.integrity_check).slice(0,5).join(`; `);b.warn(`Database integrity check failed — recreating`,{dbPath:e,issues:n})}catch(t){b.warn(`Integrity check query failed — recreating database`,{dbPath:e,error:g(t)})}try{this.db?.close()}catch{}this.db=null,this.stmtCache.clear();try{a(e)}catch{}try{a(`${e}-wal`)}catch{}try{a(`${e}-shm`)}catch{}return this.db=new t(e),b.info(`Database recreated successfully — full reindex required`,{dbPath:e}),!1}isCorruptionError(e){if(this.recovering)return!1;let t=e instanceof Error?e.message:String(e);return/database disk image is malformed|file is not a database|database or disk is full/.test(t)}recover(){if(this.recovering)throw Error(`BetterSqlite3Adapter: recovery already in progress`);this.recovering=!0;try{b.warn(`Runtime corruption detected — recovering database`,{dbPath:this.dbPath});try{this.db?.close()}catch{}this.db=null,this.stmtCache.clear();try{a(this.dbPath)}catch{}try{a(`${this.dbPath}-wal`)}catch{}try{a(`${this.dbPath}-shm`)}catch{}if(!this.DatabaseCtor)throw Error(`DatabaseCtor is not initialized`);this.db=this.DatabaseCtor(this.dbPath),this.db.pragma(`journal_mode = WAL`),this.db.pragma(`foreign_keys = ON`),this.db.pragma(`synchronous = NORMAL`);try{x(`sqlite-vec`).load(this.db),this.vectorCapable=!0}catch{this.vectorCapable=!1}b.info(`Database recovered — full reindex required`,{dbPath:this.dbPath})}finally{this.recovering=!1}}getDb(){if(!this.db)throw Error(`BetterSqlite3Adapter: database not opened`);return this.db}prepareCached(e){let t=this.stmtCache.get(e);if(t)return t;let n=this.getDb().prepare(e);return this.stmtCache.set(e,n),n}};function ne(e){return x.resolve(`sql.js/dist/${e}`)}function re(e){return e.match(/^\s*(?:INSERT(?:\s+OR\s+\w+)?\s+INTO|UPDATE)\s+([A-Za-z_][A-Za-z0-9_]*)/i)?.[1]??null}var C=class{type=`sql.js`;vectorCapable=!1;db=null;dbPath=``;dirty=!1;inTransaction=!1;foreignKeysEnabled=!1;async open(e){this.dbPath=e;let n=(await import(`sql.js`)).default,i=await n({locateFile:e=>ne(e)});if(t(e)){let t=r(e);this.db=new i.Database(t)}else this.db=new i.Database}exec(e){let t=e.trimStart().toUpperCase();this.getDb().run(e),t.startsWith(`BEGIN`)?this.inTransaction=!0:(t.startsWith(`COMMIT`)||t.startsWith(`ROLLBACK`))&&(this.inTransaction=!1),this.dirty=!0}pragma(e){let t=e.trim().toLowerCase();t===`foreign_keys = on`||t===`foreign_keys=on`?this.foreignKeysEnabled=!0:(t===`foreign_keys = off`||t===`foreign_keys=off`)&&(this.foreignKeysEnabled=!1),this.getDb().exec(`PRAGMA ${e}`)}queryAll(e,t=[]){let n=this.getDb().prepare(e);try{t.length>0&&n.bind(t);let e=[];for(;n.step();)e.push(n.getAsObject());return e}finally{n.free()}}run(e,t=[]){let n=this.getDb(),r=e.trimStart().toUpperCase(),i=re(e),a=this.foreignKeysEnabled&&!this.inTransaction&&i!==null&&(r.startsWith(`INSERT`)||r.startsWith(`UPDATE`));a&&n.run(`SAVEPOINT fk_check`);try{if(t.length>0){let r=n.prepare(e);try{r.bind(t),r.step()}finally{r.free()}}else n.run(e);if(a){if(n.exec(`PRAGMA foreign_key_check(${i})`).length>0)throw n.run(`ROLLBACK TO fk_check`),n.run(`RELEASE fk_check`),Error(`FOREIGN KEY constraint failed`);n.run(`RELEASE fk_check`)}}catch(e){if(a)try{n.run(`ROLLBACK TO fk_check`),n.run(`RELEASE fk_check`)}catch{}throw e}this.dirty=!0}flush(){if(!this.dirty||!this.db)return;let e=this.db.export(),r=`${this.dbPath}.tmp`,a=c(this.dbPath);a&&!t(a)&&n(a,{recursive:!0}),o(r,Buffer.from(e)),i(r,this.dbPath),this.dirty=!1}close(){if(this.db){let e=this.db,t;try{this.flush()}catch(e){t=e;try{a(`${this.dbPath}.tmp`)}catch{}}try{e.close()}finally{this.db=null}if(t)throw t}}getDb(){if(!this.db)throw Error(`SqlJsAdapter: database not opened`);return this.db}};function w(){try{return x.resolve(`better-sqlite3/package.json`).replace(/[\\/]package\.json$/,``)}catch{return null}}function T(){let e=w();if(!e)return null;let n=u(e,`build`,`Release`,`better_sqlite3.node`);return t(n)?n:null}async function ie(){let e=w();if(!e)return`package-missing`;if(!t(u(e,`build`,`Release`,`better_sqlite3.node`)))return`binding-missing`;try{let{execSync:e}=await import(`node:child_process`);return e(`"${process.execPath}" -e "require('better-sqlite3')"`,{stdio:`pipe`,timeout:15e3}),`ok`}catch(e){let t=e instanceof Error&&`stderr`in e?String(e.stderr):``;return/NODE_MODULE_VERSION/.test(t)?`abi-mismatch`:/Could not locate the bindings file|no native build was found/.test(t)?`binding-missing`:`error`}}async function ae(e=!1){let n=w();if(!n)return b.info(`better-sqlite3 package is not installed — skipping native rebuild`),!1;try{let{execSync:r}=await import(`node:child_process`),i=n.replace(/[\\/]node_modules[\\/]better-sqlite3$/,``);if(e){let e=u(n,`build`,`Release`,`better_sqlite3.node`);if(t(e))try{a(e),b.info(`Deleted stale native binding before rebuild`,{path:e})}catch(t){b.warn(`Cannot delete stale native binding — file may be locked by another process`,{path:e,error:t instanceof Error?t.message:String(t)})}}return b.info(`Attempting native module rebuild for better-sqlite3`,{cwd:i}),r(`npm rebuild better-sqlite3`,{cwd:i,stdio:`pipe`,timeout:6e4}),b.info(`Native module rebuild completed successfully`),!0}catch(e){return b.warn(`Native module rebuild failed — continuing with sql.js fallback`,g(e)),!1}}async function oe(){try{let{execSync:e}=await import(`node:child_process`),t=x.resolve(`@vpxa/aikit/package.json`).replace(/[\\/]package\.json$/,``);return b.info(`Attempting to install better-sqlite3 for native adapter recovery`,{cwd:t}),e(`npm install better-sqlite3 --no-save --package-lock=false`,{cwd:t,stdio:`pipe`,timeout:12e4}),b.info(`better-sqlite3 install completed successfully`),!0}catch(e){return b.warn(`better-sqlite3 install failed — continuing with sql.js fallback`,g(e)),!1}}let E=!1;function D(){return!!process.env.VITEST||process.argv.some(e=>e.includes(`vitest`))}async function O(e){if(!k.isVitestRuntime()){let e=await k.probeNativeModuleAbi();e===`abi-mismatch`?(b.info(`Detected NODE_MODULE_VERSION mismatch via pre-flight probe — rebuilding before load`),await k.tryRebuildNativeModule(!0)&&b.info(`Pre-flight rebuild succeeded — proceeding with native adapter`)):e===`binding-missing`?(b.info(`No native binding found — attempting rebuild before load`),await k.tryRebuildNativeModule(!1)):e===`package-missing`&&(b.info(`better-sqlite3 package is not installed — attempting install before load`),await oe())}{let t=k.createNativeAdapter();try{return await t.open(e),t}catch(t){let n=t instanceof Error?t.message:String(t);if(!k.isVitestRuntime()&&/NODE_MODULE_VERSION|Could not locate the bindings file|no native build was found/.test(n)&&await k.tryRebuildNativeModule(!1)){let t=k.createNativeAdapter();try{return await t.open(e),b.info(`better-sqlite3 recovered after native module rebuild`),t}catch{}}E||(E=!0,b.warn(`[aikit] better-sqlite3 unavailable — falling back to sql.js (vector search disabled). Reinstall with prebuild support or rebuild from source to enable vector search.`,g(t)))}}let t=k.createFallbackAdapter();try{return await t.open(e),t}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`[aikit] SQLite adapter "sql.js" failed to load: ${t}`)}}async function se(e){let t=new C;return await t.open(e),t}const k={BetterSqlite3Adapter:S,SqlJsAdapter:C,isVitestRuntime:D,resolveNativeModulePackageDir:w,resolveNativeBindingPath:T,probeNativeModuleAbi:ie,tryRebuildNativeModule:ae,createNativeAdapter:()=>new S,createFallbackAdapter:()=>new C},A=new Set([`sessions`,`stash`,`checkpoints`,`leases`,`signals`,`audit_log`,`replay_entries`,`session_metadata`]);function ce(e){let t=l(e)||`.db`,n=s(e,t);return u(c(e),`${n}-control${t}`)}function le(e){return A.has(e)?`control`:`content`}function j(e,t={}){let n=t.splitEnabled??!1;return{splitEnabled:n,contentDbPath:t.contentDbPath??e,controlDbPath:t.controlDbPath??(n?ce(e):e)}}function ue(e,t=process.env){let n=t.AIKIT_SPLIT_STATE?.trim().toLowerCase();return j(e,{splitEnabled:n===`1`||n===`true`||n===`yes`||n===`on`})}const M=`_state_partition_meta`;function N(e){return`"${e.replaceAll(`"`,`""`)}"`}function P(e){let r=c(e);t(r)||n(r,{recursive:!0})}async function F(e){return P(e),O(e)}function I(e,t){return e.queryAll(`SELECT name FROM sqlite_master WHERE type = 'table' AND name = ?`,[t]).length>0}function L(e,t){return e.queryAll(`SELECT sql FROM sqlite_master WHERE type = 'table' AND name = ?`,[t])[0]?.sql??void 0}function R(e,t){return e.queryAll(`PRAGMA table_info(${N(t)})`).map(e=>e.name)}function z(e,t){return e.queryAll(`SELECT COUNT(*) AS count FROM ${N(t)}`)[0]?.count??0}function B(e,t,n){if(!I(e,n))return;if(!I(t,n)){let r=L(e,n);if(!r)return;t.exec(r)}let r=R(t,n);if(r.length===0)return;let i=r.map(N).join(`, `),a=r.map(()=>`?`).join(`, `),o=e.queryAll(`SELECT ${i} FROM ${N(n)}`);if(o.length===0)return;let s=`INSERT OR REPLACE INTO ${N(n)} (${i}) VALUES (${a})`;for(let e of o)t.run(s,r.map(t=>e[t]??null))}function V(e){e.exec(`
83
83
  CREATE TABLE IF NOT EXISTS ${M} (
84
84
  key TEXT PRIMARY KEY,
85
85
  value TEXT NOT NULL,