@askexenow/exe-os 0.8.46 → 0.8.48

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.
@@ -417,17 +417,6 @@ var init_db_retry = __esm({
417
417
  });
418
418
 
419
419
  // src/lib/database.ts
420
- var database_exports = {};
421
- __export(database_exports, {
422
- disposeDatabase: () => disposeDatabase,
423
- disposeTurso: () => disposeTurso,
424
- ensureSchema: () => ensureSchema,
425
- getClient: () => getClient,
426
- getRawClient: () => getRawClient,
427
- initDatabase: () => initDatabase,
428
- initTurso: () => initTurso,
429
- isInitialized: () => isInitialized
430
- });
431
420
  import { createClient } from "@libsql/client";
432
421
  async function initDatabase(config) {
433
422
  if (_client) {
@@ -1271,14 +1260,7 @@ async function ensureSchema() {
1271
1260
  }
1272
1261
  }
1273
1262
  }
1274
- async function disposeDatabase() {
1275
- if (_client) {
1276
- _client.close();
1277
- _client = null;
1278
- _resilientClient = null;
1279
- }
1280
- }
1281
- var _client, _resilientClient, initTurso, disposeTurso;
1263
+ var _client, _resilientClient, initTurso;
1282
1264
  var init_database = __esm({
1283
1265
  "src/lib/database.ts"() {
1284
1266
  "use strict";
@@ -1286,7 +1268,6 @@ var init_database = __esm({
1286
1268
  _client = null;
1287
1269
  _resilientClient = null;
1288
1270
  initTurso = initDatabase;
1289
- disposeTurso = disposeDatabase;
1290
1271
  }
1291
1272
  });
1292
1273
 
@@ -5423,6 +5404,7 @@ __export(cloud_sync_exports, {
5423
5404
  cloudPullBlob: () => cloudPullBlob,
5424
5405
  cloudPullConversations: () => cloudPullConversations,
5425
5406
  cloudPullDocuments: () => cloudPullDocuments,
5407
+ cloudPullGlobalProcedures: () => cloudPullGlobalProcedures,
5426
5408
  cloudPullGraphRAG: () => cloudPullGraphRAG,
5427
5409
  cloudPullRoster: () => cloudPullRoster,
5428
5410
  cloudPullTasks: () => cloudPullTasks,
@@ -5431,6 +5413,7 @@ __export(cloud_sync_exports, {
5431
5413
  cloudPushBlob: () => cloudPushBlob,
5432
5414
  cloudPushConversations: () => cloudPushConversations,
5433
5415
  cloudPushDocuments: () => cloudPushDocuments,
5416
+ cloudPushGlobalProcedures: () => cloudPushGlobalProcedures,
5434
5417
  cloudPushGraphRAG: () => cloudPushGraphRAG,
5435
5418
  cloudPushRoster: () => cloudPushRoster,
5436
5419
  cloudPushTasks: () => cloudPushTasks,
@@ -5592,19 +5575,16 @@ async function cloudSync(config) {
5592
5575
  } catch {
5593
5576
  throw new Error("[cloud-sync] Database not initialized. Call initStore() before cloudSync().");
5594
5577
  }
5595
- let pullMeta;
5596
5578
  try {
5597
- pullMeta = await client.execute(
5598
- "SELECT value FROM sync_meta WHERE key = 'last_cloud_pull_version'"
5579
+ await client.execute(
5580
+ "CREATE TABLE IF NOT EXISTS sync_meta (key TEXT PRIMARY KEY, value TEXT NOT NULL)"
5599
5581
  );
5600
5582
  } catch (e) {
5601
- logError(`[cloud-sync] sync_meta read failed (${e instanceof Error ? e.message : String(e)}), attempting ensureSchema`);
5602
- const { ensureSchema: ensureSchema2 } = await Promise.resolve().then(() => (init_database(), database_exports));
5603
- await ensureSchema2();
5604
- pullMeta = await client.execute(
5605
- "SELECT value FROM sync_meta WHERE key = 'last_cloud_pull_version'"
5606
- );
5583
+ logError(`[cloud-sync] sync_meta CREATE failed: ${e instanceof Error ? e.message : String(e)}`);
5607
5584
  }
5585
+ const pullMeta = await client.execute(
5586
+ "SELECT value FROM sync_meta WHERE key = 'last_cloud_pull_version'"
5587
+ );
5608
5588
  const lastPullVersion = pullMeta.rows.length > 0 ? Number(pullMeta.rows[0].value) : 0;
5609
5589
  const pullResult = await cloudPull(lastPullVersion, config);
5610
5590
  let pulled = 0;
@@ -5693,6 +5673,16 @@ async function cloudSync(config) {
5693
5673
  } catch (err) {
5694
5674
  logError(`[cloud-sync] Roster pull: ${err instanceof Error ? err.message : String(err)}`);
5695
5675
  }
5676
+ try {
5677
+ await cloudPushGlobalProcedures(config);
5678
+ } catch (err) {
5679
+ logError(`[cloud-sync] Global procedures push: ${err instanceof Error ? err.message : String(err)}`);
5680
+ }
5681
+ try {
5682
+ await cloudPullGlobalProcedures(config);
5683
+ } catch (err) {
5684
+ logError(`[cloud-sync] Global procedures pull: ${err instanceof Error ? err.message : String(err)}`);
5685
+ }
5696
5686
  let behaviorsResult = { pushed: false, pulled: 0 };
5697
5687
  try {
5698
5688
  behaviorsResult.pushed = await cloudPushBehaviors(config);
@@ -6006,6 +5996,43 @@ async function cloudPullBlob(route, config) {
6006
5996
  return null;
6007
5997
  }
6008
5998
  }
5999
+ async function cloudPushGlobalProcedures(config) {
6000
+ const client = getClient();
6001
+ const result = await client.execute("SELECT * FROM global_procedures LIMIT 1000");
6002
+ const rows = result.rows;
6003
+ const { ok } = await cloudPushBlob(
6004
+ "/sync/push-global-procedures",
6005
+ rows,
6006
+ "last_global_procedures_push_version",
6007
+ config
6008
+ );
6009
+ return ok;
6010
+ }
6011
+ async function cloudPullGlobalProcedures(config) {
6012
+ const remoteProcs = await cloudPullBlob(
6013
+ "/sync/pull-global-procedures",
6014
+ config
6015
+ );
6016
+ if (!remoteProcs || remoteProcs.length === 0) return { pulled: 0 };
6017
+ const client = getClient();
6018
+ const stmts = remoteProcs.map((p) => ({
6019
+ sql: `INSERT OR IGNORE INTO global_procedures
6020
+ (id, title, content, priority, domain, active, created_at, updated_at)
6021
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
6022
+ args: [
6023
+ p.id ?? null,
6024
+ p.title ?? null,
6025
+ p.content ?? null,
6026
+ p.priority ?? "p0",
6027
+ p.domain ?? null,
6028
+ p.active ?? 1,
6029
+ p.created_at ?? null,
6030
+ p.updated_at ?? null
6031
+ ]
6032
+ }));
6033
+ await client.batch(stmts, "write");
6034
+ return { pulled: remoteProcs.length };
6035
+ }
6009
6036
  async function cloudPushBehaviors(config) {
6010
6037
  const client = getClient();
6011
6038
  const result = await client.execute("SELECT * FROM behaviors LIMIT 10000");
@@ -213,22 +213,6 @@ var init_config = __esm({
213
213
  }
214
214
  });
215
215
 
216
- // src/lib/db-retry.ts
217
- var init_db_retry = __esm({
218
- "src/lib/db-retry.ts"() {
219
- "use strict";
220
- }
221
- });
222
-
223
- // src/lib/database.ts
224
- import { createClient } from "@libsql/client";
225
- var init_database = __esm({
226
- "src/lib/database.ts"() {
227
- "use strict";
228
- init_db_retry();
229
- }
230
- });
231
-
232
216
  // src/lib/license.ts
233
217
  var license_exports = {};
234
218
  __export(license_exports, {
@@ -740,12 +724,14 @@ function isMainModule(importMetaUrl) {
740
724
  }
741
725
 
742
726
  // src/lib/cloud-sync.ts
743
- init_database();
744
727
  import { readFileSync as readFileSync4, writeFileSync as writeFileSync2, existsSync as existsSync5, readdirSync, mkdirSync as mkdirSync2, appendFileSync, unlinkSync, openSync, closeSync } from "fs";
745
728
  import crypto4 from "crypto";
746
729
  import path5 from "path";
747
730
  import { homedir } from "os";
748
731
 
732
+ // src/lib/database.ts
733
+ import { createClient } from "@libsql/client";
734
+
749
735
  // src/lib/crypto.ts
750
736
  import crypto3 from "crypto";
751
737