@miniaxolotl/grove-server 1.11.20 → 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
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: "
|
|
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 z6 } from "zod";
|
|
206
|
-
var capabilities, capabilitySchema, oauthScopes, uuidSchema, operationSchema, expectedVersionSchema, captureSchema, kindSchema, sourceSchema, rememberSchema, listSchema, recallSchema, versionSchema, forgetSchema, projectSchema, grantSchema, connectionSchema, connectionUpdateSchema, agentSchema, agentNames, connectSchema, approveConnectSchema, memorySchema, GroveError;
|
|
206
|
+
var capabilities, capabilitySchema, oauthScopes, uuidSchema, localDateSchema, operationSchema, expectedVersionSchema, captureSchema, kindSchema, sourceSchema, rememberSchema, listSchema, recallSchema, versionSchema, forgetSchema, projectSchema, grantSchema, connectionSchema, connectionUpdateSchema, agentSchema, agentNames, connectSchema, approveConnectSchema, memorySchema, GroveError;
|
|
207
207
|
var init_contracts = __esm({
|
|
208
208
|
"lib/shared/src/contracts.ts"() {
|
|
209
209
|
"use strict";
|
|
@@ -218,6 +218,7 @@ var init_contracts = __esm({
|
|
|
218
218
|
capabilitySchema = z6.enum(capabilities);
|
|
219
219
|
oauthScopes = ["openid", "offline_access"];
|
|
220
220
|
uuidSchema = z6.uuid();
|
|
221
|
+
localDateSchema = z6.iso.date().refine((date) => !date.startsWith("0000-"));
|
|
221
222
|
operationSchema = z6.uuid().describe(
|
|
222
223
|
"New UUID for this write. Reuse the same UUID and identical arguments when retrying; changed arguments require a new operation."
|
|
223
224
|
);
|
|
@@ -2592,6 +2593,34 @@ import { Model, knexSnakeCaseMappers } from "objection";
|
|
|
2592
2593
|
// lib/database/src/migrations.ts
|
|
2593
2594
|
init_define_GROVE_TELEMETRY();
|
|
2594
2595
|
|
|
2596
|
+
// lib/database/src/daily-note-migration.ts
|
|
2597
|
+
init_define_GROVE_TELEMETRY();
|
|
2598
|
+
var dailyNotes = {
|
|
2599
|
+
name: "20261117_042_daily_notes",
|
|
2600
|
+
async up(db) {
|
|
2601
|
+
await db.raw(`
|
|
2602
|
+
CREATE TABLE daily_notes (
|
|
2603
|
+
account_id uuid NOT NULL REFERENCES accounts(id) ON DELETE CASCADE,
|
|
2604
|
+
local_date date NOT NULL,
|
|
2605
|
+
memory_id uuid,
|
|
2606
|
+
PRIMARY KEY (account_id, local_date),
|
|
2607
|
+
UNIQUE (account_id, memory_id),
|
|
2608
|
+
FOREIGN KEY (account_id, memory_id) REFERENCES memories(account_id,id)
|
|
2609
|
+
ON DELETE SET NULL (memory_id)
|
|
2610
|
+
);
|
|
2611
|
+
ALTER TABLE daily_notes ENABLE ROW LEVEL SECURITY;
|
|
2612
|
+
ALTER TABLE daily_notes FORCE ROW LEVEL SECURITY;
|
|
2613
|
+
CREATE POLICY daily_notes_tenant ON daily_notes
|
|
2614
|
+
USING (account_id=nullif(current_setting('grove.account_id',true),'')::uuid);
|
|
2615
|
+
GRANT SELECT, INSERT ON daily_notes TO grove_runtime;
|
|
2616
|
+
GRANT SELECT, DELETE ON daily_notes TO grove_worker;
|
|
2617
|
+
`);
|
|
2618
|
+
},
|
|
2619
|
+
async down() {
|
|
2620
|
+
throw new Error("Use a forward migration; retain daily note identities");
|
|
2621
|
+
}
|
|
2622
|
+
};
|
|
2623
|
+
|
|
2595
2624
|
// lib/database/src/writing-allowance-migration.ts
|
|
2596
2625
|
init_define_GROVE_TELEMETRY();
|
|
2597
2626
|
var writingAllowance = {
|
|
@@ -6331,7 +6360,8 @@ var migrations = [
|
|
|
6331
6360
|
writingTools,
|
|
6332
6361
|
nativeSharing,
|
|
6333
6362
|
billingTrial,
|
|
6334
|
-
writingAllowance
|
|
6363
|
+
writingAllowance,
|
|
6364
|
+
dailyNotes
|
|
6335
6365
|
];
|
|
6336
6366
|
var migrationSource = {
|
|
6337
6367
|
getMigrations: async () => migrations,
|
|
@@ -26183,9 +26213,14 @@ function cleanupHandlers(db, deleteIdentity, cancelBilling) {
|
|
|
26183
26213
|
if (table) {
|
|
26184
26214
|
await taskTransaction(db, task, async (trx) => {
|
|
26185
26215
|
signal.throwIfAborted();
|
|
26186
|
-
const
|
|
26187
|
-
|
|
26188
|
-
|
|
26216
|
+
const deleteBatch = async (target2) => {
|
|
26217
|
+
const rows = await trx(target2).select(trx.raw("ctid::text AS row_id")).limit(batchSize);
|
|
26218
|
+
if (rows.length)
|
|
26219
|
+
await trx(target2).whereRaw("ctid=ANY(?::tid[])", [rows.map((row) => row.rowId)]).delete();
|
|
26220
|
+
return rows.length;
|
|
26221
|
+
};
|
|
26222
|
+
const count2 = await deleteBatch(table);
|
|
26223
|
+
const daily = table === "notebook_expiries" ? await deleteBatch("daily_notes") : 0;
|
|
26189
26224
|
const research = table === "inference_usage" ? await trx("research_account_usage").select("day").limit(batchSize) : [];
|
|
26190
26225
|
if (research.length)
|
|
26191
26226
|
await trx("research_account_usage").whereIn(
|
|
@@ -26195,9 +26230,9 @@ function cleanupHandlers(db, deleteIdentity, cancelBilling) {
|
|
|
26195
26230
|
const cache = table === "memory_briefs" ? await pruneCache(trx, false) : 0;
|
|
26196
26231
|
return {
|
|
26197
26232
|
cursor: {
|
|
26198
|
-
stage:
|
|
26233
|
+
stage: count2 === batchSize || daily === batchSize || research.length === batchSize || cache === batchSize ? stage : stage + 1
|
|
26199
26234
|
},
|
|
26200
|
-
processed: Number(task.processed) +
|
|
26235
|
+
processed: Number(task.processed) + count2 + daily + research.length + cache
|
|
26201
26236
|
};
|
|
26202
26237
|
});
|
|
26203
26238
|
return;
|
|
@@ -28233,6 +28268,34 @@ var MemoryService = class _MemoryService {
|
|
|
28233
28268
|
async remember(principal, input) {
|
|
28234
28269
|
return this.saveMemory(principal, input, false);
|
|
28235
28270
|
}
|
|
28271
|
+
async dailyNoteFor(trx, accountId, localDate) {
|
|
28272
|
+
const row = await trx("daily_notes as daily").leftJoin("memories as note", function() {
|
|
28273
|
+
this.on("note.account_id", "daily.account_id").andOn(
|
|
28274
|
+
"note.id",
|
|
28275
|
+
"daily.memory_id"
|
|
28276
|
+
);
|
|
28277
|
+
}).where({ "daily.account_id": accountId, "daily.local_date": localDate }).first("note.id");
|
|
28278
|
+
return !row ? { state: "empty" } : row.id ? { state: "saved", id: row.id } : { state: "deleted" };
|
|
28279
|
+
}
|
|
28280
|
+
async dailyNote(principal, date) {
|
|
28281
|
+
if (principal.type !== "session") throw forbidden();
|
|
28282
|
+
const localDate = localDateSchema.parse(date);
|
|
28283
|
+
return this.access(
|
|
28284
|
+
principal,
|
|
28285
|
+
"memory:read",
|
|
28286
|
+
({ trx, account }) => this.dailyNoteFor(trx, account.id, localDate)
|
|
28287
|
+
);
|
|
28288
|
+
}
|
|
28289
|
+
async createDailyNote(principal, date, input) {
|
|
28290
|
+
if (principal.type !== "session") throw forbidden();
|
|
28291
|
+
const localDate = localDateSchema.parse(date);
|
|
28292
|
+
if (input.id || input.expectedVersion || input.archived || input.capture !== "explicit")
|
|
28293
|
+
throw new GroveError(
|
|
28294
|
+
"invalid_request",
|
|
28295
|
+
"A daily note must start with a new, active note"
|
|
28296
|
+
);
|
|
28297
|
+
return this.saveMemory(principal, input, false, localDate);
|
|
28298
|
+
}
|
|
28236
28299
|
async captureWeb(principal, raw) {
|
|
28237
28300
|
const input = browserCaptureRequestSchema.parse(raw);
|
|
28238
28301
|
return this.access(
|
|
@@ -28501,7 +28564,7 @@ var MemoryService = class _MemoryService {
|
|
|
28501
28564
|
return this.inTransaction(trx).updateMemory(principal, input);
|
|
28502
28565
|
});
|
|
28503
28566
|
}
|
|
28504
|
-
async saveMemory(principal, request2, partial) {
|
|
28567
|
+
async saveMemory(principal, request2, partial, localDate) {
|
|
28505
28568
|
let created = false;
|
|
28506
28569
|
const result = await this.access(
|
|
28507
28570
|
principal,
|
|
@@ -28517,8 +28580,23 @@ var MemoryService = class _MemoryService {
|
|
|
28517
28580
|
trx,
|
|
28518
28581
|
account.id,
|
|
28519
28582
|
request2.operationId,
|
|
28520
|
-
{ action: partial ? "update_memory" : "remember", ...request2 },
|
|
28583
|
+
localDate ? { action: "create_daily_note", localDate, ...request2 } : { action: partial ? "update_memory" : "remember", ...request2 },
|
|
28521
28584
|
async () => {
|
|
28585
|
+
if (localDate) {
|
|
28586
|
+
const daily = await this.dailyNoteFor(trx, account.id, localDate);
|
|
28587
|
+
if (daily.state === "saved")
|
|
28588
|
+
throw new GroveError(
|
|
28589
|
+
"daily_note_exists",
|
|
28590
|
+
"A daily note was already saved for this date. Copy any draft text you want to keep.",
|
|
28591
|
+
409
|
|
28592
|
+
);
|
|
28593
|
+
if (daily.state === "deleted")
|
|
28594
|
+
throw new GroveError(
|
|
28595
|
+
"daily_note_deleted",
|
|
28596
|
+
"The daily note for this date was deleted. Your draft was not saved.",
|
|
28597
|
+
410
|
|
28598
|
+
);
|
|
28599
|
+
}
|
|
28522
28600
|
let old;
|
|
28523
28601
|
if (request2.id) {
|
|
28524
28602
|
old = await this.query(trx, grant).findById(request2.id).forUpdate();
|
|
@@ -28628,6 +28706,12 @@ var MemoryService = class _MemoryService {
|
|
|
28628
28706
|
id: randomUUID14(),
|
|
28629
28707
|
status: input.archived ? "archived" : "active"
|
|
28630
28708
|
});
|
|
28709
|
+
if (localDate)
|
|
28710
|
+
await trx("daily_notes").insert({
|
|
28711
|
+
accountId: account.id,
|
|
28712
|
+
localDate,
|
|
28713
|
+
memoryId: row2.id
|
|
28714
|
+
});
|
|
28631
28715
|
const session = editSession ?? principal.sessionId;
|
|
28632
28716
|
await this.revise(
|
|
28633
28717
|
trx,
|
|
@@ -48776,6 +48860,24 @@ function createApp(deps) {
|
|
|
48776
48860
|
)
|
|
48777
48861
|
})
|
|
48778
48862
|
);
|
|
48863
|
+
app.get(
|
|
48864
|
+
"/v1/memories/daily/:date",
|
|
48865
|
+
async (c) => c.json({
|
|
48866
|
+
success: true,
|
|
48867
|
+
data: await service.dailyNote(c.get("principal"), c.req.param("date"))
|
|
48868
|
+
})
|
|
48869
|
+
);
|
|
48870
|
+
app.post(
|
|
48871
|
+
"/v1/memories/daily/:date",
|
|
48872
|
+
async (c) => c.json({
|
|
48873
|
+
success: true,
|
|
48874
|
+
data: await service.createDailyNote(
|
|
48875
|
+
c.get("principal"),
|
|
48876
|
+
c.req.param("date"),
|
|
48877
|
+
await mutation(c, rememberSchema)
|
|
48878
|
+
)
|
|
48879
|
+
})
|
|
48880
|
+
);
|
|
48779
48881
|
app.post("/v1/memories", async (c) => {
|
|
48780
48882
|
const input = await mutation(
|
|
48781
48883
|
c,
|