@miniaxolotl/grove-server 1.11.21 → 1.11.23
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/bootstrap.js +29 -1
- package/dist/bootstrap.js.map +4 -4
- package/dist/migrate.js +29 -1
- package/dist/migrate.js.map +4 -4
- package/dist/server.js +112 -10
- package/dist/server.js.map +4 -4
- package/dist/telemetry-build.json +1 -1
- package/dist/worker.js +94 -10
- package/dist/worker.js.map +4 -4
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"enabled":true,"revision":"
|
|
1
|
+
{"enabled":true,"revision":"3001fd909e21b74b7aae506a64b50d6a934b516f","version":"1.11.23","component":"api"}
|
package/dist/worker.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: "
|
|
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" };
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
24
|
|
|
@@ -203,7 +203,7 @@ var init_limits = __esm({
|
|
|
203
203
|
|
|
204
204
|
// lib/shared/src/contracts.ts
|
|
205
205
|
import { z as z7 } from "zod";
|
|
206
|
-
var capabilities, capabilitySchema, uuidSchema, operationSchema, expectedVersionSchema, captureSchema, kindSchema, sourceSchema, rememberSchema, listSchema, recallSchema, versionSchema, forgetSchema, projectSchema, grantSchema, connectionSchema, connectionUpdateSchema, agentSchema, connectSchema, approveConnectSchema, memorySchema, GroveError;
|
|
206
|
+
var capabilities, capabilitySchema, uuidSchema, localDateSchema, operationSchema, expectedVersionSchema, captureSchema, kindSchema, sourceSchema, rememberSchema, listSchema, recallSchema, versionSchema, forgetSchema, projectSchema, grantSchema, connectionSchema, connectionUpdateSchema, agentSchema, connectSchema, approveConnectSchema, memorySchema, GroveError;
|
|
207
207
|
var init_contracts = __esm({
|
|
208
208
|
"lib/shared/src/contracts.ts"() {
|
|
209
209
|
"use strict";
|
|
@@ -217,6 +217,7 @@ var init_contracts = __esm({
|
|
|
217
217
|
];
|
|
218
218
|
capabilitySchema = z7.enum(capabilities);
|
|
219
219
|
uuidSchema = z7.uuid();
|
|
220
|
+
localDateSchema = z7.iso.date().refine((date) => !date.startsWith("0000-"));
|
|
220
221
|
operationSchema = z7.uuid().describe(
|
|
221
222
|
"New UUID for this write. Reuse the same UUID and identical arguments when retrying; changed arguments require a new operation."
|
|
222
223
|
);
|
|
@@ -2577,6 +2578,34 @@ import { Model, knexSnakeCaseMappers } from "objection";
|
|
|
2577
2578
|
// lib/database/src/migrations.ts
|
|
2578
2579
|
init_define_GROVE_TELEMETRY();
|
|
2579
2580
|
|
|
2581
|
+
// lib/database/src/daily-note-migration.ts
|
|
2582
|
+
init_define_GROVE_TELEMETRY();
|
|
2583
|
+
var dailyNotes = {
|
|
2584
|
+
name: "20261117_042_daily_notes",
|
|
2585
|
+
async up(db) {
|
|
2586
|
+
await db.raw(`
|
|
2587
|
+
CREATE TABLE daily_notes (
|
|
2588
|
+
account_id uuid NOT NULL REFERENCES accounts(id) ON DELETE CASCADE,
|
|
2589
|
+
local_date date NOT NULL,
|
|
2590
|
+
memory_id uuid,
|
|
2591
|
+
PRIMARY KEY (account_id, local_date),
|
|
2592
|
+
UNIQUE (account_id, memory_id),
|
|
2593
|
+
FOREIGN KEY (account_id, memory_id) REFERENCES memories(account_id,id)
|
|
2594
|
+
ON DELETE SET NULL (memory_id)
|
|
2595
|
+
);
|
|
2596
|
+
ALTER TABLE daily_notes ENABLE ROW LEVEL SECURITY;
|
|
2597
|
+
ALTER TABLE daily_notes FORCE ROW LEVEL SECURITY;
|
|
2598
|
+
CREATE POLICY daily_notes_tenant ON daily_notes
|
|
2599
|
+
USING (account_id=nullif(current_setting('grove.account_id',true),'')::uuid);
|
|
2600
|
+
GRANT SELECT, INSERT ON daily_notes TO grove_runtime;
|
|
2601
|
+
GRANT SELECT, DELETE ON daily_notes TO grove_worker;
|
|
2602
|
+
`);
|
|
2603
|
+
},
|
|
2604
|
+
async down() {
|
|
2605
|
+
throw new Error("Use a forward migration; retain daily note identities");
|
|
2606
|
+
}
|
|
2607
|
+
};
|
|
2608
|
+
|
|
2580
2609
|
// lib/database/src/writing-allowance-migration.ts
|
|
2581
2610
|
init_define_GROVE_TELEMETRY();
|
|
2582
2611
|
var writingAllowance = {
|
|
@@ -6316,7 +6345,8 @@ var migrations = [
|
|
|
6316
6345
|
writingTools,
|
|
6317
6346
|
nativeSharing,
|
|
6318
6347
|
billingTrial,
|
|
6319
|
-
writingAllowance
|
|
6348
|
+
writingAllowance,
|
|
6349
|
+
dailyNotes
|
|
6320
6350
|
];
|
|
6321
6351
|
var migrationSource = {
|
|
6322
6352
|
getMigrations: async () => migrations,
|
|
@@ -25466,9 +25496,14 @@ function cleanupHandlers(db, deleteIdentity, cancelBilling) {
|
|
|
25466
25496
|
if (table) {
|
|
25467
25497
|
await taskTransaction(db, task, async (trx) => {
|
|
25468
25498
|
signal.throwIfAborted();
|
|
25469
|
-
const
|
|
25470
|
-
|
|
25471
|
-
|
|
25499
|
+
const deleteBatch = async (target2) => {
|
|
25500
|
+
const rows = await trx(target2).select(trx.raw("ctid::text AS row_id")).limit(batchSize);
|
|
25501
|
+
if (rows.length)
|
|
25502
|
+
await trx(target2).whereRaw("ctid=ANY(?::tid[])", [rows.map((row) => row.rowId)]).delete();
|
|
25503
|
+
return rows.length;
|
|
25504
|
+
};
|
|
25505
|
+
const count2 = await deleteBatch(table);
|
|
25506
|
+
const daily = table === "notebook_expiries" ? await deleteBatch("daily_notes") : 0;
|
|
25472
25507
|
const research = table === "inference_usage" ? await trx("research_account_usage").select("day").limit(batchSize) : [];
|
|
25473
25508
|
if (research.length)
|
|
25474
25509
|
await trx("research_account_usage").whereIn(
|
|
@@ -25478,9 +25513,9 @@ function cleanupHandlers(db, deleteIdentity, cancelBilling) {
|
|
|
25478
25513
|
const cache = table === "memory_briefs" ? await pruneCache(trx, false) : 0;
|
|
25479
25514
|
return {
|
|
25480
25515
|
cursor: {
|
|
25481
|
-
stage:
|
|
25516
|
+
stage: count2 === batchSize || daily === batchSize || research.length === batchSize || cache === batchSize ? stage : stage + 1
|
|
25482
25517
|
},
|
|
25483
|
-
processed: Number(task.processed) +
|
|
25518
|
+
processed: Number(task.processed) + count2 + daily + research.length + cache
|
|
25484
25519
|
};
|
|
25485
25520
|
});
|
|
25486
25521
|
return;
|
|
@@ -26960,6 +26995,34 @@ var MemoryService = class _MemoryService {
|
|
|
26960
26995
|
async remember(principal, input) {
|
|
26961
26996
|
return this.saveMemory(principal, input, false);
|
|
26962
26997
|
}
|
|
26998
|
+
async dailyNoteFor(trx, accountId, localDate) {
|
|
26999
|
+
const row = await trx("daily_notes as daily").leftJoin("memories as note", function() {
|
|
27000
|
+
this.on("note.account_id", "daily.account_id").andOn(
|
|
27001
|
+
"note.id",
|
|
27002
|
+
"daily.memory_id"
|
|
27003
|
+
);
|
|
27004
|
+
}).where({ "daily.account_id": accountId, "daily.local_date": localDate }).first("note.id");
|
|
27005
|
+
return !row ? { state: "empty" } : row.id ? { state: "saved", id: row.id } : { state: "deleted" };
|
|
27006
|
+
}
|
|
27007
|
+
async dailyNote(principal, date) {
|
|
27008
|
+
if (principal.type !== "session") throw forbidden();
|
|
27009
|
+
const localDate = localDateSchema.parse(date);
|
|
27010
|
+
return this.access(
|
|
27011
|
+
principal,
|
|
27012
|
+
"memory:read",
|
|
27013
|
+
({ trx, account }) => this.dailyNoteFor(trx, account.id, localDate)
|
|
27014
|
+
);
|
|
27015
|
+
}
|
|
27016
|
+
async createDailyNote(principal, date, input) {
|
|
27017
|
+
if (principal.type !== "session") throw forbidden();
|
|
27018
|
+
const localDate = localDateSchema.parse(date);
|
|
27019
|
+
if (input.id || input.expectedVersion || input.archived || input.capture !== "explicit")
|
|
27020
|
+
throw new GroveError(
|
|
27021
|
+
"invalid_request",
|
|
27022
|
+
"A daily note must start with a new, active note"
|
|
27023
|
+
);
|
|
27024
|
+
return this.saveMemory(principal, input, false, localDate);
|
|
27025
|
+
}
|
|
26963
27026
|
async captureWeb(principal, raw) {
|
|
26964
27027
|
const input = browserCaptureRequestSchema.parse(raw);
|
|
26965
27028
|
return this.access(
|
|
@@ -27228,7 +27291,7 @@ var MemoryService = class _MemoryService {
|
|
|
27228
27291
|
return this.inTransaction(trx).updateMemory(principal, input);
|
|
27229
27292
|
});
|
|
27230
27293
|
}
|
|
27231
|
-
async saveMemory(principal, request2, partial) {
|
|
27294
|
+
async saveMemory(principal, request2, partial, localDate) {
|
|
27232
27295
|
let created = false;
|
|
27233
27296
|
const result = await this.access(
|
|
27234
27297
|
principal,
|
|
@@ -27244,8 +27307,23 @@ var MemoryService = class _MemoryService {
|
|
|
27244
27307
|
trx,
|
|
27245
27308
|
account.id,
|
|
27246
27309
|
request2.operationId,
|
|
27247
|
-
{ action: partial ? "update_memory" : "remember", ...request2 },
|
|
27310
|
+
localDate ? { action: "create_daily_note", localDate, ...request2 } : { action: partial ? "update_memory" : "remember", ...request2 },
|
|
27248
27311
|
async () => {
|
|
27312
|
+
if (localDate) {
|
|
27313
|
+
const daily = await this.dailyNoteFor(trx, account.id, localDate);
|
|
27314
|
+
if (daily.state === "saved")
|
|
27315
|
+
throw new GroveError(
|
|
27316
|
+
"daily_note_exists",
|
|
27317
|
+
"A daily note was already saved for this date. Copy any draft text you want to keep.",
|
|
27318
|
+
409
|
|
27319
|
+
);
|
|
27320
|
+
if (daily.state === "deleted")
|
|
27321
|
+
throw new GroveError(
|
|
27322
|
+
"daily_note_deleted",
|
|
27323
|
+
"The daily note for this date was deleted. Your draft was not saved.",
|
|
27324
|
+
410
|
|
27325
|
+
);
|
|
27326
|
+
}
|
|
27249
27327
|
let old;
|
|
27250
27328
|
if (request2.id) {
|
|
27251
27329
|
old = await this.query(trx, grant).findById(request2.id).forUpdate();
|
|
@@ -27355,6 +27433,12 @@ var MemoryService = class _MemoryService {
|
|
|
27355
27433
|
id: randomUUID13(),
|
|
27356
27434
|
status: input.archived ? "archived" : "active"
|
|
27357
27435
|
});
|
|
27436
|
+
if (localDate)
|
|
27437
|
+
await trx("daily_notes").insert({
|
|
27438
|
+
accountId: account.id,
|
|
27439
|
+
localDate,
|
|
27440
|
+
memoryId: row2.id
|
|
27441
|
+
});
|
|
27358
27442
|
const session = editSession ?? principal.sessionId;
|
|
27359
27443
|
await this.revise(
|
|
27360
27444
|
trx,
|