@miniaxolotl/grove-server 1.11.23 → 1.11.24

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/dist/server.js CHANGED
@@ -18,7 +18,7 @@ var __export = (target2, all2) => {
18
18
  var define_GROVE_TELEMETRY_default;
19
19
  var init_define_GROVE_TELEMETRY = __esm({
20
20
  "<define:__GROVE_TELEMETRY__>"() {
21
- define_GROVE_TELEMETRY_default = { enabled: true, revision: "3001fd909e21b74b7aae506a64b50d6a934b516f", version: "1.11.23", component: "api", key: "phc_AqVrjhk7W2X2pFjyngY7uWxcSSRREfJhgr8mBmKbXYEh", cliDsn: "https://3f6d0711b5890dea4ce8e6ccf2a1a7fd@o4511632209346560.ingest.us.sentry.io/4512290791620608", apiDsn: "https://4524e8910e318110277babdfe818999b@o4511632209346560.ingest.us.sentry.io/4512290791489536" };
21
+ define_GROVE_TELEMETRY_default = { enabled: true, revision: "9ee71cc987a443c020fbf6030f76664b4cc5e914", version: "1.11.24", component: "api", key: "phc_AqVrjhk7W2X2pFjyngY7uWxcSSRREfJhgr8mBmKbXYEh", cliDsn: "https://3f6d0711b5890dea4ce8e6ccf2a1a7fd@o4511632209346560.ingest.us.sentry.io/4512290791620608", apiDsn: "https://4524e8910e318110277babdfe818999b@o4511632209346560.ingest.us.sentry.io/4512290791489536" };
22
22
  }
23
23
  });
24
24
 
@@ -2621,6 +2621,32 @@ var dailyNotes = {
2621
2621
  }
2622
2622
  };
2623
2623
 
2624
+ // lib/database/src/cache-retention-migration.ts
2625
+ init_define_GROVE_TELEMETRY();
2626
+ var cacheRetention = {
2627
+ name: "20261118_043_cache_retention",
2628
+ async up(db) {
2629
+ const { rows } = await db.raw(
2630
+ "SELECT pg_get_functiondef('grove_schedule_cleanup()'::regprocedure) AS definition"
2631
+ );
2632
+ const definition2 = rows[0].definition;
2633
+ const anchor = "OR EXISTS(SELECT 1 FROM rate_buckets r";
2634
+ if (definition2.split(anchor).length !== 2)
2635
+ throw new Error("Unsupported retention scheduler baseline");
2636
+ await db.raw(
2637
+ definition2.replace(
2638
+ anchor,
2639
+ `OR EXISTS(SELECT 1 FROM ai_cache c WHERE c.account_id=a.id AND c.expires_at<=now())
2640
+ OR EXISTS(SELECT 1 FROM ai_provider_backoff b WHERE b.account_id=a.id AND b.retry_at<now()-interval '1 day')
2641
+ ${anchor}`
2642
+ )
2643
+ );
2644
+ },
2645
+ async down() {
2646
+ throw new Error("Use a forward migration");
2647
+ }
2648
+ };
2649
+
2624
2650
  // lib/database/src/writing-allowance-migration.ts
2625
2651
  init_define_GROVE_TELEMETRY();
2626
2652
  var writingAllowance = {
@@ -6361,7 +6387,8 @@ var migrations = [
6361
6387
  nativeSharing,
6362
6388
  billingTrial,
6363
6389
  writingAllowance,
6364
- dailyNotes
6390
+ dailyNotes,
6391
+ cacheRetention
6365
6392
  ];
6366
6393
  var migrationSource = {
6367
6394
  getMigrations: async () => migrations,
@@ -6481,6 +6508,9 @@ async function probeDatabase(db) {
6481
6508
  );
6482
6509
  await db.raw("SELECT policy, version FROM writing_consents LIMIT 0");
6483
6510
  await db.raw("SELECT connection_id FROM writing_cancellations LIMIT 0");
6511
+ await db.raw(
6512
+ "SELECT account_id, local_date, memory_id FROM daily_notes LIMIT 0"
6513
+ );
6484
6514
  }
6485
6515
  var MemoryModel = class extends Model {
6486
6516
  static tableName = "memories";
@@ -21981,14 +22011,16 @@ async function owned2(trx, id2) {
21981
22011
  return row;
21982
22012
  }
21983
22013
  async function expireDocumentDrafts(trx) {
21984
- const expired = trx("document_import_batches").select("id").where("expiresAt", "<=", trx.fn.now()).where({ draftsCleared: false }).whereIn("status", ["uploading", "preparing", "ready", "cancelled"]).orderBy("id").limit(20);
22014
+ const limit = 20;
22015
+ const expired = trx("document_import_batches").select("id").where("expiresAt", "<=", trx.fn.now()).where({ draftsCleared: false }).whereIn("status", ["uploading", "preparing", "ready", "cancelled"]).orderBy("id").limit(limit);
21985
22016
  await trx("document_import_files").whereIn("batchId", expired).where({ originalReady: false }).whereNotNull("staging").update({ staging: null });
21986
22017
  await trx("document_import_notes").whereIn("batchId", expired).whereNull("memoryId").whereNot("content", "[Expired import draft]").update({
21987
22018
  content: "[Expired import draft]",
21988
22019
  included: false,
21989
22020
  suggestion: null
21990
22021
  });
21991
- await trx("document_import_batches").whereIn("id", expired).update({ draftsCleared: true });
22022
+ const processed = await trx("document_import_batches").whereIn("id", expired).update({ draftsCleared: true });
22023
+ return { processed, fullPage: processed === limit };
21992
22024
  }
21993
22025
  var DocumentImports = class {
21994
22026
  constructor(service) {
@@ -22478,8 +22510,9 @@ var available = (q) => q.whereNull("removedAt").where(
22478
22510
  (sub) => sub.where("accepted", true).orWhere("expiresAt", ">", q.client.raw("now()"))
22479
22511
  );
22480
22512
  async function expireConversationDocuments(trx) {
22481
- const docs = await trx("conversation_documents").where({ accepted: false }).whereNull("removedAt").where("expiresAt", "<=", trx.fn.now()).orderBy("id").limit(25).select("id", "conversationId");
22482
- if (!docs.length) return;
22513
+ const limit = 25;
22514
+ const docs = await trx("conversation_documents").where({ accepted: false }).whereNull("removedAt").where("expiresAt", "<=", trx.fn.now()).orderBy("id").limit(limit).select("id", "conversationId");
22515
+ if (!docs.length) return { processed: 0, fullPage: false };
22483
22516
  await trx("conversation_document_chunks").whereIn(
22484
22517
  "documentId",
22485
22518
  docs.map((d) => d.id)
@@ -22497,6 +22530,7 @@ async function expireConversationDocuments(trx) {
22497
22530
  "id",
22498
22531
  docs.map((d) => d.conversationId)
22499
22532
  ).increment("documentsVersion", 1);
22533
+ return { processed: docs.length, fullPage: docs.length === limit };
22500
22534
  }
22501
22535
  async function documentSnapshot(trx, conversationId, query) {
22502
22536
  const chat = await documentChat(trx, conversationId);
@@ -26262,8 +26296,8 @@ function cleanupHandlers(db, deleteIdentity, cancelBilling) {
26262
26296
  const retention_cleanup = async (task, signal) => {
26263
26297
  await taskTransaction(db, task, async (trx) => {
26264
26298
  signal.throwIfAborted();
26265
- await expireDocumentDrafts(trx);
26266
- await expireConversationDocuments(trx);
26299
+ const drafts = await expireDocumentDrafts(trx);
26300
+ const uploads = await expireConversationDocuments(trx);
26267
26301
  const writingExpired = await expireWriting(trx);
26268
26302
  const expired = await trx("memories").where("purgeAt", "<=", trx.fn.now()).select("id").orderBy("id").limit(batchSize);
26269
26303
  if (expired.length) {
@@ -26279,8 +26313,8 @@ function cleanupHandlers(db, deleteIdentity, cancelBilling) {
26279
26313
  await trx("rate_buckets").whereIn("minute", buckets).delete();
26280
26314
  const cache = await pruneCache(trx, true);
26281
26315
  return {
26282
- processed: Number(task.processed) + expired.length + cache + writingExpired,
26283
- complete: expired.length < batchSize && buckets.length < batchSize && writingExpired < batchSize && cache < batchSize
26316
+ processed: Number(task.processed) + expired.length + cache + writingExpired + drafts.processed + uploads.processed,
26317
+ complete: !drafts.fullPage && !uploads.fullPage && expired.length < batchSize && buckets.length < batchSize && writingExpired < batchSize && cache < batchSize
26284
26318
  };
26285
26319
  });
26286
26320
  };