@miniaxolotl/grove-server 1.11.16 → 1.11.20
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 +83 -1
- package/dist/bootstrap.js.map +4 -4
- package/dist/migrate.js +83 -1
- package/dist/migrate.js.map +4 -4
- package/dist/server.js +1809 -1062
- package/dist/server.js.map +4 -4
- package/dist/telemetry-build.json +1 -1
- package/dist/worker.js +1568 -742
- package/dist/worker.js.map +4 -4
- package/package.json +3 -3
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: "1d7c46db0a798134b2f2a336825081fc1e10e4f9", version: "1.11.20", 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
|
|
|
@@ -170,6 +170,626 @@ var init_models = __esm({
|
|
|
170
170
|
}
|
|
171
171
|
});
|
|
172
172
|
|
|
173
|
+
// lib/shared/src/note-writing.ts
|
|
174
|
+
var noteWritingPolicyVersion, noteWritingInstructions, noteContentDescription;
|
|
175
|
+
var init_note_writing = __esm({
|
|
176
|
+
"lib/shared/src/note-writing.ts"() {
|
|
177
|
+
"use strict";
|
|
178
|
+
init_define_GROVE_TELEMETRY();
|
|
179
|
+
noteWritingPolicyVersion = "note-writing-v2";
|
|
180
|
+
noteWritingInstructions = [
|
|
181
|
+
"Write human-readable notes: simple, concise, focused on one subject and understandable without the original chat. Use plain language; preserve important facts, decisions, reasons and uncertainty. Omit filler, repetition and conversational preambles. Honor explicit requests for detail or verbatim content; never invent sources, owners or deadlines.",
|
|
182
|
+
"Use CommonMark/GitHub-flavored Markdown. A short note can be one sentence; do not force a template. Use descriptive headings and lists when helpful, checkboxes only for real tasks, tables only for tabular information, and fenced blocks for code/literal examples. Do not wrap the whole note in a Markdown fence. Do not rely on raw HTML, Mermaid, math or wiki-link rendering. Preserve existing links and grove-media: attachment references; never fabricate attachment IDs.",
|
|
183
|
+
"For passage edits, read the exact current note and version, use preview_memory_patch with exact source splices, show the diff, then apply_memory_patch with the unchanged review token and operationId. Edit only the requested portion; never silently fall back to full-body replacement. Legacy supplied content is the complete intended body, not a changed fragment. Preserve unrequested facts, structure, task states, links and verbatim examples. Do not summarize away unrelated information or rewrite historical revisions. Apply this style to authored note bodies only, not ordinary replies, structured evidence or verbatim source excerpts."
|
|
184
|
+
].join("\n\n");
|
|
185
|
+
noteContentDescription = "The complete note body in CommonMark/GitHub-flavored Markdown (1\u20136000 characters). Write concise, human-readable prose; headings/lists only when useful. On edits this replaces the whole body, not a fragment: preserve unrequested content, links and attachment references. Do not wrap the whole note in a code fence.";
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// lib/shared/src/limits.ts
|
|
190
|
+
var NOTE_CONTENT_MAX, NOTE_TITLE_MAX, NOTE_EXCERPT_MAX, DOC_BYTES_MAX, WEB_URL_MAX, SHARE_CURSOR_MAX;
|
|
191
|
+
var init_limits = __esm({
|
|
192
|
+
"lib/shared/src/limits.ts"() {
|
|
193
|
+
"use strict";
|
|
194
|
+
init_define_GROVE_TELEMETRY();
|
|
195
|
+
NOTE_CONTENT_MAX = 6e3;
|
|
196
|
+
NOTE_TITLE_MAX = 110;
|
|
197
|
+
NOTE_EXCERPT_MAX = 160;
|
|
198
|
+
DOC_BYTES_MAX = 3 * 1024 * 1024;
|
|
199
|
+
WEB_URL_MAX = 4096;
|
|
200
|
+
SHARE_CURSOR_MAX = 2048;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// lib/shared/src/contracts.ts
|
|
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;
|
|
207
|
+
var init_contracts = __esm({
|
|
208
|
+
"lib/shared/src/contracts.ts"() {
|
|
209
|
+
"use strict";
|
|
210
|
+
init_define_GROVE_TELEMETRY();
|
|
211
|
+
init_note_writing();
|
|
212
|
+
init_limits();
|
|
213
|
+
capabilities = [
|
|
214
|
+
"memory:read",
|
|
215
|
+
"memory:write",
|
|
216
|
+
"memory:delete"
|
|
217
|
+
];
|
|
218
|
+
capabilitySchema = z7.enum(capabilities);
|
|
219
|
+
uuidSchema = z7.uuid();
|
|
220
|
+
operationSchema = z7.uuid().describe(
|
|
221
|
+
"New UUID for this write. Reuse the same UUID and identical arguments when retrying; changed arguments require a new operation."
|
|
222
|
+
);
|
|
223
|
+
expectedVersionSchema = z7.number().int().positive().describe(
|
|
224
|
+
"Current version returned by a fresh read of the exact target. On conflict, read again and review before making a new write; never guess a version."
|
|
225
|
+
);
|
|
226
|
+
captureSchema = z7.enum(["explicit", "automatic"]).default("explicit").describe(
|
|
227
|
+
"Use explicit only for a user-requested save/update; use automatic for agent-initiated capture. Honor private/paused automatic-capture settings. This flag is not proof of user consent."
|
|
228
|
+
);
|
|
229
|
+
kindSchema = z7.enum(["preference", "fact", "decision", "solution", "handoff"]).describe(
|
|
230
|
+
"Categorize by purpose: preference, fact, decision, solution or task handoff. This is not a notebook name or topic tag."
|
|
231
|
+
);
|
|
232
|
+
sourceSchema = z7.object({
|
|
233
|
+
agent: z7.enum(["website", "opencode", "claude", "codex", "cli", "import", "api"]).default("api"),
|
|
234
|
+
session: z7.string().max(128).optional(),
|
|
235
|
+
verification: z7.string().max(500).optional()
|
|
236
|
+
}).strict();
|
|
237
|
+
rememberSchema = z7.object({
|
|
238
|
+
operationId: operationSchema,
|
|
239
|
+
id: uuidSchema.optional(),
|
|
240
|
+
expectedVersion: expectedVersionSchema.optional(),
|
|
241
|
+
content: z7.string().trim().min(1).max(NOTE_CONTENT_MAX).describe(noteContentDescription),
|
|
242
|
+
capture: captureSchema,
|
|
243
|
+
archived: z7.boolean().default(false),
|
|
244
|
+
kind: kindSchema.default("fact"),
|
|
245
|
+
autoKind: z7.boolean().default(false),
|
|
246
|
+
projectId: uuidSchema.nullable().default(null).describe(
|
|
247
|
+
"Destination notebook UUID, or null for Personal. Omission defaults to Personal; use the requested or established permitted scope."
|
|
248
|
+
),
|
|
249
|
+
taskId: z7.string().min(1).max(128).optional(),
|
|
250
|
+
retentionDays: z7.number().int().min(1).max(365).nullable().optional(),
|
|
251
|
+
source: sourceSchema.default({ agent: "api" })
|
|
252
|
+
}).strict().superRefine((input, ctx) => {
|
|
253
|
+
if (input.autoKind && input.kind === "handoff")
|
|
254
|
+
ctx.addIssue({ code: "custom", message: "Handoff kind is explicit" });
|
|
255
|
+
if (Boolean(input.id) !== Boolean(input.expectedVersion)) {
|
|
256
|
+
ctx.addIssue({
|
|
257
|
+
code: "custom",
|
|
258
|
+
message: "Corrections require both id and expectedVersion"
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
if (input.id && input.archived)
|
|
262
|
+
ctx.addIssue({
|
|
263
|
+
code: "custom",
|
|
264
|
+
message: "Use the archive action for existing memories"
|
|
265
|
+
});
|
|
266
|
+
if (input.kind === "handoff" !== Boolean(input.taskId)) {
|
|
267
|
+
ctx.addIssue({
|
|
268
|
+
code: "custom",
|
|
269
|
+
message: "Handoffs require a stable taskId; durable memories cannot have one"
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
listSchema = z7.object({
|
|
274
|
+
projectId: uuidSchema.nullable().optional().describe(
|
|
275
|
+
"Filter by notebook UUID, or null for Personal. Omit to inspect all granted scopes; do not broaden automatic searches beyond the current scope."
|
|
276
|
+
),
|
|
277
|
+
kind: kindSchema.optional(),
|
|
278
|
+
tag: z7.string().trim().min(1).max(40).optional(),
|
|
279
|
+
sourceAgent: sourceSchema.shape.agent.removeDefault().optional(),
|
|
280
|
+
updatedAfter: z7.iso.datetime().optional(),
|
|
281
|
+
sort: z7.enum(["updated_desc", "updated_asc", "created_desc", "relevance"]).optional(),
|
|
282
|
+
lifetime: z7.enum(["permanent", "ephemeral"]).optional(),
|
|
283
|
+
status: z7.enum(["active", "archived", "expired", "all"]).default("active"),
|
|
284
|
+
query: z7.string().trim().max(1e3).optional(),
|
|
285
|
+
searchMode: z7.enum(["hybrid", "lexical"]).optional(),
|
|
286
|
+
cursor: z7.string().max(2048).optional(),
|
|
287
|
+
limit: z7.number().int().min(1).max(100).default(30)
|
|
288
|
+
}).strict();
|
|
289
|
+
recallSchema = z7.object({
|
|
290
|
+
query: z7.string().trim().max(1e3).default(""),
|
|
291
|
+
projectId: uuidSchema.nullable().default(null).describe(
|
|
292
|
+
"Current notebook UUID, or null for Personal (the default). Other notebooks are not included; includePersonal controls additional Personal context."
|
|
293
|
+
),
|
|
294
|
+
includePersonal: z7.boolean().default(true),
|
|
295
|
+
taskId: z7.string().max(128).optional(),
|
|
296
|
+
limit: z7.number().int().min(1).max(12).default(8),
|
|
297
|
+
maxCharacters: z7.number().int().min(256).max(NOTE_CONTENT_MAX).default(NOTE_CONTENT_MAX)
|
|
298
|
+
}).strict();
|
|
299
|
+
versionSchema = z7.object({
|
|
300
|
+
operationId: operationSchema,
|
|
301
|
+
expectedVersion: expectedVersionSchema,
|
|
302
|
+
revision: z7.number().int().positive().optional(),
|
|
303
|
+
durable: z7.boolean().optional()
|
|
304
|
+
}).strict();
|
|
305
|
+
forgetSchema = z7.object({
|
|
306
|
+
operationId: operationSchema,
|
|
307
|
+
items: z7.array(
|
|
308
|
+
z7.object({
|
|
309
|
+
id: uuidSchema,
|
|
310
|
+
expectedVersion: expectedVersionSchema
|
|
311
|
+
}).strict()
|
|
312
|
+
).min(1).max(50)
|
|
313
|
+
}).strict();
|
|
314
|
+
projectSchema = z7.object({
|
|
315
|
+
name: z7.string().trim().min(1).max(120),
|
|
316
|
+
identity: z7.string().trim().min(1).max(500),
|
|
317
|
+
parentId: uuidSchema.nullable().optional(),
|
|
318
|
+
expectedVersion: z7.number().int().positive().optional()
|
|
319
|
+
}).strict();
|
|
320
|
+
grantSchema = z7.object({
|
|
321
|
+
name: z7.string().trim().min(1).max(100),
|
|
322
|
+
capabilities: z7.array(capabilitySchema).min(1).max(3),
|
|
323
|
+
personal: z7.boolean().default(true),
|
|
324
|
+
allProjects: z7.boolean().default(false),
|
|
325
|
+
projectIds: z7.array(uuidSchema).max(100).default([]),
|
|
326
|
+
expiresAt: z7.iso.datetime().optional(),
|
|
327
|
+
writingEnabled: z7.boolean().optional(),
|
|
328
|
+
sharingEnabled: z7.boolean().optional()
|
|
329
|
+
}).strict();
|
|
330
|
+
connectionSchema = grantSchema.extend({
|
|
331
|
+
clientId: z7.string().min(1).max(500)
|
|
332
|
+
});
|
|
333
|
+
connectionUpdateSchema = grantSchema.extend({
|
|
334
|
+
expectedState: z7.string().regex(/^[a-f0-9]{64}$/).optional()
|
|
335
|
+
});
|
|
336
|
+
agentSchema = z7.enum(["opencode", "claude", "codex"]);
|
|
337
|
+
connectSchema = z7.object({
|
|
338
|
+
agent: agentSchema,
|
|
339
|
+
project: projectSchema.nullable()
|
|
340
|
+
}).strict();
|
|
341
|
+
approveConnectSchema = grantSchema.extend({
|
|
342
|
+
currentProject: z7.boolean().default(true)
|
|
343
|
+
});
|
|
344
|
+
memorySchema = z7.object({
|
|
345
|
+
id: uuidSchema,
|
|
346
|
+
projectId: uuidSchema.nullable(),
|
|
347
|
+
content: z7.string(),
|
|
348
|
+
kind: kindSchema,
|
|
349
|
+
autoKind: z7.boolean().optional(),
|
|
350
|
+
status: z7.enum(["active", "archived"]),
|
|
351
|
+
version: z7.number().int(),
|
|
352
|
+
source: sourceSchema,
|
|
353
|
+
taskId: z7.string().nullable(),
|
|
354
|
+
retentionDays: z7.number().int().nullable().optional(),
|
|
355
|
+
expiresAt: z7.string().nullable(),
|
|
356
|
+
purgeAt: z7.string().nullable(),
|
|
357
|
+
createdAt: z7.string(),
|
|
358
|
+
updatedAt: z7.string(),
|
|
359
|
+
indexing: z7.enum(["disabled", "pending", "ready", "failed"]),
|
|
360
|
+
enrichment: z7.custom().optional()
|
|
361
|
+
});
|
|
362
|
+
GroveError = class extends Error {
|
|
363
|
+
constructor(code2, message, status = 400, details) {
|
|
364
|
+
super(message);
|
|
365
|
+
this.code = code2;
|
|
366
|
+
this.status = status;
|
|
367
|
+
this.details = details;
|
|
368
|
+
this.name = "GroveError";
|
|
369
|
+
}
|
|
370
|
+
code;
|
|
371
|
+
status;
|
|
372
|
+
details;
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
// lib/shared/src/media.ts
|
|
378
|
+
function mediaReference(id2) {
|
|
379
|
+
if (!uuid.test(id2)) throw new Error("invalid_media_id");
|
|
380
|
+
return `grove-media:${id2}`;
|
|
381
|
+
}
|
|
382
|
+
function mediaObjectKey(accountId, mediaId, objectId) {
|
|
383
|
+
if (![accountId, mediaId, objectId].every((id2) => uuid.test(id2)))
|
|
384
|
+
throw new Error("invalid_media_key");
|
|
385
|
+
return `media/${accountId}/${mediaId}/${objectId}`;
|
|
386
|
+
}
|
|
387
|
+
function validateMediaKey(key2) {
|
|
388
|
+
const [prefix, accountId, mediaId, objectId, extra] = key2.split("/");
|
|
389
|
+
if (prefix !== "media" || extra !== void 0 || !accountId || !mediaId || !objectId || mediaObjectKey(accountId, mediaId, objectId) !== key2)
|
|
390
|
+
throw new Error("invalid_media_key");
|
|
391
|
+
return key2;
|
|
392
|
+
}
|
|
393
|
+
var imageLimits, imageMimeTypes, mediaMimeTypes, uuid;
|
|
394
|
+
var init_media = __esm({
|
|
395
|
+
"lib/shared/src/media.ts"() {
|
|
396
|
+
"use strict";
|
|
397
|
+
init_define_GROVE_TELEMETRY();
|
|
398
|
+
imageLimits = {
|
|
399
|
+
bytes: 10 * 1024 * 1024,
|
|
400
|
+
pixels: 24e6,
|
|
401
|
+
dimension: 1e4
|
|
402
|
+
};
|
|
403
|
+
imageMimeTypes = [
|
|
404
|
+
"image/png",
|
|
405
|
+
"image/jpeg",
|
|
406
|
+
"image/webp"
|
|
407
|
+
];
|
|
408
|
+
mediaMimeTypes = [...imageMimeTypes, "audio/wav"];
|
|
409
|
+
uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
// lib/shared/src/search.ts
|
|
414
|
+
function noteTitle2(content3, organized) {
|
|
415
|
+
const first = content3.trim().split("\n")[0];
|
|
416
|
+
const heading = first.match(/^#{1,6}\s+(.+)/)?.[1].trim();
|
|
417
|
+
if (!heading && organized) return organized;
|
|
418
|
+
const text5 = (heading || first).slice(0, NOTE_TITLE_MAX);
|
|
419
|
+
return /[\uD800-\uDBFF]$/.test(text5) ? text5.slice(0, -1) : text5;
|
|
420
|
+
}
|
|
421
|
+
function plainExcerpt(content3, length = NOTE_EXCERPT_MAX) {
|
|
422
|
+
const text5 = content3.trim().replace(/^#{1,6}[ \t]+[^\n]+\n+/, "").replace(/^[ \t]*(?:`{3,}|~{3,})[^\n]*$/gm, "").replace(/^[ \t]*(?:>[ \t]*)+/gm, "").replace(/^[ \t]*(?:[-+*]|\d+[.)])[ \t]+(?:\[[ xX]\][ \t]*)?/gm, "").replace(/!?\[([^\]\n]+)\]\([^\n)]*\)/g, "$1").replace(/[#*`_]/g, "").replace(/\s+/g, " ").trim();
|
|
423
|
+
return text5.length > length ? `${text5.slice(0, length).trimEnd()}\u2026` : text5;
|
|
424
|
+
}
|
|
425
|
+
function searchExpansion(query) {
|
|
426
|
+
if (!/^[\p{L}\p{N}\s_]+$/u.test(query) || /\bor\b/i.test(query)) return;
|
|
427
|
+
const tokens = query.match(/[\p{L}\p{N}]+/gu) ?? [];
|
|
428
|
+
if (!tokens.length || tokens.length > 16 || tokens.some((t) => t.length > 64))
|
|
429
|
+
return;
|
|
430
|
+
return {
|
|
431
|
+
tokens,
|
|
432
|
+
prefix: tokens.at(-1).length >= 2 ? tokens.map((t, i) => t + (i === tokens.length - 1 ? ":*" : "")).join(" & ") : void 0
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
var init_search = __esm({
|
|
436
|
+
"lib/shared/src/search.ts"() {
|
|
437
|
+
"use strict";
|
|
438
|
+
init_define_GROVE_TELEMETRY();
|
|
439
|
+
init_limits();
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
// lib/shared/src/share-durations.ts
|
|
444
|
+
var init_share_durations = __esm({
|
|
445
|
+
"lib/shared/src/share-durations.ts"() {
|
|
446
|
+
"use strict";
|
|
447
|
+
init_define_GROVE_TELEMETRY();
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
// lib/shared/src/sharing.ts
|
|
452
|
+
import { z as z23 } from "zod";
|
|
453
|
+
var shareTokenSchema, shareDurationSchema, shareMutationSchema, shareEnableSchema, shareScopeSchema, publicShareQuerySchema, notebook, publicNoteSchema, publicShareSchema;
|
|
454
|
+
var init_sharing = __esm({
|
|
455
|
+
"lib/shared/src/sharing.ts"() {
|
|
456
|
+
"use strict";
|
|
457
|
+
init_define_GROVE_TELEMETRY();
|
|
458
|
+
init_contracts();
|
|
459
|
+
init_search();
|
|
460
|
+
init_limits();
|
|
461
|
+
init_share_durations();
|
|
462
|
+
shareTokenSchema = z23.string().regex(/^gsh_[A-Za-z0-9_-]{43}$/);
|
|
463
|
+
shareDurationSchema = z23.enum([
|
|
464
|
+
"1h",
|
|
465
|
+
"4h",
|
|
466
|
+
"1d",
|
|
467
|
+
"1w",
|
|
468
|
+
"2w",
|
|
469
|
+
"1mo"
|
|
470
|
+
]);
|
|
471
|
+
shareMutationSchema = z23.object({
|
|
472
|
+
operationId: operationSchema,
|
|
473
|
+
expectedVersion: z23.number().int().positive()
|
|
474
|
+
}).strict();
|
|
475
|
+
shareEnableSchema = shareMutationSchema.extend({
|
|
476
|
+
expectedVersion: z23.number().int().min(0),
|
|
477
|
+
expectedTargetVersion: z23.number().int().positive(),
|
|
478
|
+
includeDescendants: z23.boolean().default(false),
|
|
479
|
+
duration: shareDurationSchema.nullable().optional()
|
|
480
|
+
});
|
|
481
|
+
shareScopeSchema = shareMutationSchema.extend({
|
|
482
|
+
includeDescendants: z23.boolean().optional(),
|
|
483
|
+
duration: shareDurationSchema.nullable().optional()
|
|
484
|
+
}).refine(
|
|
485
|
+
(value) => value.includeDescendants !== void 0 || value.duration !== void 0,
|
|
486
|
+
"Choose a sharing setting to change"
|
|
487
|
+
);
|
|
488
|
+
publicShareQuerySchema = z23.object({
|
|
489
|
+
cursor: z23.string().max(SHARE_CURSOR_MAX).optional(),
|
|
490
|
+
limit: z23.coerce.number().int().min(1).max(100).default(30)
|
|
491
|
+
}).strict();
|
|
492
|
+
notebook = z23.object({ id: uuidSchema, name: z23.string() }).strict();
|
|
493
|
+
publicNoteSchema = z23.object({
|
|
494
|
+
id: uuidSchema,
|
|
495
|
+
title: z23.string(),
|
|
496
|
+
content: z23.string(),
|
|
497
|
+
updatedAt: z23.string(),
|
|
498
|
+
linkedNoteIds: z23.array(uuidSchema)
|
|
499
|
+
}).strict();
|
|
500
|
+
publicShareSchema = z23.object({
|
|
501
|
+
kind: z23.enum(["note", "notebook"]),
|
|
502
|
+
root: notebook,
|
|
503
|
+
notebook: notebook.nullable(),
|
|
504
|
+
note: publicNoteSchema.nullable(),
|
|
505
|
+
notebooks: z23.array(notebook),
|
|
506
|
+
notes: z23.array(
|
|
507
|
+
publicNoteSchema.pick({ id: true, title: true, updatedAt: true })
|
|
508
|
+
),
|
|
509
|
+
nextCursor: z23.string().nullable()
|
|
510
|
+
}).strict();
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
// lib/memory/src/media.ts
|
|
515
|
+
var media_exports = {};
|
|
516
|
+
__export(media_exports, {
|
|
517
|
+
MediaAttachments: () => MediaAttachments,
|
|
518
|
+
mediaDescriptor: () => mediaDescriptor
|
|
519
|
+
});
|
|
520
|
+
import { createHash as createHash17, randomUUID as randomUUID12 } from "node:crypto";
|
|
521
|
+
var missing6, conflict3, mediaDescriptor, MediaAttachments;
|
|
522
|
+
var init_media2 = __esm({
|
|
523
|
+
"lib/memory/src/media.ts"() {
|
|
524
|
+
"use strict";
|
|
525
|
+
init_define_GROVE_TELEMETRY();
|
|
526
|
+
init_contracts();
|
|
527
|
+
init_media();
|
|
528
|
+
init_sharing();
|
|
529
|
+
missing6 = () => new GroveError("not_found", "Media is unavailable", 404);
|
|
530
|
+
conflict3 = () => new GroveError(
|
|
531
|
+
"media_changed",
|
|
532
|
+
"The note or upload changed. Reload and retry.",
|
|
533
|
+
409
|
|
534
|
+
);
|
|
535
|
+
mediaDescriptor = (row) => ({
|
|
536
|
+
id: row.id,
|
|
537
|
+
reference: mediaReference(row.id),
|
|
538
|
+
mime: row.mime,
|
|
539
|
+
bytes: row.bytes,
|
|
540
|
+
width: row.width,
|
|
541
|
+
height: row.height,
|
|
542
|
+
durationMs: row.durationMs ?? null
|
|
543
|
+
});
|
|
544
|
+
MediaAttachments = class {
|
|
545
|
+
constructor(service) {
|
|
546
|
+
this.service = service;
|
|
547
|
+
}
|
|
548
|
+
service;
|
|
549
|
+
async note(trx, id2, grant) {
|
|
550
|
+
const note = await trx("memories").where({ id: id2 }).where(
|
|
551
|
+
(q) => q.whereNull("expiresAt").orWhere("expiresAt", ">", trx.fn.now())
|
|
552
|
+
).first();
|
|
553
|
+
if (!note || grant && (note.projectId === null ? !grant.personal : !(grant.allProjects || grant.projectIds.includes(note.projectId))))
|
|
554
|
+
throw missing6();
|
|
555
|
+
return note;
|
|
556
|
+
}
|
|
557
|
+
async claim(principal, input) {
|
|
558
|
+
return this.service.access(
|
|
559
|
+
principal,
|
|
560
|
+
"memory:write",
|
|
561
|
+
async ({ trx, account, grant }) => {
|
|
562
|
+
const note = await this.note(trx, input.memoryId, grant);
|
|
563
|
+
if (note.status !== "active") throw missing6();
|
|
564
|
+
const existing = await trx("media_objects").where({ id: input.id }).first();
|
|
565
|
+
if (existing && (existing.memoryId !== input.memoryId || existing.mime !== input.mime || existing.bytes !== input.bytes || existing.sha256 !== input.sha256))
|
|
566
|
+
throw conflict3();
|
|
567
|
+
if (existing?.status === "ready") return { row: existing, replay: true };
|
|
568
|
+
if (note.version !== input.version) throw conflict3();
|
|
569
|
+
if (existing?.status === "pending" && new Date(existing.leaseUntil) > /* @__PURE__ */ new Date())
|
|
570
|
+
throw conflict3();
|
|
571
|
+
const quota = await trx("accounts").where({ id: account.id }).first("mediaBytes", "mediaAttempts");
|
|
572
|
+
if (Number(quota.mediaBytes) + input.bytes > 1024 * 1024 * 1024 || quota.mediaAttempts >= 1e3)
|
|
573
|
+
throw new GroveError("media_quota", "Media storage limit reached", 429);
|
|
574
|
+
const leaseId = randomUUID12(), objectKey = mediaObjectKey(account.id, input.id, leaseId);
|
|
575
|
+
const values = {
|
|
576
|
+
memoryId: input.memoryId,
|
|
577
|
+
bytes: input.bytes,
|
|
578
|
+
mime: input.mime,
|
|
579
|
+
sha256: input.sha256,
|
|
580
|
+
status: "pending",
|
|
581
|
+
leaseId,
|
|
582
|
+
objectKey,
|
|
583
|
+
leaseUntil: trx.raw("clock_timestamp()+interval '120 seconds'")
|
|
584
|
+
};
|
|
585
|
+
const [row] = existing ? await trx("media_objects").where({ id: input.id }).update(values).returning("*") : await trx("media_objects").insert({ accountId: account.id, id: input.id, ...values }).returning("*");
|
|
586
|
+
await trx("media_upload_attempts").insert({
|
|
587
|
+
accountId: account.id,
|
|
588
|
+
mediaId: input.id,
|
|
589
|
+
id: leaseId,
|
|
590
|
+
objectKey
|
|
591
|
+
});
|
|
592
|
+
await trx("accounts").where({ id: account.id }).increment({ mediaBytes: input.bytes, mediaAttempts: 1 });
|
|
593
|
+
return { row, replay: false };
|
|
594
|
+
}
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
async finish(principal, input, leaseId, dimensions) {
|
|
598
|
+
return this.service.access(
|
|
599
|
+
principal,
|
|
600
|
+
"memory:write",
|
|
601
|
+
async ({ trx, grant }) => {
|
|
602
|
+
const note = await this.note(trx, input.memoryId, grant);
|
|
603
|
+
if (note.status !== "active" || note.version !== input.version)
|
|
604
|
+
throw conflict3();
|
|
605
|
+
const [row] = await trx("media_objects").where({
|
|
606
|
+
id: input.id,
|
|
607
|
+
memoryId: input.memoryId,
|
|
608
|
+
leaseId,
|
|
609
|
+
status: "pending"
|
|
610
|
+
}).where("leaseUntil", ">", trx.raw("clock_timestamp()")).update({
|
|
611
|
+
width: dimensions.width,
|
|
612
|
+
height: dimensions.height,
|
|
613
|
+
durationMs: dimensions.durationMs ?? null,
|
|
614
|
+
status: "ready"
|
|
615
|
+
}).returning("*");
|
|
616
|
+
if (!row) throw conflict3();
|
|
617
|
+
await trx("accounts").where({ id: principal.accountId }).increment("exportVersion", 1);
|
|
618
|
+
return mediaDescriptor(row);
|
|
619
|
+
}
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
async fail(principal, id2, leaseId) {
|
|
623
|
+
return this.service.access(
|
|
624
|
+
principal,
|
|
625
|
+
"memory:write",
|
|
626
|
+
async ({ trx, grant }) => {
|
|
627
|
+
const target2 = await trx("media_objects").where({ id: id2, leaseId, status: "pending" }).first("memoryId");
|
|
628
|
+
if (!target2) return;
|
|
629
|
+
await this.note(trx, target2.memoryId, grant);
|
|
630
|
+
await trx("media_objects").where({ id: id2, leaseId, status: "pending" }).update({ status: "failed" });
|
|
631
|
+
}
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
async read(principal, memoryId, id2, version2) {
|
|
635
|
+
return this.service.access(
|
|
636
|
+
principal,
|
|
637
|
+
"memory:read",
|
|
638
|
+
async ({ trx, grant }) => {
|
|
639
|
+
const note = await this.note(trx, memoryId, grant);
|
|
640
|
+
const row = await trx("media_objects as o").join("media_revision_bindings as b", function() {
|
|
641
|
+
this.on("b.accountId", "=", "o.accountId").andOn(
|
|
642
|
+
"b.mediaId",
|
|
643
|
+
"=",
|
|
644
|
+
"o.id"
|
|
645
|
+
);
|
|
646
|
+
}).where({
|
|
647
|
+
"o.id": id2,
|
|
648
|
+
"o.memoryId": memoryId,
|
|
649
|
+
"o.status": "ready",
|
|
650
|
+
"b.memoryId": memoryId,
|
|
651
|
+
"b.version": version2 ?? note.version
|
|
652
|
+
}).select("o.*").first();
|
|
653
|
+
if (!row) throw missing6();
|
|
654
|
+
return {
|
|
655
|
+
key: row.objectKey,
|
|
656
|
+
mime: row.mime,
|
|
657
|
+
bytes: row.bytes,
|
|
658
|
+
sha256: row.sha256
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
async publicRead(token, memoryId, id2) {
|
|
664
|
+
if (!shareTokenSchema.safeParse(token).success) throw missing6();
|
|
665
|
+
const admitted = await this.service.db.raw(
|
|
666
|
+
"SELECT grove_share_admit('global') AS allowed"
|
|
667
|
+
);
|
|
668
|
+
if (!admitted.rows[0].allowed)
|
|
669
|
+
throw new GroveError("rate_limited", "Retry later", 429);
|
|
670
|
+
const { rows } = await this.service.db.raw(
|
|
671
|
+
"SELECT grove_public_media(?,?::uuid,?::uuid) AS value",
|
|
672
|
+
[createHash17("sha256").update(token).digest("hex"), memoryId, id2]
|
|
673
|
+
);
|
|
674
|
+
const value = rows[0].value;
|
|
675
|
+
if (value?.limited)
|
|
676
|
+
throw new GroveError("rate_limited", "Retry later", 429);
|
|
677
|
+
if (!value) throw missing6();
|
|
678
|
+
return value;
|
|
679
|
+
}
|
|
680
|
+
async transcript(principal, memoryId, id2) {
|
|
681
|
+
const object = await this.read(principal, memoryId, id2);
|
|
682
|
+
if (object.mime !== "audio/wav") throw missing6();
|
|
683
|
+
return this.service.access(
|
|
684
|
+
principal,
|
|
685
|
+
"memory:read",
|
|
686
|
+
async ({ trx, grant }) => {
|
|
687
|
+
await this.note(trx, memoryId, grant);
|
|
688
|
+
const row = await trx("media_transcripts").where({ mediaId: id2 }).select("text", "version").first();
|
|
689
|
+
return row ?? { text: "", version: 0 };
|
|
690
|
+
}
|
|
691
|
+
);
|
|
692
|
+
}
|
|
693
|
+
async listForNote(principal, memoryId, version2) {
|
|
694
|
+
return this.service.access(
|
|
695
|
+
principal,
|
|
696
|
+
"memory:read",
|
|
697
|
+
async ({ trx, grant }) => {
|
|
698
|
+
const note = await this.note(trx, memoryId, grant);
|
|
699
|
+
const bound = version2 ?? note.version;
|
|
700
|
+
const rows = await trx("media_objects as o").join("media_revision_bindings as b", function() {
|
|
701
|
+
this.on("b.accountId", "=", "o.accountId").andOn(
|
|
702
|
+
"b.mediaId",
|
|
703
|
+
"=",
|
|
704
|
+
"o.id"
|
|
705
|
+
);
|
|
706
|
+
}).leftJoin("media_transcripts as t", function() {
|
|
707
|
+
this.on("t.accountId", "=", "o.accountId").andOn(
|
|
708
|
+
"t.mediaId",
|
|
709
|
+
"=",
|
|
710
|
+
"o.id"
|
|
711
|
+
);
|
|
712
|
+
}).where({
|
|
713
|
+
"o.memoryId": memoryId,
|
|
714
|
+
"o.status": "ready",
|
|
715
|
+
"b.memoryId": memoryId,
|
|
716
|
+
"b.version": bound
|
|
717
|
+
}).select(
|
|
718
|
+
"o.id",
|
|
719
|
+
"o.mime",
|
|
720
|
+
"o.bytes",
|
|
721
|
+
"o.width",
|
|
722
|
+
"o.height",
|
|
723
|
+
"o.durationMs",
|
|
724
|
+
"t.version as transcriptVersion",
|
|
725
|
+
"t.text as transcriptText"
|
|
726
|
+
).orderBy("o.id");
|
|
727
|
+
return rows.map((row) => ({
|
|
728
|
+
id: row.id,
|
|
729
|
+
reference: mediaReference(row.id),
|
|
730
|
+
mime: row.mime,
|
|
731
|
+
bytes: row.bytes,
|
|
732
|
+
width: row.width,
|
|
733
|
+
height: row.height,
|
|
734
|
+
durationMs: row.durationMs ?? null,
|
|
735
|
+
version: bound,
|
|
736
|
+
transcriptVersion: row.transcriptVersion ?? 0,
|
|
737
|
+
hasTranscript: typeof row.transcriptText === "string" && row.transcriptText.length > 0
|
|
738
|
+
}));
|
|
739
|
+
}
|
|
740
|
+
);
|
|
741
|
+
}
|
|
742
|
+
async describeForNote(principal, memoryId, id2, version2) {
|
|
743
|
+
const items = await this.listForNote(principal, memoryId, version2);
|
|
744
|
+
const found = items.find((item) => item.id === id2);
|
|
745
|
+
if (!found) throw missing6();
|
|
746
|
+
return found;
|
|
747
|
+
}
|
|
748
|
+
async saveTranscript(principal, memoryId, id2, input) {
|
|
749
|
+
return this.service.access(
|
|
750
|
+
principal,
|
|
751
|
+
"memory:write",
|
|
752
|
+
async ({ trx, account, grant }) => {
|
|
753
|
+
const note = await this.note(trx, memoryId, grant);
|
|
754
|
+
const object = await trx("media_objects").where({ id: id2, memoryId, mime: "audio/wav", status: "ready" }).first();
|
|
755
|
+
if (!object || !await trx("media_revision_bindings").where({ mediaId: id2, memoryId, version: note.version }).first())
|
|
756
|
+
throw missing6();
|
|
757
|
+
const old = await trx("media_transcripts").where({ mediaId: id2 }).first(), fingerprint2 = createHash17("sha256").update(JSON.stringify(input)).digest("hex");
|
|
758
|
+
if (old?.operationId === input.operationId) {
|
|
759
|
+
if (old.fingerprint !== fingerprint2) throw conflict3();
|
|
760
|
+
return { text: old.text, version: old.version };
|
|
761
|
+
}
|
|
762
|
+
if ((old?.version ?? 0) !== input.expectedVersion) throw conflict3();
|
|
763
|
+
const version2 = input.expectedVersion + 1;
|
|
764
|
+
await trx("media_transcripts").insert({
|
|
765
|
+
accountId: account.id,
|
|
766
|
+
mediaId: id2,
|
|
767
|
+
text: input.text,
|
|
768
|
+
version: version2,
|
|
769
|
+
operationId: input.operationId,
|
|
770
|
+
fingerprint: fingerprint2
|
|
771
|
+
}).onConflict(["accountId", "mediaId"]).merge({
|
|
772
|
+
text: input.text,
|
|
773
|
+
version: version2,
|
|
774
|
+
operationId: input.operationId,
|
|
775
|
+
fingerprint: fingerprint2,
|
|
776
|
+
updatedAt: trx.fn.now()
|
|
777
|
+
});
|
|
778
|
+
await trx("media_transcript_revisions").insert({
|
|
779
|
+
accountId: account.id,
|
|
780
|
+
mediaId: id2,
|
|
781
|
+
version: version2,
|
|
782
|
+
text: input.text
|
|
783
|
+
});
|
|
784
|
+
await trx("accounts").where({ id: account.id }).increment("exportVersion", 1);
|
|
785
|
+
return { text: input.text, version: version2 };
|
|
786
|
+
}
|
|
787
|
+
);
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
});
|
|
792
|
+
|
|
173
793
|
// node_modules/.pnpm/@opentelemetry+api@1.10.0/node_modules/@opentelemetry/api/dist/diag/types.mjs
|
|
174
794
|
var DiagLogLevel;
|
|
175
795
|
var init_types = __esm({
|
|
@@ -1957,6 +2577,22 @@ import { Model, knexSnakeCaseMappers } from "objection";
|
|
|
1957
2577
|
// lib/database/src/migrations.ts
|
|
1958
2578
|
init_define_GROVE_TELEMETRY();
|
|
1959
2579
|
|
|
2580
|
+
// lib/database/src/writing-allowance-migration.ts
|
|
2581
|
+
init_define_GROVE_TELEMETRY();
|
|
2582
|
+
var writingAllowance = {
|
|
2583
|
+
name: "20261107_041_writing_allowance",
|
|
2584
|
+
async up(db) {
|
|
2585
|
+
await db.raw(`
|
|
2586
|
+
ALTER TABLE action_usage DROP CONSTRAINT action_usage_metric_check;
|
|
2587
|
+
ALTER TABLE action_usage ADD CONSTRAINT action_usage_metric_check
|
|
2588
|
+
CHECK(metric IN ('recall','ask','organization','assistance','writing'));
|
|
2589
|
+
`);
|
|
2590
|
+
},
|
|
2591
|
+
async down() {
|
|
2592
|
+
throw new Error("Use a forward migration");
|
|
2593
|
+
}
|
|
2594
|
+
};
|
|
2595
|
+
|
|
1960
2596
|
// lib/database/src/structured-document-migration.ts
|
|
1961
2597
|
init_define_GROVE_TELEMETRY();
|
|
1962
2598
|
var structuredDocuments = {
|
|
@@ -2191,6 +2827,72 @@ var nativeSharing = {
|
|
|
2191
2827
|
}
|
|
2192
2828
|
};
|
|
2193
2829
|
|
|
2830
|
+
// lib/database/src/trial-migration.ts
|
|
2831
|
+
init_define_GROVE_TELEMETRY();
|
|
2832
|
+
var billingTrial = {
|
|
2833
|
+
name: "20261107_040_billing_trial",
|
|
2834
|
+
async up(db) {
|
|
2835
|
+
await db.raw(`
|
|
2836
|
+
CREATE TABLE billing_trials (
|
|
2837
|
+
account_id uuid PRIMARY KEY REFERENCES accounts(id),
|
|
2838
|
+
consumed_at timestamptz NOT NULL DEFAULT now(),
|
|
2839
|
+
subscription_id text,
|
|
2840
|
+
reset_by uuid REFERENCES accounts(id),
|
|
2841
|
+
reset_at timestamptz
|
|
2842
|
+
);
|
|
2843
|
+
`);
|
|
2844
|
+
await db.raw(
|
|
2845
|
+
"ALTER TABLE billing_trials ENABLE ROW LEVEL SECURITY"
|
|
2846
|
+
);
|
|
2847
|
+
await db.raw("ALTER TABLE billing_trials FORCE ROW LEVEL SECURITY");
|
|
2848
|
+
await db.raw(
|
|
2849
|
+
`CREATE POLICY tenant ON billing_trials USING (account_id = NULLIF(current_setting('grove.account_id',true),'')::uuid) WITH CHECK (account_id = NULLIF(current_setting('grove.account_id',true),'')::uuid)`
|
|
2850
|
+
);
|
|
2851
|
+
await db.raw("GRANT SELECT, INSERT, UPDATE ON billing_trials TO grove_runtime");
|
|
2852
|
+
await db.raw("GRANT SELECT ON billing_trials TO grove_worker");
|
|
2853
|
+
await db.raw(`
|
|
2854
|
+
CREATE FUNCTION grove_admin_trial_reset(target uuid, operation uuid, explanation text) RETURNS jsonb
|
|
2855
|
+
LANGUAGE plpgsql SECURITY DEFINER SET search_path=pg_catalog,public,pg_temp AS $$
|
|
2856
|
+
DECLARE actor uuid; previous public.system_admin_audit; original text; deleted integer;
|
|
2857
|
+
BEGIN
|
|
2858
|
+
actor := public.grove_admin_guard();
|
|
2859
|
+
IF target IS NULL OR operation IS NULL OR explanation IS NULL OR length(trim(explanation)) NOT BETWEEN 3 AND 300 THEN
|
|
2860
|
+
RAISE EXCEPTION 'invalid_request' USING ERRCODE='GA002';
|
|
2861
|
+
END IF;
|
|
2862
|
+
SELECT * INTO previous FROM public.system_admin_audit WHERE id=operation;
|
|
2863
|
+
IF FOUND THEN
|
|
2864
|
+
IF previous.kind<>'change' OR previous.actor_id IS DISTINCT FROM actor OR previous.account_id IS DISTINCT FROM target
|
|
2865
|
+
OR previous.reason IS DISTINCT FROM explanation THEN
|
|
2866
|
+
RAISE EXCEPTION 'operation_conflict' USING ERRCODE='GA003';
|
|
2867
|
+
END IF;
|
|
2868
|
+
RETURN previous.after;
|
|
2869
|
+
END IF;
|
|
2870
|
+
original := current_setting('grove.account_id',true);
|
|
2871
|
+
PERFORM set_config('grove.account_id',target::text,true);
|
|
2872
|
+
DELETE FROM public.billing_trials WHERE account_id=target;
|
|
2873
|
+
GET DIAGNOSTICS deleted = ROW_COUNT;
|
|
2874
|
+
PERFORM set_config('grove.account_id',COALESCE(original,''),true);
|
|
2875
|
+
IF deleted = 0 THEN
|
|
2876
|
+
RAISE EXCEPTION 'trial_not_consumed' USING ERRCODE='GA007';
|
|
2877
|
+
END IF;
|
|
2878
|
+
INSERT INTO public.system_admin_audit(id,actor_id,account_id,kind,reason,before,after)
|
|
2879
|
+
VALUES(operation,actor,target,'change',explanation,
|
|
2880
|
+
jsonb_build_object('trialEligible',false),
|
|
2881
|
+
jsonb_build_object('trialEligible',true));
|
|
2882
|
+
RETURN jsonb_build_object('accountId',target,'eligible',true);
|
|
2883
|
+
EXCEPTION WHEN OTHERS THEN
|
|
2884
|
+
IF original IS NOT NULL THEN PERFORM set_config('grove.account_id',original,true); END IF;
|
|
2885
|
+
RAISE;
|
|
2886
|
+
END $$;
|
|
2887
|
+
REVOKE ALL ON FUNCTION grove_admin_trial_reset(uuid,uuid,text) FROM PUBLIC,grove_runtime,grove_worker;
|
|
2888
|
+
GRANT EXECUTE ON FUNCTION grove_admin_trial_reset(uuid,uuid,text) TO grove_runtime;
|
|
2889
|
+
`);
|
|
2890
|
+
},
|
|
2891
|
+
async down() {
|
|
2892
|
+
throw new Error("Use a forward migration");
|
|
2893
|
+
}
|
|
2894
|
+
};
|
|
2895
|
+
|
|
2194
2896
|
// lib/database/src/action-usage-migration.ts
|
|
2195
2897
|
init_define_GROVE_TELEMETRY();
|
|
2196
2898
|
var actionUsage = {
|
|
@@ -5612,7 +6314,9 @@ var migrations = [
|
|
|
5612
6314
|
structuredDocuments,
|
|
5613
6315
|
browserCapture,
|
|
5614
6316
|
writingTools,
|
|
5615
|
-
nativeSharing
|
|
6317
|
+
nativeSharing,
|
|
6318
|
+
billingTrial,
|
|
6319
|
+
writingAllowance
|
|
5616
6320
|
];
|
|
5617
6321
|
var migrationSource = {
|
|
5618
6322
|
getMigrations: async () => migrations,
|
|
@@ -5761,6 +6465,8 @@ import { z } from "zod";
|
|
|
5761
6465
|
init_define_GROVE_TELEMETRY();
|
|
5762
6466
|
var billingFlagKey = "billing-enabled";
|
|
5763
6467
|
var billingPriceFlagKey = "billing-pro-monthly-usd";
|
|
6468
|
+
var billingPriceYearlyFlagKey = "billing-pro-yearly-usd";
|
|
6469
|
+
var trialDurationDays = 7;
|
|
5764
6470
|
var resourceLimits = {
|
|
5765
6471
|
free: {
|
|
5766
6472
|
notes: 1e4,
|
|
@@ -5769,6 +6475,7 @@ var resourceLimits = {
|
|
|
5769
6475
|
ask: 300,
|
|
5770
6476
|
organization: 1e3,
|
|
5771
6477
|
assistance: 50,
|
|
6478
|
+
writing: 100,
|
|
5772
6479
|
concurrency: 2
|
|
5773
6480
|
},
|
|
5774
6481
|
pro: {
|
|
@@ -5778,6 +6485,7 @@ var resourceLimits = {
|
|
|
5778
6485
|
ask: 1500,
|
|
5779
6486
|
organization: 5e3,
|
|
5780
6487
|
assistance: 250,
|
|
6488
|
+
writing: 1e3,
|
|
5781
6489
|
concurrency: 2
|
|
5782
6490
|
}
|
|
5783
6491
|
};
|
|
@@ -5883,12 +6591,14 @@ var serverSchema = z.object({
|
|
|
5883
6591
|
resourceLimits.free.organization
|
|
5884
6592
|
),
|
|
5885
6593
|
BILLING_FREE_ASSISTANCE_MONTHLY: allowance(resourceLimits.free.assistance),
|
|
6594
|
+
BILLING_FREE_WRITING_MONTHLY: allowance(resourceLimits.free.writing),
|
|
5886
6595
|
BILLING_PRO_NOTES: allowance(resourceLimits.pro.notes),
|
|
5887
6596
|
BILLING_PRO_NOTEBOOKS: allowance(resourceLimits.pro.notebooks),
|
|
5888
6597
|
BILLING_PRO_RECALL_MONTHLY: allowance(resourceLimits.pro.recall),
|
|
5889
6598
|
BILLING_PRO_ASK_MONTHLY: allowance(resourceLimits.pro.ask),
|
|
5890
6599
|
BILLING_PRO_ORGANIZATION_MONTHLY: allowance(resourceLimits.pro.organization),
|
|
5891
6600
|
BILLING_PRO_ASSISTANCE_MONTHLY: allowance(resourceLimits.pro.assistance),
|
|
6601
|
+
BILLING_PRO_WRITING_MONTHLY: allowance(resourceLimits.pro.writing),
|
|
5892
6602
|
// Reject old deployment settings instead of silently treating characters as time.
|
|
5893
6603
|
BILLING_FREE_SYNTHESIS_MONTHLY_CHARACTERS: z.string().optional(),
|
|
5894
6604
|
BILLING_PRO_SYNTHESIS_MONTHLY_CHARACTERS: z.string().optional(),
|
|
@@ -6036,10 +6746,10 @@ function isSpeechVoice(value) {
|
|
|
6036
6746
|
// lib/memory/src/index.ts
|
|
6037
6747
|
init_define_GROVE_TELEMETRY();
|
|
6038
6748
|
import {
|
|
6039
|
-
createHash as
|
|
6749
|
+
createHash as createHash18,
|
|
6040
6750
|
createHmac as createHmac3,
|
|
6041
6751
|
randomBytes as randomBytes2,
|
|
6042
|
-
randomUUID as
|
|
6752
|
+
randomUUID as randomUUID13,
|
|
6043
6753
|
timingSafeEqual as timingSafeEqual2
|
|
6044
6754
|
} from "node:crypto";
|
|
6045
6755
|
|
|
@@ -14210,194 +14920,40 @@ var settingsUpdateSchema = z6.object({
|
|
|
14210
14920
|
|
|
14211
14921
|
// lib/shared/src/memory-tools.ts
|
|
14212
14922
|
init_define_GROVE_TELEMETRY();
|
|
14213
|
-
|
|
14214
|
-
|
|
14215
|
-
// lib/shared/src/contracts.ts
|
|
14216
|
-
init_define_GROVE_TELEMETRY();
|
|
14217
|
-
import { z as z7 } from "zod";
|
|
14923
|
+
init_contracts();
|
|
14924
|
+
import { z as z10 } from "zod";
|
|
14218
14925
|
|
|
14219
|
-
// lib/shared/src/
|
|
14926
|
+
// lib/shared/src/agent-media.ts
|
|
14220
14927
|
init_define_GROVE_TELEMETRY();
|
|
14221
|
-
|
|
14222
|
-
|
|
14223
|
-
|
|
14224
|
-
|
|
14225
|
-
|
|
14226
|
-
|
|
14227
|
-
|
|
14228
|
-
|
|
14229
|
-
// lib/shared/src/contracts.ts
|
|
14230
|
-
var capabilities = [
|
|
14231
|
-
"memory:read",
|
|
14232
|
-
"memory:write",
|
|
14233
|
-
"memory:delete"
|
|
14234
|
-
];
|
|
14235
|
-
var capabilitySchema = z7.enum(capabilities);
|
|
14236
|
-
var uuidSchema = z7.uuid();
|
|
14237
|
-
var operationSchema = z7.uuid().describe(
|
|
14238
|
-
"New UUID for this write. Reuse the same UUID and identical arguments when retrying; changed arguments require a new operation."
|
|
14239
|
-
);
|
|
14240
|
-
var expectedVersionSchema = z7.number().int().positive().describe(
|
|
14241
|
-
"Current version returned by a fresh read of the exact target. On conflict, read again and review before making a new write; never guess a version."
|
|
14242
|
-
);
|
|
14243
|
-
var captureSchema = z7.enum(["explicit", "automatic"]).default("explicit").describe(
|
|
14244
|
-
"Use explicit only for a user-requested save/update; use automatic for agent-initiated capture. Honor private/paused automatic-capture settings. This flag is not proof of user consent."
|
|
14245
|
-
);
|
|
14246
|
-
var kindSchema = z7.enum(["preference", "fact", "decision", "solution", "handoff"]).describe(
|
|
14247
|
-
"Categorize by purpose: preference, fact, decision, solution or task handoff. This is not a notebook name or topic tag."
|
|
14248
|
-
);
|
|
14249
|
-
var sourceSchema = z7.object({
|
|
14250
|
-
agent: z7.enum(["website", "opencode", "claude", "codex", "cli", "import", "api"]).default("api"),
|
|
14251
|
-
session: z7.string().max(128).optional(),
|
|
14252
|
-
verification: z7.string().max(500).optional()
|
|
14253
|
-
}).strict();
|
|
14254
|
-
var rememberSchema = z7.object({
|
|
14255
|
-
operationId: operationSchema,
|
|
14256
|
-
id: uuidSchema.optional(),
|
|
14257
|
-
expectedVersion: expectedVersionSchema.optional(),
|
|
14258
|
-
content: z7.string().trim().min(1).max(6e3).describe(noteContentDescription),
|
|
14259
|
-
capture: captureSchema,
|
|
14260
|
-
archived: z7.boolean().default(false),
|
|
14261
|
-
kind: kindSchema.default("fact"),
|
|
14262
|
-
autoKind: z7.boolean().default(false),
|
|
14263
|
-
projectId: uuidSchema.nullable().default(null).describe(
|
|
14264
|
-
"Destination notebook UUID, or null for Personal. Omission defaults to Personal; use the requested or established permitted scope."
|
|
14265
|
-
),
|
|
14266
|
-
taskId: z7.string().min(1).max(128).optional(),
|
|
14267
|
-
retentionDays: z7.number().int().min(1).max(365).nullable().optional(),
|
|
14268
|
-
source: sourceSchema.default({ agent: "api" })
|
|
14269
|
-
}).strict().superRefine((input, ctx) => {
|
|
14270
|
-
if (input.autoKind && input.kind === "handoff")
|
|
14271
|
-
ctx.addIssue({ code: "custom", message: "Handoff kind is explicit" });
|
|
14272
|
-
if (Boolean(input.id) !== Boolean(input.expectedVersion)) {
|
|
14273
|
-
ctx.addIssue({
|
|
14274
|
-
code: "custom",
|
|
14275
|
-
message: "Corrections require both id and expectedVersion"
|
|
14276
|
-
});
|
|
14277
|
-
}
|
|
14278
|
-
if (input.id && input.archived)
|
|
14279
|
-
ctx.addIssue({
|
|
14280
|
-
code: "custom",
|
|
14281
|
-
message: "Use the archive action for existing memories"
|
|
14282
|
-
});
|
|
14283
|
-
if (input.kind === "handoff" !== Boolean(input.taskId)) {
|
|
14284
|
-
ctx.addIssue({
|
|
14285
|
-
code: "custom",
|
|
14286
|
-
message: "Handoffs require a stable taskId; durable memories cannot have one"
|
|
14287
|
-
});
|
|
14288
|
-
}
|
|
14289
|
-
});
|
|
14290
|
-
var listSchema = z7.object({
|
|
14291
|
-
projectId: uuidSchema.nullable().optional().describe(
|
|
14292
|
-
"Filter by notebook UUID, or null for Personal. Omit to inspect all granted scopes; do not broaden automatic searches beyond the current scope."
|
|
14293
|
-
),
|
|
14294
|
-
kind: kindSchema.optional(),
|
|
14295
|
-
tag: z7.string().trim().min(1).max(40).optional(),
|
|
14296
|
-
sourceAgent: sourceSchema.shape.agent.removeDefault().optional(),
|
|
14297
|
-
updatedAfter: z7.iso.datetime().optional(),
|
|
14298
|
-
sort: z7.enum(["updated_desc", "updated_asc", "created_desc", "relevance"]).optional(),
|
|
14299
|
-
lifetime: z7.enum(["permanent", "ephemeral"]).optional(),
|
|
14300
|
-
status: z7.enum(["active", "archived", "expired", "all"]).default("active"),
|
|
14301
|
-
query: z7.string().trim().max(1e3).optional(),
|
|
14302
|
-
searchMode: z7.enum(["hybrid", "lexical"]).optional(),
|
|
14303
|
-
cursor: z7.string().max(2048).optional(),
|
|
14304
|
-
limit: z7.number().int().min(1).max(100).default(30)
|
|
14305
|
-
}).strict();
|
|
14306
|
-
var recallSchema = z7.object({
|
|
14307
|
-
query: z7.string().trim().max(1e3).default(""),
|
|
14308
|
-
projectId: uuidSchema.nullable().default(null).describe(
|
|
14309
|
-
"Current notebook UUID, or null for Personal (the default). Other notebooks are not included; includePersonal controls additional Personal context."
|
|
14310
|
-
),
|
|
14311
|
-
includePersonal: z7.boolean().default(true),
|
|
14312
|
-
taskId: z7.string().max(128).optional(),
|
|
14313
|
-
limit: z7.number().int().min(1).max(12).default(8),
|
|
14314
|
-
maxCharacters: z7.number().int().min(256).max(6e3).default(6e3)
|
|
14315
|
-
}).strict();
|
|
14316
|
-
var versionSchema = z7.object({
|
|
14317
|
-
operationId: operationSchema,
|
|
14318
|
-
expectedVersion: expectedVersionSchema,
|
|
14319
|
-
revision: z7.number().int().positive().optional(),
|
|
14320
|
-
durable: z7.boolean().optional()
|
|
14321
|
-
}).strict();
|
|
14322
|
-
var forgetSchema = z7.object({
|
|
14323
|
-
operationId: operationSchema,
|
|
14324
|
-
items: z7.array(
|
|
14325
|
-
z7.object({
|
|
14326
|
-
id: uuidSchema,
|
|
14327
|
-
expectedVersion: expectedVersionSchema
|
|
14328
|
-
}).strict()
|
|
14329
|
-
).min(1).max(50)
|
|
14330
|
-
}).strict();
|
|
14331
|
-
var projectSchema = z7.object({
|
|
14332
|
-
name: z7.string().trim().min(1).max(120),
|
|
14333
|
-
identity: z7.string().trim().min(1).max(500),
|
|
14334
|
-
parentId: uuidSchema.nullable().optional(),
|
|
14335
|
-
expectedVersion: z7.number().int().positive().optional()
|
|
14336
|
-
}).strict();
|
|
14337
|
-
var grantSchema = z7.object({
|
|
14338
|
-
name: z7.string().trim().min(1).max(100),
|
|
14339
|
-
capabilities: z7.array(capabilitySchema).min(1).max(3),
|
|
14340
|
-
personal: z7.boolean().default(true),
|
|
14341
|
-
allProjects: z7.boolean().default(false),
|
|
14342
|
-
projectIds: z7.array(uuidSchema).max(100).default([]),
|
|
14343
|
-
expiresAt: z7.iso.datetime().optional(),
|
|
14344
|
-
writingEnabled: z7.boolean().optional(),
|
|
14345
|
-
sharingEnabled: z7.boolean().optional()
|
|
14928
|
+
init_contracts();
|
|
14929
|
+
import { z as z8 } from "zod";
|
|
14930
|
+
var listNoteMediaSchema = z8.object({
|
|
14931
|
+
memoryId: uuidSchema.describe("Exact note ID to inventory."),
|
|
14932
|
+
version: expectedVersionSchema.optional().describe(
|
|
14933
|
+
"Exact bound revision; omit for the current revision. History renders while the note stays accessible."
|
|
14934
|
+
)
|
|
14346
14935
|
}).strict();
|
|
14347
|
-
var
|
|
14348
|
-
|
|
14349
|
-
|
|
14350
|
-
|
|
14351
|
-
expectedState: z7.string().regex(/^[a-f0-9]{64}$/).optional()
|
|
14352
|
-
});
|
|
14353
|
-
var agentSchema = z7.enum(["opencode", "claude", "codex"]);
|
|
14354
|
-
var connectSchema = z7.object({
|
|
14355
|
-
agent: agentSchema,
|
|
14356
|
-
project: projectSchema.nullable()
|
|
14936
|
+
var describeNoteMediaSchema = z8.object({
|
|
14937
|
+
memoryId: uuidSchema.describe("Exact note ID holding the attachment."),
|
|
14938
|
+
mediaId: uuidSchema.describe("Opaque attachment UUID from list output."),
|
|
14939
|
+
version: expectedVersionSchema.optional().describe("Exact bound revision; omit for the current revision.")
|
|
14357
14940
|
}).strict();
|
|
14358
|
-
var
|
|
14359
|
-
|
|
14360
|
-
|
|
14361
|
-
|
|
14362
|
-
id: uuidSchema,
|
|
14363
|
-
projectId: uuidSchema.nullable(),
|
|
14364
|
-
content: z7.string(),
|
|
14365
|
-
kind: kindSchema,
|
|
14366
|
-
autoKind: z7.boolean().optional(),
|
|
14367
|
-
status: z7.enum(["active", "archived"]),
|
|
14368
|
-
version: z7.number().int(),
|
|
14369
|
-
source: sourceSchema,
|
|
14370
|
-
taskId: z7.string().nullable(),
|
|
14371
|
-
retentionDays: z7.number().int().nullable().optional(),
|
|
14372
|
-
expiresAt: z7.string().nullable(),
|
|
14373
|
-
purgeAt: z7.string().nullable(),
|
|
14374
|
-
createdAt: z7.string(),
|
|
14375
|
-
updatedAt: z7.string(),
|
|
14376
|
-
indexing: z7.enum(["disabled", "pending", "ready", "failed"]),
|
|
14377
|
-
enrichment: z7.custom().optional()
|
|
14378
|
-
});
|
|
14379
|
-
var GroveError = class extends Error {
|
|
14380
|
-
constructor(code2, message, status = 400) {
|
|
14381
|
-
super(message);
|
|
14382
|
-
this.code = code2;
|
|
14383
|
-
this.status = status;
|
|
14384
|
-
this.name = "GroveError";
|
|
14385
|
-
}
|
|
14386
|
-
code;
|
|
14387
|
-
status;
|
|
14388
|
-
};
|
|
14941
|
+
var readMediaTranscriptSchema = describeNoteMediaSchema;
|
|
14942
|
+
|
|
14943
|
+
// lib/shared/src/memory-tools.ts
|
|
14944
|
+
init_note_writing();
|
|
14389
14945
|
|
|
14390
14946
|
// lib/shared/src/document-edits.ts
|
|
14391
14947
|
init_define_GROVE_TELEMETRY();
|
|
14392
|
-
import { z as
|
|
14393
|
-
var text3 =
|
|
14394
|
-
var sourceEditSchema =
|
|
14395
|
-
from:
|
|
14396
|
-
to:
|
|
14948
|
+
import { z as z9 } from "zod";
|
|
14949
|
+
var text3 = z9.string().max(6e3).refine((s) => !/[\uD800-\uDFFF]/u.test(s));
|
|
14950
|
+
var sourceEditSchema = z9.object({
|
|
14951
|
+
from: z9.number().int().min(0).max(6e3),
|
|
14952
|
+
to: z9.number().int().min(0).max(6e3),
|
|
14397
14953
|
oldText: text3,
|
|
14398
14954
|
text: text3
|
|
14399
14955
|
}).strict();
|
|
14400
|
-
var sourceEditsSchema =
|
|
14956
|
+
var sourceEditsSchema = z9.array(sourceEditSchema).min(1).max(50);
|
|
14401
14957
|
function applySourceEdits(source3, raw) {
|
|
14402
14958
|
const edits = sourceEditsSchema.parse(raw);
|
|
14403
14959
|
let inserted = 0;
|
|
@@ -14435,27 +14991,27 @@ function sourceEditsBetween(before, after) {
|
|
|
14435
14991
|
}
|
|
14436
14992
|
|
|
14437
14993
|
// lib/shared/src/memory-tools.ts
|
|
14438
|
-
var memoryUpdateSchema =
|
|
14994
|
+
var memoryUpdateSchema = z10.object({
|
|
14439
14995
|
operationId: operationSchema,
|
|
14440
14996
|
id: uuidSchema,
|
|
14441
14997
|
expectedVersion: expectedVersionSchema,
|
|
14442
14998
|
editSession: uuidSchema.optional().describe(
|
|
14443
14999
|
"Stable UUID for one editing session. Small nearby source edits may share one history revision; this is not actor identity or authorization."
|
|
14444
15000
|
),
|
|
14445
|
-
checkpoint:
|
|
15001
|
+
checkpoint: z10.boolean().optional().describe(
|
|
14446
15002
|
"Explicit save boundary: keep this change as its own revision and close the editing burst."
|
|
14447
15003
|
),
|
|
14448
15004
|
edits: sourceEditsSchema.optional().describe(
|
|
14449
15005
|
"Exact sequential UTF-16 source splices. Prefer this for passage edits; oldText must match at from/to. Never include content with edits."
|
|
14450
15006
|
),
|
|
14451
|
-
content:
|
|
15007
|
+
content: z10.string().trim().min(1).max(6e3).describe(noteContentDescription).optional(),
|
|
14452
15008
|
kind: kindSchema.optional(),
|
|
14453
|
-
autoKind:
|
|
15009
|
+
autoKind: z10.boolean().optional(),
|
|
14454
15010
|
projectId: uuidSchema.nullable().optional().describe(
|
|
14455
15011
|
"Destination notebook UUID; null moves to Personal. Omit to preserve the current notebook. Filing changes require user direction."
|
|
14456
15012
|
),
|
|
14457
|
-
taskId:
|
|
14458
|
-
retentionDays:
|
|
15013
|
+
taskId: z10.string().min(1).max(128).nullable().optional(),
|
|
15014
|
+
retentionDays: z10.number().int().min(1).max(365).nullable().optional(),
|
|
14459
15015
|
source: sourceSchema.optional(),
|
|
14460
15016
|
capture: captureSchema
|
|
14461
15017
|
}).strict().refine(
|
|
@@ -14474,48 +15030,48 @@ var memoryUpdateSchema = z9.object({
|
|
|
14474
15030
|
(input) => !(input.content !== void 0 && input.edits !== void 0),
|
|
14475
15031
|
"Use content or edits, not both"
|
|
14476
15032
|
);
|
|
14477
|
-
var memoryPatchPreviewSchema =
|
|
15033
|
+
var memoryPatchPreviewSchema = z10.object({
|
|
14478
15034
|
id: uuidSchema,
|
|
14479
15035
|
expectedVersion: expectedVersionSchema,
|
|
14480
15036
|
operationId: operationSchema,
|
|
14481
15037
|
edits: sourceEditsSchema,
|
|
14482
15038
|
editSession: uuidSchema.optional(),
|
|
14483
|
-
checkpoint:
|
|
15039
|
+
checkpoint: z10.boolean().optional(),
|
|
14484
15040
|
capture: captureSchema
|
|
14485
15041
|
}).strict();
|
|
14486
|
-
var memoryPatchApplySchema = memoryPatchPreviewSchema.extend({ review:
|
|
15042
|
+
var memoryPatchApplySchema = memoryPatchPreviewSchema.extend({ review: z10.string().min(1).max(300) }).strict();
|
|
14487
15043
|
var moveMemoriesSchema = forgetSchema.extend({ projectId: uuidSchema.nullable() }).refine(
|
|
14488
15044
|
(input) => new Set(input.items.map((item) => item.id)).size === input.items.length,
|
|
14489
15045
|
"Duplicate note IDs"
|
|
14490
15046
|
);
|
|
14491
|
-
var notebookListSchema =
|
|
14492
|
-
status:
|
|
15047
|
+
var notebookListSchema = z10.object({
|
|
15048
|
+
status: z10.enum(["active", "archived"]).default("active"),
|
|
14493
15049
|
parentId: uuidSchema.nullable().optional(),
|
|
14494
|
-
query:
|
|
14495
|
-
cursor:
|
|
14496
|
-
limit:
|
|
15050
|
+
query: z10.string().trim().max(120).optional(),
|
|
15051
|
+
cursor: z10.string().max(2048).optional(),
|
|
15052
|
+
limit: z10.number().int().min(1).max(100).default(30)
|
|
14497
15053
|
}).strict();
|
|
14498
|
-
var notebookCreateSchema =
|
|
15054
|
+
var notebookCreateSchema = z10.object({
|
|
14499
15055
|
operationId: operationSchema,
|
|
14500
|
-
name:
|
|
15056
|
+
name: z10.string().trim().min(1).max(120),
|
|
14501
15057
|
parentId: uuidSchema.nullable().default(null)
|
|
14502
15058
|
}).strict();
|
|
14503
|
-
var notebookUpdateSchema =
|
|
15059
|
+
var notebookUpdateSchema = z10.object({
|
|
14504
15060
|
operationId: operationSchema,
|
|
14505
15061
|
id: uuidSchema,
|
|
14506
15062
|
expectedVersion: expectedVersionSchema,
|
|
14507
|
-
name:
|
|
15063
|
+
name: z10.string().trim().min(1).max(120).optional(),
|
|
14508
15064
|
parentId: uuidSchema.nullable().optional()
|
|
14509
15065
|
}).strict().refine(
|
|
14510
15066
|
(input) => input.name !== void 0 || input.parentId !== void 0,
|
|
14511
15067
|
"Supply a name or parent"
|
|
14512
15068
|
);
|
|
14513
|
-
var notebookToolLifecycleSchema =
|
|
15069
|
+
var notebookToolLifecycleSchema = z10.object({
|
|
14514
15070
|
id: uuidSchema,
|
|
14515
|
-
action:
|
|
15071
|
+
action: z10.enum(["preview", "archive", "restore", "delete"]),
|
|
14516
15072
|
operationId: operationSchema.optional(),
|
|
14517
15073
|
expectedVersion: expectedVersionSchema.optional(),
|
|
14518
|
-
fingerprint:
|
|
15074
|
+
fingerprint: z10.string().regex(/^[a-f0-9]{64}$/).optional()
|
|
14519
15075
|
}).strict().refine(
|
|
14520
15076
|
(input) => input.action === "preview" || !!(input.operationId && input.expectedVersion && input.fingerprint),
|
|
14521
15077
|
"Changes require operationId, expectedVersion and the preview fingerprint"
|
|
@@ -14523,7 +15079,7 @@ var notebookToolLifecycleSchema = z9.object({
|
|
|
14523
15079
|
var memoryTools = {
|
|
14524
15080
|
get_memory_document: {
|
|
14525
15081
|
title: "Read a structured note",
|
|
14526
|
-
schema:
|
|
15082
|
+
schema: z10.object({ id: uuidSchema, revision: expectedVersionSchema.optional() }).strict(),
|
|
14527
15083
|
readOnly: true,
|
|
14528
15084
|
description: "Read exact structured blocks with stable IDs and source. UTF-16 source offsets for edits are relative to the complete concatenated source, not a node. Check revision and permissions before editing."
|
|
14529
15085
|
},
|
|
@@ -14539,7 +15095,7 @@ var memoryTools = {
|
|
|
14539
15095
|
},
|
|
14540
15096
|
compare_memory_revisions: {
|
|
14541
15097
|
title: "Compare note revisions",
|
|
14542
|
-
schema:
|
|
15098
|
+
schema: z10.object({
|
|
14543
15099
|
id: uuidSchema,
|
|
14544
15100
|
beforeVersion: expectedVersionSchema,
|
|
14545
15101
|
afterVersion: expectedVersionSchema
|
|
@@ -14572,16 +15128,16 @@ var memoryTools = {
|
|
|
14572
15128
|
},
|
|
14573
15129
|
get_memory: {
|
|
14574
15130
|
title: "Read a memory",
|
|
14575
|
-
schema:
|
|
15131
|
+
schema: z10.object({
|
|
14576
15132
|
id: uuidSchema,
|
|
14577
|
-
revision:
|
|
15133
|
+
revision: z10.number().int().positive().optional()
|
|
14578
15134
|
}).strict(),
|
|
14579
15135
|
readOnly: true,
|
|
14580
15136
|
description: "Read one exact note by ID, optionally at a historical revision. Current scope, deletion and historical-source expiry checks still apply."
|
|
14581
15137
|
},
|
|
14582
15138
|
memory_history: {
|
|
14583
15139
|
title: "Read memory history",
|
|
14584
|
-
schema:
|
|
15140
|
+
schema: z10.object({ id: uuidSchema }).strict(),
|
|
14585
15141
|
readOnly: true,
|
|
14586
15142
|
description: "Read up to 100 most recent logical revisions of an accessible note. Nearby small edits share an entry. revision is the history number; version is the immutable source version to use for reads, comparisons and restore. firstVersion/saves describe the group."
|
|
14587
15143
|
},
|
|
@@ -14597,7 +15153,7 @@ var memoryTools = {
|
|
|
14597
15153
|
},
|
|
14598
15154
|
archive_memory: {
|
|
14599
15155
|
title: "Archive a memory",
|
|
14600
|
-
schema:
|
|
15156
|
+
schema: z10.object({
|
|
14601
15157
|
id: uuidSchema,
|
|
14602
15158
|
operationId: operationSchema,
|
|
14603
15159
|
expectedVersion: expectedVersionSchema
|
|
@@ -14630,15 +15186,36 @@ var memoryTools = {
|
|
|
14630
15186
|
schema: notebookToolLifecycleSchema,
|
|
14631
15187
|
destructive: true,
|
|
14632
15188
|
description: "Owner website session only: preview a notebook subtree, then archive/restore/soft-delete using its fingerprint, expectedVersion and operationId. Agent OAuth/API keys cannot administer subtrees. Deletion hides retained history and has no ordinary Undo."
|
|
15189
|
+
},
|
|
15190
|
+
list_note_media: {
|
|
15191
|
+
title: "List note media",
|
|
15192
|
+
schema: listNoteMediaSchema,
|
|
15193
|
+
readOnly: true,
|
|
15194
|
+
description: "List image/recording attachments bound to one accessible note revision with safe metadata only (mime, bytes, dimensions, duration, transcript presence). No bytes, keys, or hashes. Use describe/read tools for details; fetch bytes only through the authorized media route."
|
|
15195
|
+
},
|
|
15196
|
+
describe_note_media: {
|
|
15197
|
+
title: "Describe note media",
|
|
15198
|
+
schema: describeNoteMediaSchema,
|
|
15199
|
+
readOnly: true,
|
|
15200
|
+
description: "Describe one bound image/recording with safe metadata and transcript version. No bytes, keys, or hashes. Use listed IDs; never invent attachment references."
|
|
15201
|
+
},
|
|
15202
|
+
read_media_transcript: {
|
|
15203
|
+
title: "Read media transcript",
|
|
15204
|
+
schema: readMediaTranscriptSchema,
|
|
15205
|
+
readOnly: true,
|
|
15206
|
+
description: "Read the current saved transcript text (up to 6000 characters) for one bound WAV recording. Empty when no transcript was saved. Suggested speech output is never auto-applied; save only through explicit note edits."
|
|
14633
15207
|
}
|
|
14634
15208
|
};
|
|
14635
15209
|
|
|
15210
|
+
// lib/memory/src/index.ts
|
|
15211
|
+
init_contracts();
|
|
15212
|
+
|
|
14636
15213
|
// lib/shared/src/documents/index.ts
|
|
14637
15214
|
init_define_GROVE_TELEMETRY();
|
|
14638
15215
|
|
|
14639
15216
|
// lib/shared/src/documents/schema.ts
|
|
14640
15217
|
init_define_GROVE_TELEMETRY();
|
|
14641
|
-
import { z as
|
|
15218
|
+
import { z as z11 } from "zod";
|
|
14642
15219
|
var documentLimits = {
|
|
14643
15220
|
characters: 6e3,
|
|
14644
15221
|
blocks: 256,
|
|
@@ -14654,16 +15231,16 @@ var DocumentError = class extends Error {
|
|
|
14654
15231
|
}
|
|
14655
15232
|
code;
|
|
14656
15233
|
};
|
|
14657
|
-
var sourceSchema2 =
|
|
15234
|
+
var sourceSchema2 = z11.string().max(documentLimits.characters).refine(
|
|
14658
15235
|
(text5) => !/[\uD800-\uDFFF]/u.test(text5),
|
|
14659
15236
|
"Source must contain well-formed Unicode"
|
|
14660
15237
|
);
|
|
14661
|
-
var id =
|
|
14662
|
-
var hash =
|
|
14663
|
-
var revision =
|
|
14664
|
-
var blockSchema =
|
|
15238
|
+
var id = z11.uuid();
|
|
15239
|
+
var hash = z11.string().regex(/^[a-f0-9]{64}$/);
|
|
15240
|
+
var revision = z11.number().int().positive().max(Number.MAX_SAFE_INTEGER);
|
|
15241
|
+
var blockSchema = z11.object({
|
|
14665
15242
|
id,
|
|
14666
|
-
kind:
|
|
15243
|
+
kind: z11.enum([
|
|
14667
15244
|
"heading",
|
|
14668
15245
|
"paragraph",
|
|
14669
15246
|
"list",
|
|
@@ -14677,52 +15254,52 @@ var blockSchema = z10.object({
|
|
|
14677
15254
|
source: sourceSchema2.refine((s) => s.length > 0),
|
|
14678
15255
|
hash
|
|
14679
15256
|
}).strict();
|
|
14680
|
-
var documentSchema =
|
|
14681
|
-
schemaVersion:
|
|
15257
|
+
var documentSchema = z11.object({
|
|
15258
|
+
schemaVersion: z11.literal(1),
|
|
14682
15259
|
noteId: id,
|
|
14683
15260
|
revision,
|
|
14684
15261
|
hash,
|
|
14685
|
-
blocks:
|
|
15262
|
+
blocks: z11.array(blockSchema).min(1).max(documentLimits.blocks)
|
|
14686
15263
|
}).strict();
|
|
14687
|
-
var createDocumentSchema =
|
|
15264
|
+
var createDocumentSchema = z11.object({
|
|
14688
15265
|
noteId: id,
|
|
14689
15266
|
revision,
|
|
14690
15267
|
source: sourceSchema2.refine((s) => s.length > 0)
|
|
14691
15268
|
}).strict();
|
|
14692
|
-
var anchorSchema =
|
|
15269
|
+
var anchorSchema = z11.object({ afterId: id.nullable(), beforeId: id.nullable() }).strict();
|
|
14693
15270
|
var target = { nodeId: id, expectedHash: hash };
|
|
14694
|
-
var operationSchema2 =
|
|
14695
|
-
|
|
14696
|
-
type:
|
|
15271
|
+
var operationSchema2 = z11.discriminatedUnion("type", [
|
|
15272
|
+
z11.object({
|
|
15273
|
+
type: z11.literal("replace_text"),
|
|
14697
15274
|
...target,
|
|
14698
|
-
from:
|
|
14699
|
-
to:
|
|
15275
|
+
from: z11.number().int().min(0).max(documentLimits.characters),
|
|
15276
|
+
to: z11.number().int().min(0).max(documentLimits.characters),
|
|
14700
15277
|
oldText: sourceSchema2,
|
|
14701
15278
|
text: sourceSchema2
|
|
14702
15279
|
}).strict(),
|
|
14703
|
-
|
|
14704
|
-
|
|
14705
|
-
|
|
14706
|
-
type:
|
|
15280
|
+
z11.object({ type: z11.literal("delete_block"), ...target }).strict(),
|
|
15281
|
+
z11.object({ type: z11.literal("move_block"), ...target, anchor: anchorSchema }).strict(),
|
|
15282
|
+
z11.object({
|
|
15283
|
+
type: z11.literal("insert_block"),
|
|
14707
15284
|
source: sourceSchema2.refine((s) => s.length > 0),
|
|
14708
15285
|
anchor: anchorSchema
|
|
14709
15286
|
}).strict()
|
|
14710
15287
|
]);
|
|
14711
|
-
var patchSchema =
|
|
15288
|
+
var patchSchema = z11.object({
|
|
14712
15289
|
noteId: id,
|
|
14713
15290
|
baseRevision: revision,
|
|
14714
15291
|
baseHash: hash,
|
|
14715
15292
|
operationId: id,
|
|
14716
|
-
operations:
|
|
15293
|
+
operations: z11.array(operationSchema2).min(1).max(documentLimits.operations)
|
|
14717
15294
|
}).strict();
|
|
14718
|
-
var editScopeSchema =
|
|
14719
|
-
nodeIds:
|
|
14720
|
-
insertions:
|
|
14721
|
-
ranges:
|
|
14722
|
-
|
|
15295
|
+
var editScopeSchema = z11.object({
|
|
15296
|
+
nodeIds: z11.array(id).max(documentLimits.blocks),
|
|
15297
|
+
insertions: z11.array(anchorSchema).max(documentLimits.blocks + 1),
|
|
15298
|
+
ranges: z11.array(
|
|
15299
|
+
z11.object({
|
|
14723
15300
|
nodeId: id,
|
|
14724
|
-
from:
|
|
14725
|
-
to:
|
|
15301
|
+
from: z11.number().int().min(0).max(documentLimits.characters),
|
|
15302
|
+
to: z11.number().int().min(0).max(documentLimits.characters)
|
|
14726
15303
|
}).strict()
|
|
14727
15304
|
).max(documentLimits.blocks).optional()
|
|
14728
15305
|
}).strict();
|
|
@@ -16991,6 +17568,7 @@ async function compareDocuments(beforeInput, afterInput) {
|
|
|
16991
17568
|
|
|
16992
17569
|
// lib/memory/src/document-storage.ts
|
|
16993
17570
|
init_define_GROVE_TELEMETRY();
|
|
17571
|
+
init_contracts();
|
|
16994
17572
|
import { createHash as createHash4 } from "node:crypto";
|
|
16995
17573
|
|
|
16996
17574
|
// lib/memory/src/revision-groups.ts
|
|
@@ -17121,16 +17699,17 @@ async function documentRevisionValues(trx, row, edit) {
|
|
|
17121
17699
|
|
|
17122
17700
|
// lib/shared/src/notebook-organization.ts
|
|
17123
17701
|
init_define_GROVE_TELEMETRY();
|
|
17124
|
-
|
|
17125
|
-
|
|
17126
|
-
|
|
17127
|
-
|
|
17128
|
-
|
|
17702
|
+
init_contracts();
|
|
17703
|
+
import { z as z12 } from "zod";
|
|
17704
|
+
var notebookCatalogSchema = z12.object({
|
|
17705
|
+
status: z12.enum(["active", "archived"]).default("active"),
|
|
17706
|
+
limit: z12.coerce.number().int().min(1).max(200).default(200),
|
|
17707
|
+
cursor: z12.string().max(2e3).optional()
|
|
17129
17708
|
}).strict();
|
|
17130
|
-
var organizeNotebookSchema =
|
|
17709
|
+
var organizeNotebookSchema = z12.object({
|
|
17131
17710
|
operationId: uuidSchema,
|
|
17132
|
-
expectedVersion:
|
|
17133
|
-
expectedState:
|
|
17711
|
+
expectedVersion: z12.number().int().positive(),
|
|
17712
|
+
expectedState: z12.string().regex(/^[a-f0-9]{64}$/),
|
|
17134
17713
|
parentId: uuidSchema.nullable(),
|
|
17135
17714
|
beforeId: uuidSchema.optional(),
|
|
17136
17715
|
afterId: uuidSchema.optional()
|
|
@@ -17140,6 +17719,7 @@ var organizeNotebookSchema = z11.object({
|
|
|
17140
17719
|
|
|
17141
17720
|
// lib/memory/src/notebook-organization.ts
|
|
17142
17721
|
init_define_GROVE_TELEMETRY();
|
|
17722
|
+
init_contracts();
|
|
17143
17723
|
var notebookFields = [
|
|
17144
17724
|
"id",
|
|
17145
17725
|
"name",
|
|
@@ -17211,6 +17791,7 @@ async function organizeNotebook(trx, id2, input, state) {
|
|
|
17211
17791
|
|
|
17212
17792
|
// lib/memory/src/notebook-lifecycle.ts
|
|
17213
17793
|
init_define_GROVE_TELEMETRY();
|
|
17794
|
+
init_contracts();
|
|
17214
17795
|
import { createHash as createHash6 } from "node:crypto";
|
|
17215
17796
|
|
|
17216
17797
|
// lib/memory/src/relationship-data.ts
|
|
@@ -17219,30 +17800,30 @@ import { createHash as createHash5 } from "node:crypto";
|
|
|
17219
17800
|
|
|
17220
17801
|
// lib/shared/src/relationships.ts
|
|
17221
17802
|
init_define_GROVE_TELEMETRY();
|
|
17222
|
-
import { z as
|
|
17803
|
+
import { z as z13 } from "zod";
|
|
17223
17804
|
var relationshipPolicyVersion = "substantive-bridge-v3";
|
|
17224
|
-
var connectionLevelSchema =
|
|
17225
|
-
var connectionTypeSchema =
|
|
17805
|
+
var connectionLevelSchema = z13.enum(["note", "notebook"]);
|
|
17806
|
+
var connectionTypeSchema = z13.enum([
|
|
17226
17807
|
"complementary",
|
|
17227
17808
|
"conflicting",
|
|
17228
17809
|
"duplicate",
|
|
17229
17810
|
"connected"
|
|
17230
17811
|
]);
|
|
17231
|
-
var relationshipEvidenceSchema =
|
|
17232
|
-
id:
|
|
17233
|
-
version:
|
|
17234
|
-
quote:
|
|
17812
|
+
var relationshipEvidenceSchema = z13.object({
|
|
17813
|
+
id: z13.uuid(),
|
|
17814
|
+
version: z13.number().int().positive(),
|
|
17815
|
+
quote: z13.string().min(6).max(600)
|
|
17235
17816
|
}).strict();
|
|
17236
|
-
var relationshipAssessmentSchema =
|
|
17237
|
-
relationship:
|
|
17817
|
+
var relationshipAssessmentSchema = z13.object({
|
|
17818
|
+
relationship: z13.enum([
|
|
17238
17819
|
"complementary",
|
|
17239
17820
|
"conflicting",
|
|
17240
17821
|
"duplicate",
|
|
17241
17822
|
"connected",
|
|
17242
17823
|
"unrelated"
|
|
17243
17824
|
]),
|
|
17244
|
-
reason:
|
|
17245
|
-
basis:
|
|
17825
|
+
reason: z13.string().trim().max(600),
|
|
17826
|
+
basis: z13.enum([
|
|
17246
17827
|
"additional_context",
|
|
17247
17828
|
"same_information",
|
|
17248
17829
|
"incompatible_claims",
|
|
@@ -17253,11 +17834,11 @@ var relationshipAssessmentSchema = z12.object({
|
|
|
17253
17834
|
"dependency",
|
|
17254
17835
|
"none"
|
|
17255
17836
|
]),
|
|
17256
|
-
direction:
|
|
17257
|
-
evidence:
|
|
17837
|
+
direction: z13.enum(["both", "left_to_right", "right_to_left"]),
|
|
17838
|
+
evidence: z13.array(relationshipEvidenceSchema).max(8)
|
|
17258
17839
|
}).strict();
|
|
17259
|
-
var relationshipSupportSchema =
|
|
17260
|
-
kind:
|
|
17840
|
+
var relationshipSupportSchema = z13.object({
|
|
17841
|
+
kind: z13.enum([
|
|
17261
17842
|
"shared_attribute",
|
|
17262
17843
|
"specific_subject",
|
|
17263
17844
|
"specific_mechanism",
|
|
@@ -17269,34 +17850,34 @@ var relationshipSupportSchema = z12.object({
|
|
|
17269
17850
|
"template",
|
|
17270
17851
|
"generic_topic"
|
|
17271
17852
|
]),
|
|
17272
|
-
subject:
|
|
17273
|
-
property:
|
|
17274
|
-
leftValue:
|
|
17275
|
-
rightValue:
|
|
17276
|
-
conditions:
|
|
17277
|
-
leftEvidence:
|
|
17278
|
-
rightEvidence:
|
|
17853
|
+
subject: z13.string().trim().min(1).max(200),
|
|
17854
|
+
property: z13.string().trim().min(1).max(160),
|
|
17855
|
+
leftValue: z13.string().trim().min(1).max(300),
|
|
17856
|
+
rightValue: z13.string().trim().min(1).max(300),
|
|
17857
|
+
conditions: z13.string().trim().min(1).max(300),
|
|
17858
|
+
leftEvidence: z13.array(z13.number().int().min(0).max(7)).min(1).max(4),
|
|
17859
|
+
rightEvidence: z13.array(z13.number().int().min(0).max(7)).min(1).max(4)
|
|
17279
17860
|
}).strict();
|
|
17280
17861
|
var noteAssessmentSchema = relationshipAssessmentSchema.extend({
|
|
17281
|
-
support:
|
|
17282
|
-
relationship:
|
|
17862
|
+
support: z13.array(relationshipSupportSchema).max(1),
|
|
17863
|
+
relationship: z13.enum([
|
|
17283
17864
|
"complementary",
|
|
17284
17865
|
"conflicting",
|
|
17285
17866
|
"duplicate",
|
|
17286
17867
|
"unrelated"
|
|
17287
17868
|
]),
|
|
17288
|
-
basis:
|
|
17869
|
+
basis: z13.enum([
|
|
17289
17870
|
"additional_context",
|
|
17290
17871
|
"same_information",
|
|
17291
17872
|
"incompatible_claims",
|
|
17292
17873
|
"none"
|
|
17293
17874
|
]),
|
|
17294
|
-
direction:
|
|
17875
|
+
direction: z13.literal("both")
|
|
17295
17876
|
});
|
|
17296
17877
|
var notebookAssessmentSchema = relationshipAssessmentSchema.extend({
|
|
17297
|
-
support:
|
|
17298
|
-
relationship:
|
|
17299
|
-
basis:
|
|
17878
|
+
support: z13.array(relationshipSupportSchema).max(1),
|
|
17879
|
+
relationship: z13.enum(["connected", "unrelated"]),
|
|
17880
|
+
basis: z13.enum([
|
|
17300
17881
|
"shared_theme",
|
|
17301
17882
|
"shared_goal",
|
|
17302
17883
|
"shared_entity",
|
|
@@ -17305,21 +17886,21 @@ var notebookAssessmentSchema = relationshipAssessmentSchema.extend({
|
|
|
17305
17886
|
"none"
|
|
17306
17887
|
])
|
|
17307
17888
|
});
|
|
17308
|
-
var connectionQuerySchema =
|
|
17889
|
+
var connectionQuerySchema = z13.object({
|
|
17309
17890
|
level: connectionLevelSchema,
|
|
17310
|
-
endpointId:
|
|
17311
|
-
connectionId:
|
|
17891
|
+
endpointId: z13.uuid().optional(),
|
|
17892
|
+
connectionId: z13.uuid().optional(),
|
|
17312
17893
|
// Graph reads contain only edges whose two endpoints are loaded.
|
|
17313
|
-
endpointIds:
|
|
17314
|
-
limit:
|
|
17315
|
-
cursor:
|
|
17316
|
-
includeDismissed:
|
|
17894
|
+
endpointIds: z13.array(z13.uuid()).max(100).optional(),
|
|
17895
|
+
limit: z13.number().int().min(1).max(100).default(30),
|
|
17896
|
+
cursor: z13.string().max(1e3).optional(),
|
|
17897
|
+
includeDismissed: z13.boolean().default(false)
|
|
17317
17898
|
}).strict();
|
|
17318
|
-
var connectionReviewSchema =
|
|
17319
|
-
operationId:
|
|
17320
|
-
expectedRevision:
|
|
17321
|
-
expectedReviewVersion:
|
|
17322
|
-
dismissed:
|
|
17899
|
+
var connectionReviewSchema = z13.object({
|
|
17900
|
+
operationId: z13.uuid(),
|
|
17901
|
+
expectedRevision: z13.string().regex(/^[a-f0-9]{64}$/),
|
|
17902
|
+
expectedReviewVersion: z13.number().int().min(0),
|
|
17903
|
+
dismissed: z13.boolean()
|
|
17323
17904
|
}).strict();
|
|
17324
17905
|
function normalizeRelationshipAssessment(value) {
|
|
17325
17906
|
return value.relationship === "unrelated" ? { ...value, reason: "", basis: "none", direction: "both", evidence: [] } : value;
|
|
@@ -18149,6 +18730,7 @@ function lexicalCandidates(content3, pool, limit) {
|
|
|
18149
18730
|
init_define_GROVE_TELEMETRY();
|
|
18150
18731
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
18151
18732
|
import { setTimeout as setTimeout5 } from "node:timers/promises";
|
|
18733
|
+
init_contracts();
|
|
18152
18734
|
var configurations = /* @__PURE__ */ new WeakMap();
|
|
18153
18735
|
function configureBillingQuotas(db, configuration) {
|
|
18154
18736
|
configurations.set(db, configuration);
|
|
@@ -18374,7 +18956,8 @@ async function resourceUsage(db, trx, accountId) {
|
|
|
18374
18956
|
"recall",
|
|
18375
18957
|
"ask",
|
|
18376
18958
|
"organization",
|
|
18377
|
-
"assistance"
|
|
18959
|
+
"assistance",
|
|
18960
|
+
"writing"
|
|
18378
18961
|
]) {
|
|
18379
18962
|
const row = rows.find((r) => r.metric === metric);
|
|
18380
18963
|
metrics2[metric] = {
|
|
@@ -18422,6 +19005,28 @@ async function assertCapacity(trx, resource, creates) {
|
|
|
18422
19005
|
);
|
|
18423
19006
|
}
|
|
18424
19007
|
}
|
|
19008
|
+
async function trialState(trx, accountId) {
|
|
19009
|
+
const row = await trx("billing_trials").where({ accountId }).first();
|
|
19010
|
+
if (!row) return { eligible: true, consumedAt: null, resetAt: null };
|
|
19011
|
+
return {
|
|
19012
|
+
eligible: false,
|
|
19013
|
+
consumedAt: row.consumedAt ? new Date(row.consumedAt).toISOString() : null,
|
|
19014
|
+
resetAt: row.resetAt ? new Date(row.resetAt).toISOString() : null
|
|
19015
|
+
};
|
|
19016
|
+
}
|
|
19017
|
+
async function consumeTrial(trx, accountId, subscriptionId) {
|
|
19018
|
+
const existing = await trx("billing_trials").where({ accountId }).first();
|
|
19019
|
+
if (existing)
|
|
19020
|
+
throw new GroveError(
|
|
19021
|
+
"trial_already_used",
|
|
19022
|
+
"This account already used its Pro trial",
|
|
19023
|
+
409
|
|
19024
|
+
);
|
|
19025
|
+
await trx("billing_trials").insert({
|
|
19026
|
+
accountId,
|
|
19027
|
+
subscriptionId: subscriptionId ?? null
|
|
19028
|
+
});
|
|
19029
|
+
}
|
|
18425
19030
|
async function withGenerationSlot(db, accountId, run2, parent = databaseSignal()) {
|
|
18426
19031
|
const id2 = randomUUID2();
|
|
18427
19032
|
const acquired = await tenant(db, accountId, async (trx) => {
|
|
@@ -19122,19 +19727,19 @@ import { createHash as createHash8 } from "node:crypto";
|
|
|
19122
19727
|
// lib/shared/src/summaries.ts
|
|
19123
19728
|
init_define_GROVE_TELEMETRY();
|
|
19124
19729
|
init_models();
|
|
19125
|
-
import { z as
|
|
19730
|
+
import { z as z14 } from "zod";
|
|
19126
19731
|
var summaryEvidenceSchema = sourceRefSchema.extend({
|
|
19127
|
-
quote:
|
|
19732
|
+
quote: z14.string().trim().min(1).max(600)
|
|
19128
19733
|
});
|
|
19129
|
-
var notebookSummarySchema =
|
|
19130
|
-
title:
|
|
19131
|
-
sections:
|
|
19132
|
-
|
|
19133
|
-
heading:
|
|
19134
|
-
statements:
|
|
19135
|
-
|
|
19136
|
-
text:
|
|
19137
|
-
sources:
|
|
19734
|
+
var notebookSummarySchema = z14.object({
|
|
19735
|
+
title: z14.string().trim().min(1).max(120),
|
|
19736
|
+
sections: z14.array(
|
|
19737
|
+
z14.object({
|
|
19738
|
+
heading: z14.string().trim().min(1).max(80),
|
|
19739
|
+
statements: z14.array(
|
|
19740
|
+
z14.object({
|
|
19741
|
+
text: z14.string().trim().min(1).max(500),
|
|
19742
|
+
sources: z14.array(summaryEvidenceSchema).min(1).max(2)
|
|
19138
19743
|
}).strict()
|
|
19139
19744
|
).max(3)
|
|
19140
19745
|
}).strict()
|
|
@@ -19438,9 +20043,11 @@ async function runNotebookSummary(db, providers, dailyLimit, job, resolveProfile
|
|
|
19438
20043
|
|
|
19439
20044
|
// lib/memory/src/assistance-data.ts
|
|
19440
20045
|
init_define_GROVE_TELEMETRY();
|
|
20046
|
+
init_note_writing();
|
|
19441
20047
|
|
|
19442
20048
|
// lib/memory/src/note-changes.ts
|
|
19443
20049
|
init_define_GROVE_TELEMETRY();
|
|
20050
|
+
init_contracts();
|
|
19444
20051
|
var changedSources = () => new GroveError(
|
|
19445
20052
|
"sources_changed",
|
|
19446
20053
|
"These notes changed. Refresh the preview.",
|
|
@@ -19560,92 +20167,93 @@ var presentAssistance = (row) => ({
|
|
|
19560
20167
|
|
|
19561
20168
|
// lib/memory/src/assistance-jobs.ts
|
|
19562
20169
|
init_define_GROVE_TELEMETRY();
|
|
20170
|
+
init_contracts();
|
|
19563
20171
|
|
|
19564
20172
|
// lib/shared/src/assistance.ts
|
|
19565
20173
|
init_define_GROVE_TELEMETRY();
|
|
19566
20174
|
init_models();
|
|
19567
|
-
import { z as
|
|
20175
|
+
import { z as z15 } from "zod";
|
|
19568
20176
|
var assistancePreferences = {
|
|
19569
20177
|
filing: "filingEnabled",
|
|
19570
20178
|
actions: "actionListsEnabled",
|
|
19571
20179
|
digest: "digestsEnabled",
|
|
19572
20180
|
cleanup: "cleanupEnabled"
|
|
19573
20181
|
};
|
|
19574
|
-
var selected =
|
|
20182
|
+
var selected = z15.array(sourceRefSchema).min(1).max(6).refine(
|
|
19575
20183
|
(refs) => new Set(refs.map((r) => r.id)).size === refs.length,
|
|
19576
20184
|
"Select distinct notes"
|
|
19577
20185
|
);
|
|
19578
|
-
var assistanceRequestSchema =
|
|
19579
|
-
|
|
19580
|
-
id:
|
|
19581
|
-
kind:
|
|
20186
|
+
var assistanceRequestSchema = z15.discriminatedUnion("kind", [
|
|
20187
|
+
z15.object({
|
|
20188
|
+
id: z15.uuid(),
|
|
20189
|
+
kind: z15.literal("filing"),
|
|
19582
20190
|
sources: selected.max(1)
|
|
19583
20191
|
}).strict(),
|
|
19584
|
-
|
|
19585
|
-
id:
|
|
19586
|
-
kind:
|
|
20192
|
+
z15.object({
|
|
20193
|
+
id: z15.uuid(),
|
|
20194
|
+
kind: z15.literal("actions"),
|
|
19587
20195
|
sources: selected,
|
|
19588
|
-
projectId:
|
|
20196
|
+
projectId: z15.uuid().nullable()
|
|
19589
20197
|
}).strict(),
|
|
19590
|
-
|
|
19591
|
-
id:
|
|
19592
|
-
kind:
|
|
19593
|
-
visitId:
|
|
19594
|
-
after:
|
|
20198
|
+
z15.object({
|
|
20199
|
+
id: z15.uuid(),
|
|
20200
|
+
kind: z15.literal("digest"),
|
|
20201
|
+
visitId: z15.uuid(),
|
|
20202
|
+
after: z15.uuid().optional()
|
|
19595
20203
|
}).strict(),
|
|
19596
|
-
|
|
20204
|
+
z15.object({ id: z15.uuid(), kind: z15.literal("cleanup"), projectId: z15.uuid() }).strict()
|
|
19597
20205
|
]);
|
|
19598
|
-
var actionListSchema =
|
|
19599
|
-
items:
|
|
19600
|
-
|
|
19601
|
-
text:
|
|
19602
|
-
sources:
|
|
20206
|
+
var actionListSchema = z15.object({
|
|
20207
|
+
items: z15.array(
|
|
20208
|
+
z15.object({
|
|
20209
|
+
text: z15.string().trim().min(1).max(240),
|
|
20210
|
+
sources: z15.array(summaryEvidenceSchema).min(1).max(2)
|
|
19603
20211
|
}).strict()
|
|
19604
20212
|
).max(12)
|
|
19605
20213
|
}).strict();
|
|
19606
|
-
var filingSchema =
|
|
19607
|
-
destination:
|
|
19608
|
-
reason:
|
|
19609
|
-
evidence:
|
|
20214
|
+
var filingSchema = z15.object({
|
|
20215
|
+
destination: z15.array(z15.uuid()).max(1),
|
|
20216
|
+
reason: z15.string().trim().max(300),
|
|
20217
|
+
evidence: z15.array(summaryEvidenceSchema).max(4)
|
|
19610
20218
|
}).strict();
|
|
19611
|
-
var digestSummarySchema =
|
|
19612
|
-
items:
|
|
20219
|
+
var digestSummarySchema = z15.object({
|
|
20220
|
+
items: z15.array(
|
|
19613
20221
|
actionListSchema.shape.items.element.extend({
|
|
19614
|
-
kind:
|
|
20222
|
+
kind: z15.enum(["new", "change", "decision", "open_action"])
|
|
19615
20223
|
})
|
|
19616
20224
|
).max(12)
|
|
19617
20225
|
}).strict();
|
|
19618
|
-
var cleanupAssessmentSchema =
|
|
19619
|
-
kind:
|
|
19620
|
-
reason:
|
|
19621
|
-
evidence:
|
|
19622
|
-
replacement:
|
|
19623
|
-
content:
|
|
20226
|
+
var cleanupAssessmentSchema = z15.object({
|
|
20227
|
+
kind: z15.enum(["duplicate", "conflicting", "superseded", "unrelated"]),
|
|
20228
|
+
reason: z15.string().trim().max(400),
|
|
20229
|
+
evidence: z15.array(summaryEvidenceSchema).max(4),
|
|
20230
|
+
replacement: z15.array(z15.uuid()).max(1),
|
|
20231
|
+
content: z15.string().trim().max(6e3)
|
|
19624
20232
|
}).strict();
|
|
19625
20233
|
var cleanupJudgmentSchema = cleanupAssessmentSchema.extend({
|
|
19626
|
-
support:
|
|
20234
|
+
support: z15.array(relationshipSupportSchema).max(1)
|
|
19627
20235
|
});
|
|
19628
|
-
var assistanceApplySchema =
|
|
19629
|
-
expectedVersion:
|
|
19630
|
-
candidate:
|
|
19631
|
-
action:
|
|
19632
|
-
edits:
|
|
19633
|
-
|
|
19634
|
-
index:
|
|
19635
|
-
text:
|
|
20236
|
+
var assistanceApplySchema = z15.object({
|
|
20237
|
+
expectedVersion: z15.number().int().positive(),
|
|
20238
|
+
candidate: z15.string().max(128).optional(),
|
|
20239
|
+
action: z15.enum(["combine", "update"]).optional(),
|
|
20240
|
+
edits: z15.array(
|
|
20241
|
+
z15.object({
|
|
20242
|
+
index: z15.number().int().min(0).max(11),
|
|
20243
|
+
text: z15.string().trim().min(1).max(240)
|
|
19636
20244
|
}).strict()
|
|
19637
20245
|
).max(12).optional()
|
|
19638
20246
|
}).strict();
|
|
19639
|
-
var assistanceReviewSchema =
|
|
19640
|
-
candidate:
|
|
19641
|
-
expectedVersion:
|
|
19642
|
-
dismissed:
|
|
20247
|
+
var assistanceReviewSchema = z15.object({
|
|
20248
|
+
candidate: z15.string().max(128),
|
|
20249
|
+
expectedVersion: z15.number().int().min(0),
|
|
20250
|
+
dismissed: z15.boolean()
|
|
19643
20251
|
}).strict();
|
|
19644
|
-
var notebookVisitSchema =
|
|
19645
|
-
id:
|
|
19646
|
-
projectId:
|
|
19647
|
-
token:
|
|
19648
|
-
from:
|
|
20252
|
+
var notebookVisitSchema = z15.object({
|
|
20253
|
+
id: z15.uuid(),
|
|
20254
|
+
projectId: z15.uuid(),
|
|
20255
|
+
token: z15.string().regex(/^\d+$/).max(20),
|
|
20256
|
+
from: z15.string().regex(/^\d+$/).max(20).nullable()
|
|
19649
20257
|
}).strict();
|
|
19650
20258
|
|
|
19651
20259
|
// lib/memory/src/assistance-actions.ts
|
|
@@ -19792,6 +20400,7 @@ async function filingStep(trx, row, providers, jobId) {
|
|
|
19792
20400
|
|
|
19793
20401
|
// lib/memory/src/assistance-cleanup.ts
|
|
19794
20402
|
init_define_GROVE_TELEMETRY();
|
|
20403
|
+
init_note_writing();
|
|
19795
20404
|
async function cleanupStep(trx, row, providers) {
|
|
19796
20405
|
if (row.input.kind !== "cleanup") throw new Error("Invalid cleanup request");
|
|
19797
20406
|
const state = row.state;
|
|
@@ -19910,6 +20519,7 @@ ${substantiveRelationshipPolicy} Review these two notes for cleanup, not Related
|
|
|
19910
20519
|
|
|
19911
20520
|
// lib/memory/src/notebook-digests.ts
|
|
19912
20521
|
init_define_GROVE_TELEMETRY();
|
|
20522
|
+
init_contracts();
|
|
19913
20523
|
async function recordNotebookExpiry(trx, accountId, projectId) {
|
|
19914
20524
|
await trx.raw(
|
|
19915
20525
|
`WITH due AS MATERIALIZED (
|
|
@@ -21174,97 +21784,78 @@ import { createHash as createHash13, randomUUID as randomUUID7 } from "node:cryp
|
|
|
21174
21784
|
// lib/memory/src/conversation-documents.ts
|
|
21175
21785
|
init_define_GROVE_TELEMETRY();
|
|
21176
21786
|
import { createHash as createHash12, randomUUID as randomUUID4 } from "node:crypto";
|
|
21787
|
+
init_contracts();
|
|
21177
21788
|
|
|
21178
21789
|
// lib/shared/src/conversation-documents.ts
|
|
21179
21790
|
init_define_GROVE_TELEMETRY();
|
|
21180
|
-
import { z as
|
|
21181
|
-
var documentStatementSchema =
|
|
21182
|
-
text:
|
|
21183
|
-
sources:
|
|
21184
|
-
|
|
21185
|
-
id:
|
|
21186
|
-
version:
|
|
21187
|
-
quote:
|
|
21791
|
+
import { z as z16 } from "zod";
|
|
21792
|
+
var documentStatementSchema = z16.object({
|
|
21793
|
+
text: z16.string().trim().min(1).max(900),
|
|
21794
|
+
sources: z16.array(
|
|
21795
|
+
z16.object({
|
|
21796
|
+
id: z16.uuid(),
|
|
21797
|
+
version: z16.number().int().positive(),
|
|
21798
|
+
quote: z16.string().min(1).max(1e3)
|
|
21188
21799
|
}).strict()
|
|
21189
21800
|
).min(1).max(6)
|
|
21190
21801
|
}).strict();
|
|
21191
|
-
var documentAcceptanceSchema =
|
|
21802
|
+
var documentAcceptanceSchema = z16.object({ expectedVersion: z16.number().int().nonnegative() }).strict();
|
|
21192
21803
|
var documentConversionSchema = documentAcceptanceSchema.extend({
|
|
21193
|
-
id:
|
|
21804
|
+
id: z16.uuid()
|
|
21194
21805
|
});
|
|
21195
21806
|
|
|
21196
|
-
// lib/
|
|
21197
|
-
|
|
21198
|
-
var imageLimits = {
|
|
21199
|
-
bytes: 10 * 1024 * 1024,
|
|
21200
|
-
pixels: 24e6,
|
|
21201
|
-
dimension: 1e4
|
|
21202
|
-
};
|
|
21203
|
-
var imageMimeTypes = [
|
|
21204
|
-
"image/png",
|
|
21205
|
-
"image/jpeg",
|
|
21206
|
-
"image/webp"
|
|
21207
|
-
];
|
|
21208
|
-
var mediaMimeTypes = [...imageMimeTypes, "audio/wav"];
|
|
21209
|
-
var uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
21210
|
-
function mediaObjectKey(accountId, mediaId, objectId) {
|
|
21211
|
-
if (![accountId, mediaId, objectId].every((id2) => uuid.test(id2)))
|
|
21212
|
-
throw new Error("invalid_media_key");
|
|
21213
|
-
return `media/${accountId}/${mediaId}/${objectId}`;
|
|
21214
|
-
}
|
|
21215
|
-
function validateMediaKey(key2) {
|
|
21216
|
-
const [prefix, accountId, mediaId, objectId, extra] = key2.split("/");
|
|
21217
|
-
if (prefix !== "media" || extra !== void 0 || !accountId || !mediaId || !objectId || mediaObjectKey(accountId, mediaId, objectId) !== key2)
|
|
21218
|
-
throw new Error("invalid_media_key");
|
|
21219
|
-
return key2;
|
|
21220
|
-
}
|
|
21807
|
+
// lib/memory/src/conversation-documents.ts
|
|
21808
|
+
init_media();
|
|
21221
21809
|
|
|
21222
21810
|
// lib/memory/src/document-imports.ts
|
|
21223
21811
|
init_define_GROVE_TELEMETRY();
|
|
21224
21812
|
import { createHash as createHash11, randomUUID as randomUUID3 } from "node:crypto";
|
|
21813
|
+
init_contracts();
|
|
21814
|
+
init_media();
|
|
21225
21815
|
|
|
21226
21816
|
// lib/shared/src/document-imports.ts
|
|
21227
21817
|
init_define_GROVE_TELEMETRY();
|
|
21228
|
-
import { z as
|
|
21818
|
+
import { z as z17 } from "zod";
|
|
21229
21819
|
var documentImportLimits = {
|
|
21230
21820
|
files: 25,
|
|
21231
21821
|
bytes: 3 * 1024 * 1024,
|
|
21232
21822
|
notes: 500
|
|
21233
21823
|
};
|
|
21234
|
-
var importDestinationSchema =
|
|
21235
|
-
|
|
21236
|
-
|
|
21237
|
-
name:
|
|
21238
|
-
parentId:
|
|
21824
|
+
var importDestinationSchema = z17.union([
|
|
21825
|
+
z17.object({ projectId: z17.uuid(), version: z17.number().int().positive() }).strict(),
|
|
21826
|
+
z17.object({
|
|
21827
|
+
name: z17.string().trim().min(1).max(100),
|
|
21828
|
+
parentId: z17.uuid().nullable().default(null)
|
|
21239
21829
|
}).strict(),
|
|
21240
|
-
|
|
21830
|
+
z17.null()
|
|
21241
21831
|
]);
|
|
21242
|
-
var importBatchCreateSchema =
|
|
21243
|
-
var importDraftEditSchema =
|
|
21244
|
-
expectedVersion:
|
|
21245
|
-
content:
|
|
21246
|
-
included:
|
|
21832
|
+
var importBatchCreateSchema = z17.object({ id: z17.uuid() }).strict();
|
|
21833
|
+
var importDraftEditSchema = z17.object({
|
|
21834
|
+
expectedVersion: z17.number().int().positive(),
|
|
21835
|
+
content: z17.string().trim().min(1).max(6e3).optional(),
|
|
21836
|
+
included: z17.boolean().optional(),
|
|
21247
21837
|
destination: importDestinationSchema.optional()
|
|
21248
21838
|
}).strict();
|
|
21249
|
-
var importBatchConfirmSchema =
|
|
21250
|
-
var importPlacementSchema =
|
|
21251
|
-
expectedVersion:
|
|
21839
|
+
var importBatchConfirmSchema = z17.object({ id: z17.uuid(), expectedVersion: z17.number().int().positive() }).strict();
|
|
21840
|
+
var importPlacementSchema = z17.object({
|
|
21841
|
+
expectedVersion: z17.number().int().positive(),
|
|
21252
21842
|
destination: importDestinationSchema
|
|
21253
21843
|
}).strict();
|
|
21254
|
-
var importSuggestionsSchema =
|
|
21255
|
-
groups:
|
|
21256
|
-
|
|
21257
|
-
files:
|
|
21258
|
-
destination:
|
|
21259
|
-
name:
|
|
21260
|
-
reason:
|
|
21261
|
-
evidence:
|
|
21844
|
+
var importSuggestionsSchema = z17.object({
|
|
21845
|
+
groups: z17.array(
|
|
21846
|
+
z17.object({
|
|
21847
|
+
files: z17.array(z17.uuid()).min(1).max(25),
|
|
21848
|
+
destination: z17.array(z17.uuid()).max(1),
|
|
21849
|
+
name: z17.array(z17.string().trim().min(1).max(100)).max(1),
|
|
21850
|
+
reason: z17.string().min(1).max(300),
|
|
21851
|
+
evidence: z17.array(summaryEvidenceSchema).max(6)
|
|
21262
21852
|
}).strict()
|
|
21263
21853
|
).max(25)
|
|
21264
21854
|
}).strict();
|
|
21265
21855
|
|
|
21266
21856
|
// lib/memory/src/tasks.ts
|
|
21267
21857
|
init_define_GROVE_TELEMETRY();
|
|
21858
|
+
init_contracts();
|
|
21268
21859
|
import { createHash as createHash10 } from "node:crypto";
|
|
21269
21860
|
var fingerprint = (value) => createHash10("sha256").update(JSON.stringify(value)).digest("hex");
|
|
21270
21861
|
|
|
@@ -21682,9 +22273,13 @@ function conversationDocumentHandlers(service, extract) {
|
|
|
21682
22273
|
};
|
|
21683
22274
|
}
|
|
21684
22275
|
|
|
22276
|
+
// lib/memory/src/conversations.ts
|
|
22277
|
+
init_contracts();
|
|
22278
|
+
init_note_writing();
|
|
22279
|
+
|
|
21685
22280
|
// lib/shared/src/conversations.ts
|
|
21686
22281
|
init_define_GROVE_TELEMETRY();
|
|
21687
|
-
import { z as
|
|
22282
|
+
import { z as z18 } from "zod";
|
|
21688
22283
|
init_models();
|
|
21689
22284
|
|
|
21690
22285
|
// lib/shared/src/ask-tools.ts
|
|
@@ -21705,15 +22300,15 @@ var defaultAskTools = {
|
|
|
21705
22300
|
var askToolIds = Object.keys(askToolCatalog);
|
|
21706
22301
|
|
|
21707
22302
|
// lib/shared/src/conversations.ts
|
|
21708
|
-
var askToolsSchema =
|
|
22303
|
+
var askToolsSchema = z18.object({ exa: z18.boolean(), tavily: z18.boolean(), organize: z18.boolean() }).strict();
|
|
21709
22304
|
var askToolsPatchSchema = askToolsSchema.partial().refine(
|
|
21710
22305
|
(patch) => Object.keys(patch).length > 0,
|
|
21711
22306
|
"Choose at least one tool to update"
|
|
21712
22307
|
);
|
|
21713
|
-
var toolSettingsSchema =
|
|
22308
|
+
var toolSettingsSchema = z18.object({
|
|
21714
22309
|
tools: askToolsSchema,
|
|
21715
|
-
expectedVersion:
|
|
21716
|
-
saveDefault:
|
|
22310
|
+
expectedVersion: z18.number().int().nonnegative(),
|
|
22311
|
+
saveDefault: z18.boolean().optional(),
|
|
21717
22312
|
defaultPatch: askToolsPatchSchema.optional()
|
|
21718
22313
|
}).strict().refine(
|
|
21719
22314
|
({ tools, saveDefault, defaultPatch }) => !defaultPatch || saveDefault && Object.entries(defaultPatch).every(
|
|
@@ -21721,52 +22316,52 @@ var toolSettingsSchema = z17.object({
|
|
|
21721
22316
|
),
|
|
21722
22317
|
"Saved defaults must match the changed conversation tools"
|
|
21723
22318
|
);
|
|
21724
|
-
var researchRequestSchema =
|
|
21725
|
-
provider:
|
|
21726
|
-
query:
|
|
21727
|
-
urls:
|
|
22319
|
+
var researchRequestSchema = z18.object({
|
|
22320
|
+
provider: z18.enum(["exa", "tavily"]),
|
|
22321
|
+
query: z18.string().max(500),
|
|
22322
|
+
urls: z18.array(z18.string().max(2e3)).max(3)
|
|
21728
22323
|
}).strict();
|
|
21729
|
-
var webStatementSchema =
|
|
21730
|
-
text:
|
|
21731
|
-
urls:
|
|
22324
|
+
var webStatementSchema = z18.object({
|
|
22325
|
+
text: z18.string().trim().min(1).max(1200),
|
|
22326
|
+
urls: z18.array(z18.string().max(2e3)).min(1).max(5)
|
|
21732
22327
|
}).strict();
|
|
21733
|
-
var destinationSchema =
|
|
21734
|
-
var organizationProposalSchema =
|
|
21735
|
-
notebooks:
|
|
21736
|
-
|
|
21737
|
-
key:
|
|
21738
|
-
name:
|
|
22328
|
+
var destinationSchema = z18.union([z18.uuid(), z18.string().regex(/^new:[a-z0-9_-]{1,40}$/)]).nullable();
|
|
22329
|
+
var organizationProposalSchema = z18.object({
|
|
22330
|
+
notebooks: z18.array(
|
|
22331
|
+
z18.object({
|
|
22332
|
+
key: z18.string().regex(/^[a-z0-9_-]{1,40}$/),
|
|
22333
|
+
name: z18.string().trim().min(1).max(120),
|
|
21739
22334
|
parent: destinationSchema.default(null)
|
|
21740
22335
|
}).strict()
|
|
21741
22336
|
).max(6).default([]),
|
|
21742
|
-
renames:
|
|
21743
|
-
sourceRefSchema.extend({ name:
|
|
22337
|
+
renames: z18.array(
|
|
22338
|
+
sourceRefSchema.extend({ name: z18.string().trim().min(1).max(120) })
|
|
21744
22339
|
).max(6).default([]),
|
|
21745
|
-
moves:
|
|
21746
|
-
notebookMoves:
|
|
21747
|
-
notes:
|
|
21748
|
-
|
|
21749
|
-
content:
|
|
22340
|
+
moves: z18.array(sourceRefSchema.extend({ destination: destinationSchema })).max(30).default([]),
|
|
22341
|
+
notebookMoves: z18.array(sourceRefSchema.extend({ destination: destinationSchema })).max(6).optional(),
|
|
22342
|
+
notes: z18.array(
|
|
22343
|
+
z18.object({
|
|
22344
|
+
content: z18.string().trim().min(1).max(6e3),
|
|
21750
22345
|
destination: destinationSchema
|
|
21751
22346
|
}).strict()
|
|
21752
22347
|
).max(3).default([])
|
|
21753
22348
|
}).strict();
|
|
21754
|
-
var lifecycleProposalSchema =
|
|
21755
|
-
action:
|
|
21756
|
-
notes:
|
|
21757
|
-
notebooks:
|
|
22349
|
+
var lifecycleProposalSchema = z18.object({
|
|
22350
|
+
action: z18.enum(["archive", "restore", "delete"]),
|
|
22351
|
+
notes: z18.array(sourceRefSchema).max(30).default([]),
|
|
22352
|
+
notebooks: z18.array(sourceRefSchema).max(6).default([])
|
|
21758
22353
|
}).strict();
|
|
21759
|
-
var conversationScopeSchema =
|
|
21760
|
-
projectId:
|
|
21761
|
-
includePersonal:
|
|
22354
|
+
var conversationScopeSchema = z18.object({
|
|
22355
|
+
projectId: z18.uuid().nullable().optional(),
|
|
22356
|
+
includePersonal: z18.boolean().default(false)
|
|
21762
22357
|
}).strict();
|
|
21763
22358
|
var conversationCreateSchema = conversationScopeSchema.extend({
|
|
21764
|
-
id:
|
|
22359
|
+
id: z18.uuid()
|
|
21765
22360
|
});
|
|
21766
|
-
var conversationContextSchema =
|
|
21767
|
-
notes:
|
|
21768
|
-
notebooks:
|
|
21769
|
-
only:
|
|
22361
|
+
var conversationContextSchema = z18.object({
|
|
22362
|
+
notes: z18.array(z18.uuid().transform((id2) => id2.toLowerCase())).max(12),
|
|
22363
|
+
notebooks: z18.array(z18.uuid().transform((id2) => id2.toLowerCase())).max(6),
|
|
22364
|
+
only: z18.boolean()
|
|
21770
22365
|
}).strict().refine(
|
|
21771
22366
|
({ notes, notebooks }) => notes.length + notebooks.length > 0,
|
|
21772
22367
|
"Choose a source"
|
|
@@ -21774,18 +22369,18 @@ var conversationContextSchema = z17.object({
|
|
|
21774
22369
|
({ notes, notebooks }) => new Set(notes).size === notes.length && new Set(notebooks).size === notebooks.length,
|
|
21775
22370
|
"Choose each source once"
|
|
21776
22371
|
);
|
|
21777
|
-
var conversationTurnSchema =
|
|
21778
|
-
id:
|
|
21779
|
-
query:
|
|
21780
|
-
format:
|
|
21781
|
-
expectedVersion:
|
|
21782
|
-
refreshSources:
|
|
22372
|
+
var conversationTurnSchema = z18.object({
|
|
22373
|
+
id: z18.uuid(),
|
|
22374
|
+
query: z18.string().trim().min(1).max(6e3),
|
|
22375
|
+
format: z18.enum(["plain", "markdown"]).default("plain"),
|
|
22376
|
+
expectedVersion: z18.number().int().min(0),
|
|
22377
|
+
refreshSources: z18.boolean().optional(),
|
|
21783
22378
|
context: conversationContextSchema.optional(),
|
|
21784
|
-
documentsVersion:
|
|
22379
|
+
documentsVersion: z18.number().int().nonnegative().optional()
|
|
21785
22380
|
}).strict();
|
|
21786
|
-
var conversationPlanSchema =
|
|
21787
|
-
query:
|
|
21788
|
-
intent:
|
|
22381
|
+
var conversationPlanSchema = z18.object({
|
|
22382
|
+
query: z18.string().trim().min(1).max(1e3),
|
|
22383
|
+
intent: z18.enum([
|
|
21789
22384
|
"answer",
|
|
21790
22385
|
"find",
|
|
21791
22386
|
"edit",
|
|
@@ -21796,50 +22391,50 @@ var conversationPlanSchema = z17.object({
|
|
|
21796
22391
|
"restore",
|
|
21797
22392
|
"delete"
|
|
21798
22393
|
]),
|
|
21799
|
-
references:
|
|
21800
|
-
research:
|
|
21801
|
-
organizeAfter:
|
|
22394
|
+
references: z18.array(z18.uuid()).max(8),
|
|
22395
|
+
research: z18.array(researchRequestSchema).max(2).default([]),
|
|
22396
|
+
organizeAfter: z18.uuid().nullable().default(null)
|
|
21802
22397
|
}).strict();
|
|
21803
|
-
var noteProposalSchema =
|
|
21804
|
-
kind:
|
|
22398
|
+
var noteProposalSchema = z18.object({
|
|
22399
|
+
kind: z18.enum(["edit", "merge", "create"]),
|
|
21805
22400
|
target: sourceRefSchema.nullable(),
|
|
21806
|
-
sources:
|
|
21807
|
-
content:
|
|
22401
|
+
sources: z18.array(sourceRefSchema).max(6),
|
|
22402
|
+
content: z18.string().trim().min(1).max(6e3)
|
|
21808
22403
|
}).strict();
|
|
21809
|
-
var conversationReplySchema =
|
|
21810
|
-
message:
|
|
22404
|
+
var conversationReplySchema = z18.object({
|
|
22405
|
+
message: z18.string().trim().max(2e3),
|
|
21811
22406
|
statements: answerSchema.shape.statements,
|
|
21812
22407
|
proposal: noteProposalSchema.nullable(),
|
|
21813
|
-
webStatements:
|
|
22408
|
+
webStatements: z18.array(webStatementSchema).max(8).default([])
|
|
21814
22409
|
}).strict();
|
|
21815
22410
|
var conversationGenerationSchema = conversationReplySchema.omit({ proposal: true }).extend({
|
|
21816
|
-
documentStatements:
|
|
21817
|
-
lifecycle:
|
|
21818
|
-
organization:
|
|
21819
|
-
proposals:
|
|
22411
|
+
documentStatements: z18.array(documentStatementSchema).max(8).default([]),
|
|
22412
|
+
lifecycle: z18.array(lifecycleProposalSchema).max(1).default([]),
|
|
22413
|
+
organization: z18.array(organizationProposalSchema).max(1).default([]),
|
|
22414
|
+
proposals: z18.array(
|
|
21820
22415
|
noteProposalSchema.extend({
|
|
21821
|
-
target:
|
|
22416
|
+
target: z18.array(sourceRefSchema).max(1)
|
|
21822
22417
|
})
|
|
21823
22418
|
).max(1)
|
|
21824
22419
|
});
|
|
21825
22420
|
function conversationResponseSchema(intent, notes, web, writes) {
|
|
21826
22421
|
const proposal = conversationGenerationSchema.shape.proposals.element;
|
|
21827
22422
|
return conversationGenerationSchema.extend({
|
|
21828
|
-
lifecycle: writes && ["archive", "restore", "delete"].includes(intent) ?
|
|
22423
|
+
lifecycle: writes && ["archive", "restore", "delete"].includes(intent) ? z18.array(
|
|
21829
22424
|
lifecycleProposalSchema.extend({
|
|
21830
|
-
action:
|
|
22425
|
+
action: z18.literal(intent)
|
|
21831
22426
|
})
|
|
21832
|
-
).max(1).default([]) :
|
|
21833
|
-
statements: notes ? conversationReplySchema.shape.statements :
|
|
21834
|
-
webStatements: web ? conversationReplySchema.shape.webStatements :
|
|
21835
|
-
organization: writes && intent === "organize" ? conversationGenerationSchema.shape.organization :
|
|
21836
|
-
proposals: !writes ?
|
|
22427
|
+
).max(1).default([]) : z18.tuple([]).default([]),
|
|
22428
|
+
statements: notes ? conversationReplySchema.shape.statements : z18.tuple([]),
|
|
22429
|
+
webStatements: web ? conversationReplySchema.shape.webStatements : z18.tuple([]).default([]),
|
|
22430
|
+
organization: writes && intent === "organize" ? conversationGenerationSchema.shape.organization : z18.tuple([]).default([]),
|
|
22431
|
+
proposals: !writes ? z18.tuple([]).default([]) : intent === "create" ? z18.array(
|
|
21837
22432
|
proposal.extend({
|
|
21838
|
-
kind:
|
|
21839
|
-
target:
|
|
21840
|
-
sources:
|
|
22433
|
+
kind: z18.literal("create"),
|
|
22434
|
+
target: z18.tuple([]),
|
|
22435
|
+
sources: z18.tuple([])
|
|
21841
22436
|
})
|
|
21842
|
-
).max(1) : notes && (intent === "edit" || intent === "merge") ?
|
|
22437
|
+
).max(1) : notes && (intent === "edit" || intent === "merge") ? z18.array(proposal.extend({ kind: z18.literal(intent) })).max(1) : z18.tuple([]).default([])
|
|
21843
22438
|
});
|
|
21844
22439
|
}
|
|
21845
22440
|
|
|
@@ -21849,6 +22444,7 @@ var inConversationScope = (scope, projectId) => scope.projectId === void 0 || pr
|
|
|
21849
22444
|
|
|
21850
22445
|
// lib/memory/src/conversation-context.ts
|
|
21851
22446
|
init_define_GROVE_TELEMETRY();
|
|
22447
|
+
init_contracts();
|
|
21852
22448
|
async function resolveConversationContext(trx, scope, selection, query) {
|
|
21853
22449
|
if (!selection) return { sources: [], notebooks: [] };
|
|
21854
22450
|
const unavailable4 = () => new GroveError(
|
|
@@ -22101,6 +22697,7 @@ async function applyOrganization(service, principal, trx, turnId, proposal, scop
|
|
|
22101
22697
|
// lib/memory/src/conversation-lifecycle.ts
|
|
22102
22698
|
init_define_GROVE_TELEMETRY();
|
|
22103
22699
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
22700
|
+
init_contracts();
|
|
22104
22701
|
async function lifecyclePreview(service, principal, trx, changes, sources, notebooks, scope) {
|
|
22105
22702
|
if (!changes.notes.length && !changes.notebooks.length)
|
|
22106
22703
|
throw changedSources();
|
|
@@ -23545,6 +24142,7 @@ var Conversations = class {
|
|
|
23545
24142
|
|
|
23546
24143
|
// lib/memory/src/relationships.ts
|
|
23547
24144
|
init_define_GROVE_TELEMETRY();
|
|
24145
|
+
init_contracts();
|
|
23548
24146
|
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
23549
24147
|
var unavailable = () => new GroveError("not_found", "Connection unavailable", 404);
|
|
23550
24148
|
var Relationships = class {
|
|
@@ -23895,32 +24493,7 @@ function semanticMatches(trx, eligible2, embedder, vector, limit) {
|
|
|
23895
24493
|
|
|
23896
24494
|
// lib/memory/src/lexical.ts
|
|
23897
24495
|
init_define_GROVE_TELEMETRY();
|
|
23898
|
-
|
|
23899
|
-
// lib/shared/src/search.ts
|
|
23900
|
-
init_define_GROVE_TELEMETRY();
|
|
23901
|
-
function noteTitle2(content3, organized) {
|
|
23902
|
-
const first = content3.trim().split("\n")[0];
|
|
23903
|
-
const heading = first.match(/^#{1,6}\s+(.+)/)?.[1].trim();
|
|
23904
|
-
if (!heading && organized) return organized;
|
|
23905
|
-
const text5 = (heading || first).slice(0, 110);
|
|
23906
|
-
return /[\uD800-\uDBFF]$/.test(text5) ? text5.slice(0, -1) : text5;
|
|
23907
|
-
}
|
|
23908
|
-
function plainExcerpt(content3, length = 160) {
|
|
23909
|
-
const text5 = content3.trim().replace(/^#{1,6}[ \t]+[^\n]+\n+/, "").replace(/^[ \t]*(?:`{3,}|~{3,})[^\n]*$/gm, "").replace(/^[ \t]*(?:>[ \t]*)+/gm, "").replace(/^[ \t]*(?:[-+*]|\d+[.)])[ \t]+(?:\[[ xX]\][ \t]*)?/gm, "").replace(/!?\[([^\]\n]+)\]\([^\n)]*\)/g, "$1").replace(/[#*`_]/g, "").replace(/\s+/g, " ").trim();
|
|
23910
|
-
return text5.length > length ? `${text5.slice(0, length).trimEnd()}\u2026` : text5;
|
|
23911
|
-
}
|
|
23912
|
-
function searchExpansion(query) {
|
|
23913
|
-
if (!/^[\p{L}\p{N}\s_]+$/u.test(query) || /\bor\b/i.test(query)) return;
|
|
23914
|
-
const tokens = query.match(/[\p{L}\p{N}]+/gu) ?? [];
|
|
23915
|
-
if (!tokens.length || tokens.length > 16 || tokens.some((t) => t.length > 64))
|
|
23916
|
-
return;
|
|
23917
|
-
return {
|
|
23918
|
-
tokens,
|
|
23919
|
-
prefix: tokens.at(-1).length >= 2 ? tokens.map((t, i) => t + (i === tokens.length - 1 ? ":*" : "")).join(" & ") : void 0
|
|
23920
|
-
};
|
|
23921
|
-
}
|
|
23922
|
-
|
|
23923
|
-
// lib/memory/src/lexical.ts
|
|
24496
|
+
init_search();
|
|
23924
24497
|
var searchVersion = "title-prefix-trgm-shortfall40-v1";
|
|
23925
24498
|
function lexicalQuery(trx, eligible2, query, providers, account, semantic) {
|
|
23926
24499
|
const expansion = searchExpansion(query);
|
|
@@ -24062,6 +24635,8 @@ async function relevancePage(trx, query, limit, after) {
|
|
|
24062
24635
|
|
|
24063
24636
|
// lib/memory/src/search-evidence.ts
|
|
24064
24637
|
init_define_GROVE_TELEMETRY();
|
|
24638
|
+
init_contracts();
|
|
24639
|
+
init_search();
|
|
24065
24640
|
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
24066
24641
|
async function searchEvidence(trx, items, query, rows) {
|
|
24067
24642
|
if (!items.length) return {};
|
|
@@ -24169,6 +24744,7 @@ async function admitOperation(owner, principal, run2) {
|
|
|
24169
24744
|
// lib/memory/src/assistance.ts
|
|
24170
24745
|
init_define_GROVE_TELEMETRY();
|
|
24171
24746
|
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
24747
|
+
init_contracts();
|
|
24172
24748
|
var missing5 = () => new GroveError("not_found", "Preview unavailable", 404);
|
|
24173
24749
|
var conflict2 = () => new GroveError("preview_changed", "This preview changed. Reopen it.", 409);
|
|
24174
24750
|
var NotebookAssistance = class {
|
|
@@ -24459,10 +25035,11 @@ import {
|
|
|
24459
25035
|
createHash as createHash14,
|
|
24460
25036
|
randomBytes
|
|
24461
25037
|
} from "node:crypto";
|
|
25038
|
+
init_contracts();
|
|
24462
25039
|
|
|
24463
25040
|
// lib/shared/src/writing-assistance.ts
|
|
24464
25041
|
init_define_GROVE_TELEMETRY();
|
|
24465
|
-
import { z as
|
|
25042
|
+
import { z as z19 } from "zod";
|
|
24466
25043
|
var writingTools2 = [
|
|
24467
25044
|
{
|
|
24468
25045
|
id: "concise",
|
|
@@ -24501,7 +25078,7 @@ var writingTools2 = [
|
|
|
24501
25078
|
instruction: "Suggest three English antonyms for the selected word. These deliberately change its meaning. Return only short words or phrases, not definitions or commentary. Do not invent opposites for names or words with no clear opposite."
|
|
24502
25079
|
}
|
|
24503
25080
|
];
|
|
24504
|
-
var writingToolSchema =
|
|
25081
|
+
var writingToolSchema = z19.enum([
|
|
24505
25082
|
"concise",
|
|
24506
25083
|
"verbose",
|
|
24507
25084
|
"rewrite",
|
|
@@ -24530,22 +25107,22 @@ function selectWritingSentence(source3, from, to) {
|
|
|
24530
25107
|
from += selected2.length - selected2.trimStart().length;
|
|
24531
25108
|
return { language: "en", from, to: from + original.length, original };
|
|
24532
25109
|
}
|
|
24533
|
-
var writingContextSchema =
|
|
24534
|
-
previousSentence:
|
|
24535
|
-
nextSentence:
|
|
24536
|
-
sentenceBefore:
|
|
24537
|
-
sentenceAfter:
|
|
24538
|
-
startsSentence:
|
|
24539
|
-
endsSentence:
|
|
24540
|
-
startsParagraph:
|
|
24541
|
-
endsParagraph:
|
|
25110
|
+
var writingContextSchema = z19.object({
|
|
25111
|
+
previousSentence: z19.string().max(writingLimits.contextExcerpt),
|
|
25112
|
+
nextSentence: z19.string().max(writingLimits.contextExcerpt),
|
|
25113
|
+
sentenceBefore: z19.string().max(writingLimits.contextExcerpt),
|
|
25114
|
+
sentenceAfter: z19.string().max(writingLimits.contextExcerpt),
|
|
25115
|
+
startsSentence: z19.boolean(),
|
|
25116
|
+
endsSentence: z19.boolean(),
|
|
25117
|
+
startsParagraph: z19.boolean(),
|
|
25118
|
+
endsParagraph: z19.boolean()
|
|
24542
25119
|
}).strict();
|
|
24543
|
-
var writingRequestSchema =
|
|
24544
|
-
id:
|
|
24545
|
-
sessionId:
|
|
24546
|
-
language:
|
|
25120
|
+
var writingRequestSchema = z19.object({
|
|
25121
|
+
id: z19.uuid(),
|
|
25122
|
+
sessionId: z19.uuid(),
|
|
25123
|
+
language: z19.literal("en"),
|
|
24547
25124
|
tool: writingToolSchema,
|
|
24548
|
-
sentence:
|
|
25125
|
+
sentence: z19.string().min(1).max(writingLimits.sentence).refine(
|
|
24549
25126
|
(text5) => selectWritingSentence(text5, 0, text5.length)?.original === text5,
|
|
24550
25127
|
"Select one English sentence."
|
|
24551
25128
|
),
|
|
@@ -24564,8 +25141,8 @@ var writingRequestSchema = z18.object({
|
|
|
24564
25141
|
message: "Select one word."
|
|
24565
25142
|
});
|
|
24566
25143
|
});
|
|
24567
|
-
var writingAlternativesSchema =
|
|
24568
|
-
alternatives:
|
|
25144
|
+
var writingAlternativesSchema = z19.object({
|
|
25145
|
+
alternatives: z19.array(z19.string().trim().min(1).max(writingLimits.alternative)).min(2).max(writingLimits.alternatives)
|
|
24569
25146
|
}).strict();
|
|
24570
25147
|
function validateWritingAlternatives(request2, raw) {
|
|
24571
25148
|
const result = writingAlternativesSchema.parse(raw);
|
|
@@ -24585,12 +25162,12 @@ function validateWritingAlternatives(request2, raw) {
|
|
|
24585
25162
|
alternatives
|
|
24586
25163
|
};
|
|
24587
25164
|
}
|
|
24588
|
-
var writingAvailabilitySchema =
|
|
24589
|
-
available:
|
|
24590
|
-
authorized:
|
|
24591
|
-
consented:
|
|
24592
|
-
policy:
|
|
24593
|
-
provider:
|
|
25165
|
+
var writingAvailabilitySchema = z19.object({
|
|
25166
|
+
available: z19.boolean(),
|
|
25167
|
+
authorized: z19.boolean(),
|
|
25168
|
+
consented: z19.boolean(),
|
|
25169
|
+
policy: z19.string().max(100),
|
|
25170
|
+
provider: z19.string().max(1e3).nullable()
|
|
24594
25171
|
});
|
|
24595
25172
|
|
|
24596
25173
|
// lib/memory/src/writing-jobs.ts
|
|
@@ -24656,7 +25233,7 @@ async function cancelRows(trx, rows, status = "cancelled") {
|
|
|
24656
25233
|
await settleNamedAction(
|
|
24657
25234
|
trx,
|
|
24658
25235
|
row.accountId,
|
|
24659
|
-
"
|
|
25236
|
+
"writing",
|
|
24660
25237
|
operation(row.id),
|
|
24661
25238
|
row.providerStartedAt ? "completed" : "released"
|
|
24662
25239
|
);
|
|
@@ -24714,7 +25291,7 @@ function writingHandlers(service, key2, db = service.db, providerNotice) {
|
|
|
24714
25291
|
await settleNamedAction(
|
|
24715
25292
|
trx,
|
|
24716
25293
|
row2.accountId,
|
|
24717
|
-
"
|
|
25294
|
+
"writing",
|
|
24718
25295
|
operation(row2.id),
|
|
24719
25296
|
"completed",
|
|
24720
25297
|
true
|
|
@@ -24758,7 +25335,7 @@ function writingHandlers(service, key2, db = service.db, providerNotice) {
|
|
|
24758
25335
|
db,
|
|
24759
25336
|
trx,
|
|
24760
25337
|
row.accountId,
|
|
24761
|
-
"
|
|
25338
|
+
"writing",
|
|
24762
25339
|
operation(row.id)
|
|
24763
25340
|
)
|
|
24764
25341
|
);
|
|
@@ -24806,7 +25383,7 @@ function writingHandlers(service, key2, db = service.db, providerNotice) {
|
|
|
24806
25383
|
await settleNamedAction(
|
|
24807
25384
|
trx,
|
|
24808
25385
|
row.accountId,
|
|
24809
|
-
"
|
|
25386
|
+
"writing",
|
|
24810
25387
|
operation(row.id),
|
|
24811
25388
|
"completed",
|
|
24812
25389
|
true
|
|
@@ -24824,7 +25401,7 @@ function writingHandlers(service, key2, db = service.db, providerNotice) {
|
|
|
24824
25401
|
await settleNamedAction(
|
|
24825
25402
|
trx,
|
|
24826
25403
|
row.accountId,
|
|
24827
|
-
"
|
|
25404
|
+
"writing",
|
|
24828
25405
|
operation(row.id),
|
|
24829
25406
|
"completed",
|
|
24830
25407
|
true
|
|
@@ -24960,17 +25537,18 @@ function cleanupHandlers(db, deleteIdentity, cancelBilling) {
|
|
|
24960
25537
|
|
|
24961
25538
|
// lib/memory/src/files.ts
|
|
24962
25539
|
init_define_GROVE_TELEMETRY();
|
|
25540
|
+
init_contracts();
|
|
24963
25541
|
|
|
24964
25542
|
// lib/shared/src/files.ts
|
|
24965
25543
|
init_define_GROVE_TELEMETRY();
|
|
24966
|
-
import { z as
|
|
24967
|
-
var fileSourceSchema =
|
|
24968
|
-
var fileCursorSchema =
|
|
24969
|
-
var fileSearchSchema =
|
|
24970
|
-
query:
|
|
24971
|
-
kind:
|
|
24972
|
-
sort:
|
|
24973
|
-
view:
|
|
25544
|
+
import { z as z20 } from "zod";
|
|
25545
|
+
var fileSourceSchema = z20.enum(["chat", "import", "media"]);
|
|
25546
|
+
var fileCursorSchema = z20.object({ owner: z20.uuid(), binding: z20.string(), key: z20.string().max(512) }).strict();
|
|
25547
|
+
var fileSearchSchema = z20.object({
|
|
25548
|
+
query: z20.string().trim().max(200).default(""),
|
|
25549
|
+
kind: z20.enum(["document", "image", "recording"]).optional(),
|
|
25550
|
+
sort: z20.enum(["newest", "name", "size"]).default("newest"),
|
|
25551
|
+
view: z20.enum([
|
|
24974
25552
|
"all",
|
|
24975
25553
|
"temporary",
|
|
24976
25554
|
"attention",
|
|
@@ -24978,26 +25556,27 @@ var fileSearchSchema = z19.object({
|
|
|
24978
25556
|
"unfiled",
|
|
24979
25557
|
"history"
|
|
24980
25558
|
]).default("all"),
|
|
24981
|
-
memoryId:
|
|
24982
|
-
projectId:
|
|
24983
|
-
conversationId:
|
|
24984
|
-
after:
|
|
25559
|
+
memoryId: z20.uuid().optional(),
|
|
25560
|
+
projectId: z20.uuid().optional(),
|
|
25561
|
+
conversationId: z20.uuid().optional(),
|
|
25562
|
+
after: z20.string().max(2048).optional()
|
|
24985
25563
|
}).strict();
|
|
24986
|
-
var fileLocationsSchema =
|
|
25564
|
+
var fileLocationsSchema = z20.object({
|
|
24987
25565
|
source: fileSourceSchema,
|
|
24988
|
-
id:
|
|
24989
|
-
after:
|
|
25566
|
+
id: z20.uuid(),
|
|
25567
|
+
after: z20.string().max(2048).optional()
|
|
24990
25568
|
}).strict();
|
|
24991
|
-
var filePositionSchema =
|
|
24992
|
-
value:
|
|
25569
|
+
var filePositionSchema = z20.object({
|
|
25570
|
+
value: z20.string().max(200),
|
|
24993
25571
|
source: fileSourceSchema,
|
|
24994
|
-
id:
|
|
25572
|
+
id: z20.uuid()
|
|
24995
25573
|
}).strict();
|
|
24996
25574
|
|
|
24997
25575
|
// lib/memory/src/speech.ts
|
|
24998
25576
|
init_define_GROVE_TELEMETRY();
|
|
24999
25577
|
import { createHash as createHash15, randomUUID as randomUUID10 } from "node:crypto";
|
|
25000
25578
|
import { setTimeout as setTimeout6 } from "node:timers/promises";
|
|
25579
|
+
init_contracts();
|
|
25001
25580
|
var keys = (kind) => kind === "speech_transcribe" ? {
|
|
25002
25581
|
preference: "transcriptionEnabled",
|
|
25003
25582
|
version: "transcriptionVersion",
|
|
@@ -25784,14 +26363,17 @@ function exportHandlers(db, store, media) {
|
|
|
25784
26363
|
|
|
25785
26364
|
// lib/memory/src/imports.ts
|
|
25786
26365
|
init_define_GROVE_TELEMETRY();
|
|
26366
|
+
init_contracts();
|
|
25787
26367
|
|
|
25788
26368
|
// lib/shared/src/jobs.ts
|
|
25789
26369
|
init_define_GROVE_TELEMETRY();
|
|
25790
|
-
import { z as
|
|
26370
|
+
import { z as z22 } from "zod";
|
|
25791
26371
|
|
|
25792
26372
|
// lib/shared/src/web-capture.ts
|
|
25793
26373
|
init_define_GROVE_TELEMETRY();
|
|
25794
|
-
|
|
26374
|
+
init_contracts();
|
|
26375
|
+
init_limits();
|
|
26376
|
+
import { z as z21 } from "zod";
|
|
25795
26377
|
var trackingParameters = /* @__PURE__ */ new Set([
|
|
25796
26378
|
"utm_source",
|
|
25797
26379
|
"utm_medium",
|
|
@@ -25811,7 +26393,7 @@ function containsControlCharacters(value) {
|
|
|
25811
26393
|
});
|
|
25812
26394
|
}
|
|
25813
26395
|
function normalizeWebUrl(input) {
|
|
25814
|
-
if (typeof input !== "string" || input.length >
|
|
26396
|
+
if (typeof input !== "string" || input.length > WEB_URL_MAX || !/^https?:\/\//i.test(input) || /\s/u.test(input) || containsControlCharacters(input))
|
|
25815
26397
|
throw new Error("Invalid source URL");
|
|
25816
26398
|
let url;
|
|
25817
26399
|
try {
|
|
@@ -25828,34 +26410,41 @@ function normalizeWebUrl(input) {
|
|
|
25828
26410
|
});
|
|
25829
26411
|
if (retained.length !== parts.length) url.search = retained.join("&");
|
|
25830
26412
|
const normalized = url.href;
|
|
25831
|
-
if (normalized.length >
|
|
26413
|
+
if (normalized.length > WEB_URL_MAX)
|
|
26414
|
+
throw new Error("Invalid source URL: too long");
|
|
25832
26415
|
return normalized;
|
|
25833
26416
|
}
|
|
25834
|
-
var webCaptureSchema =
|
|
25835
|
-
url:
|
|
26417
|
+
var webCaptureSchema = z21.object({
|
|
26418
|
+
url: z21.string().max(WEB_URL_MAX).transform((value, ctx) => {
|
|
25836
26419
|
try {
|
|
25837
26420
|
return normalizeWebUrl(value);
|
|
25838
26421
|
} catch {
|
|
25839
26422
|
ctx.addIssue({ code: "custom", message: "Invalid source URL" });
|
|
25840
|
-
return
|
|
26423
|
+
return z21.NEVER;
|
|
25841
26424
|
}
|
|
25842
26425
|
}),
|
|
25843
|
-
title:
|
|
26426
|
+
title: z21.string().max(300).refine((value) => !containsControlCharacters(value), {
|
|
25844
26427
|
message: "Source title must be a single line"
|
|
25845
26428
|
}),
|
|
25846
|
-
capturedAt:
|
|
26429
|
+
capturedAt: z21.iso.datetime()
|
|
25847
26430
|
}).strict();
|
|
25848
|
-
var browserCaptureRequestSchema =
|
|
25849
|
-
operationId:
|
|
26431
|
+
var browserCaptureRequestSchema = z21.object({
|
|
26432
|
+
operationId: z21.uuid(),
|
|
26433
|
+
id: z21.uuid().optional(),
|
|
26434
|
+
expectedVersion: z21.number().int().positive().optional(),
|
|
26435
|
+
editSession: z21.uuid().optional(),
|
|
25850
26436
|
content: rememberSchema.shape.content,
|
|
25851
|
-
projectId:
|
|
25852
|
-
capture:
|
|
26437
|
+
projectId: z21.uuid().nullable(),
|
|
26438
|
+
capture: z21.literal("explicit"),
|
|
25853
26439
|
provenance: webCaptureSchema.optional()
|
|
25854
|
-
}).strict()
|
|
25855
|
-
|
|
26440
|
+
}).strict().refine(
|
|
26441
|
+
(input) => Boolean(input.id) === Boolean(input.expectedVersion),
|
|
26442
|
+
"Updates require both id and expectedVersion"
|
|
26443
|
+
);
|
|
26444
|
+
var browserPageRequestSchema = z21.object({
|
|
25856
26445
|
url: webCaptureSchema.shape.url,
|
|
25857
|
-
projectId:
|
|
25858
|
-
cursor:
|
|
26446
|
+
projectId: z21.uuid().nullable(),
|
|
26447
|
+
cursor: z21.string().max(2048).optional()
|
|
25859
26448
|
}).strict();
|
|
25860
26449
|
|
|
25861
26450
|
// lib/shared/src/jobs.ts
|
|
@@ -25866,22 +26455,22 @@ var queueLanes = [
|
|
|
25866
26455
|
"maintenance",
|
|
25867
26456
|
"bulk"
|
|
25868
26457
|
];
|
|
25869
|
-
var exportRequestSchema =
|
|
25870
|
-
id:
|
|
25871
|
-
projectId:
|
|
25872
|
-
includeDescendants:
|
|
25873
|
-
includeMedia:
|
|
26458
|
+
var exportRequestSchema = z22.object({
|
|
26459
|
+
id: z22.uuid(),
|
|
26460
|
+
projectId: z22.uuid().optional(),
|
|
26461
|
+
includeDescendants: z22.boolean().default(false),
|
|
26462
|
+
includeMedia: z22.boolean().optional()
|
|
25874
26463
|
}).strict();
|
|
25875
|
-
var importRecordSchema =
|
|
25876
|
-
sourceId:
|
|
25877
|
-
content:
|
|
25878
|
-
projectId:
|
|
26464
|
+
var importRecordSchema = z22.object({
|
|
26465
|
+
sourceId: z22.string().min(1).max(200),
|
|
26466
|
+
content: z22.string().min(1).max(6e3),
|
|
26467
|
+
projectId: z22.uuid().nullable().default(null),
|
|
25879
26468
|
webCapture: webCaptureSchema.optional()
|
|
25880
26469
|
}).strict();
|
|
25881
|
-
var importRequestSchema =
|
|
25882
|
-
id:
|
|
25883
|
-
source:
|
|
25884
|
-
records:
|
|
26470
|
+
var importRequestSchema = z22.object({
|
|
26471
|
+
id: z22.uuid(),
|
|
26472
|
+
source: z22.string().regex(/^[a-zA-Z0-9._-]{1,100}$/),
|
|
26473
|
+
records: z22.array(importRecordSchema).min(1).max(100)
|
|
25885
26474
|
}).strict();
|
|
25886
26475
|
|
|
25887
26476
|
// lib/memory/src/imports.ts
|
|
@@ -25990,135 +26579,93 @@ function importHandlers(service, connectors = /* @__PURE__ */ new Map()) {
|
|
|
25990
26579
|
return { import: importTask, connector_sync };
|
|
25991
26580
|
}
|
|
25992
26581
|
|
|
26582
|
+
// lib/memory/src/index.ts
|
|
26583
|
+
init_contracts();
|
|
26584
|
+
|
|
25993
26585
|
// lib/memory/src/connect.ts
|
|
25994
26586
|
init_define_GROVE_TELEMETRY();
|
|
26587
|
+
init_contracts();
|
|
25995
26588
|
|
|
25996
26589
|
// lib/memory/src/sharing.ts
|
|
25997
26590
|
init_define_GROVE_TELEMETRY();
|
|
26591
|
+
init_contracts();
|
|
26592
|
+
init_sharing();
|
|
25998
26593
|
|
|
25999
|
-
// lib/
|
|
26000
|
-
|
|
26001
|
-
import { z as z22 } from "zod";
|
|
26002
|
-
|
|
26003
|
-
// lib/shared/src/share-durations.ts
|
|
26004
|
-
init_define_GROVE_TELEMETRY();
|
|
26005
|
-
|
|
26006
|
-
// lib/shared/src/sharing.ts
|
|
26007
|
-
var shareTokenSchema = z22.string().regex(/^gsh_[A-Za-z0-9_-]{43}$/);
|
|
26008
|
-
var shareDurationSchema = z22.enum([
|
|
26009
|
-
"1h",
|
|
26010
|
-
"4h",
|
|
26011
|
-
"1d",
|
|
26012
|
-
"1w",
|
|
26013
|
-
"2w",
|
|
26014
|
-
"1mo"
|
|
26015
|
-
]);
|
|
26016
|
-
var shareMutationSchema = z22.object({
|
|
26017
|
-
operationId: operationSchema,
|
|
26018
|
-
expectedVersion: z22.number().int().positive()
|
|
26019
|
-
}).strict();
|
|
26020
|
-
var shareEnableSchema = shareMutationSchema.extend({
|
|
26021
|
-
expectedVersion: z22.number().int().min(0),
|
|
26022
|
-
expectedTargetVersion: z22.number().int().positive(),
|
|
26023
|
-
includeDescendants: z22.boolean().default(false),
|
|
26024
|
-
duration: shareDurationSchema.nullable().optional()
|
|
26025
|
-
});
|
|
26026
|
-
var shareScopeSchema = shareMutationSchema.extend({
|
|
26027
|
-
includeDescendants: z22.boolean().optional(),
|
|
26028
|
-
duration: shareDurationSchema.nullable().optional()
|
|
26029
|
-
}).refine(
|
|
26030
|
-
(value) => value.includeDescendants !== void 0 || value.duration !== void 0,
|
|
26031
|
-
"Choose a sharing setting to change"
|
|
26032
|
-
);
|
|
26033
|
-
var publicShareQuerySchema = z22.object({
|
|
26034
|
-
cursor: z22.string().max(2048).optional(),
|
|
26035
|
-
limit: z22.coerce.number().int().min(1).max(100).default(30)
|
|
26036
|
-
}).strict();
|
|
26037
|
-
var notebook = z22.object({ id: uuidSchema, name: z22.string() }).strict();
|
|
26038
|
-
var publicNoteSchema = z22.object({
|
|
26039
|
-
id: uuidSchema,
|
|
26040
|
-
title: z22.string(),
|
|
26041
|
-
content: z22.string(),
|
|
26042
|
-
updatedAt: z22.string(),
|
|
26043
|
-
linkedNoteIds: z22.array(uuidSchema)
|
|
26044
|
-
}).strict();
|
|
26045
|
-
var publicShareSchema = z22.object({
|
|
26046
|
-
kind: z22.enum(["note", "notebook"]),
|
|
26047
|
-
root: notebook,
|
|
26048
|
-
notebook: notebook.nullable(),
|
|
26049
|
-
note: publicNoteSchema.nullable(),
|
|
26050
|
-
notebooks: z22.array(notebook),
|
|
26051
|
-
notes: z22.array(
|
|
26052
|
-
publicNoteSchema.pick({ id: true, title: true, updatedAt: true })
|
|
26053
|
-
),
|
|
26054
|
-
nextCursor: z22.string().nullable()
|
|
26055
|
-
}).strict();
|
|
26056
|
-
|
|
26057
|
-
// lib/memory/src/media.ts
|
|
26058
|
-
init_define_GROVE_TELEMETRY();
|
|
26594
|
+
// lib/memory/src/index.ts
|
|
26595
|
+
init_media2();
|
|
26059
26596
|
|
|
26060
26597
|
// lib/memory/src/conversation-history.ts
|
|
26061
26598
|
init_define_GROVE_TELEMETRY();
|
|
26599
|
+
init_contracts();
|
|
26062
26600
|
|
|
26063
26601
|
// lib/shared/src/conversation-history.ts
|
|
26064
26602
|
init_define_GROVE_TELEMETRY();
|
|
26065
|
-
import { z as
|
|
26066
|
-
var conversationHistorySchema =
|
|
26067
|
-
query:
|
|
26068
|
-
after:
|
|
26603
|
+
import { z as z24 } from "zod";
|
|
26604
|
+
var conversationHistorySchema = z24.object({
|
|
26605
|
+
query: z24.string().trim().max(200).default(""),
|
|
26606
|
+
after: z24.string().max(2048).optional()
|
|
26069
26607
|
}).strict();
|
|
26070
|
-
var conversationHistoryCursorSchema =
|
|
26071
|
-
owner:
|
|
26072
|
-
query:
|
|
26073
|
-
id:
|
|
26074
|
-
at:
|
|
26608
|
+
var conversationHistoryCursorSchema = z24.object({
|
|
26609
|
+
owner: z24.uuid(),
|
|
26610
|
+
query: z24.string(),
|
|
26611
|
+
id: z24.uuid(),
|
|
26612
|
+
at: z24.iso.datetime()
|
|
26075
26613
|
});
|
|
26076
26614
|
|
|
26077
26615
|
// lib/memory/src/tools.ts
|
|
26078
26616
|
init_define_GROVE_TELEMETRY();
|
|
26617
|
+
init_contracts();
|
|
26079
26618
|
|
|
26080
26619
|
// lib/shared/src/notebook-lifecycle.ts
|
|
26081
26620
|
init_define_GROVE_TELEMETRY();
|
|
26082
|
-
|
|
26083
|
-
|
|
26621
|
+
init_contracts();
|
|
26622
|
+
import { z as z25 } from "zod";
|
|
26623
|
+
var notebookLifecycleSchema = z25.object({
|
|
26084
26624
|
operationId: operationSchema,
|
|
26085
|
-
expectedVersion:
|
|
26086
|
-
fingerprint:
|
|
26625
|
+
expectedVersion: z25.number().int().positive(),
|
|
26626
|
+
fingerprint: z25.string().regex(/^[a-f0-9]{64}$/)
|
|
26087
26627
|
}).strict();
|
|
26088
26628
|
|
|
26089
26629
|
// lib/memory/src/system-admin.ts
|
|
26090
26630
|
init_define_GROVE_TELEMETRY();
|
|
26631
|
+
init_contracts();
|
|
26091
26632
|
|
|
26092
26633
|
// lib/shared/src/system-admin.ts
|
|
26093
26634
|
init_define_GROVE_TELEMETRY();
|
|
26094
|
-
|
|
26095
|
-
|
|
26635
|
+
init_contracts();
|
|
26636
|
+
import { z as z26 } from "zod";
|
|
26637
|
+
var adminChangeSchema = z26.object({
|
|
26096
26638
|
accountId: uuidSchema,
|
|
26097
26639
|
operationId: uuidSchema,
|
|
26098
|
-
expectedVersion:
|
|
26099
|
-
role:
|
|
26100
|
-
access:
|
|
26101
|
-
reason:
|
|
26640
|
+
expectedVersion: z26.number().int().min(0),
|
|
26641
|
+
role: z26.enum(["user", "system_admin"]),
|
|
26642
|
+
access: z26.enum(["default", "pro", "unlimited"]),
|
|
26643
|
+
reason: z26.string().trim().min(3).max(300)
|
|
26102
26644
|
}).strict();
|
|
26103
|
-
var adminSettingsSchema =
|
|
26104
|
-
captureEnabled:
|
|
26105
|
-
recallEnabled:
|
|
26106
|
-
suspended:
|
|
26107
|
-
supportNote:
|
|
26645
|
+
var adminSettingsSchema = z26.object({
|
|
26646
|
+
captureEnabled: z26.boolean(),
|
|
26647
|
+
recallEnabled: z26.boolean(),
|
|
26648
|
+
suspended: z26.boolean(),
|
|
26649
|
+
supportNote: z26.string().max(500)
|
|
26108
26650
|
}).strict();
|
|
26109
|
-
var adminSupportSchema =
|
|
26651
|
+
var adminSupportSchema = z26.object({
|
|
26110
26652
|
accountId: uuidSchema,
|
|
26111
26653
|
operationId: uuidSchema,
|
|
26112
|
-
expectedVersion:
|
|
26654
|
+
expectedVersion: z26.number().int().min(0),
|
|
26113
26655
|
expectedSettings: adminSettingsSchema,
|
|
26114
26656
|
settings: adminSettingsSchema,
|
|
26115
|
-
reason:
|
|
26657
|
+
reason: z26.string().trim().min(3).max(300)
|
|
26116
26658
|
}).strict();
|
|
26117
|
-
var
|
|
26118
|
-
|
|
26119
|
-
|
|
26120
|
-
|
|
26121
|
-
|
|
26659
|
+
var adminTrialResetSchema = z26.object({
|
|
26660
|
+
accountId: uuidSchema,
|
|
26661
|
+
operationId: uuidSchema,
|
|
26662
|
+
reason: z26.string().trim().min(3).max(300)
|
|
26663
|
+
}).strict();
|
|
26664
|
+
var adminDetailsSchema = z26.object({ accountId: uuidSchema }).strict();
|
|
26665
|
+
var adminBrowseSchema = z26.object({ after: uuidSchema.optional() }).strict();
|
|
26666
|
+
var adminUsageReportSchema = z26.object({
|
|
26667
|
+
from: z26.iso.date().optional(),
|
|
26668
|
+
to: z26.iso.date().optional(),
|
|
26122
26669
|
after: uuidSchema.optional()
|
|
26123
26670
|
}).strict().superRefine((input, ctx) => {
|
|
26124
26671
|
if (!!input.from !== !!input.to || input.from && input.to && (input.from > input.to || Date.parse(input.to) - Date.parse(input.from) > 365 * 864e5))
|
|
@@ -26130,7 +26677,7 @@ var adminUsageReportSchema = z25.object({
|
|
|
26130
26677
|
|
|
26131
26678
|
// lib/memory/src/index.ts
|
|
26132
26679
|
var revisionActors = /* @__PURE__ */ new WeakMap();
|
|
26133
|
-
var
|
|
26680
|
+
var missing7 = () => new GroveError("not_found", "Memory not found", 404);
|
|
26134
26681
|
var forbidden = () => new GroveError(
|
|
26135
26682
|
"forbidden",
|
|
26136
26683
|
"This connection does not grant that access",
|
|
@@ -26142,7 +26689,7 @@ var stable = (value) => JSON.stringify(
|
|
|
26142
26689
|
Object.entries(entry).sort(([a], [b]) => a.localeCompare(b))
|
|
26143
26690
|
) : entry
|
|
26144
26691
|
);
|
|
26145
|
-
var digest = (value) =>
|
|
26692
|
+
var digest = (value) => createHash18("sha256").update(value).digest("hex");
|
|
26146
26693
|
var MemoryService = class _MemoryService {
|
|
26147
26694
|
constructor(db, cursorSecret, embedder, providers = {}, dailyRequestLimit = 2e3) {
|
|
26148
26695
|
this.db = db;
|
|
@@ -26430,24 +26977,63 @@ var MemoryService = class _MemoryService {
|
|
|
26430
26977
|
...input
|
|
26431
26978
|
},
|
|
26432
26979
|
async () => {
|
|
26433
|
-
|
|
26980
|
+
if (input.id) {
|
|
26981
|
+
const target2 = await this.query(trx, grant).findById(input.id).forUpdate();
|
|
26982
|
+
if (!target2 || target2.status !== "active" || target2.expiresAt && new Date(target2.expiresAt) <= /* @__PURE__ */ new Date())
|
|
26983
|
+
throw missing7();
|
|
26984
|
+
}
|
|
26985
|
+
const writer = this.inTransaction(trx);
|
|
26986
|
+
const note2 = input.id ? await writer.updateMemory(principal, {
|
|
26987
|
+
operationId: randomUUID13(),
|
|
26988
|
+
id: input.id,
|
|
26989
|
+
expectedVersion: input.expectedVersion,
|
|
26990
|
+
editSession: input.editSession,
|
|
26991
|
+
content: input.content,
|
|
26992
|
+
projectId: input.projectId,
|
|
26993
|
+
capture: "explicit"
|
|
26994
|
+
}) : await writer.remember(
|
|
26434
26995
|
principal,
|
|
26435
26996
|
rememberSchema.parse({
|
|
26436
|
-
operationId:
|
|
26997
|
+
operationId: randomUUID13(),
|
|
26437
26998
|
content: input.content,
|
|
26438
26999
|
projectId: input.projectId,
|
|
26439
27000
|
capture: "explicit",
|
|
26440
27001
|
source: { agent: "api" }
|
|
26441
27002
|
})
|
|
26442
27003
|
);
|
|
26443
|
-
if (input.
|
|
26444
|
-
await trx("web_captures").
|
|
27004
|
+
if (input.id)
|
|
27005
|
+
await trx("web_captures").where({
|
|
26445
27006
|
accountId: account.id,
|
|
26446
27007
|
memoryId: note2.id,
|
|
26447
|
-
version: note2.version,
|
|
26448
|
-
provenance: JSON.stringify(input.provenance),
|
|
26449
27008
|
active: true
|
|
26450
|
-
});
|
|
27009
|
+
}).update({ active: false });
|
|
27010
|
+
if (input.provenance) {
|
|
27011
|
+
const retained = await trx("web_captures").where({
|
|
27012
|
+
accountId: account.id,
|
|
27013
|
+
memoryId: note2.id,
|
|
27014
|
+
version: note2.version
|
|
27015
|
+
}).first();
|
|
27016
|
+
if (retained && stable(retained.provenance) !== stable(input.provenance))
|
|
27017
|
+
throw new GroveError(
|
|
27018
|
+
"version_conflict",
|
|
27019
|
+
"Source changed without a new note revision",
|
|
27020
|
+
409
|
|
27021
|
+
);
|
|
27022
|
+
if (retained)
|
|
27023
|
+
await trx("web_captures").where({
|
|
27024
|
+
accountId: account.id,
|
|
27025
|
+
memoryId: note2.id,
|
|
27026
|
+
version: note2.version
|
|
27027
|
+
}).update({ active: true });
|
|
27028
|
+
else
|
|
27029
|
+
await trx("web_captures").insert({
|
|
27030
|
+
accountId: account.id,
|
|
27031
|
+
memoryId: note2.id,
|
|
27032
|
+
version: note2.version,
|
|
27033
|
+
provenance: JSON.stringify(input.provenance),
|
|
27034
|
+
active: true
|
|
27035
|
+
});
|
|
27036
|
+
}
|
|
26451
27037
|
return {
|
|
26452
27038
|
action: "browser_capture",
|
|
26453
27039
|
connectionId: principal.connectionId,
|
|
@@ -26463,6 +27049,12 @@ var MemoryService = class _MemoryService {
|
|
|
26463
27049
|
"This capture is no longer available",
|
|
26464
27050
|
410
|
|
26465
27051
|
);
|
|
27052
|
+
if (note.version !== receipt.version)
|
|
27053
|
+
throw new GroveError(
|
|
27054
|
+
"version_conflict",
|
|
27055
|
+
"The saved version is no longer current. Check its receipt before continuing.",
|
|
27056
|
+
409
|
|
27057
|
+
);
|
|
26466
27058
|
return this.present(trx, note);
|
|
26467
27059
|
}
|
|
26468
27060
|
);
|
|
@@ -26532,7 +27124,7 @@ var MemoryService = class _MemoryService {
|
|
|
26532
27124
|
return this.access(principal, "memory:read", async ({ trx, grant }) => {
|
|
26533
27125
|
const row = await this.query(trx, grant).findById(id2);
|
|
26534
27126
|
if (!row || row.expiresAt && new Date(row.expiresAt) <= /* @__PURE__ */ new Date())
|
|
26535
|
-
throw
|
|
27127
|
+
throw missing7();
|
|
26536
27128
|
const document3 = await revisionDocument(trx, id2, revision2 ?? row.version);
|
|
26537
27129
|
if ((revision2 === void 0 || revision2 === row.version) && document3.blocks.map((b) => b.source).join("") !== row.content)
|
|
26538
27130
|
throw new GroveError(
|
|
@@ -26577,7 +27169,7 @@ var MemoryService = class _MemoryService {
|
|
|
26577
27169
|
);
|
|
26578
27170
|
const row = await this.query(trx, grant).findById(input.id);
|
|
26579
27171
|
if (!row || row.status !== "active" || row.expiresAt && new Date(row.expiresAt) <= /* @__PURE__ */ new Date())
|
|
26580
|
-
throw
|
|
27172
|
+
throw missing7();
|
|
26581
27173
|
if (row.version !== input.expectedVersion)
|
|
26582
27174
|
throw new GroveError(
|
|
26583
27175
|
"version_conflict",
|
|
@@ -26657,7 +27249,7 @@ var MemoryService = class _MemoryService {
|
|
|
26657
27249
|
let old;
|
|
26658
27250
|
if (request2.id) {
|
|
26659
27251
|
old = await this.query(trx, grant).findById(request2.id).forUpdate();
|
|
26660
|
-
if (!old) throw
|
|
27252
|
+
if (!old) throw missing7();
|
|
26661
27253
|
if (old.version !== request2.expectedVersion)
|
|
26662
27254
|
throw new GroveError(
|
|
26663
27255
|
"version_conflict",
|
|
@@ -26669,7 +27261,7 @@ var MemoryService = class _MemoryService {
|
|
|
26669
27261
|
let exactContent;
|
|
26670
27262
|
if (edits) {
|
|
26671
27263
|
if (!old || old.status !== "active" || old.expiresAt && new Date(old.expiresAt) <= /* @__PURE__ */ new Date())
|
|
26672
|
-
throw
|
|
27264
|
+
throw missing7();
|
|
26673
27265
|
const revision2 = await trx("memory_revisions").where({ memoryId: old.id, version: old.version }).first("content");
|
|
26674
27266
|
if (!revision2 || revision2.content !== old.content)
|
|
26675
27267
|
throw new GroveError(
|
|
@@ -26760,7 +27352,7 @@ var MemoryService = class _MemoryService {
|
|
|
26760
27352
|
version: input.expectedVersion + 1
|
|
26761
27353
|
}) : await MemoryModel.query(trx).insertAndFetch({
|
|
26762
27354
|
...values,
|
|
26763
|
-
id:
|
|
27355
|
+
id: randomUUID13(),
|
|
26764
27356
|
status: input.archived ? "archived" : "active"
|
|
26765
27357
|
});
|
|
26766
27358
|
const session = editSession ?? principal.sessionId;
|
|
@@ -26804,10 +27396,32 @@ var MemoryService = class _MemoryService {
|
|
|
26804
27396
|
async get(principal, id2) {
|
|
26805
27397
|
return this.access(principal, "memory:read", async ({ trx, grant }) => {
|
|
26806
27398
|
const row = await this.query(trx, grant).findById(id2);
|
|
26807
|
-
if (!row) throw
|
|
27399
|
+
if (!row) throw missing7();
|
|
26808
27400
|
return this.present(trx, row);
|
|
26809
27401
|
});
|
|
26810
27402
|
}
|
|
27403
|
+
async listNoteMedia(principal, memoryId, version2) {
|
|
27404
|
+
const { MediaAttachments: MediaAttachments2 } = await Promise.resolve().then(() => (init_media2(), media_exports));
|
|
27405
|
+
return new MediaAttachments2(this).listForNote(principal, memoryId, version2);
|
|
27406
|
+
}
|
|
27407
|
+
async describeNoteMedia(principal, memoryId, id2, version2) {
|
|
27408
|
+
const { MediaAttachments: MediaAttachments2 } = await Promise.resolve().then(() => (init_media2(), media_exports));
|
|
27409
|
+
return new MediaAttachments2(this).describeForNote(
|
|
27410
|
+
principal,
|
|
27411
|
+
memoryId,
|
|
27412
|
+
id2,
|
|
27413
|
+
version2
|
|
27414
|
+
);
|
|
27415
|
+
}
|
|
27416
|
+
async readMediaTranscript(principal, memoryId, id2) {
|
|
27417
|
+
const { MediaAttachments: MediaAttachments2 } = await Promise.resolve().then(() => (init_media2(), media_exports));
|
|
27418
|
+
const attachments = new MediaAttachments2(this);
|
|
27419
|
+
const meta = await attachments.describeForNote(principal, memoryId, id2);
|
|
27420
|
+
if (!meta.mime.startsWith("audio/")) throw missing7();
|
|
27421
|
+
const saved = await attachments.transcript(principal, memoryId, id2);
|
|
27422
|
+
const text5 = typeof saved.text === "string" ? saved.text.slice(0, 6e3) : "";
|
|
27423
|
+
return { text: text5, version: saved.version, mediaId: id2, memoryId };
|
|
27424
|
+
}
|
|
26811
27425
|
async moveMemories(principal, raw) {
|
|
26812
27426
|
const input = moveMemoriesSchema.parse(raw);
|
|
26813
27427
|
return this.access(
|
|
@@ -26824,7 +27438,7 @@ var MemoryService = class _MemoryService {
|
|
|
26824
27438
|
const domain2 = this.inTransaction(trx);
|
|
26825
27439
|
for (const item of input.items)
|
|
26826
27440
|
await domain2.updateMemory(principal, {
|
|
26827
|
-
operationId:
|
|
27441
|
+
operationId: randomUUID13(),
|
|
26828
27442
|
...item,
|
|
26829
27443
|
projectId: input.projectId,
|
|
26830
27444
|
capture: "explicit"
|
|
@@ -26947,7 +27561,7 @@ var MemoryService = class _MemoryService {
|
|
|
26947
27561
|
}
|
|
26948
27562
|
async revisions(principal, id2) {
|
|
26949
27563
|
return this.access(principal, "memory:read", async ({ trx, grant }) => {
|
|
26950
|
-
if (!await this.query(trx, grant).findById(id2)) throw
|
|
27564
|
+
if (!await this.query(trx, grant).findById(id2)) throw missing7();
|
|
26951
27565
|
const groups = trx("memory_revisions").where({ memoryId: id2 }).select(
|
|
26952
27566
|
trx.raw(
|
|
26953
27567
|
"DISTINCT ON (coalesce((revision_group->>'start')::integer,version)) version,content,source,created_at,revision_group"
|
|
@@ -26969,9 +27583,9 @@ var MemoryService = class _MemoryService {
|
|
|
26969
27583
|
const note = await this.query(trx, grant).findById(id2).where(
|
|
26970
27584
|
(q) => q.whereNull("expiresAt").orWhere("expiresAt", ">", trx.fn.now())
|
|
26971
27585
|
);
|
|
26972
|
-
if (!note) throw
|
|
27586
|
+
if (!note) throw missing7();
|
|
26973
27587
|
const revision2 = await trx("memory_revisions").where({ memoryId: id2, version: version2 }).select("version", "content", "createdAt").first();
|
|
26974
|
-
if (!revision2) throw
|
|
27588
|
+
if (!revision2) throw missing7();
|
|
26975
27589
|
return {
|
|
26976
27590
|
...revision2,
|
|
26977
27591
|
id: id2,
|
|
@@ -27018,7 +27632,7 @@ var MemoryService = class _MemoryService {
|
|
|
27018
27632
|
trx,
|
|
27019
27633
|
principal.accountId,
|
|
27020
27634
|
metric,
|
|
27021
|
-
|
|
27635
|
+
randomUUID13(),
|
|
27022
27636
|
1
|
|
27023
27637
|
);
|
|
27024
27638
|
}
|
|
@@ -27650,7 +28264,7 @@ ${input.query}`.slice(-1e3) : input.query;
|
|
|
27650
28264
|
{ action, id: id2, ...input },
|
|
27651
28265
|
async () => {
|
|
27652
28266
|
const old = await this.query(trx, grant).findById(id2).forUpdate();
|
|
27653
|
-
if (!old) throw
|
|
28267
|
+
if (!old) throw missing7();
|
|
27654
28268
|
if (old.version !== input.expectedVersion)
|
|
27655
28269
|
throw new GroveError(
|
|
27656
28270
|
"version_conflict",
|
|
@@ -27658,7 +28272,7 @@ ${input.query}`.slice(-1e3) : input.query;
|
|
|
27658
28272
|
409
|
|
27659
28273
|
);
|
|
27660
28274
|
const historical = input.revision ? await trx("memory_revisions").where({ memoryId: id2, version: input.revision }).first() : void 0;
|
|
27661
|
-
if (input.revision && !historical) throw
|
|
28275
|
+
if (input.revision && !historical) throw missing7();
|
|
27662
28276
|
const durable = input.durable;
|
|
27663
28277
|
const row2 = await MemoryModel.query(trx).patchAndFetchById(id2, {
|
|
27664
28278
|
version: old.version + 1,
|
|
@@ -28004,7 +28618,7 @@ ${input.query}`.slice(-1e3) : input.query;
|
|
|
28004
28618
|
}).returning("*");
|
|
28005
28619
|
}
|
|
28006
28620
|
if (!options.key) return { connection };
|
|
28007
|
-
const id2 =
|
|
28621
|
+
const id2 = randomUUID13();
|
|
28008
28622
|
const secret = `grv_${id2}_${randomBytes2(32).toString("base64url")}`;
|
|
28009
28623
|
await trx("api_keys").insert({
|
|
28010
28624
|
id: id2,
|
|
@@ -28117,7 +28731,7 @@ ${input.query}`.slice(-1e3) : input.query;
|
|
|
28117
28731
|
throw new GroveError("not_found", "Project not found", 404);
|
|
28118
28732
|
if (refresh && this.providers.generation && account[briefPreference(scope)]) {
|
|
28119
28733
|
const target2 = briefTarget(scope);
|
|
28120
|
-
const usageOperation = `brief:${
|
|
28734
|
+
const usageOperation = `brief:${randomUUID13()}`;
|
|
28121
28735
|
await reserveAction(
|
|
28122
28736
|
this.db,
|
|
28123
28737
|
trx,
|
|
@@ -28141,7 +28755,7 @@ ${input.query}`.slice(-1e3) : input.query;
|
|
|
28141
28755
|
async retryProcessing(principal, id2, expectedVersion) {
|
|
28142
28756
|
return this.access(principal, "memory:write", async ({ trx, grant }) => {
|
|
28143
28757
|
const row = await this.query(trx, grant).findById(id2).forUpdate();
|
|
28144
|
-
if (!row) throw
|
|
28758
|
+
if (!row) throw missing7();
|
|
28145
28759
|
if (row.version !== expectedVersion)
|
|
28146
28760
|
throw new GroveError(
|
|
28147
28761
|
"version_conflict",
|
|
@@ -28235,6 +28849,7 @@ var sessionPrincipal = (accountId, subject) => ({
|
|
|
28235
28849
|
init_define_GROVE_TELEMETRY();
|
|
28236
28850
|
import { createCipheriv as createCipheriv2, createDecipheriv as createDecipheriv2, randomBytes as randomBytes3 } from "node:crypto";
|
|
28237
28851
|
init_models();
|
|
28852
|
+
init_contracts();
|
|
28238
28853
|
|
|
28239
28854
|
// packages/api/src/embedding.ts
|
|
28240
28855
|
init_define_GROVE_TELEMETRY();
|
|
@@ -28551,7 +29166,8 @@ import { createClient } from "@vercel/flags-core";
|
|
|
28551
29166
|
|
|
28552
29167
|
// packages/api/src/billing.ts
|
|
28553
29168
|
init_define_GROVE_TELEMETRY();
|
|
28554
|
-
import { randomUUID as
|
|
29169
|
+
import { randomUUID as randomUUID14 } from "node:crypto";
|
|
29170
|
+
init_contracts();
|
|
28555
29171
|
var ongoing = (status) => !["canceled", "incomplete_expired"].includes(status);
|
|
28556
29172
|
var replaceableCheckout = (session, subscriptions) => {
|
|
28557
29173
|
if (session.status === "expired") return true;
|
|
@@ -28576,20 +29192,31 @@ var Billing = class {
|
|
|
28576
29192
|
}
|
|
28577
29193
|
service;
|
|
28578
29194
|
options;
|
|
28579
|
-
checkoutParameters(accountId, customerId, priceId) {
|
|
29195
|
+
checkoutParameters(accountId, customerId, priceId, trialDays) {
|
|
28580
29196
|
return {
|
|
28581
29197
|
mode: "subscription",
|
|
28582
29198
|
customer: customerId,
|
|
28583
29199
|
client_reference_id: accountId,
|
|
28584
29200
|
line_items: [{ price: priceId, quantity: 1 }],
|
|
28585
|
-
subscription_data: {
|
|
29201
|
+
subscription_data: {
|
|
29202
|
+
metadata: { groveAccountId: accountId },
|
|
29203
|
+
...trialDays ? { trial_period_days: trialDays } : {}
|
|
29204
|
+
},
|
|
29205
|
+
// Card-required trials must always collect a payment method; ordinary
|
|
29206
|
+
// checkout keeps Stripe's default behavior.
|
|
29207
|
+
...trialDays ? { payment_method_collection: "always" } : {},
|
|
28586
29208
|
success_url: `${this.options.siteUrl}/app/settings/billing?checkout=success`,
|
|
28587
29209
|
cancel_url: `${this.options.siteUrl}/app/settings/billing?checkout=canceled`
|
|
28588
29210
|
};
|
|
28589
29211
|
}
|
|
28590
|
-
async checkoutSession(accountId, row) {
|
|
29212
|
+
async checkoutSession(accountId, row, trialDays) {
|
|
28591
29213
|
const id2 = row.checkoutId ?? (await this.options.stripe.checkout.sessions.create(
|
|
28592
|
-
this.checkoutParameters(
|
|
29214
|
+
this.checkoutParameters(
|
|
29215
|
+
accountId,
|
|
29216
|
+
row.customerId,
|
|
29217
|
+
row.checkoutPrice,
|
|
29218
|
+
trialDays
|
|
29219
|
+
),
|
|
28593
29220
|
{ idempotencyKey: `grove-checkout-${row.checkoutOperation}` }
|
|
28594
29221
|
)).id;
|
|
28595
29222
|
return this.options.stripe.checkout.sessions.retrieve(id2);
|
|
@@ -28639,6 +29266,29 @@ var Billing = class {
|
|
|
28639
29266
|
);
|
|
28640
29267
|
return price;
|
|
28641
29268
|
}
|
|
29269
|
+
/**
|
|
29270
|
+
* Monthly flag pricing is required; yearly is optional so an unset yearly
|
|
29271
|
+
* variant never breaks the billing page. Checkout still resolves (and
|
|
29272
|
+
* rejects invalid quotes) per interval.
|
|
29273
|
+
*/
|
|
29274
|
+
async flagQuotes(subject) {
|
|
29275
|
+
const pricing = this.options.pricing;
|
|
29276
|
+
const monthly = await pricing.month?.quote(subject);
|
|
29277
|
+
if (!monthly)
|
|
29278
|
+
throw new GroveError(
|
|
29279
|
+
"billing_price_missing",
|
|
29280
|
+
"This subscription option is unavailable",
|
|
29281
|
+
400
|
|
29282
|
+
);
|
|
29283
|
+
const quotes = [monthly];
|
|
29284
|
+
if (pricing.year) {
|
|
29285
|
+
try {
|
|
29286
|
+
quotes.push(await pricing.year.quote(subject));
|
|
29287
|
+
} catch {
|
|
29288
|
+
}
|
|
29289
|
+
}
|
|
29290
|
+
return quotes;
|
|
29291
|
+
}
|
|
28642
29292
|
/** Refresh under the customer row lock. Event arrival order never determines access. */
|
|
28643
29293
|
async sync(trx, accountId, customerId) {
|
|
28644
29294
|
const subscriptions = await this.options.stripe.subscriptions.list({
|
|
@@ -28677,6 +29327,10 @@ var Billing = class {
|
|
|
28677
29327
|
"cancelAtPeriodEnd"
|
|
28678
29328
|
]);
|
|
28679
29329
|
}
|
|
29330
|
+
const trialing = subscriptions.data.find((s) => s.status === "trialing");
|
|
29331
|
+
if (trialing) {
|
|
29332
|
+
await trx("billing_trials").where({ accountId }).whereNull("subscriptionId").update({ subscriptionId: trialing.id });
|
|
29333
|
+
}
|
|
28680
29334
|
await trx("billing_subscriptions").where({ accountId, customerId }).whereNotIn(
|
|
28681
29335
|
"id",
|
|
28682
29336
|
subscriptions.data.map((s) => s.id)
|
|
@@ -28711,6 +29365,13 @@ var Billing = class {
|
|
|
28711
29365
|
cancelAtPeriodEnd: subscription.cancelAtPeriodEnd,
|
|
28712
29366
|
periodEnd: new Date(subscription.periodEnd).toISOString()
|
|
28713
29367
|
} : null,
|
|
29368
|
+
trial: await trialState(trx, principal.accountId).then(
|
|
29369
|
+
(state2) => state2.eligible ? { eligible: true, consumedAt: null } : {
|
|
29370
|
+
eligible: false,
|
|
29371
|
+
consumedAt: state2.consumedAt,
|
|
29372
|
+
resetAt: state2.resetAt
|
|
29373
|
+
}
|
|
29374
|
+
),
|
|
28714
29375
|
usage: await billingUsage(this.service.db, trx, principal.accountId),
|
|
28715
29376
|
resources: await resourceUsage(
|
|
28716
29377
|
this.service.db,
|
|
@@ -28720,7 +29381,7 @@ var Billing = class {
|
|
|
28720
29381
|
};
|
|
28721
29382
|
}
|
|
28722
29383
|
);
|
|
28723
|
-
const prices = this.options.pricing ?
|
|
29384
|
+
const prices = this.options.pricing ? await this.flagQuotes(principal.subject) : enabled ? await Promise.all(
|
|
28724
29385
|
Object.keys(this.options.prices).map(
|
|
28725
29386
|
async (interval) => {
|
|
28726
29387
|
const price = await this.price(interval);
|
|
@@ -28751,13 +29412,16 @@ var Billing = class {
|
|
|
28751
29412
|
);
|
|
28752
29413
|
await trx("billing_customers").insert({ accountId: principal.accountId }).onConflict("accountId").ignore();
|
|
28753
29414
|
});
|
|
28754
|
-
if (this.options.pricing && interval
|
|
29415
|
+
if (this.options.pricing && !this.options.pricing[interval])
|
|
28755
29416
|
throw new GroveError(
|
|
28756
29417
|
"billing_price_missing",
|
|
28757
29418
|
"This subscription option is unavailable",
|
|
28758
29419
|
400
|
|
28759
29420
|
);
|
|
28760
|
-
const price = this.options.pricing ? await this.options.pricing.resolve(
|
|
29421
|
+
const price = this.options.pricing?.[interval] ? await this.options.pricing[interval].resolve(
|
|
29422
|
+
principal.subject,
|
|
29423
|
+
expectedAmount
|
|
29424
|
+
) : await this.price(interval);
|
|
28761
29425
|
await this.service.access(principal, "admin", async ({ trx }) => {
|
|
28762
29426
|
const row = await trx("billing_customers").where({ accountId: principal.accountId }).forUpdate().first();
|
|
28763
29427
|
if (row.checkoutPrice && row.checkoutPrice !== price.id) {
|
|
@@ -28772,7 +29436,7 @@ var Billing = class {
|
|
|
28772
29436
|
await trx("billing_customers").where({ accountId: principal.accountId }).update({
|
|
28773
29437
|
checkoutId: null,
|
|
28774
29438
|
checkoutPrice: price.id,
|
|
28775
|
-
checkoutOperation:
|
|
29439
|
+
checkoutOperation: randomUUID14()
|
|
28776
29440
|
});
|
|
28777
29441
|
}
|
|
28778
29442
|
if (!row.checkoutPrice)
|
|
@@ -28822,7 +29486,7 @@ var Billing = class {
|
|
|
28822
29486
|
await trx("billing_customers").where({ accountId: principal.accountId }).update({
|
|
28823
29487
|
checkoutId: null,
|
|
28824
29488
|
checkoutPrice: null,
|
|
28825
|
-
checkoutOperation:
|
|
29489
|
+
checkoutOperation: randomUUID14()
|
|
28826
29490
|
});
|
|
28827
29491
|
return null;
|
|
28828
29492
|
}
|
|
@@ -28838,6 +29502,140 @@ var Billing = class {
|
|
|
28838
29502
|
);
|
|
28839
29503
|
return result ?? this.checkout(principal, interval, expectedAmount);
|
|
28840
29504
|
}
|
|
29505
|
+
/**
|
|
29506
|
+
* Card-required 7-day Pro trial. Single use per account: consumption is
|
|
29507
|
+
* recorded when the trial checkout is created (same row lock that fences
|
|
29508
|
+
* concurrent checkouts) and only an admin reset restores eligibility.
|
|
29509
|
+
* Abandoned/expired trial checkouts still count as used.
|
|
29510
|
+
*/
|
|
29511
|
+
async startTrial(principal, interval, expectedAmount) {
|
|
29512
|
+
await this.service.access(principal, "admin", async ({ account, trx }) => {
|
|
29513
|
+
if (!await this.options.enabled(account.clerkSubject))
|
|
29514
|
+
throw new GroveError(
|
|
29515
|
+
"billing_disabled",
|
|
29516
|
+
"Subscriptions are not available yet",
|
|
29517
|
+
404
|
|
29518
|
+
);
|
|
29519
|
+
const state = await trialState(trx, principal.accountId);
|
|
29520
|
+
if (!state.eligible)
|
|
29521
|
+
throw new GroveError(
|
|
29522
|
+
"trial_already_used",
|
|
29523
|
+
"This account already used its Pro trial",
|
|
29524
|
+
409
|
|
29525
|
+
);
|
|
29526
|
+
await trx("billing_customers").insert({ accountId: principal.accountId }).onConflict("accountId").ignore();
|
|
29527
|
+
});
|
|
29528
|
+
if (this.options.pricing && !this.options.pricing[interval])
|
|
29529
|
+
throw new GroveError(
|
|
29530
|
+
"billing_price_missing",
|
|
29531
|
+
"This subscription option is unavailable",
|
|
29532
|
+
400
|
|
29533
|
+
);
|
|
29534
|
+
const price = this.options.pricing?.[interval] ? await this.options.pricing[interval].resolve(
|
|
29535
|
+
principal.subject,
|
|
29536
|
+
expectedAmount
|
|
29537
|
+
) : await this.price(interval);
|
|
29538
|
+
await this.service.access(principal, "admin", async ({ trx }) => {
|
|
29539
|
+
const row = await trx("billing_customers").where({ accountId: principal.accountId }).forUpdate().first();
|
|
29540
|
+
if (row.checkoutPrice && row.checkoutPrice !== price.id) {
|
|
29541
|
+
const previous3 = row.customerId ? await this.checkoutSession(principal.accountId, row) : null;
|
|
29542
|
+
const subscriptions = previous3?.status === "complete" ? await this.sync(trx, principal.accountId, row.customerId) : [];
|
|
29543
|
+
if (previous3 && !replaceableCheckout(previous3, subscriptions))
|
|
29544
|
+
throw new GroveError(
|
|
29545
|
+
"checkout_pending",
|
|
29546
|
+
"Finish or let your existing checkout expire before starting a trial",
|
|
29547
|
+
409
|
|
29548
|
+
);
|
|
29549
|
+
await trx("billing_customers").where({ accountId: principal.accountId }).update({
|
|
29550
|
+
checkoutId: null,
|
|
29551
|
+
checkoutPrice: price.id,
|
|
29552
|
+
checkoutOperation: randomUUID14()
|
|
29553
|
+
});
|
|
29554
|
+
}
|
|
29555
|
+
if (!row.checkoutPrice)
|
|
29556
|
+
await trx("billing_customers").where({ accountId: principal.accountId }).update({ checkoutPrice: price.id });
|
|
29557
|
+
});
|
|
29558
|
+
await this.service.access(principal, "admin", async ({ trx }) => {
|
|
29559
|
+
const row = await trx("billing_customers").where({ accountId: principal.accountId }).forUpdate().first();
|
|
29560
|
+
if (!row.customerId) {
|
|
29561
|
+
const customer = await this.options.stripe.customers.create(
|
|
29562
|
+
{ metadata: { groveAccountId: principal.accountId } },
|
|
29563
|
+
{ idempotencyKey: `grove-customer-${principal.accountId}` }
|
|
29564
|
+
);
|
|
29565
|
+
await trx("billing_customers").where({ accountId: principal.accountId }).update({ customerId: customer.id });
|
|
29566
|
+
}
|
|
29567
|
+
});
|
|
29568
|
+
const result = await this.service.access(
|
|
29569
|
+
principal,
|
|
29570
|
+
"admin",
|
|
29571
|
+
async ({ trx, account }) => {
|
|
29572
|
+
if (!await this.options.enabled(account.clerkSubject))
|
|
29573
|
+
throw new GroveError(
|
|
29574
|
+
"billing_disabled",
|
|
29575
|
+
"Subscriptions are not available yet",
|
|
29576
|
+
404
|
|
29577
|
+
);
|
|
29578
|
+
const row = await trx("billing_customers").where({ accountId: principal.accountId }).forUpdate().first();
|
|
29579
|
+
if (row.checkoutPrice !== price.id)
|
|
29580
|
+
throw new GroveError(
|
|
29581
|
+
"checkout_pending",
|
|
29582
|
+
"Your checkout changed. Refresh billing and try again.",
|
|
29583
|
+
409
|
|
29584
|
+
);
|
|
29585
|
+
const state = await trialState(trx, principal.accountId);
|
|
29586
|
+
if (!state.eligible)
|
|
29587
|
+
throw new GroveError(
|
|
29588
|
+
"trial_already_used",
|
|
29589
|
+
"This account already used its Pro trial",
|
|
29590
|
+
409
|
|
29591
|
+
);
|
|
29592
|
+
const customerId = row.customerId;
|
|
29593
|
+
const subscriptions = await this.sync(
|
|
29594
|
+
trx,
|
|
29595
|
+
principal.accountId,
|
|
29596
|
+
customerId
|
|
29597
|
+
);
|
|
29598
|
+
if (subscriptions.some((s) => ongoing(s.status)))
|
|
29599
|
+
throw new GroveError(
|
|
29600
|
+
"subscription_exists",
|
|
29601
|
+
"Manage your existing subscription instead",
|
|
29602
|
+
409
|
|
29603
|
+
);
|
|
29604
|
+
if (row.checkoutId) {
|
|
29605
|
+
const existing = await this.checkoutSession(principal.accountId, row);
|
|
29606
|
+
if (existing.status === "open")
|
|
29607
|
+
throw new GroveError(
|
|
29608
|
+
"checkout_pending",
|
|
29609
|
+
"Finish or let your existing checkout expire before starting a trial",
|
|
29610
|
+
409
|
|
29611
|
+
);
|
|
29612
|
+
}
|
|
29613
|
+
const session = await this.checkoutSession(
|
|
29614
|
+
principal.accountId,
|
|
29615
|
+
row,
|
|
29616
|
+
trialDurationDays
|
|
29617
|
+
);
|
|
29618
|
+
if (replaceableCheckout(session, subscriptions)) {
|
|
29619
|
+
await trx("billing_customers").where({ accountId: principal.accountId }).update({
|
|
29620
|
+
checkoutId: null,
|
|
29621
|
+
checkoutPrice: null,
|
|
29622
|
+
checkoutOperation: randomUUID14()
|
|
29623
|
+
});
|
|
29624
|
+
return null;
|
|
29625
|
+
}
|
|
29626
|
+
if (session.status !== "open")
|
|
29627
|
+
throw new GroveError(
|
|
29628
|
+
"checkout_processing",
|
|
29629
|
+
"Your subscription is processing. Refresh billing shortly.",
|
|
29630
|
+
409
|
|
29631
|
+
);
|
|
29632
|
+
await consumeTrial(trx, principal.accountId, void 0);
|
|
29633
|
+
await trx("billing_customers").where({ accountId: principal.accountId }).update({ checkoutId: session.id });
|
|
29634
|
+
return destination2(session.url, "checkout.stripe.com");
|
|
29635
|
+
}
|
|
29636
|
+
);
|
|
29637
|
+
return result ?? this.startTrial(principal, interval, expectedAmount);
|
|
29638
|
+
}
|
|
28841
29639
|
async portal(principal) {
|
|
28842
29640
|
return this.service.access(principal, "admin", async ({ trx, account }) => {
|
|
28843
29641
|
if (!await this.options.enabled(account.clerkSubject))
|
|
@@ -28902,14 +29700,17 @@ var Billing = class {
|
|
|
28902
29700
|
|
|
28903
29701
|
// packages/api/src/billing-pricing.ts
|
|
28904
29702
|
init_define_GROVE_TELEMETRY();
|
|
28905
|
-
|
|
28906
|
-
|
|
29703
|
+
init_contracts();
|
|
29704
|
+
var FlagPricing = class {
|
|
29705
|
+
constructor(stripe, productId, interval, dollars) {
|
|
28907
29706
|
this.stripe = stripe;
|
|
28908
29707
|
this.productId = productId;
|
|
29708
|
+
this.interval = interval;
|
|
28909
29709
|
this.dollars = dollars;
|
|
28910
29710
|
}
|
|
28911
29711
|
stripe;
|
|
28912
29712
|
productId;
|
|
29713
|
+
interval;
|
|
28913
29714
|
dollars;
|
|
28914
29715
|
async quote(subject) {
|
|
28915
29716
|
const dollars = await this.dollars(subject);
|
|
@@ -28920,7 +29721,7 @@ var MonthlyPricing = class {
|
|
|
28920
29721
|
"Subscription pricing is unavailable. Try again shortly.",
|
|
28921
29722
|
503
|
|
28922
29723
|
);
|
|
28923
|
-
return { interval:
|
|
29724
|
+
return { interval: this.interval, amount: cents, currency: "usd" };
|
|
28924
29725
|
}
|
|
28925
29726
|
async resolve(subject, expectedAmount) {
|
|
28926
29727
|
const quote = await this.quote(subject);
|
|
@@ -28937,7 +29738,7 @@ var MonthlyPricing = class {
|
|
|
28937
29738
|
"This subscription is unavailable",
|
|
28938
29739
|
503
|
|
28939
29740
|
);
|
|
28940
|
-
const key2 = `grove-pro-${this.productId}-usd
|
|
29741
|
+
const key2 = `grove-pro-${this.productId}-usd-${this.interval}-${quote.amount}`;
|
|
28941
29742
|
const existing = await this.stripe.prices.list({
|
|
28942
29743
|
lookup_keys: [key2],
|
|
28943
29744
|
active: true,
|
|
@@ -28949,7 +29750,7 @@ var MonthlyPricing = class {
|
|
|
28949
29750
|
currency: "usd",
|
|
28950
29751
|
unit_amount: quote.amount,
|
|
28951
29752
|
recurring: {
|
|
28952
|
-
interval:
|
|
29753
|
+
interval: this.interval,
|
|
28953
29754
|
interval_count: 1,
|
|
28954
29755
|
usage_type: "licensed"
|
|
28955
29756
|
},
|
|
@@ -28958,7 +29759,7 @@ var MonthlyPricing = class {
|
|
|
28958
29759
|
},
|
|
28959
29760
|
{ idempotencyKey: key2 }
|
|
28960
29761
|
);
|
|
28961
|
-
if (price.unit_amount !== quote.amount || price.currency !== "usd" || price.product !== this.productId || !price.active || price.recurring?.interval !==
|
|
29762
|
+
if (price.unit_amount !== quote.amount || price.currency !== "usd" || price.product !== this.productId || !price.active || price.recurring?.interval !== this.interval || price.recurring.interval_count !== 1 || price.recurring.usage_type !== "licensed")
|
|
28962
29763
|
throw new GroveError(
|
|
28963
29764
|
"billing_price_invalid",
|
|
28964
29765
|
"Subscription pricing could not be verified",
|
|
@@ -28967,6 +29768,16 @@ var MonthlyPricing = class {
|
|
|
28967
29768
|
return price;
|
|
28968
29769
|
}
|
|
28969
29770
|
};
|
|
29771
|
+
var MonthlyPricing = class extends FlagPricing {
|
|
29772
|
+
constructor(stripe, productId, dollars) {
|
|
29773
|
+
super(stripe, productId, "month", dollars);
|
|
29774
|
+
}
|
|
29775
|
+
};
|
|
29776
|
+
var YearlyPricing = class extends FlagPricing {
|
|
29777
|
+
constructor(stripe, productId, dollars) {
|
|
29778
|
+
super(stripe, productId, "year", dollars);
|
|
29779
|
+
}
|
|
29780
|
+
};
|
|
28970
29781
|
|
|
28971
29782
|
// packages/api/src/billing-runtime.ts
|
|
28972
29783
|
function createBilling(env, service) {
|
|
@@ -28975,7 +29786,7 @@ function createBilling(env, service) {
|
|
|
28975
29786
|
const enabled = async (subject) => {
|
|
28976
29787
|
const result = await client.evaluate(
|
|
28977
29788
|
billingFlagKey,
|
|
28978
|
-
|
|
29789
|
+
true,
|
|
28979
29790
|
{ user: { id: subject } }
|
|
28980
29791
|
);
|
|
28981
29792
|
return result.value === true;
|
|
@@ -29009,6 +29820,7 @@ function createBilling(env, service) {
|
|
|
29009
29820
|
ask: env[`BILLING_${tier}_ASK_MONTHLY`],
|
|
29010
29821
|
organization: env[`BILLING_${tier}_ORGANIZATION_MONTHLY`],
|
|
29011
29822
|
assistance: env[`BILLING_${tier}_ASSISTANCE_MONTHLY`],
|
|
29823
|
+
writing: env[`BILLING_${tier}_WRITING_MONTHLY`],
|
|
29012
29824
|
concurrency: resourceLimits.free.concurrency
|
|
29013
29825
|
});
|
|
29014
29826
|
configureBillingQuotas(service.db, {
|
|
@@ -29031,14 +29843,24 @@ function createBilling(env, service) {
|
|
|
29031
29843
|
proLimits: limits2("PRO"),
|
|
29032
29844
|
proResources: resources("PRO"),
|
|
29033
29845
|
portalConfigurationId: env.STRIPE_PORTAL_CONFIGURATION_ID,
|
|
29034
|
-
pricing: env.STRIPE_PRO_PRODUCT_ID ?
|
|
29035
|
-
|
|
29036
|
-
|
|
29037
|
-
|
|
29038
|
-
|
|
29039
|
-
|
|
29040
|
-
|
|
29041
|
-
|
|
29846
|
+
pricing: env.STRIPE_PRO_PRODUCT_ID ? {
|
|
29847
|
+
month: new MonthlyPricing(
|
|
29848
|
+
stripe,
|
|
29849
|
+
env.STRIPE_PRO_PRODUCT_ID,
|
|
29850
|
+
async (subject) => {
|
|
29851
|
+
const result = await client.evaluate(billingPriceFlagKey, 19.99, { user: { id: subject } });
|
|
29852
|
+
return result.value;
|
|
29853
|
+
}
|
|
29854
|
+
),
|
|
29855
|
+
year: new YearlyPricing(
|
|
29856
|
+
stripe,
|
|
29857
|
+
env.STRIPE_PRO_PRODUCT_ID,
|
|
29858
|
+
async (subject) => {
|
|
29859
|
+
const result = await client.evaluate(billingPriceYearlyFlagKey, null, { user: { id: subject } });
|
|
29860
|
+
return result.value;
|
|
29861
|
+
}
|
|
29862
|
+
)
|
|
29863
|
+
} : void 0
|
|
29042
29864
|
});
|
|
29043
29865
|
service.beforeAccountDeletion = (trx, accountId) => billing2.cancelForDeletion(accountId, trx);
|
|
29044
29866
|
return { billing: billing2, close: () => client.shutdown() };
|
|
@@ -29189,9 +30011,10 @@ function createArtifacts(env) {
|
|
|
29189
30011
|
|
|
29190
30012
|
// packages/api/src/media-store.ts
|
|
29191
30013
|
init_define_GROVE_TELEMETRY();
|
|
30014
|
+
init_media();
|
|
29192
30015
|
import { constants as constants2 } from "node:fs";
|
|
29193
30016
|
import { link, lstat, mkdir as mkdir2, open as open2, realpath, unlink as unlink2 } from "node:fs/promises";
|
|
29194
|
-
import { randomUUID as
|
|
30017
|
+
import { randomUUID as randomUUID15 } from "node:crypto";
|
|
29195
30018
|
import { dirname as dirname2, resolve as resolve2, sep } from "node:path";
|
|
29196
30019
|
import { Readable as Readable3 } from "node:stream";
|
|
29197
30020
|
import {
|
|
@@ -29252,7 +30075,7 @@ function localMedia(root) {
|
|
|
29252
30075
|
const publish = async (key2, image, signal) => {
|
|
29253
30076
|
signal.throwIfAborted();
|
|
29254
30077
|
const target2 = await directories(key2, true);
|
|
29255
|
-
const temporary = `${target2}.${
|
|
30078
|
+
const temporary = `${target2}.${randomUUID15()}.partial`;
|
|
29256
30079
|
const file = await open2(
|
|
29257
30080
|
temporary,
|
|
29258
30081
|
constants2.O_CREAT | constants2.O_EXCL | constants2.O_WRONLY | constants2.O_NOFOLLOW,
|
|
@@ -29346,7 +30169,7 @@ function s3Media(client, bucket, spacesLifecycleVerified = false) {
|
|
|
29346
30169
|
if (name !== "NoSuchLifecycleConfiguration" && !(name === "AccessDenied" && spacesLifecycleVerified))
|
|
29347
30170
|
throw error3;
|
|
29348
30171
|
}
|
|
29349
|
-
const probe = `media-probes/${
|
|
30172
|
+
const probe = `media-probes/${randomUUID15()}`;
|
|
29350
30173
|
try {
|
|
29351
30174
|
const put = (body) => client.send(
|
|
29352
30175
|
new PutObjectCommand2({
|
|
@@ -29696,8 +30519,8 @@ This is a transactional account notification.`,
|
|
|
29696
30519
|
// packages/api/src/broker.ts
|
|
29697
30520
|
init_define_GROVE_TELEMETRY();
|
|
29698
30521
|
import amqp from "amqplib";
|
|
29699
|
-
import { z as
|
|
29700
|
-
var envelope =
|
|
30522
|
+
import { z as z27 } from "zod";
|
|
30523
|
+
var envelope = z27.object({ kind: z27.enum(["memory", "email", "task"]), id: z27.uuid() }).strict();
|
|
29701
30524
|
var queueName = (lane) => `grove.jobs.v2.${lane}`;
|
|
29702
30525
|
var limits = {
|
|
29703
30526
|
"x-message-ttl": 36e5,
|
|
@@ -29886,7 +30709,7 @@ function createLaneExecutor(runners) {
|
|
|
29886
30709
|
|
|
29887
30710
|
// lib/telemetry/src/index.ts
|
|
29888
30711
|
init_define_GROVE_TELEMETRY();
|
|
29889
|
-
import { createHmac as createHmac4, randomUUID as
|
|
30712
|
+
import { createHmac as createHmac4, randomUUID as randomUUID17 } from "node:crypto";
|
|
29890
30713
|
import { performance as performance2 } from "node:perf_hooks";
|
|
29891
30714
|
|
|
29892
30715
|
// node_modules/.pnpm/posthog-node@5.56.2_@opentelemetry+api@1.10.0/node_modules/posthog-node/dist/entrypoints/index.node.mjs
|
|
@@ -36136,13 +36959,13 @@ var FeatureFlagEvaluations = class _FeatureFlagEvaluations {
|
|
|
36136
36959
|
}
|
|
36137
36960
|
only(keys2) {
|
|
36138
36961
|
const filtered = {};
|
|
36139
|
-
const
|
|
36962
|
+
const missing8 = [];
|
|
36140
36963
|
for (const key2 of keys2) {
|
|
36141
36964
|
const flag = this._flags[key2];
|
|
36142
36965
|
if (flag) filtered[key2] = flag;
|
|
36143
|
-
else
|
|
36966
|
+
else missing8.push(key2);
|
|
36144
36967
|
}
|
|
36145
|
-
if (
|
|
36968
|
+
if (missing8.length > 0) this._host.logWarning(`FeatureFlagEvaluations.only() was called with flag keys that are not in the evaluation set and will be dropped: ${missing8.join(", ")}`);
|
|
36146
36969
|
return this._cloneWith(filtered);
|
|
36147
36970
|
}
|
|
36148
36971
|
get keys() {
|
|
@@ -45558,7 +46381,7 @@ function safeMetric(metric, identity) {
|
|
|
45558
46381
|
|
|
45559
46382
|
// lib/telemetry/src/preference.ts
|
|
45560
46383
|
init_define_GROVE_TELEMETRY();
|
|
45561
|
-
import { randomUUID as
|
|
46384
|
+
import { randomUUID as randomUUID16 } from "node:crypto";
|
|
45562
46385
|
import {
|
|
45563
46386
|
chmodSync,
|
|
45564
46387
|
closeSync,
|
|
@@ -45609,7 +46432,7 @@ function installationIdentity(directory = telemetryDirectory()) {
|
|
|
45609
46432
|
try {
|
|
45610
46433
|
const fd = openSync(path2, "wx", 384);
|
|
45611
46434
|
try {
|
|
45612
|
-
writeFileSync(fd, `${
|
|
46435
|
+
writeFileSync(fd, `${randomUUID16()}
|
|
45613
46436
|
`);
|
|
45614
46437
|
} finally {
|
|
45615
46438
|
closeSync(fd);
|
|
@@ -45984,7 +46807,7 @@ function telemetry(surface) {
|
|
|
45984
46807
|
const server = surface === "api" || surface === "worker";
|
|
45985
46808
|
const enabled = build.enabled && !environmentDisabled() && (!server || process.env.GROVE_TELEMETRY_ENABLED === "true");
|
|
45986
46809
|
const directory = telemetryDirectory();
|
|
45987
|
-
const identity = enabled ? server ?
|
|
46810
|
+
const identity = enabled ? server ? randomUUID17() : installationIdentity(directory) : "";
|
|
45988
46811
|
reporter2 = new Reporter({
|
|
45989
46812
|
...build,
|
|
45990
46813
|
enabled,
|
|
@@ -46002,6 +46825,8 @@ var closeTelemetry = (timeoutMs = 550) => Promise.allSettled(
|
|
|
46002
46825
|
|
|
46003
46826
|
// packages/api/src/media-input.ts
|
|
46004
46827
|
init_define_GROVE_TELEMETRY();
|
|
46828
|
+
init_contracts();
|
|
46829
|
+
init_media();
|
|
46005
46830
|
import { Writable } from "node:stream";
|
|
46006
46831
|
import { pipeline as pipeline2 } from "node:stream/promises";
|
|
46007
46832
|
async function readMediaBytes(source3, signal, maximum = imageLimits.bytes) {
|
|
@@ -46033,7 +46858,8 @@ async function readMediaBytes(source3, signal, maximum = imageLimits.bytes) {
|
|
|
46033
46858
|
|
|
46034
46859
|
// packages/api/src/document-extraction.ts
|
|
46035
46860
|
init_define_GROVE_TELEMETRY();
|
|
46036
|
-
|
|
46861
|
+
init_contracts();
|
|
46862
|
+
import { createHash as createHash19 } from "node:crypto";
|
|
46037
46863
|
import { spawn } from "node:child_process";
|
|
46038
46864
|
import { realpath as realpath2 } from "node:fs/promises";
|
|
46039
46865
|
import { dirname as dirname5, resolve as resolve4 } from "node:path";
|
|
@@ -46268,7 +47094,7 @@ async function extractDocument(bytes, filename, signal) {
|
|
|
46268
47094
|
const segments = segmentDocument(pages);
|
|
46269
47095
|
return {
|
|
46270
47096
|
mime: isPdf ? "application/pdf" : isDocx ? "application/vnd.openxmlformats-officedocument.wordprocessingml.document" : "text/plain",
|
|
46271
|
-
sha256:
|
|
47097
|
+
sha256: createHash19("sha256").update(bytes).digest("hex"),
|
|
46272
47098
|
pages,
|
|
46273
47099
|
segments,
|
|
46274
47100
|
emptyPages: pages.filter((p) => !p.text.trim()).map((p) => p.page)
|