@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/server.js
CHANGED
|
@@ -18,7 +18,7 @@ var __export = (target2, all2) => {
|
|
|
18
18
|
var define_GROVE_TELEMETRY_default;
|
|
19
19
|
var init_define_GROVE_TELEMETRY = __esm({
|
|
20
20
|
"<define:__GROVE_TELEMETRY__>"() {
|
|
21
|
-
define_GROVE_TELEMETRY_default = { enabled: true, revision: "
|
|
21
|
+
define_GROVE_TELEMETRY_default = { enabled: true, revision: "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,644 @@ 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 z6 } from "zod";
|
|
206
|
+
var capabilities, capabilitySchema, oauthScopes, uuidSchema, operationSchema, expectedVersionSchema, captureSchema, kindSchema, sourceSchema, rememberSchema, listSchema, recallSchema, versionSchema, forgetSchema, projectSchema, grantSchema, connectionSchema, connectionUpdateSchema, agentSchema, agentNames, connectSchema, approveConnectSchema, memorySchema, GroveError;
|
|
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 = z6.enum(capabilities);
|
|
219
|
+
oauthScopes = ["openid", "offline_access"];
|
|
220
|
+
uuidSchema = z6.uuid();
|
|
221
|
+
operationSchema = z6.uuid().describe(
|
|
222
|
+
"New UUID for this write. Reuse the same UUID and identical arguments when retrying; changed arguments require a new operation."
|
|
223
|
+
);
|
|
224
|
+
expectedVersionSchema = z6.number().int().positive().describe(
|
|
225
|
+
"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."
|
|
226
|
+
);
|
|
227
|
+
captureSchema = z6.enum(["explicit", "automatic"]).default("explicit").describe(
|
|
228
|
+
"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."
|
|
229
|
+
);
|
|
230
|
+
kindSchema = z6.enum(["preference", "fact", "decision", "solution", "handoff"]).describe(
|
|
231
|
+
"Categorize by purpose: preference, fact, decision, solution or task handoff. This is not a notebook name or topic tag."
|
|
232
|
+
);
|
|
233
|
+
sourceSchema = z6.object({
|
|
234
|
+
agent: z6.enum(["website", "opencode", "claude", "codex", "cli", "import", "api"]).default("api"),
|
|
235
|
+
session: z6.string().max(128).optional(),
|
|
236
|
+
verification: z6.string().max(500).optional()
|
|
237
|
+
}).strict();
|
|
238
|
+
rememberSchema = z6.object({
|
|
239
|
+
operationId: operationSchema,
|
|
240
|
+
id: uuidSchema.optional(),
|
|
241
|
+
expectedVersion: expectedVersionSchema.optional(),
|
|
242
|
+
content: z6.string().trim().min(1).max(NOTE_CONTENT_MAX).describe(noteContentDescription),
|
|
243
|
+
capture: captureSchema,
|
|
244
|
+
archived: z6.boolean().default(false),
|
|
245
|
+
kind: kindSchema.default("fact"),
|
|
246
|
+
autoKind: z6.boolean().default(false),
|
|
247
|
+
projectId: uuidSchema.nullable().default(null).describe(
|
|
248
|
+
"Destination notebook UUID, or null for Personal. Omission defaults to Personal; use the requested or established permitted scope."
|
|
249
|
+
),
|
|
250
|
+
taskId: z6.string().min(1).max(128).optional(),
|
|
251
|
+
retentionDays: z6.number().int().min(1).max(365).nullable().optional(),
|
|
252
|
+
source: sourceSchema.default({ agent: "api" })
|
|
253
|
+
}).strict().superRefine((input, ctx) => {
|
|
254
|
+
if (input.autoKind && input.kind === "handoff")
|
|
255
|
+
ctx.addIssue({ code: "custom", message: "Handoff kind is explicit" });
|
|
256
|
+
if (Boolean(input.id) !== Boolean(input.expectedVersion)) {
|
|
257
|
+
ctx.addIssue({
|
|
258
|
+
code: "custom",
|
|
259
|
+
message: "Corrections require both id and expectedVersion"
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
if (input.id && input.archived)
|
|
263
|
+
ctx.addIssue({
|
|
264
|
+
code: "custom",
|
|
265
|
+
message: "Use the archive action for existing memories"
|
|
266
|
+
});
|
|
267
|
+
if (input.kind === "handoff" !== Boolean(input.taskId)) {
|
|
268
|
+
ctx.addIssue({
|
|
269
|
+
code: "custom",
|
|
270
|
+
message: "Handoffs require a stable taskId; durable memories cannot have one"
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
listSchema = z6.object({
|
|
275
|
+
projectId: uuidSchema.nullable().optional().describe(
|
|
276
|
+
"Filter by notebook UUID, or null for Personal. Omit to inspect all granted scopes; do not broaden automatic searches beyond the current scope."
|
|
277
|
+
),
|
|
278
|
+
kind: kindSchema.optional(),
|
|
279
|
+
tag: z6.string().trim().min(1).max(40).optional(),
|
|
280
|
+
sourceAgent: sourceSchema.shape.agent.removeDefault().optional(),
|
|
281
|
+
updatedAfter: z6.iso.datetime().optional(),
|
|
282
|
+
sort: z6.enum(["updated_desc", "updated_asc", "created_desc", "relevance"]).optional(),
|
|
283
|
+
lifetime: z6.enum(["permanent", "ephemeral"]).optional(),
|
|
284
|
+
status: z6.enum(["active", "archived", "expired", "all"]).default("active"),
|
|
285
|
+
query: z6.string().trim().max(1e3).optional(),
|
|
286
|
+
searchMode: z6.enum(["hybrid", "lexical"]).optional(),
|
|
287
|
+
cursor: z6.string().max(2048).optional(),
|
|
288
|
+
limit: z6.number().int().min(1).max(100).default(30)
|
|
289
|
+
}).strict();
|
|
290
|
+
recallSchema = z6.object({
|
|
291
|
+
query: z6.string().trim().max(1e3).default(""),
|
|
292
|
+
projectId: uuidSchema.nullable().default(null).describe(
|
|
293
|
+
"Current notebook UUID, or null for Personal (the default). Other notebooks are not included; includePersonal controls additional Personal context."
|
|
294
|
+
),
|
|
295
|
+
includePersonal: z6.boolean().default(true),
|
|
296
|
+
taskId: z6.string().max(128).optional(),
|
|
297
|
+
limit: z6.number().int().min(1).max(12).default(8),
|
|
298
|
+
maxCharacters: z6.number().int().min(256).max(NOTE_CONTENT_MAX).default(NOTE_CONTENT_MAX)
|
|
299
|
+
}).strict();
|
|
300
|
+
versionSchema = z6.object({
|
|
301
|
+
operationId: operationSchema,
|
|
302
|
+
expectedVersion: expectedVersionSchema,
|
|
303
|
+
revision: z6.number().int().positive().optional(),
|
|
304
|
+
durable: z6.boolean().optional()
|
|
305
|
+
}).strict();
|
|
306
|
+
forgetSchema = z6.object({
|
|
307
|
+
operationId: operationSchema,
|
|
308
|
+
items: z6.array(
|
|
309
|
+
z6.object({
|
|
310
|
+
id: uuidSchema,
|
|
311
|
+
expectedVersion: expectedVersionSchema
|
|
312
|
+
}).strict()
|
|
313
|
+
).min(1).max(50)
|
|
314
|
+
}).strict();
|
|
315
|
+
projectSchema = z6.object({
|
|
316
|
+
name: z6.string().trim().min(1).max(120),
|
|
317
|
+
identity: z6.string().trim().min(1).max(500),
|
|
318
|
+
parentId: uuidSchema.nullable().optional(),
|
|
319
|
+
expectedVersion: z6.number().int().positive().optional()
|
|
320
|
+
}).strict();
|
|
321
|
+
grantSchema = z6.object({
|
|
322
|
+
name: z6.string().trim().min(1).max(100),
|
|
323
|
+
capabilities: z6.array(capabilitySchema).min(1).max(3),
|
|
324
|
+
personal: z6.boolean().default(true),
|
|
325
|
+
allProjects: z6.boolean().default(false),
|
|
326
|
+
projectIds: z6.array(uuidSchema).max(100).default([]),
|
|
327
|
+
expiresAt: z6.iso.datetime().optional(),
|
|
328
|
+
writingEnabled: z6.boolean().optional(),
|
|
329
|
+
sharingEnabled: z6.boolean().optional()
|
|
330
|
+
}).strict();
|
|
331
|
+
connectionSchema = grantSchema.extend({
|
|
332
|
+
clientId: z6.string().min(1).max(500)
|
|
333
|
+
});
|
|
334
|
+
connectionUpdateSchema = grantSchema.extend({
|
|
335
|
+
expectedState: z6.string().regex(/^[a-f0-9]{64}$/).optional()
|
|
336
|
+
});
|
|
337
|
+
agentSchema = z6.enum(["opencode", "claude", "codex"]);
|
|
338
|
+
agentNames = {
|
|
339
|
+
opencode: "OpenCode",
|
|
340
|
+
claude: "Claude Code",
|
|
341
|
+
codex: "Codex"
|
|
342
|
+
};
|
|
343
|
+
connectSchema = z6.object({
|
|
344
|
+
agent: agentSchema,
|
|
345
|
+
project: projectSchema.nullable()
|
|
346
|
+
}).strict();
|
|
347
|
+
approveConnectSchema = grantSchema.extend({
|
|
348
|
+
currentProject: z6.boolean().default(true)
|
|
349
|
+
});
|
|
350
|
+
memorySchema = z6.object({
|
|
351
|
+
id: uuidSchema,
|
|
352
|
+
projectId: uuidSchema.nullable(),
|
|
353
|
+
content: z6.string(),
|
|
354
|
+
kind: kindSchema,
|
|
355
|
+
autoKind: z6.boolean().optional(),
|
|
356
|
+
status: z6.enum(["active", "archived"]),
|
|
357
|
+
version: z6.number().int(),
|
|
358
|
+
source: sourceSchema,
|
|
359
|
+
taskId: z6.string().nullable(),
|
|
360
|
+
retentionDays: z6.number().int().nullable().optional(),
|
|
361
|
+
expiresAt: z6.string().nullable(),
|
|
362
|
+
purgeAt: z6.string().nullable(),
|
|
363
|
+
createdAt: z6.string(),
|
|
364
|
+
updatedAt: z6.string(),
|
|
365
|
+
indexing: z6.enum(["disabled", "pending", "ready", "failed"]),
|
|
366
|
+
enrichment: z6.custom().optional()
|
|
367
|
+
});
|
|
368
|
+
GroveError = class extends Error {
|
|
369
|
+
constructor(code2, message, status = 400, details) {
|
|
370
|
+
super(message);
|
|
371
|
+
this.code = code2;
|
|
372
|
+
this.status = status;
|
|
373
|
+
this.details = details;
|
|
374
|
+
this.name = "GroveError";
|
|
375
|
+
}
|
|
376
|
+
code;
|
|
377
|
+
status;
|
|
378
|
+
details;
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
// lib/shared/src/media.ts
|
|
384
|
+
function mediaReference(id2) {
|
|
385
|
+
if (!uuid.test(id2)) throw new Error("invalid_media_id");
|
|
386
|
+
return `grove-media:${id2}`;
|
|
387
|
+
}
|
|
388
|
+
function mediaObjectKey(accountId, mediaId, objectId) {
|
|
389
|
+
if (![accountId, mediaId, objectId].every((id2) => uuid.test(id2)))
|
|
390
|
+
throw new Error("invalid_media_key");
|
|
391
|
+
return `media/${accountId}/${mediaId}/${objectId}`;
|
|
392
|
+
}
|
|
393
|
+
function validateMediaKey(key2) {
|
|
394
|
+
const [prefix, accountId, mediaId, objectId, extra] = key2.split("/");
|
|
395
|
+
if (prefix !== "media" || extra !== void 0 || !accountId || !mediaId || !objectId || mediaObjectKey(accountId, mediaId, objectId) !== key2)
|
|
396
|
+
throw new Error("invalid_media_key");
|
|
397
|
+
return key2;
|
|
398
|
+
}
|
|
399
|
+
var imageLimits, imageMimeTypes, mediaMimeTypes, uuid;
|
|
400
|
+
var init_media = __esm({
|
|
401
|
+
"lib/shared/src/media.ts"() {
|
|
402
|
+
"use strict";
|
|
403
|
+
init_define_GROVE_TELEMETRY();
|
|
404
|
+
imageLimits = {
|
|
405
|
+
bytes: 10 * 1024 * 1024,
|
|
406
|
+
pixels: 24e6,
|
|
407
|
+
dimension: 1e4
|
|
408
|
+
};
|
|
409
|
+
imageMimeTypes = [
|
|
410
|
+
"image/png",
|
|
411
|
+
"image/jpeg",
|
|
412
|
+
"image/webp"
|
|
413
|
+
];
|
|
414
|
+
mediaMimeTypes = [...imageMimeTypes, "audio/wav"];
|
|
415
|
+
uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
// lib/shared/src/search.ts
|
|
420
|
+
function noteTitle2(content3, organized) {
|
|
421
|
+
const first = content3.trim().split("\n")[0];
|
|
422
|
+
const heading = first.match(/^#{1,6}\s+(.+)/)?.[1].trim();
|
|
423
|
+
if (!heading && organized) return organized;
|
|
424
|
+
const text5 = (heading || first).slice(0, NOTE_TITLE_MAX);
|
|
425
|
+
return /[\uD800-\uDBFF]$/.test(text5) ? text5.slice(0, -1) : text5;
|
|
426
|
+
}
|
|
427
|
+
function plainExcerpt(content3, length = NOTE_EXCERPT_MAX) {
|
|
428
|
+
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();
|
|
429
|
+
return text5.length > length ? `${text5.slice(0, length).trimEnd()}\u2026` : text5;
|
|
430
|
+
}
|
|
431
|
+
function searchExpansion(query) {
|
|
432
|
+
if (!/^[\p{L}\p{N}\s_]+$/u.test(query) || /\bor\b/i.test(query)) return;
|
|
433
|
+
const tokens = query.match(/[\p{L}\p{N}]+/gu) ?? [];
|
|
434
|
+
if (!tokens.length || tokens.length > 16 || tokens.some((t) => t.length > 64))
|
|
435
|
+
return;
|
|
436
|
+
return {
|
|
437
|
+
tokens,
|
|
438
|
+
prefix: tokens.at(-1).length >= 2 ? tokens.map((t, i) => t + (i === tokens.length - 1 ? ":*" : "")).join(" & ") : void 0
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
var init_search = __esm({
|
|
442
|
+
"lib/shared/src/search.ts"() {
|
|
443
|
+
"use strict";
|
|
444
|
+
init_define_GROVE_TELEMETRY();
|
|
445
|
+
init_limits();
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
// lib/shared/src/share-durations.ts
|
|
450
|
+
var shareDurations;
|
|
451
|
+
var init_share_durations = __esm({
|
|
452
|
+
"lib/shared/src/share-durations.ts"() {
|
|
453
|
+
"use strict";
|
|
454
|
+
init_define_GROVE_TELEMETRY();
|
|
455
|
+
shareDurations = {
|
|
456
|
+
"1h": { label: "1 hour", seconds: 3600 },
|
|
457
|
+
"4h": { label: "4 hours", seconds: 14400 },
|
|
458
|
+
"1d": { label: "1 day", seconds: 86400 },
|
|
459
|
+
"1w": { label: "1 week", seconds: 604800 },
|
|
460
|
+
"2w": { label: "2 weeks", seconds: 1209600 },
|
|
461
|
+
"1mo": { label: "1 month", seconds: 2592e3 }
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
// lib/shared/src/sharing.ts
|
|
467
|
+
import { z as z22 } from "zod";
|
|
468
|
+
function sharedNoteTitle(content3) {
|
|
469
|
+
return noteTitle2(content3) || "Untitled note";
|
|
470
|
+
}
|
|
471
|
+
var shareTokenSchema, shareDurationSchema, shareMutationSchema, shareEnableSchema, shareScopeSchema, publicShareQuerySchema, notebook, publicNoteSchema, publicShareSchema;
|
|
472
|
+
var init_sharing = __esm({
|
|
473
|
+
"lib/shared/src/sharing.ts"() {
|
|
474
|
+
"use strict";
|
|
475
|
+
init_define_GROVE_TELEMETRY();
|
|
476
|
+
init_contracts();
|
|
477
|
+
init_search();
|
|
478
|
+
init_limits();
|
|
479
|
+
init_share_durations();
|
|
480
|
+
shareTokenSchema = z22.string().regex(/^gsh_[A-Za-z0-9_-]{43}$/);
|
|
481
|
+
shareDurationSchema = z22.enum([
|
|
482
|
+
"1h",
|
|
483
|
+
"4h",
|
|
484
|
+
"1d",
|
|
485
|
+
"1w",
|
|
486
|
+
"2w",
|
|
487
|
+
"1mo"
|
|
488
|
+
]);
|
|
489
|
+
shareMutationSchema = z22.object({
|
|
490
|
+
operationId: operationSchema,
|
|
491
|
+
expectedVersion: z22.number().int().positive()
|
|
492
|
+
}).strict();
|
|
493
|
+
shareEnableSchema = shareMutationSchema.extend({
|
|
494
|
+
expectedVersion: z22.number().int().min(0),
|
|
495
|
+
expectedTargetVersion: z22.number().int().positive(),
|
|
496
|
+
includeDescendants: z22.boolean().default(false),
|
|
497
|
+
duration: shareDurationSchema.nullable().optional()
|
|
498
|
+
});
|
|
499
|
+
shareScopeSchema = shareMutationSchema.extend({
|
|
500
|
+
includeDescendants: z22.boolean().optional(),
|
|
501
|
+
duration: shareDurationSchema.nullable().optional()
|
|
502
|
+
}).refine(
|
|
503
|
+
(value) => value.includeDescendants !== void 0 || value.duration !== void 0,
|
|
504
|
+
"Choose a sharing setting to change"
|
|
505
|
+
);
|
|
506
|
+
publicShareQuerySchema = z22.object({
|
|
507
|
+
cursor: z22.string().max(SHARE_CURSOR_MAX).optional(),
|
|
508
|
+
limit: z22.coerce.number().int().min(1).max(100).default(30)
|
|
509
|
+
}).strict();
|
|
510
|
+
notebook = z22.object({ id: uuidSchema, name: z22.string() }).strict();
|
|
511
|
+
publicNoteSchema = z22.object({
|
|
512
|
+
id: uuidSchema,
|
|
513
|
+
title: z22.string(),
|
|
514
|
+
content: z22.string(),
|
|
515
|
+
updatedAt: z22.string(),
|
|
516
|
+
linkedNoteIds: z22.array(uuidSchema)
|
|
517
|
+
}).strict();
|
|
518
|
+
publicShareSchema = z22.object({
|
|
519
|
+
kind: z22.enum(["note", "notebook"]),
|
|
520
|
+
root: notebook,
|
|
521
|
+
notebook: notebook.nullable(),
|
|
522
|
+
note: publicNoteSchema.nullable(),
|
|
523
|
+
notebooks: z22.array(notebook),
|
|
524
|
+
notes: z22.array(
|
|
525
|
+
publicNoteSchema.pick({ id: true, title: true, updatedAt: true })
|
|
526
|
+
),
|
|
527
|
+
nextCursor: z22.string().nullable()
|
|
528
|
+
}).strict();
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
// lib/memory/src/media.ts
|
|
533
|
+
var media_exports = {};
|
|
534
|
+
__export(media_exports, {
|
|
535
|
+
MediaAttachments: () => MediaAttachments,
|
|
536
|
+
mediaDescriptor: () => mediaDescriptor
|
|
537
|
+
});
|
|
538
|
+
import { createHash as createHash18, randomUUID as randomUUID13 } from "node:crypto";
|
|
539
|
+
var missing8, conflict4, mediaDescriptor, MediaAttachments;
|
|
540
|
+
var init_media2 = __esm({
|
|
541
|
+
"lib/memory/src/media.ts"() {
|
|
542
|
+
"use strict";
|
|
543
|
+
init_define_GROVE_TELEMETRY();
|
|
544
|
+
init_contracts();
|
|
545
|
+
init_media();
|
|
546
|
+
init_sharing();
|
|
547
|
+
missing8 = () => new GroveError("not_found", "Media is unavailable", 404);
|
|
548
|
+
conflict4 = () => new GroveError(
|
|
549
|
+
"media_changed",
|
|
550
|
+
"The note or upload changed. Reload and retry.",
|
|
551
|
+
409
|
|
552
|
+
);
|
|
553
|
+
mediaDescriptor = (row) => ({
|
|
554
|
+
id: row.id,
|
|
555
|
+
reference: mediaReference(row.id),
|
|
556
|
+
mime: row.mime,
|
|
557
|
+
bytes: row.bytes,
|
|
558
|
+
width: row.width,
|
|
559
|
+
height: row.height,
|
|
560
|
+
durationMs: row.durationMs ?? null
|
|
561
|
+
});
|
|
562
|
+
MediaAttachments = class {
|
|
563
|
+
constructor(service) {
|
|
564
|
+
this.service = service;
|
|
565
|
+
}
|
|
566
|
+
service;
|
|
567
|
+
async note(trx, id2, grant) {
|
|
568
|
+
const note = await trx("memories").where({ id: id2 }).where(
|
|
569
|
+
(q) => q.whereNull("expiresAt").orWhere("expiresAt", ">", trx.fn.now())
|
|
570
|
+
).first();
|
|
571
|
+
if (!note || grant && (note.projectId === null ? !grant.personal : !(grant.allProjects || grant.projectIds.includes(note.projectId))))
|
|
572
|
+
throw missing8();
|
|
573
|
+
return note;
|
|
574
|
+
}
|
|
575
|
+
async claim(principal, input) {
|
|
576
|
+
return this.service.access(
|
|
577
|
+
principal,
|
|
578
|
+
"memory:write",
|
|
579
|
+
async ({ trx, account, grant }) => {
|
|
580
|
+
const note = await this.note(trx, input.memoryId, grant);
|
|
581
|
+
if (note.status !== "active") throw missing8();
|
|
582
|
+
const existing = await trx("media_objects").where({ id: input.id }).first();
|
|
583
|
+
if (existing && (existing.memoryId !== input.memoryId || existing.mime !== input.mime || existing.bytes !== input.bytes || existing.sha256 !== input.sha256))
|
|
584
|
+
throw conflict4();
|
|
585
|
+
if (existing?.status === "ready") return { row: existing, replay: true };
|
|
586
|
+
if (note.version !== input.version) throw conflict4();
|
|
587
|
+
if (existing?.status === "pending" && new Date(existing.leaseUntil) > /* @__PURE__ */ new Date())
|
|
588
|
+
throw conflict4();
|
|
589
|
+
const quota = await trx("accounts").where({ id: account.id }).first("mediaBytes", "mediaAttempts");
|
|
590
|
+
if (Number(quota.mediaBytes) + input.bytes > 1024 * 1024 * 1024 || quota.mediaAttempts >= 1e3)
|
|
591
|
+
throw new GroveError("media_quota", "Media storage limit reached", 429);
|
|
592
|
+
const leaseId = randomUUID13(), objectKey = mediaObjectKey(account.id, input.id, leaseId);
|
|
593
|
+
const values = {
|
|
594
|
+
memoryId: input.memoryId,
|
|
595
|
+
bytes: input.bytes,
|
|
596
|
+
mime: input.mime,
|
|
597
|
+
sha256: input.sha256,
|
|
598
|
+
status: "pending",
|
|
599
|
+
leaseId,
|
|
600
|
+
objectKey,
|
|
601
|
+
leaseUntil: trx.raw("clock_timestamp()+interval '120 seconds'")
|
|
602
|
+
};
|
|
603
|
+
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("*");
|
|
604
|
+
await trx("media_upload_attempts").insert({
|
|
605
|
+
accountId: account.id,
|
|
606
|
+
mediaId: input.id,
|
|
607
|
+
id: leaseId,
|
|
608
|
+
objectKey
|
|
609
|
+
});
|
|
610
|
+
await trx("accounts").where({ id: account.id }).increment({ mediaBytes: input.bytes, mediaAttempts: 1 });
|
|
611
|
+
return { row, replay: false };
|
|
612
|
+
}
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
async finish(principal, input, leaseId, dimensions) {
|
|
616
|
+
return this.service.access(
|
|
617
|
+
principal,
|
|
618
|
+
"memory:write",
|
|
619
|
+
async ({ trx, grant }) => {
|
|
620
|
+
const note = await this.note(trx, input.memoryId, grant);
|
|
621
|
+
if (note.status !== "active" || note.version !== input.version)
|
|
622
|
+
throw conflict4();
|
|
623
|
+
const [row] = await trx("media_objects").where({
|
|
624
|
+
id: input.id,
|
|
625
|
+
memoryId: input.memoryId,
|
|
626
|
+
leaseId,
|
|
627
|
+
status: "pending"
|
|
628
|
+
}).where("leaseUntil", ">", trx.raw("clock_timestamp()")).update({
|
|
629
|
+
width: dimensions.width,
|
|
630
|
+
height: dimensions.height,
|
|
631
|
+
durationMs: dimensions.durationMs ?? null,
|
|
632
|
+
status: "ready"
|
|
633
|
+
}).returning("*");
|
|
634
|
+
if (!row) throw conflict4();
|
|
635
|
+
await trx("accounts").where({ id: principal.accountId }).increment("exportVersion", 1);
|
|
636
|
+
return mediaDescriptor(row);
|
|
637
|
+
}
|
|
638
|
+
);
|
|
639
|
+
}
|
|
640
|
+
async fail(principal, id2, leaseId) {
|
|
641
|
+
return this.service.access(
|
|
642
|
+
principal,
|
|
643
|
+
"memory:write",
|
|
644
|
+
async ({ trx, grant }) => {
|
|
645
|
+
const target2 = await trx("media_objects").where({ id: id2, leaseId, status: "pending" }).first("memoryId");
|
|
646
|
+
if (!target2) return;
|
|
647
|
+
await this.note(trx, target2.memoryId, grant);
|
|
648
|
+
await trx("media_objects").where({ id: id2, leaseId, status: "pending" }).update({ status: "failed" });
|
|
649
|
+
}
|
|
650
|
+
);
|
|
651
|
+
}
|
|
652
|
+
async read(principal, memoryId, id2, version2) {
|
|
653
|
+
return this.service.access(
|
|
654
|
+
principal,
|
|
655
|
+
"memory:read",
|
|
656
|
+
async ({ trx, grant }) => {
|
|
657
|
+
const note = await this.note(trx, memoryId, grant);
|
|
658
|
+
const row = await trx("media_objects as o").join("media_revision_bindings as b", function() {
|
|
659
|
+
this.on("b.accountId", "=", "o.accountId").andOn(
|
|
660
|
+
"b.mediaId",
|
|
661
|
+
"=",
|
|
662
|
+
"o.id"
|
|
663
|
+
);
|
|
664
|
+
}).where({
|
|
665
|
+
"o.id": id2,
|
|
666
|
+
"o.memoryId": memoryId,
|
|
667
|
+
"o.status": "ready",
|
|
668
|
+
"b.memoryId": memoryId,
|
|
669
|
+
"b.version": version2 ?? note.version
|
|
670
|
+
}).select("o.*").first();
|
|
671
|
+
if (!row) throw missing8();
|
|
672
|
+
return {
|
|
673
|
+
key: row.objectKey,
|
|
674
|
+
mime: row.mime,
|
|
675
|
+
bytes: row.bytes,
|
|
676
|
+
sha256: row.sha256
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
);
|
|
680
|
+
}
|
|
681
|
+
async publicRead(token, memoryId, id2) {
|
|
682
|
+
if (!shareTokenSchema.safeParse(token).success) throw missing8();
|
|
683
|
+
const admitted = await this.service.db.raw(
|
|
684
|
+
"SELECT grove_share_admit('global') AS allowed"
|
|
685
|
+
);
|
|
686
|
+
if (!admitted.rows[0].allowed)
|
|
687
|
+
throw new GroveError("rate_limited", "Retry later", 429);
|
|
688
|
+
const { rows } = await this.service.db.raw(
|
|
689
|
+
"SELECT grove_public_media(?,?::uuid,?::uuid) AS value",
|
|
690
|
+
[createHash18("sha256").update(token).digest("hex"), memoryId, id2]
|
|
691
|
+
);
|
|
692
|
+
const value = rows[0].value;
|
|
693
|
+
if (value?.limited)
|
|
694
|
+
throw new GroveError("rate_limited", "Retry later", 429);
|
|
695
|
+
if (!value) throw missing8();
|
|
696
|
+
return value;
|
|
697
|
+
}
|
|
698
|
+
async transcript(principal, memoryId, id2) {
|
|
699
|
+
const object = await this.read(principal, memoryId, id2);
|
|
700
|
+
if (object.mime !== "audio/wav") throw missing8();
|
|
701
|
+
return this.service.access(
|
|
702
|
+
principal,
|
|
703
|
+
"memory:read",
|
|
704
|
+
async ({ trx, grant }) => {
|
|
705
|
+
await this.note(trx, memoryId, grant);
|
|
706
|
+
const row = await trx("media_transcripts").where({ mediaId: id2 }).select("text", "version").first();
|
|
707
|
+
return row ?? { text: "", version: 0 };
|
|
708
|
+
}
|
|
709
|
+
);
|
|
710
|
+
}
|
|
711
|
+
async listForNote(principal, memoryId, version2) {
|
|
712
|
+
return this.service.access(
|
|
713
|
+
principal,
|
|
714
|
+
"memory:read",
|
|
715
|
+
async ({ trx, grant }) => {
|
|
716
|
+
const note = await this.note(trx, memoryId, grant);
|
|
717
|
+
const bound = version2 ?? note.version;
|
|
718
|
+
const rows = await trx("media_objects as o").join("media_revision_bindings as b", function() {
|
|
719
|
+
this.on("b.accountId", "=", "o.accountId").andOn(
|
|
720
|
+
"b.mediaId",
|
|
721
|
+
"=",
|
|
722
|
+
"o.id"
|
|
723
|
+
);
|
|
724
|
+
}).leftJoin("media_transcripts as t", function() {
|
|
725
|
+
this.on("t.accountId", "=", "o.accountId").andOn(
|
|
726
|
+
"t.mediaId",
|
|
727
|
+
"=",
|
|
728
|
+
"o.id"
|
|
729
|
+
);
|
|
730
|
+
}).where({
|
|
731
|
+
"o.memoryId": memoryId,
|
|
732
|
+
"o.status": "ready",
|
|
733
|
+
"b.memoryId": memoryId,
|
|
734
|
+
"b.version": bound
|
|
735
|
+
}).select(
|
|
736
|
+
"o.id",
|
|
737
|
+
"o.mime",
|
|
738
|
+
"o.bytes",
|
|
739
|
+
"o.width",
|
|
740
|
+
"o.height",
|
|
741
|
+
"o.durationMs",
|
|
742
|
+
"t.version as transcriptVersion",
|
|
743
|
+
"t.text as transcriptText"
|
|
744
|
+
).orderBy("o.id");
|
|
745
|
+
return rows.map((row) => ({
|
|
746
|
+
id: row.id,
|
|
747
|
+
reference: mediaReference(row.id),
|
|
748
|
+
mime: row.mime,
|
|
749
|
+
bytes: row.bytes,
|
|
750
|
+
width: row.width,
|
|
751
|
+
height: row.height,
|
|
752
|
+
durationMs: row.durationMs ?? null,
|
|
753
|
+
version: bound,
|
|
754
|
+
transcriptVersion: row.transcriptVersion ?? 0,
|
|
755
|
+
hasTranscript: typeof row.transcriptText === "string" && row.transcriptText.length > 0
|
|
756
|
+
}));
|
|
757
|
+
}
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
async describeForNote(principal, memoryId, id2, version2) {
|
|
761
|
+
const items = await this.listForNote(principal, memoryId, version2);
|
|
762
|
+
const found = items.find((item) => item.id === id2);
|
|
763
|
+
if (!found) throw missing8();
|
|
764
|
+
return found;
|
|
765
|
+
}
|
|
766
|
+
async saveTranscript(principal, memoryId, id2, input) {
|
|
767
|
+
return this.service.access(
|
|
768
|
+
principal,
|
|
769
|
+
"memory:write",
|
|
770
|
+
async ({ trx, account, grant }) => {
|
|
771
|
+
const note = await this.note(trx, memoryId, grant);
|
|
772
|
+
const object = await trx("media_objects").where({ id: id2, memoryId, mime: "audio/wav", status: "ready" }).first();
|
|
773
|
+
if (!object || !await trx("media_revision_bindings").where({ mediaId: id2, memoryId, version: note.version }).first())
|
|
774
|
+
throw missing8();
|
|
775
|
+
const old = await trx("media_transcripts").where({ mediaId: id2 }).first(), fingerprint2 = createHash18("sha256").update(JSON.stringify(input)).digest("hex");
|
|
776
|
+
if (old?.operationId === input.operationId) {
|
|
777
|
+
if (old.fingerprint !== fingerprint2) throw conflict4();
|
|
778
|
+
return { text: old.text, version: old.version };
|
|
779
|
+
}
|
|
780
|
+
if ((old?.version ?? 0) !== input.expectedVersion) throw conflict4();
|
|
781
|
+
const version2 = input.expectedVersion + 1;
|
|
782
|
+
await trx("media_transcripts").insert({
|
|
783
|
+
accountId: account.id,
|
|
784
|
+
mediaId: id2,
|
|
785
|
+
text: input.text,
|
|
786
|
+
version: version2,
|
|
787
|
+
operationId: input.operationId,
|
|
788
|
+
fingerprint: fingerprint2
|
|
789
|
+
}).onConflict(["accountId", "mediaId"]).merge({
|
|
790
|
+
text: input.text,
|
|
791
|
+
version: version2,
|
|
792
|
+
operationId: input.operationId,
|
|
793
|
+
fingerprint: fingerprint2,
|
|
794
|
+
updatedAt: trx.fn.now()
|
|
795
|
+
});
|
|
796
|
+
await trx("media_transcript_revisions").insert({
|
|
797
|
+
accountId: account.id,
|
|
798
|
+
mediaId: id2,
|
|
799
|
+
version: version2,
|
|
800
|
+
text: input.text
|
|
801
|
+
});
|
|
802
|
+
await trx("accounts").where({ id: account.id }).increment("exportVersion", 1);
|
|
803
|
+
return { text: input.text, version: version2 };
|
|
804
|
+
}
|
|
805
|
+
);
|
|
806
|
+
}
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
});
|
|
810
|
+
|
|
173
811
|
// node_modules/.pnpm/@opentelemetry+api@1.10.0/node_modules/@opentelemetry/api/dist/diag/types.mjs
|
|
174
812
|
var DiagLogLevel;
|
|
175
813
|
var init_types = __esm({
|
|
@@ -1954,6 +2592,22 @@ import { Model, knexSnakeCaseMappers } from "objection";
|
|
|
1954
2592
|
// lib/database/src/migrations.ts
|
|
1955
2593
|
init_define_GROVE_TELEMETRY();
|
|
1956
2594
|
|
|
2595
|
+
// lib/database/src/writing-allowance-migration.ts
|
|
2596
|
+
init_define_GROVE_TELEMETRY();
|
|
2597
|
+
var writingAllowance = {
|
|
2598
|
+
name: "20261107_041_writing_allowance",
|
|
2599
|
+
async up(db) {
|
|
2600
|
+
await db.raw(`
|
|
2601
|
+
ALTER TABLE action_usage DROP CONSTRAINT action_usage_metric_check;
|
|
2602
|
+
ALTER TABLE action_usage ADD CONSTRAINT action_usage_metric_check
|
|
2603
|
+
CHECK(metric IN ('recall','ask','organization','assistance','writing'));
|
|
2604
|
+
`);
|
|
2605
|
+
},
|
|
2606
|
+
async down() {
|
|
2607
|
+
throw new Error("Use a forward migration");
|
|
2608
|
+
}
|
|
2609
|
+
};
|
|
2610
|
+
|
|
1957
2611
|
// lib/database/src/structured-document-migration.ts
|
|
1958
2612
|
init_define_GROVE_TELEMETRY();
|
|
1959
2613
|
var structuredDocuments = {
|
|
@@ -2188,6 +2842,72 @@ var nativeSharing = {
|
|
|
2188
2842
|
}
|
|
2189
2843
|
};
|
|
2190
2844
|
|
|
2845
|
+
// lib/database/src/trial-migration.ts
|
|
2846
|
+
init_define_GROVE_TELEMETRY();
|
|
2847
|
+
var billingTrial = {
|
|
2848
|
+
name: "20261107_040_billing_trial",
|
|
2849
|
+
async up(db) {
|
|
2850
|
+
await db.raw(`
|
|
2851
|
+
CREATE TABLE billing_trials (
|
|
2852
|
+
account_id uuid PRIMARY KEY REFERENCES accounts(id),
|
|
2853
|
+
consumed_at timestamptz NOT NULL DEFAULT now(),
|
|
2854
|
+
subscription_id text,
|
|
2855
|
+
reset_by uuid REFERENCES accounts(id),
|
|
2856
|
+
reset_at timestamptz
|
|
2857
|
+
);
|
|
2858
|
+
`);
|
|
2859
|
+
await db.raw(
|
|
2860
|
+
"ALTER TABLE billing_trials ENABLE ROW LEVEL SECURITY"
|
|
2861
|
+
);
|
|
2862
|
+
await db.raw("ALTER TABLE billing_trials FORCE ROW LEVEL SECURITY");
|
|
2863
|
+
await db.raw(
|
|
2864
|
+
`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)`
|
|
2865
|
+
);
|
|
2866
|
+
await db.raw("GRANT SELECT, INSERT, UPDATE ON billing_trials TO grove_runtime");
|
|
2867
|
+
await db.raw("GRANT SELECT ON billing_trials TO grove_worker");
|
|
2868
|
+
await db.raw(`
|
|
2869
|
+
CREATE FUNCTION grove_admin_trial_reset(target uuid, operation uuid, explanation text) RETURNS jsonb
|
|
2870
|
+
LANGUAGE plpgsql SECURITY DEFINER SET search_path=pg_catalog,public,pg_temp AS $$
|
|
2871
|
+
DECLARE actor uuid; previous public.system_admin_audit; original text; deleted integer;
|
|
2872
|
+
BEGIN
|
|
2873
|
+
actor := public.grove_admin_guard();
|
|
2874
|
+
IF target IS NULL OR operation IS NULL OR explanation IS NULL OR length(trim(explanation)) NOT BETWEEN 3 AND 300 THEN
|
|
2875
|
+
RAISE EXCEPTION 'invalid_request' USING ERRCODE='GA002';
|
|
2876
|
+
END IF;
|
|
2877
|
+
SELECT * INTO previous FROM public.system_admin_audit WHERE id=operation;
|
|
2878
|
+
IF FOUND THEN
|
|
2879
|
+
IF previous.kind<>'change' OR previous.actor_id IS DISTINCT FROM actor OR previous.account_id IS DISTINCT FROM target
|
|
2880
|
+
OR previous.reason IS DISTINCT FROM explanation THEN
|
|
2881
|
+
RAISE EXCEPTION 'operation_conflict' USING ERRCODE='GA003';
|
|
2882
|
+
END IF;
|
|
2883
|
+
RETURN previous.after;
|
|
2884
|
+
END IF;
|
|
2885
|
+
original := current_setting('grove.account_id',true);
|
|
2886
|
+
PERFORM set_config('grove.account_id',target::text,true);
|
|
2887
|
+
DELETE FROM public.billing_trials WHERE account_id=target;
|
|
2888
|
+
GET DIAGNOSTICS deleted = ROW_COUNT;
|
|
2889
|
+
PERFORM set_config('grove.account_id',COALESCE(original,''),true);
|
|
2890
|
+
IF deleted = 0 THEN
|
|
2891
|
+
RAISE EXCEPTION 'trial_not_consumed' USING ERRCODE='GA007';
|
|
2892
|
+
END IF;
|
|
2893
|
+
INSERT INTO public.system_admin_audit(id,actor_id,account_id,kind,reason,before,after)
|
|
2894
|
+
VALUES(operation,actor,target,'change',explanation,
|
|
2895
|
+
jsonb_build_object('trialEligible',false),
|
|
2896
|
+
jsonb_build_object('trialEligible',true));
|
|
2897
|
+
RETURN jsonb_build_object('accountId',target,'eligible',true);
|
|
2898
|
+
EXCEPTION WHEN OTHERS THEN
|
|
2899
|
+
IF original IS NOT NULL THEN PERFORM set_config('grove.account_id',original,true); END IF;
|
|
2900
|
+
RAISE;
|
|
2901
|
+
END $$;
|
|
2902
|
+
REVOKE ALL ON FUNCTION grove_admin_trial_reset(uuid,uuid,text) FROM PUBLIC,grove_runtime,grove_worker;
|
|
2903
|
+
GRANT EXECUTE ON FUNCTION grove_admin_trial_reset(uuid,uuid,text) TO grove_runtime;
|
|
2904
|
+
`);
|
|
2905
|
+
},
|
|
2906
|
+
async down() {
|
|
2907
|
+
throw new Error("Use a forward migration");
|
|
2908
|
+
}
|
|
2909
|
+
};
|
|
2910
|
+
|
|
2191
2911
|
// lib/database/src/action-usage-migration.ts
|
|
2192
2912
|
init_define_GROVE_TELEMETRY();
|
|
2193
2913
|
var actionUsage = {
|
|
@@ -5609,7 +6329,9 @@ var migrations = [
|
|
|
5609
6329
|
structuredDocuments,
|
|
5610
6330
|
browserCapture,
|
|
5611
6331
|
writingTools,
|
|
5612
|
-
nativeSharing
|
|
6332
|
+
nativeSharing,
|
|
6333
|
+
billingTrial,
|
|
6334
|
+
writingAllowance
|
|
5613
6335
|
];
|
|
5614
6336
|
var migrationSource = {
|
|
5615
6337
|
getMigrations: async () => migrations,
|
|
@@ -13928,200 +14650,40 @@ var settingsUpdateSchema = z5.object({
|
|
|
13928
14650
|
|
|
13929
14651
|
// lib/shared/src/memory-tools.ts
|
|
13930
14652
|
init_define_GROVE_TELEMETRY();
|
|
13931
|
-
|
|
13932
|
-
|
|
13933
|
-
// lib/shared/src/contracts.ts
|
|
13934
|
-
init_define_GROVE_TELEMETRY();
|
|
13935
|
-
import { z as z6 } from "zod";
|
|
14653
|
+
init_contracts();
|
|
14654
|
+
import { z as z9 } from "zod";
|
|
13936
14655
|
|
|
13937
|
-
// lib/shared/src/
|
|
14656
|
+
// lib/shared/src/agent-media.ts
|
|
13938
14657
|
init_define_GROVE_TELEMETRY();
|
|
13939
|
-
|
|
13940
|
-
|
|
13941
|
-
|
|
13942
|
-
|
|
13943
|
-
|
|
13944
|
-
|
|
13945
|
-
|
|
13946
|
-
|
|
13947
|
-
// lib/shared/src/contracts.ts
|
|
13948
|
-
var capabilities = [
|
|
13949
|
-
"memory:read",
|
|
13950
|
-
"memory:write",
|
|
13951
|
-
"memory:delete"
|
|
13952
|
-
];
|
|
13953
|
-
var capabilitySchema = z6.enum(capabilities);
|
|
13954
|
-
var oauthScopes = ["openid", "offline_access"];
|
|
13955
|
-
var uuidSchema = z6.uuid();
|
|
13956
|
-
var operationSchema = z6.uuid().describe(
|
|
13957
|
-
"New UUID for this write. Reuse the same UUID and identical arguments when retrying; changed arguments require a new operation."
|
|
13958
|
-
);
|
|
13959
|
-
var expectedVersionSchema = z6.number().int().positive().describe(
|
|
13960
|
-
"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."
|
|
13961
|
-
);
|
|
13962
|
-
var captureSchema = z6.enum(["explicit", "automatic"]).default("explicit").describe(
|
|
13963
|
-
"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."
|
|
13964
|
-
);
|
|
13965
|
-
var kindSchema = z6.enum(["preference", "fact", "decision", "solution", "handoff"]).describe(
|
|
13966
|
-
"Categorize by purpose: preference, fact, decision, solution or task handoff. This is not a notebook name or topic tag."
|
|
13967
|
-
);
|
|
13968
|
-
var sourceSchema = z6.object({
|
|
13969
|
-
agent: z6.enum(["website", "opencode", "claude", "codex", "cli", "import", "api"]).default("api"),
|
|
13970
|
-
session: z6.string().max(128).optional(),
|
|
13971
|
-
verification: z6.string().max(500).optional()
|
|
13972
|
-
}).strict();
|
|
13973
|
-
var rememberSchema = z6.object({
|
|
13974
|
-
operationId: operationSchema,
|
|
13975
|
-
id: uuidSchema.optional(),
|
|
13976
|
-
expectedVersion: expectedVersionSchema.optional(),
|
|
13977
|
-
content: z6.string().trim().min(1).max(6e3).describe(noteContentDescription),
|
|
13978
|
-
capture: captureSchema,
|
|
13979
|
-
archived: z6.boolean().default(false),
|
|
13980
|
-
kind: kindSchema.default("fact"),
|
|
13981
|
-
autoKind: z6.boolean().default(false),
|
|
13982
|
-
projectId: uuidSchema.nullable().default(null).describe(
|
|
13983
|
-
"Destination notebook UUID, or null for Personal. Omission defaults to Personal; use the requested or established permitted scope."
|
|
13984
|
-
),
|
|
13985
|
-
taskId: z6.string().min(1).max(128).optional(),
|
|
13986
|
-
retentionDays: z6.number().int().min(1).max(365).nullable().optional(),
|
|
13987
|
-
source: sourceSchema.default({ agent: "api" })
|
|
13988
|
-
}).strict().superRefine((input, ctx) => {
|
|
13989
|
-
if (input.autoKind && input.kind === "handoff")
|
|
13990
|
-
ctx.addIssue({ code: "custom", message: "Handoff kind is explicit" });
|
|
13991
|
-
if (Boolean(input.id) !== Boolean(input.expectedVersion)) {
|
|
13992
|
-
ctx.addIssue({
|
|
13993
|
-
code: "custom",
|
|
13994
|
-
message: "Corrections require both id and expectedVersion"
|
|
13995
|
-
});
|
|
13996
|
-
}
|
|
13997
|
-
if (input.id && input.archived)
|
|
13998
|
-
ctx.addIssue({
|
|
13999
|
-
code: "custom",
|
|
14000
|
-
message: "Use the archive action for existing memories"
|
|
14001
|
-
});
|
|
14002
|
-
if (input.kind === "handoff" !== Boolean(input.taskId)) {
|
|
14003
|
-
ctx.addIssue({
|
|
14004
|
-
code: "custom",
|
|
14005
|
-
message: "Handoffs require a stable taskId; durable memories cannot have one"
|
|
14006
|
-
});
|
|
14007
|
-
}
|
|
14008
|
-
});
|
|
14009
|
-
var listSchema = z6.object({
|
|
14010
|
-
projectId: uuidSchema.nullable().optional().describe(
|
|
14011
|
-
"Filter by notebook UUID, or null for Personal. Omit to inspect all granted scopes; do not broaden automatic searches beyond the current scope."
|
|
14012
|
-
),
|
|
14013
|
-
kind: kindSchema.optional(),
|
|
14014
|
-
tag: z6.string().trim().min(1).max(40).optional(),
|
|
14015
|
-
sourceAgent: sourceSchema.shape.agent.removeDefault().optional(),
|
|
14016
|
-
updatedAfter: z6.iso.datetime().optional(),
|
|
14017
|
-
sort: z6.enum(["updated_desc", "updated_asc", "created_desc", "relevance"]).optional(),
|
|
14018
|
-
lifetime: z6.enum(["permanent", "ephemeral"]).optional(),
|
|
14019
|
-
status: z6.enum(["active", "archived", "expired", "all"]).default("active"),
|
|
14020
|
-
query: z6.string().trim().max(1e3).optional(),
|
|
14021
|
-
searchMode: z6.enum(["hybrid", "lexical"]).optional(),
|
|
14022
|
-
cursor: z6.string().max(2048).optional(),
|
|
14023
|
-
limit: z6.number().int().min(1).max(100).default(30)
|
|
14024
|
-
}).strict();
|
|
14025
|
-
var recallSchema = z6.object({
|
|
14026
|
-
query: z6.string().trim().max(1e3).default(""),
|
|
14027
|
-
projectId: uuidSchema.nullable().default(null).describe(
|
|
14028
|
-
"Current notebook UUID, or null for Personal (the default). Other notebooks are not included; includePersonal controls additional Personal context."
|
|
14029
|
-
),
|
|
14030
|
-
includePersonal: z6.boolean().default(true),
|
|
14031
|
-
taskId: z6.string().max(128).optional(),
|
|
14032
|
-
limit: z6.number().int().min(1).max(12).default(8),
|
|
14033
|
-
maxCharacters: z6.number().int().min(256).max(6e3).default(6e3)
|
|
14034
|
-
}).strict();
|
|
14035
|
-
var versionSchema = z6.object({
|
|
14036
|
-
operationId: operationSchema,
|
|
14037
|
-
expectedVersion: expectedVersionSchema,
|
|
14038
|
-
revision: z6.number().int().positive().optional(),
|
|
14039
|
-
durable: z6.boolean().optional()
|
|
14040
|
-
}).strict();
|
|
14041
|
-
var forgetSchema = z6.object({
|
|
14042
|
-
operationId: operationSchema,
|
|
14043
|
-
items: z6.array(
|
|
14044
|
-
z6.object({
|
|
14045
|
-
id: uuidSchema,
|
|
14046
|
-
expectedVersion: expectedVersionSchema
|
|
14047
|
-
}).strict()
|
|
14048
|
-
).min(1).max(50)
|
|
14049
|
-
}).strict();
|
|
14050
|
-
var projectSchema = z6.object({
|
|
14051
|
-
name: z6.string().trim().min(1).max(120),
|
|
14052
|
-
identity: z6.string().trim().min(1).max(500),
|
|
14053
|
-
parentId: uuidSchema.nullable().optional(),
|
|
14054
|
-
expectedVersion: z6.number().int().positive().optional()
|
|
14055
|
-
}).strict();
|
|
14056
|
-
var grantSchema = z6.object({
|
|
14057
|
-
name: z6.string().trim().min(1).max(100),
|
|
14058
|
-
capabilities: z6.array(capabilitySchema).min(1).max(3),
|
|
14059
|
-
personal: z6.boolean().default(true),
|
|
14060
|
-
allProjects: z6.boolean().default(false),
|
|
14061
|
-
projectIds: z6.array(uuidSchema).max(100).default([]),
|
|
14062
|
-
expiresAt: z6.iso.datetime().optional(),
|
|
14063
|
-
writingEnabled: z6.boolean().optional(),
|
|
14064
|
-
sharingEnabled: z6.boolean().optional()
|
|
14658
|
+
init_contracts();
|
|
14659
|
+
import { z as z7 } from "zod";
|
|
14660
|
+
var listNoteMediaSchema = z7.object({
|
|
14661
|
+
memoryId: uuidSchema.describe("Exact note ID to inventory."),
|
|
14662
|
+
version: expectedVersionSchema.optional().describe(
|
|
14663
|
+
"Exact bound revision; omit for the current revision. History renders while the note stays accessible."
|
|
14664
|
+
)
|
|
14065
14665
|
}).strict();
|
|
14066
|
-
var
|
|
14067
|
-
|
|
14068
|
-
|
|
14069
|
-
|
|
14070
|
-
expectedState: z6.string().regex(/^[a-f0-9]{64}$/).optional()
|
|
14071
|
-
});
|
|
14072
|
-
var agentSchema = z6.enum(["opencode", "claude", "codex"]);
|
|
14073
|
-
var agentNames = {
|
|
14074
|
-
opencode: "OpenCode",
|
|
14075
|
-
claude: "Claude Code",
|
|
14076
|
-
codex: "Codex"
|
|
14077
|
-
};
|
|
14078
|
-
var connectSchema = z6.object({
|
|
14079
|
-
agent: agentSchema,
|
|
14080
|
-
project: projectSchema.nullable()
|
|
14666
|
+
var describeNoteMediaSchema = z7.object({
|
|
14667
|
+
memoryId: uuidSchema.describe("Exact note ID holding the attachment."),
|
|
14668
|
+
mediaId: uuidSchema.describe("Opaque attachment UUID from list output."),
|
|
14669
|
+
version: expectedVersionSchema.optional().describe("Exact bound revision; omit for the current revision.")
|
|
14081
14670
|
}).strict();
|
|
14082
|
-
var
|
|
14083
|
-
|
|
14084
|
-
|
|
14085
|
-
|
|
14086
|
-
id: uuidSchema,
|
|
14087
|
-
projectId: uuidSchema.nullable(),
|
|
14088
|
-
content: z6.string(),
|
|
14089
|
-
kind: kindSchema,
|
|
14090
|
-
autoKind: z6.boolean().optional(),
|
|
14091
|
-
status: z6.enum(["active", "archived"]),
|
|
14092
|
-
version: z6.number().int(),
|
|
14093
|
-
source: sourceSchema,
|
|
14094
|
-
taskId: z6.string().nullable(),
|
|
14095
|
-
retentionDays: z6.number().int().nullable().optional(),
|
|
14096
|
-
expiresAt: z6.string().nullable(),
|
|
14097
|
-
purgeAt: z6.string().nullable(),
|
|
14098
|
-
createdAt: z6.string(),
|
|
14099
|
-
updatedAt: z6.string(),
|
|
14100
|
-
indexing: z6.enum(["disabled", "pending", "ready", "failed"]),
|
|
14101
|
-
enrichment: z6.custom().optional()
|
|
14102
|
-
});
|
|
14103
|
-
var GroveError = class extends Error {
|
|
14104
|
-
constructor(code2, message, status = 400) {
|
|
14105
|
-
super(message);
|
|
14106
|
-
this.code = code2;
|
|
14107
|
-
this.status = status;
|
|
14108
|
-
this.name = "GroveError";
|
|
14109
|
-
}
|
|
14110
|
-
code;
|
|
14111
|
-
status;
|
|
14112
|
-
};
|
|
14671
|
+
var readMediaTranscriptSchema = describeNoteMediaSchema;
|
|
14672
|
+
|
|
14673
|
+
// lib/shared/src/memory-tools.ts
|
|
14674
|
+
init_note_writing();
|
|
14113
14675
|
|
|
14114
14676
|
// lib/shared/src/document-edits.ts
|
|
14115
14677
|
init_define_GROVE_TELEMETRY();
|
|
14116
|
-
import { z as
|
|
14117
|
-
var text3 =
|
|
14118
|
-
var sourceEditSchema =
|
|
14119
|
-
from:
|
|
14120
|
-
to:
|
|
14678
|
+
import { z as z8 } from "zod";
|
|
14679
|
+
var text3 = z8.string().max(6e3).refine((s) => !/[\uD800-\uDFFF]/u.test(s));
|
|
14680
|
+
var sourceEditSchema = z8.object({
|
|
14681
|
+
from: z8.number().int().min(0).max(6e3),
|
|
14682
|
+
to: z8.number().int().min(0).max(6e3),
|
|
14121
14683
|
oldText: text3,
|
|
14122
14684
|
text: text3
|
|
14123
14685
|
}).strict();
|
|
14124
|
-
var sourceEditsSchema =
|
|
14686
|
+
var sourceEditsSchema = z8.array(sourceEditSchema).min(1).max(50);
|
|
14125
14687
|
function applySourceEdits(source3, raw) {
|
|
14126
14688
|
const edits = sourceEditsSchema.parse(raw);
|
|
14127
14689
|
let inserted = 0;
|
|
@@ -14159,27 +14721,27 @@ function sourceEditsBetween(before, after) {
|
|
|
14159
14721
|
}
|
|
14160
14722
|
|
|
14161
14723
|
// lib/shared/src/memory-tools.ts
|
|
14162
|
-
var memoryUpdateSchema =
|
|
14724
|
+
var memoryUpdateSchema = z9.object({
|
|
14163
14725
|
operationId: operationSchema,
|
|
14164
14726
|
id: uuidSchema,
|
|
14165
14727
|
expectedVersion: expectedVersionSchema,
|
|
14166
14728
|
editSession: uuidSchema.optional().describe(
|
|
14167
14729
|
"Stable UUID for one editing session. Small nearby source edits may share one history revision; this is not actor identity or authorization."
|
|
14168
14730
|
),
|
|
14169
|
-
checkpoint:
|
|
14731
|
+
checkpoint: z9.boolean().optional().describe(
|
|
14170
14732
|
"Explicit save boundary: keep this change as its own revision and close the editing burst."
|
|
14171
14733
|
),
|
|
14172
14734
|
edits: sourceEditsSchema.optional().describe(
|
|
14173
14735
|
"Exact sequential UTF-16 source splices. Prefer this for passage edits; oldText must match at from/to. Never include content with edits."
|
|
14174
14736
|
),
|
|
14175
|
-
content:
|
|
14737
|
+
content: z9.string().trim().min(1).max(6e3).describe(noteContentDescription).optional(),
|
|
14176
14738
|
kind: kindSchema.optional(),
|
|
14177
|
-
autoKind:
|
|
14739
|
+
autoKind: z9.boolean().optional(),
|
|
14178
14740
|
projectId: uuidSchema.nullable().optional().describe(
|
|
14179
14741
|
"Destination notebook UUID; null moves to Personal. Omit to preserve the current notebook. Filing changes require user direction."
|
|
14180
14742
|
),
|
|
14181
|
-
taskId:
|
|
14182
|
-
retentionDays:
|
|
14743
|
+
taskId: z9.string().min(1).max(128).nullable().optional(),
|
|
14744
|
+
retentionDays: z9.number().int().min(1).max(365).nullable().optional(),
|
|
14183
14745
|
source: sourceSchema.optional(),
|
|
14184
14746
|
capture: captureSchema
|
|
14185
14747
|
}).strict().refine(
|
|
@@ -14198,48 +14760,48 @@ var memoryUpdateSchema = z8.object({
|
|
|
14198
14760
|
(input) => !(input.content !== void 0 && input.edits !== void 0),
|
|
14199
14761
|
"Use content or edits, not both"
|
|
14200
14762
|
);
|
|
14201
|
-
var memoryPatchPreviewSchema =
|
|
14763
|
+
var memoryPatchPreviewSchema = z9.object({
|
|
14202
14764
|
id: uuidSchema,
|
|
14203
14765
|
expectedVersion: expectedVersionSchema,
|
|
14204
14766
|
operationId: operationSchema,
|
|
14205
14767
|
edits: sourceEditsSchema,
|
|
14206
14768
|
editSession: uuidSchema.optional(),
|
|
14207
|
-
checkpoint:
|
|
14769
|
+
checkpoint: z9.boolean().optional(),
|
|
14208
14770
|
capture: captureSchema
|
|
14209
14771
|
}).strict();
|
|
14210
|
-
var memoryPatchApplySchema = memoryPatchPreviewSchema.extend({ review:
|
|
14772
|
+
var memoryPatchApplySchema = memoryPatchPreviewSchema.extend({ review: z9.string().min(1).max(300) }).strict();
|
|
14211
14773
|
var moveMemoriesSchema = forgetSchema.extend({ projectId: uuidSchema.nullable() }).refine(
|
|
14212
14774
|
(input) => new Set(input.items.map((item) => item.id)).size === input.items.length,
|
|
14213
14775
|
"Duplicate note IDs"
|
|
14214
14776
|
);
|
|
14215
|
-
var notebookListSchema =
|
|
14216
|
-
status:
|
|
14777
|
+
var notebookListSchema = z9.object({
|
|
14778
|
+
status: z9.enum(["active", "archived"]).default("active"),
|
|
14217
14779
|
parentId: uuidSchema.nullable().optional(),
|
|
14218
|
-
query:
|
|
14219
|
-
cursor:
|
|
14220
|
-
limit:
|
|
14780
|
+
query: z9.string().trim().max(120).optional(),
|
|
14781
|
+
cursor: z9.string().max(2048).optional(),
|
|
14782
|
+
limit: z9.number().int().min(1).max(100).default(30)
|
|
14221
14783
|
}).strict();
|
|
14222
|
-
var notebookCreateSchema =
|
|
14784
|
+
var notebookCreateSchema = z9.object({
|
|
14223
14785
|
operationId: operationSchema,
|
|
14224
|
-
name:
|
|
14786
|
+
name: z9.string().trim().min(1).max(120),
|
|
14225
14787
|
parentId: uuidSchema.nullable().default(null)
|
|
14226
14788
|
}).strict();
|
|
14227
|
-
var notebookUpdateSchema =
|
|
14789
|
+
var notebookUpdateSchema = z9.object({
|
|
14228
14790
|
operationId: operationSchema,
|
|
14229
14791
|
id: uuidSchema,
|
|
14230
14792
|
expectedVersion: expectedVersionSchema,
|
|
14231
|
-
name:
|
|
14793
|
+
name: z9.string().trim().min(1).max(120).optional(),
|
|
14232
14794
|
parentId: uuidSchema.nullable().optional()
|
|
14233
14795
|
}).strict().refine(
|
|
14234
14796
|
(input) => input.name !== void 0 || input.parentId !== void 0,
|
|
14235
14797
|
"Supply a name or parent"
|
|
14236
14798
|
);
|
|
14237
|
-
var notebookToolLifecycleSchema =
|
|
14799
|
+
var notebookToolLifecycleSchema = z9.object({
|
|
14238
14800
|
id: uuidSchema,
|
|
14239
|
-
action:
|
|
14801
|
+
action: z9.enum(["preview", "archive", "restore", "delete"]),
|
|
14240
14802
|
operationId: operationSchema.optional(),
|
|
14241
14803
|
expectedVersion: expectedVersionSchema.optional(),
|
|
14242
|
-
fingerprint:
|
|
14804
|
+
fingerprint: z9.string().regex(/^[a-f0-9]{64}$/).optional()
|
|
14243
14805
|
}).strict().refine(
|
|
14244
14806
|
(input) => input.action === "preview" || !!(input.operationId && input.expectedVersion && input.fingerprint),
|
|
14245
14807
|
"Changes require operationId, expectedVersion and the preview fingerprint"
|
|
@@ -14247,7 +14809,7 @@ var notebookToolLifecycleSchema = z8.object({
|
|
|
14247
14809
|
var memoryTools = {
|
|
14248
14810
|
get_memory_document: {
|
|
14249
14811
|
title: "Read a structured note",
|
|
14250
|
-
schema:
|
|
14812
|
+
schema: z9.object({ id: uuidSchema, revision: expectedVersionSchema.optional() }).strict(),
|
|
14251
14813
|
readOnly: true,
|
|
14252
14814
|
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."
|
|
14253
14815
|
},
|
|
@@ -14263,7 +14825,7 @@ var memoryTools = {
|
|
|
14263
14825
|
},
|
|
14264
14826
|
compare_memory_revisions: {
|
|
14265
14827
|
title: "Compare note revisions",
|
|
14266
|
-
schema:
|
|
14828
|
+
schema: z9.object({
|
|
14267
14829
|
id: uuidSchema,
|
|
14268
14830
|
beforeVersion: expectedVersionSchema,
|
|
14269
14831
|
afterVersion: expectedVersionSchema
|
|
@@ -14296,16 +14858,16 @@ var memoryTools = {
|
|
|
14296
14858
|
},
|
|
14297
14859
|
get_memory: {
|
|
14298
14860
|
title: "Read a memory",
|
|
14299
|
-
schema:
|
|
14861
|
+
schema: z9.object({
|
|
14300
14862
|
id: uuidSchema,
|
|
14301
|
-
revision:
|
|
14863
|
+
revision: z9.number().int().positive().optional()
|
|
14302
14864
|
}).strict(),
|
|
14303
14865
|
readOnly: true,
|
|
14304
14866
|
description: "Read one exact note by ID, optionally at a historical revision. Current scope, deletion and historical-source expiry checks still apply."
|
|
14305
14867
|
},
|
|
14306
14868
|
memory_history: {
|
|
14307
14869
|
title: "Read memory history",
|
|
14308
|
-
schema:
|
|
14870
|
+
schema: z9.object({ id: uuidSchema }).strict(),
|
|
14309
14871
|
readOnly: true,
|
|
14310
14872
|
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."
|
|
14311
14873
|
},
|
|
@@ -14321,7 +14883,7 @@ var memoryTools = {
|
|
|
14321
14883
|
},
|
|
14322
14884
|
archive_memory: {
|
|
14323
14885
|
title: "Archive a memory",
|
|
14324
|
-
schema:
|
|
14886
|
+
schema: z9.object({
|
|
14325
14887
|
id: uuidSchema,
|
|
14326
14888
|
operationId: operationSchema,
|
|
14327
14889
|
expectedVersion: expectedVersionSchema
|
|
@@ -14354,15 +14916,36 @@ var memoryTools = {
|
|
|
14354
14916
|
schema: notebookToolLifecycleSchema,
|
|
14355
14917
|
destructive: true,
|
|
14356
14918
|
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."
|
|
14919
|
+
},
|
|
14920
|
+
list_note_media: {
|
|
14921
|
+
title: "List note media",
|
|
14922
|
+
schema: listNoteMediaSchema,
|
|
14923
|
+
readOnly: true,
|
|
14924
|
+
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."
|
|
14925
|
+
},
|
|
14926
|
+
describe_note_media: {
|
|
14927
|
+
title: "Describe note media",
|
|
14928
|
+
schema: describeNoteMediaSchema,
|
|
14929
|
+
readOnly: true,
|
|
14930
|
+
description: "Describe one bound image/recording with safe metadata and transcript version. No bytes, keys, or hashes. Use listed IDs; never invent attachment references."
|
|
14931
|
+
},
|
|
14932
|
+
read_media_transcript: {
|
|
14933
|
+
title: "Read media transcript",
|
|
14934
|
+
schema: readMediaTranscriptSchema,
|
|
14935
|
+
readOnly: true,
|
|
14936
|
+
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."
|
|
14357
14937
|
}
|
|
14358
14938
|
};
|
|
14359
14939
|
|
|
14940
|
+
// lib/memory/src/index.ts
|
|
14941
|
+
init_contracts();
|
|
14942
|
+
|
|
14360
14943
|
// lib/shared/src/documents/index.ts
|
|
14361
14944
|
init_define_GROVE_TELEMETRY();
|
|
14362
14945
|
|
|
14363
14946
|
// lib/shared/src/documents/schema.ts
|
|
14364
14947
|
init_define_GROVE_TELEMETRY();
|
|
14365
|
-
import { z as
|
|
14948
|
+
import { z as z10 } from "zod";
|
|
14366
14949
|
var documentLimits = {
|
|
14367
14950
|
characters: 6e3,
|
|
14368
14951
|
blocks: 256,
|
|
@@ -14378,16 +14961,16 @@ var DocumentError = class extends Error {
|
|
|
14378
14961
|
}
|
|
14379
14962
|
code;
|
|
14380
14963
|
};
|
|
14381
|
-
var sourceSchema2 =
|
|
14964
|
+
var sourceSchema2 = z10.string().max(documentLimits.characters).refine(
|
|
14382
14965
|
(text5) => !/[\uD800-\uDFFF]/u.test(text5),
|
|
14383
14966
|
"Source must contain well-formed Unicode"
|
|
14384
14967
|
);
|
|
14385
|
-
var id =
|
|
14386
|
-
var hash =
|
|
14387
|
-
var revision =
|
|
14388
|
-
var blockSchema =
|
|
14968
|
+
var id = z10.uuid();
|
|
14969
|
+
var hash = z10.string().regex(/^[a-f0-9]{64}$/);
|
|
14970
|
+
var revision = z10.number().int().positive().max(Number.MAX_SAFE_INTEGER);
|
|
14971
|
+
var blockSchema = z10.object({
|
|
14389
14972
|
id,
|
|
14390
|
-
kind:
|
|
14973
|
+
kind: z10.enum([
|
|
14391
14974
|
"heading",
|
|
14392
14975
|
"paragraph",
|
|
14393
14976
|
"list",
|
|
@@ -14401,52 +14984,52 @@ var blockSchema = z9.object({
|
|
|
14401
14984
|
source: sourceSchema2.refine((s) => s.length > 0),
|
|
14402
14985
|
hash
|
|
14403
14986
|
}).strict();
|
|
14404
|
-
var documentSchema =
|
|
14405
|
-
schemaVersion:
|
|
14987
|
+
var documentSchema = z10.object({
|
|
14988
|
+
schemaVersion: z10.literal(1),
|
|
14406
14989
|
noteId: id,
|
|
14407
14990
|
revision,
|
|
14408
14991
|
hash,
|
|
14409
|
-
blocks:
|
|
14992
|
+
blocks: z10.array(blockSchema).min(1).max(documentLimits.blocks)
|
|
14410
14993
|
}).strict();
|
|
14411
|
-
var createDocumentSchema =
|
|
14994
|
+
var createDocumentSchema = z10.object({
|
|
14412
14995
|
noteId: id,
|
|
14413
14996
|
revision,
|
|
14414
14997
|
source: sourceSchema2.refine((s) => s.length > 0)
|
|
14415
14998
|
}).strict();
|
|
14416
|
-
var anchorSchema =
|
|
14999
|
+
var anchorSchema = z10.object({ afterId: id.nullable(), beforeId: id.nullable() }).strict();
|
|
14417
15000
|
var target = { nodeId: id, expectedHash: hash };
|
|
14418
|
-
var operationSchema2 =
|
|
14419
|
-
|
|
14420
|
-
type:
|
|
15001
|
+
var operationSchema2 = z10.discriminatedUnion("type", [
|
|
15002
|
+
z10.object({
|
|
15003
|
+
type: z10.literal("replace_text"),
|
|
14421
15004
|
...target,
|
|
14422
|
-
from:
|
|
14423
|
-
to:
|
|
15005
|
+
from: z10.number().int().min(0).max(documentLimits.characters),
|
|
15006
|
+
to: z10.number().int().min(0).max(documentLimits.characters),
|
|
14424
15007
|
oldText: sourceSchema2,
|
|
14425
15008
|
text: sourceSchema2
|
|
14426
15009
|
}).strict(),
|
|
14427
|
-
|
|
14428
|
-
|
|
14429
|
-
|
|
14430
|
-
type:
|
|
15010
|
+
z10.object({ type: z10.literal("delete_block"), ...target }).strict(),
|
|
15011
|
+
z10.object({ type: z10.literal("move_block"), ...target, anchor: anchorSchema }).strict(),
|
|
15012
|
+
z10.object({
|
|
15013
|
+
type: z10.literal("insert_block"),
|
|
14431
15014
|
source: sourceSchema2.refine((s) => s.length > 0),
|
|
14432
15015
|
anchor: anchorSchema
|
|
14433
15016
|
}).strict()
|
|
14434
15017
|
]);
|
|
14435
|
-
var patchSchema =
|
|
15018
|
+
var patchSchema = z10.object({
|
|
14436
15019
|
noteId: id,
|
|
14437
15020
|
baseRevision: revision,
|
|
14438
15021
|
baseHash: hash,
|
|
14439
15022
|
operationId: id,
|
|
14440
|
-
operations:
|
|
15023
|
+
operations: z10.array(operationSchema2).min(1).max(documentLimits.operations)
|
|
14441
15024
|
}).strict();
|
|
14442
|
-
var editScopeSchema =
|
|
14443
|
-
nodeIds:
|
|
14444
|
-
insertions:
|
|
14445
|
-
ranges:
|
|
14446
|
-
|
|
15025
|
+
var editScopeSchema = z10.object({
|
|
15026
|
+
nodeIds: z10.array(id).max(documentLimits.blocks),
|
|
15027
|
+
insertions: z10.array(anchorSchema).max(documentLimits.blocks + 1),
|
|
15028
|
+
ranges: z10.array(
|
|
15029
|
+
z10.object({
|
|
14447
15030
|
nodeId: id,
|
|
14448
|
-
from:
|
|
14449
|
-
to:
|
|
15031
|
+
from: z10.number().int().min(0).max(documentLimits.characters),
|
|
15032
|
+
to: z10.number().int().min(0).max(documentLimits.characters)
|
|
14450
15033
|
}).strict()
|
|
14451
15034
|
).max(documentLimits.blocks).optional()
|
|
14452
15035
|
}).strict();
|
|
@@ -16715,6 +17298,7 @@ async function compareDocuments(beforeInput, afterInput) {
|
|
|
16715
17298
|
|
|
16716
17299
|
// lib/memory/src/document-storage.ts
|
|
16717
17300
|
init_define_GROVE_TELEMETRY();
|
|
17301
|
+
init_contracts();
|
|
16718
17302
|
import { createHash as createHash4 } from "node:crypto";
|
|
16719
17303
|
|
|
16720
17304
|
// lib/memory/src/revision-groups.ts
|
|
@@ -16845,16 +17429,17 @@ async function documentRevisionValues(trx, row, edit) {
|
|
|
16845
17429
|
|
|
16846
17430
|
// lib/shared/src/notebook-organization.ts
|
|
16847
17431
|
init_define_GROVE_TELEMETRY();
|
|
16848
|
-
|
|
16849
|
-
|
|
16850
|
-
|
|
16851
|
-
|
|
16852
|
-
|
|
17432
|
+
init_contracts();
|
|
17433
|
+
import { z as z11 } from "zod";
|
|
17434
|
+
var notebookCatalogSchema = z11.object({
|
|
17435
|
+
status: z11.enum(["active", "archived"]).default("active"),
|
|
17436
|
+
limit: z11.coerce.number().int().min(1).max(200).default(200),
|
|
17437
|
+
cursor: z11.string().max(2e3).optional()
|
|
16853
17438
|
}).strict();
|
|
16854
|
-
var organizeNotebookSchema =
|
|
17439
|
+
var organizeNotebookSchema = z11.object({
|
|
16855
17440
|
operationId: uuidSchema,
|
|
16856
|
-
expectedVersion:
|
|
16857
|
-
expectedState:
|
|
17441
|
+
expectedVersion: z11.number().int().positive(),
|
|
17442
|
+
expectedState: z11.string().regex(/^[a-f0-9]{64}$/),
|
|
16858
17443
|
parentId: uuidSchema.nullable(),
|
|
16859
17444
|
beforeId: uuidSchema.optional(),
|
|
16860
17445
|
afterId: uuidSchema.optional()
|
|
@@ -16864,6 +17449,7 @@ var organizeNotebookSchema = z10.object({
|
|
|
16864
17449
|
|
|
16865
17450
|
// lib/memory/src/notebook-organization.ts
|
|
16866
17451
|
init_define_GROVE_TELEMETRY();
|
|
17452
|
+
init_contracts();
|
|
16867
17453
|
var notebookFields = [
|
|
16868
17454
|
"id",
|
|
16869
17455
|
"name",
|
|
@@ -16935,6 +17521,7 @@ async function organizeNotebook(trx, id2, input, state) {
|
|
|
16935
17521
|
|
|
16936
17522
|
// lib/memory/src/notebook-lifecycle.ts
|
|
16937
17523
|
init_define_GROVE_TELEMETRY();
|
|
17524
|
+
init_contracts();
|
|
16938
17525
|
import { createHash as createHash6 } from "node:crypto";
|
|
16939
17526
|
|
|
16940
17527
|
// lib/memory/src/relationship-data.ts
|
|
@@ -16943,30 +17530,30 @@ import { createHash as createHash5 } from "node:crypto";
|
|
|
16943
17530
|
|
|
16944
17531
|
// lib/shared/src/relationships.ts
|
|
16945
17532
|
init_define_GROVE_TELEMETRY();
|
|
16946
|
-
import { z as
|
|
17533
|
+
import { z as z12 } from "zod";
|
|
16947
17534
|
var relationshipPolicyVersion = "substantive-bridge-v3";
|
|
16948
|
-
var connectionLevelSchema =
|
|
16949
|
-
var connectionTypeSchema =
|
|
17535
|
+
var connectionLevelSchema = z12.enum(["note", "notebook"]);
|
|
17536
|
+
var connectionTypeSchema = z12.enum([
|
|
16950
17537
|
"complementary",
|
|
16951
17538
|
"conflicting",
|
|
16952
17539
|
"duplicate",
|
|
16953
17540
|
"connected"
|
|
16954
17541
|
]);
|
|
16955
|
-
var relationshipEvidenceSchema =
|
|
16956
|
-
id:
|
|
16957
|
-
version:
|
|
16958
|
-
quote:
|
|
17542
|
+
var relationshipEvidenceSchema = z12.object({
|
|
17543
|
+
id: z12.uuid(),
|
|
17544
|
+
version: z12.number().int().positive(),
|
|
17545
|
+
quote: z12.string().min(6).max(600)
|
|
16959
17546
|
}).strict();
|
|
16960
|
-
var relationshipAssessmentSchema =
|
|
16961
|
-
relationship:
|
|
17547
|
+
var relationshipAssessmentSchema = z12.object({
|
|
17548
|
+
relationship: z12.enum([
|
|
16962
17549
|
"complementary",
|
|
16963
17550
|
"conflicting",
|
|
16964
17551
|
"duplicate",
|
|
16965
17552
|
"connected",
|
|
16966
17553
|
"unrelated"
|
|
16967
17554
|
]),
|
|
16968
|
-
reason:
|
|
16969
|
-
basis:
|
|
17555
|
+
reason: z12.string().trim().max(600),
|
|
17556
|
+
basis: z12.enum([
|
|
16970
17557
|
"additional_context",
|
|
16971
17558
|
"same_information",
|
|
16972
17559
|
"incompatible_claims",
|
|
@@ -16977,11 +17564,11 @@ var relationshipAssessmentSchema = z11.object({
|
|
|
16977
17564
|
"dependency",
|
|
16978
17565
|
"none"
|
|
16979
17566
|
]),
|
|
16980
|
-
direction:
|
|
16981
|
-
evidence:
|
|
17567
|
+
direction: z12.enum(["both", "left_to_right", "right_to_left"]),
|
|
17568
|
+
evidence: z12.array(relationshipEvidenceSchema).max(8)
|
|
16982
17569
|
}).strict();
|
|
16983
|
-
var relationshipSupportSchema =
|
|
16984
|
-
kind:
|
|
17570
|
+
var relationshipSupportSchema = z12.object({
|
|
17571
|
+
kind: z12.enum([
|
|
16985
17572
|
"shared_attribute",
|
|
16986
17573
|
"specific_subject",
|
|
16987
17574
|
"specific_mechanism",
|
|
@@ -16993,34 +17580,34 @@ var relationshipSupportSchema = z11.object({
|
|
|
16993
17580
|
"template",
|
|
16994
17581
|
"generic_topic"
|
|
16995
17582
|
]),
|
|
16996
|
-
subject:
|
|
16997
|
-
property:
|
|
16998
|
-
leftValue:
|
|
16999
|
-
rightValue:
|
|
17000
|
-
conditions:
|
|
17001
|
-
leftEvidence:
|
|
17002
|
-
rightEvidence:
|
|
17583
|
+
subject: z12.string().trim().min(1).max(200),
|
|
17584
|
+
property: z12.string().trim().min(1).max(160),
|
|
17585
|
+
leftValue: z12.string().trim().min(1).max(300),
|
|
17586
|
+
rightValue: z12.string().trim().min(1).max(300),
|
|
17587
|
+
conditions: z12.string().trim().min(1).max(300),
|
|
17588
|
+
leftEvidence: z12.array(z12.number().int().min(0).max(7)).min(1).max(4),
|
|
17589
|
+
rightEvidence: z12.array(z12.number().int().min(0).max(7)).min(1).max(4)
|
|
17003
17590
|
}).strict();
|
|
17004
17591
|
var noteAssessmentSchema = relationshipAssessmentSchema.extend({
|
|
17005
|
-
support:
|
|
17006
|
-
relationship:
|
|
17592
|
+
support: z12.array(relationshipSupportSchema).max(1),
|
|
17593
|
+
relationship: z12.enum([
|
|
17007
17594
|
"complementary",
|
|
17008
17595
|
"conflicting",
|
|
17009
17596
|
"duplicate",
|
|
17010
17597
|
"unrelated"
|
|
17011
17598
|
]),
|
|
17012
|
-
basis:
|
|
17599
|
+
basis: z12.enum([
|
|
17013
17600
|
"additional_context",
|
|
17014
17601
|
"same_information",
|
|
17015
17602
|
"incompatible_claims",
|
|
17016
17603
|
"none"
|
|
17017
17604
|
]),
|
|
17018
|
-
direction:
|
|
17605
|
+
direction: z12.literal("both")
|
|
17019
17606
|
});
|
|
17020
17607
|
var notebookAssessmentSchema = relationshipAssessmentSchema.extend({
|
|
17021
|
-
support:
|
|
17022
|
-
relationship:
|
|
17023
|
-
basis:
|
|
17608
|
+
support: z12.array(relationshipSupportSchema).max(1),
|
|
17609
|
+
relationship: z12.enum(["connected", "unrelated"]),
|
|
17610
|
+
basis: z12.enum([
|
|
17024
17611
|
"shared_theme",
|
|
17025
17612
|
"shared_goal",
|
|
17026
17613
|
"shared_entity",
|
|
@@ -17029,21 +17616,21 @@ var notebookAssessmentSchema = relationshipAssessmentSchema.extend({
|
|
|
17029
17616
|
"none"
|
|
17030
17617
|
])
|
|
17031
17618
|
});
|
|
17032
|
-
var connectionQuerySchema =
|
|
17619
|
+
var connectionQuerySchema = z12.object({
|
|
17033
17620
|
level: connectionLevelSchema,
|
|
17034
|
-
endpointId:
|
|
17035
|
-
connectionId:
|
|
17621
|
+
endpointId: z12.uuid().optional(),
|
|
17622
|
+
connectionId: z12.uuid().optional(),
|
|
17036
17623
|
// Graph reads contain only edges whose two endpoints are loaded.
|
|
17037
|
-
endpointIds:
|
|
17038
|
-
limit:
|
|
17039
|
-
cursor:
|
|
17040
|
-
includeDismissed:
|
|
17624
|
+
endpointIds: z12.array(z12.uuid()).max(100).optional(),
|
|
17625
|
+
limit: z12.number().int().min(1).max(100).default(30),
|
|
17626
|
+
cursor: z12.string().max(1e3).optional(),
|
|
17627
|
+
includeDismissed: z12.boolean().default(false)
|
|
17041
17628
|
}).strict();
|
|
17042
|
-
var connectionReviewSchema =
|
|
17043
|
-
operationId:
|
|
17044
|
-
expectedRevision:
|
|
17045
|
-
expectedReviewVersion:
|
|
17046
|
-
dismissed:
|
|
17629
|
+
var connectionReviewSchema = z12.object({
|
|
17630
|
+
operationId: z12.uuid(),
|
|
17631
|
+
expectedRevision: z12.string().regex(/^[a-f0-9]{64}$/),
|
|
17632
|
+
expectedReviewVersion: z12.number().int().min(0),
|
|
17633
|
+
dismissed: z12.boolean()
|
|
17047
17634
|
}).strict();
|
|
17048
17635
|
function normalizeRelationshipAssessment(value) {
|
|
17049
17636
|
return value.relationship === "unrelated" ? { ...value, reason: "", basis: "none", direction: "both", evidence: [] } : value;
|
|
@@ -17833,6 +18420,8 @@ async function cachedWork(db, accountId, feature, input, options) {
|
|
|
17833
18420
|
init_define_GROVE_TELEMETRY();
|
|
17834
18421
|
var billingFlagKey = "billing-enabled";
|
|
17835
18422
|
var billingPriceFlagKey = "billing-pro-monthly-usd";
|
|
18423
|
+
var billingPriceYearlyFlagKey = "billing-pro-yearly-usd";
|
|
18424
|
+
var trialDurationDays = 7;
|
|
17836
18425
|
var resourceLimits = {
|
|
17837
18426
|
free: {
|
|
17838
18427
|
notes: 1e4,
|
|
@@ -17841,6 +18430,7 @@ var resourceLimits = {
|
|
|
17841
18430
|
ask: 300,
|
|
17842
18431
|
organization: 1e3,
|
|
17843
18432
|
assistance: 50,
|
|
18433
|
+
writing: 100,
|
|
17844
18434
|
concurrency: 2
|
|
17845
18435
|
},
|
|
17846
18436
|
pro: {
|
|
@@ -17850,9 +18440,14 @@ var resourceLimits = {
|
|
|
17850
18440
|
ask: 1500,
|
|
17851
18441
|
organization: 5e3,
|
|
17852
18442
|
assistance: 250,
|
|
18443
|
+
writing: 1e3,
|
|
17853
18444
|
concurrency: 2
|
|
17854
18445
|
}
|
|
17855
18446
|
};
|
|
18447
|
+
var writingDailyLimits = {
|
|
18448
|
+
free: 30,
|
|
18449
|
+
pro: 200
|
|
18450
|
+
};
|
|
17856
18451
|
var billingLimits = {
|
|
17857
18452
|
free: {
|
|
17858
18453
|
generation: { daily: 1e3, monthly: 31e3 },
|
|
@@ -17918,6 +18513,7 @@ function lexicalCandidates(content3, pool, limit) {
|
|
|
17918
18513
|
init_define_GROVE_TELEMETRY();
|
|
17919
18514
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
17920
18515
|
import { setTimeout as setTimeout5 } from "node:timers/promises";
|
|
18516
|
+
init_contracts();
|
|
17921
18517
|
var configurations = /* @__PURE__ */ new WeakMap();
|
|
17922
18518
|
function configureBillingQuotas(db, configuration) {
|
|
17923
18519
|
configurations.set(db, configuration);
|
|
@@ -18046,6 +18642,25 @@ async function reserveAction(db, trx, accountId, metric, operation2, units = 5)
|
|
|
18046
18642
|
const [row] = await trx("action_usage").insert(values).onConflict(["accountId", "metric", "operation"]).merge(values).returning("id");
|
|
18047
18643
|
return { id: row.id, leaseId, metric };
|
|
18048
18644
|
}
|
|
18645
|
+
async function assertWritingDailyLimit(db, trx, accountId) {
|
|
18646
|
+
const policy2 = await resourcePolicy(db, trx, accountId);
|
|
18647
|
+
if (!policy2 || policy2.plan === "unlimited") return;
|
|
18648
|
+
const daily = writingDailyLimits[policy2.plan];
|
|
18649
|
+
await lockUsage(trx, accountId);
|
|
18650
|
+
const count2 = await trx("action_usage").where({ accountId, metric: "writing" }).whereRaw("created_at >= date_trunc('day', now() AT TIME ZONE 'UTC')").where(
|
|
18651
|
+
(q) => q.where({ status: "completed" }).orWhere(
|
|
18652
|
+
(q2) => q2.where({ status: "reserved" }).where("leaseUntil", ">", trx.fn.now())
|
|
18653
|
+
)
|
|
18654
|
+
).sum("units AS total").first();
|
|
18655
|
+
if (Number(count2?.total ?? 0) + 5 > daily * 5) {
|
|
18656
|
+
const {
|
|
18657
|
+
rows: [clock]
|
|
18658
|
+
} = await trx.raw(
|
|
18659
|
+
"SELECT (date_trunc('day', now() AT TIME ZONE 'UTC') + interval '1 day') AT TIME ZONE 'UTC' AS reset"
|
|
18660
|
+
);
|
|
18661
|
+
throw new UsageLimitError("writing", new Date(clock.reset).toISOString());
|
|
18662
|
+
}
|
|
18663
|
+
}
|
|
18049
18664
|
async function settleAction(trx, reservation, status) {
|
|
18050
18665
|
if (!reservation) return;
|
|
18051
18666
|
const count2 = await trx("action_usage").where({
|
|
@@ -18143,7 +18758,8 @@ async function resourceUsage(db, trx, accountId) {
|
|
|
18143
18758
|
"recall",
|
|
18144
18759
|
"ask",
|
|
18145
18760
|
"organization",
|
|
18146
|
-
"assistance"
|
|
18761
|
+
"assistance",
|
|
18762
|
+
"writing"
|
|
18147
18763
|
]) {
|
|
18148
18764
|
const row = rows.find((r) => r.metric === metric);
|
|
18149
18765
|
metrics2[metric] = {
|
|
@@ -18191,6 +18807,28 @@ async function assertCapacity(trx, resource, creates) {
|
|
|
18191
18807
|
);
|
|
18192
18808
|
}
|
|
18193
18809
|
}
|
|
18810
|
+
async function trialState(trx, accountId) {
|
|
18811
|
+
const row = await trx("billing_trials").where({ accountId }).first();
|
|
18812
|
+
if (!row) return { eligible: true, consumedAt: null, resetAt: null };
|
|
18813
|
+
return {
|
|
18814
|
+
eligible: false,
|
|
18815
|
+
consumedAt: row.consumedAt ? new Date(row.consumedAt).toISOString() : null,
|
|
18816
|
+
resetAt: row.resetAt ? new Date(row.resetAt).toISOString() : null
|
|
18817
|
+
};
|
|
18818
|
+
}
|
|
18819
|
+
async function consumeTrial(trx, accountId, subscriptionId) {
|
|
18820
|
+
const existing = await trx("billing_trials").where({ accountId }).first();
|
|
18821
|
+
if (existing)
|
|
18822
|
+
throw new GroveError(
|
|
18823
|
+
"trial_already_used",
|
|
18824
|
+
"This account already used its Pro trial",
|
|
18825
|
+
409
|
|
18826
|
+
);
|
|
18827
|
+
await trx("billing_trials").insert({
|
|
18828
|
+
accountId,
|
|
18829
|
+
subscriptionId: subscriptionId ?? null
|
|
18830
|
+
});
|
|
18831
|
+
}
|
|
18194
18832
|
async function withGenerationSlot(db, accountId, run, parent = databaseSignal()) {
|
|
18195
18833
|
const id2 = randomUUID2();
|
|
18196
18834
|
const acquired = await tenant(db, accountId, async (trx) => {
|
|
@@ -18891,19 +19529,19 @@ import { createHash as createHash8 } from "node:crypto";
|
|
|
18891
19529
|
// lib/shared/src/summaries.ts
|
|
18892
19530
|
init_define_GROVE_TELEMETRY();
|
|
18893
19531
|
init_models();
|
|
18894
|
-
import { z as
|
|
19532
|
+
import { z as z13 } from "zod";
|
|
18895
19533
|
var summaryEvidenceSchema = sourceRefSchema.extend({
|
|
18896
|
-
quote:
|
|
19534
|
+
quote: z13.string().trim().min(1).max(600)
|
|
18897
19535
|
});
|
|
18898
|
-
var notebookSummarySchema =
|
|
18899
|
-
title:
|
|
18900
|
-
sections:
|
|
18901
|
-
|
|
18902
|
-
heading:
|
|
18903
|
-
statements:
|
|
18904
|
-
|
|
18905
|
-
text:
|
|
18906
|
-
sources:
|
|
19536
|
+
var notebookSummarySchema = z13.object({
|
|
19537
|
+
title: z13.string().trim().min(1).max(120),
|
|
19538
|
+
sections: z13.array(
|
|
19539
|
+
z13.object({
|
|
19540
|
+
heading: z13.string().trim().min(1).max(80),
|
|
19541
|
+
statements: z13.array(
|
|
19542
|
+
z13.object({
|
|
19543
|
+
text: z13.string().trim().min(1).max(500),
|
|
19544
|
+
sources: z13.array(summaryEvidenceSchema).min(1).max(2)
|
|
18907
19545
|
}).strict()
|
|
18908
19546
|
).max(3)
|
|
18909
19547
|
}).strict()
|
|
@@ -19207,9 +19845,11 @@ async function runNotebookSummary(db, providers, dailyLimit, job, resolveProfile
|
|
|
19207
19845
|
|
|
19208
19846
|
// lib/memory/src/assistance-data.ts
|
|
19209
19847
|
init_define_GROVE_TELEMETRY();
|
|
19848
|
+
init_note_writing();
|
|
19210
19849
|
|
|
19211
19850
|
// lib/memory/src/note-changes.ts
|
|
19212
19851
|
init_define_GROVE_TELEMETRY();
|
|
19852
|
+
init_contracts();
|
|
19213
19853
|
var changedSources = () => new GroveError(
|
|
19214
19854
|
"sources_changed",
|
|
19215
19855
|
"These notes changed. Refresh the preview.",
|
|
@@ -19329,92 +19969,93 @@ var presentAssistance = (row) => ({
|
|
|
19329
19969
|
|
|
19330
19970
|
// lib/memory/src/assistance-jobs.ts
|
|
19331
19971
|
init_define_GROVE_TELEMETRY();
|
|
19972
|
+
init_contracts();
|
|
19332
19973
|
|
|
19333
19974
|
// lib/shared/src/assistance.ts
|
|
19334
19975
|
init_define_GROVE_TELEMETRY();
|
|
19335
19976
|
init_models();
|
|
19336
|
-
import { z as
|
|
19977
|
+
import { z as z14 } from "zod";
|
|
19337
19978
|
var assistancePreferences = {
|
|
19338
19979
|
filing: "filingEnabled",
|
|
19339
19980
|
actions: "actionListsEnabled",
|
|
19340
19981
|
digest: "digestsEnabled",
|
|
19341
19982
|
cleanup: "cleanupEnabled"
|
|
19342
19983
|
};
|
|
19343
|
-
var selected =
|
|
19984
|
+
var selected = z14.array(sourceRefSchema).min(1).max(6).refine(
|
|
19344
19985
|
(refs) => new Set(refs.map((r) => r.id)).size === refs.length,
|
|
19345
19986
|
"Select distinct notes"
|
|
19346
19987
|
);
|
|
19347
|
-
var assistanceRequestSchema =
|
|
19348
|
-
|
|
19349
|
-
id:
|
|
19350
|
-
kind:
|
|
19988
|
+
var assistanceRequestSchema = z14.discriminatedUnion("kind", [
|
|
19989
|
+
z14.object({
|
|
19990
|
+
id: z14.uuid(),
|
|
19991
|
+
kind: z14.literal("filing"),
|
|
19351
19992
|
sources: selected.max(1)
|
|
19352
19993
|
}).strict(),
|
|
19353
|
-
|
|
19354
|
-
id:
|
|
19355
|
-
kind:
|
|
19994
|
+
z14.object({
|
|
19995
|
+
id: z14.uuid(),
|
|
19996
|
+
kind: z14.literal("actions"),
|
|
19356
19997
|
sources: selected,
|
|
19357
|
-
projectId:
|
|
19998
|
+
projectId: z14.uuid().nullable()
|
|
19358
19999
|
}).strict(),
|
|
19359
|
-
|
|
19360
|
-
id:
|
|
19361
|
-
kind:
|
|
19362
|
-
visitId:
|
|
19363
|
-
after:
|
|
20000
|
+
z14.object({
|
|
20001
|
+
id: z14.uuid(),
|
|
20002
|
+
kind: z14.literal("digest"),
|
|
20003
|
+
visitId: z14.uuid(),
|
|
20004
|
+
after: z14.uuid().optional()
|
|
19364
20005
|
}).strict(),
|
|
19365
|
-
|
|
20006
|
+
z14.object({ id: z14.uuid(), kind: z14.literal("cleanup"), projectId: z14.uuid() }).strict()
|
|
19366
20007
|
]);
|
|
19367
|
-
var actionListSchema =
|
|
19368
|
-
items:
|
|
19369
|
-
|
|
19370
|
-
text:
|
|
19371
|
-
sources:
|
|
20008
|
+
var actionListSchema = z14.object({
|
|
20009
|
+
items: z14.array(
|
|
20010
|
+
z14.object({
|
|
20011
|
+
text: z14.string().trim().min(1).max(240),
|
|
20012
|
+
sources: z14.array(summaryEvidenceSchema).min(1).max(2)
|
|
19372
20013
|
}).strict()
|
|
19373
20014
|
).max(12)
|
|
19374
20015
|
}).strict();
|
|
19375
|
-
var filingSchema =
|
|
19376
|
-
destination:
|
|
19377
|
-
reason:
|
|
19378
|
-
evidence:
|
|
20016
|
+
var filingSchema = z14.object({
|
|
20017
|
+
destination: z14.array(z14.uuid()).max(1),
|
|
20018
|
+
reason: z14.string().trim().max(300),
|
|
20019
|
+
evidence: z14.array(summaryEvidenceSchema).max(4)
|
|
19379
20020
|
}).strict();
|
|
19380
|
-
var digestSummarySchema =
|
|
19381
|
-
items:
|
|
20021
|
+
var digestSummarySchema = z14.object({
|
|
20022
|
+
items: z14.array(
|
|
19382
20023
|
actionListSchema.shape.items.element.extend({
|
|
19383
|
-
kind:
|
|
20024
|
+
kind: z14.enum(["new", "change", "decision", "open_action"])
|
|
19384
20025
|
})
|
|
19385
20026
|
).max(12)
|
|
19386
20027
|
}).strict();
|
|
19387
|
-
var cleanupAssessmentSchema =
|
|
19388
|
-
kind:
|
|
19389
|
-
reason:
|
|
19390
|
-
evidence:
|
|
19391
|
-
replacement:
|
|
19392
|
-
content:
|
|
20028
|
+
var cleanupAssessmentSchema = z14.object({
|
|
20029
|
+
kind: z14.enum(["duplicate", "conflicting", "superseded", "unrelated"]),
|
|
20030
|
+
reason: z14.string().trim().max(400),
|
|
20031
|
+
evidence: z14.array(summaryEvidenceSchema).max(4),
|
|
20032
|
+
replacement: z14.array(z14.uuid()).max(1),
|
|
20033
|
+
content: z14.string().trim().max(6e3)
|
|
19393
20034
|
}).strict();
|
|
19394
20035
|
var cleanupJudgmentSchema = cleanupAssessmentSchema.extend({
|
|
19395
|
-
support:
|
|
20036
|
+
support: z14.array(relationshipSupportSchema).max(1)
|
|
19396
20037
|
});
|
|
19397
|
-
var assistanceApplySchema =
|
|
19398
|
-
expectedVersion:
|
|
19399
|
-
candidate:
|
|
19400
|
-
action:
|
|
19401
|
-
edits:
|
|
19402
|
-
|
|
19403
|
-
index:
|
|
19404
|
-
text:
|
|
20038
|
+
var assistanceApplySchema = z14.object({
|
|
20039
|
+
expectedVersion: z14.number().int().positive(),
|
|
20040
|
+
candidate: z14.string().max(128).optional(),
|
|
20041
|
+
action: z14.enum(["combine", "update"]).optional(),
|
|
20042
|
+
edits: z14.array(
|
|
20043
|
+
z14.object({
|
|
20044
|
+
index: z14.number().int().min(0).max(11),
|
|
20045
|
+
text: z14.string().trim().min(1).max(240)
|
|
19405
20046
|
}).strict()
|
|
19406
20047
|
).max(12).optional()
|
|
19407
20048
|
}).strict();
|
|
19408
|
-
var assistanceReviewSchema =
|
|
19409
|
-
candidate:
|
|
19410
|
-
expectedVersion:
|
|
19411
|
-
dismissed:
|
|
20049
|
+
var assistanceReviewSchema = z14.object({
|
|
20050
|
+
candidate: z14.string().max(128),
|
|
20051
|
+
expectedVersion: z14.number().int().min(0),
|
|
20052
|
+
dismissed: z14.boolean()
|
|
19412
20053
|
}).strict();
|
|
19413
|
-
var notebookVisitSchema =
|
|
19414
|
-
id:
|
|
19415
|
-
projectId:
|
|
19416
|
-
token:
|
|
19417
|
-
from:
|
|
20054
|
+
var notebookVisitSchema = z14.object({
|
|
20055
|
+
id: z14.uuid(),
|
|
20056
|
+
projectId: z14.uuid(),
|
|
20057
|
+
token: z14.string().regex(/^\d+$/).max(20),
|
|
20058
|
+
from: z14.string().regex(/^\d+$/).max(20).nullable()
|
|
19418
20059
|
}).strict();
|
|
19419
20060
|
|
|
19420
20061
|
// lib/memory/src/assistance-actions.ts
|
|
@@ -19561,6 +20202,7 @@ async function filingStep(trx, row, providers, jobId) {
|
|
|
19561
20202
|
|
|
19562
20203
|
// lib/memory/src/assistance-cleanup.ts
|
|
19563
20204
|
init_define_GROVE_TELEMETRY();
|
|
20205
|
+
init_note_writing();
|
|
19564
20206
|
async function cleanupStep(trx, row, providers) {
|
|
19565
20207
|
if (row.input.kind !== "cleanup") throw new Error("Invalid cleanup request");
|
|
19566
20208
|
const state = row.state;
|
|
@@ -19679,6 +20321,7 @@ ${substantiveRelationshipPolicy} Review these two notes for cleanup, not Related
|
|
|
19679
20321
|
|
|
19680
20322
|
// lib/memory/src/notebook-digests.ts
|
|
19681
20323
|
init_define_GROVE_TELEMETRY();
|
|
20324
|
+
init_contracts();
|
|
19682
20325
|
async function recordNotebookExpiry(trx, accountId, projectId) {
|
|
19683
20326
|
await trx.raw(
|
|
19684
20327
|
`WITH due AS MATERIALIZED (
|
|
@@ -20943,101 +21586,78 @@ import { createHash as createHash13, randomUUID as randomUUID7 } from "node:cryp
|
|
|
20943
21586
|
// lib/memory/src/conversation-documents.ts
|
|
20944
21587
|
init_define_GROVE_TELEMETRY();
|
|
20945
21588
|
import { createHash as createHash12, randomUUID as randomUUID4 } from "node:crypto";
|
|
21589
|
+
init_contracts();
|
|
20946
21590
|
|
|
20947
21591
|
// lib/shared/src/conversation-documents.ts
|
|
20948
21592
|
init_define_GROVE_TELEMETRY();
|
|
20949
|
-
import { z as
|
|
20950
|
-
var documentStatementSchema =
|
|
20951
|
-
text:
|
|
20952
|
-
sources:
|
|
20953
|
-
|
|
20954
|
-
id:
|
|
20955
|
-
version:
|
|
20956
|
-
quote:
|
|
21593
|
+
import { z as z15 } from "zod";
|
|
21594
|
+
var documentStatementSchema = z15.object({
|
|
21595
|
+
text: z15.string().trim().min(1).max(900),
|
|
21596
|
+
sources: z15.array(
|
|
21597
|
+
z15.object({
|
|
21598
|
+
id: z15.uuid(),
|
|
21599
|
+
version: z15.number().int().positive(),
|
|
21600
|
+
quote: z15.string().min(1).max(1e3)
|
|
20957
21601
|
}).strict()
|
|
20958
21602
|
).min(1).max(6)
|
|
20959
21603
|
}).strict();
|
|
20960
|
-
var documentAcceptanceSchema =
|
|
21604
|
+
var documentAcceptanceSchema = z15.object({ expectedVersion: z15.number().int().nonnegative() }).strict();
|
|
20961
21605
|
var documentConversionSchema = documentAcceptanceSchema.extend({
|
|
20962
|
-
id:
|
|
21606
|
+
id: z15.uuid()
|
|
20963
21607
|
});
|
|
20964
21608
|
|
|
20965
|
-
// lib/
|
|
20966
|
-
|
|
20967
|
-
var imageLimits = {
|
|
20968
|
-
bytes: 10 * 1024 * 1024,
|
|
20969
|
-
pixels: 24e6,
|
|
20970
|
-
dimension: 1e4
|
|
20971
|
-
};
|
|
20972
|
-
var imageMimeTypes = [
|
|
20973
|
-
"image/png",
|
|
20974
|
-
"image/jpeg",
|
|
20975
|
-
"image/webp"
|
|
20976
|
-
];
|
|
20977
|
-
var mediaMimeTypes = [...imageMimeTypes, "audio/wav"];
|
|
20978
|
-
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}$/;
|
|
20979
|
-
function mediaReference(id2) {
|
|
20980
|
-
if (!uuid.test(id2)) throw new Error("invalid_media_id");
|
|
20981
|
-
return `grove-media:${id2}`;
|
|
20982
|
-
}
|
|
20983
|
-
function mediaObjectKey(accountId, mediaId, objectId) {
|
|
20984
|
-
if (![accountId, mediaId, objectId].every((id2) => uuid.test(id2)))
|
|
20985
|
-
throw new Error("invalid_media_key");
|
|
20986
|
-
return `media/${accountId}/${mediaId}/${objectId}`;
|
|
20987
|
-
}
|
|
20988
|
-
function validateMediaKey(key2) {
|
|
20989
|
-
const [prefix, accountId, mediaId, objectId, extra] = key2.split("/");
|
|
20990
|
-
if (prefix !== "media" || extra !== void 0 || !accountId || !mediaId || !objectId || mediaObjectKey(accountId, mediaId, objectId) !== key2)
|
|
20991
|
-
throw new Error("invalid_media_key");
|
|
20992
|
-
return key2;
|
|
20993
|
-
}
|
|
21609
|
+
// lib/memory/src/conversation-documents.ts
|
|
21610
|
+
init_media();
|
|
20994
21611
|
|
|
20995
21612
|
// lib/memory/src/document-imports.ts
|
|
20996
21613
|
init_define_GROVE_TELEMETRY();
|
|
20997
21614
|
import { createHash as createHash11, randomUUID as randomUUID3 } from "node:crypto";
|
|
21615
|
+
init_contracts();
|
|
21616
|
+
init_media();
|
|
20998
21617
|
|
|
20999
21618
|
// lib/shared/src/document-imports.ts
|
|
21000
21619
|
init_define_GROVE_TELEMETRY();
|
|
21001
|
-
import { z as
|
|
21620
|
+
import { z as z16 } from "zod";
|
|
21002
21621
|
var documentImportLimits = {
|
|
21003
21622
|
files: 25,
|
|
21004
21623
|
bytes: 3 * 1024 * 1024,
|
|
21005
21624
|
notes: 500
|
|
21006
21625
|
};
|
|
21007
|
-
var importDestinationSchema =
|
|
21008
|
-
|
|
21009
|
-
|
|
21010
|
-
name:
|
|
21011
|
-
parentId:
|
|
21626
|
+
var importDestinationSchema = z16.union([
|
|
21627
|
+
z16.object({ projectId: z16.uuid(), version: z16.number().int().positive() }).strict(),
|
|
21628
|
+
z16.object({
|
|
21629
|
+
name: z16.string().trim().min(1).max(100),
|
|
21630
|
+
parentId: z16.uuid().nullable().default(null)
|
|
21012
21631
|
}).strict(),
|
|
21013
|
-
|
|
21632
|
+
z16.null()
|
|
21014
21633
|
]);
|
|
21015
|
-
var importBatchCreateSchema =
|
|
21016
|
-
var importDraftEditSchema =
|
|
21017
|
-
expectedVersion:
|
|
21018
|
-
content:
|
|
21019
|
-
included:
|
|
21634
|
+
var importBatchCreateSchema = z16.object({ id: z16.uuid() }).strict();
|
|
21635
|
+
var importDraftEditSchema = z16.object({
|
|
21636
|
+
expectedVersion: z16.number().int().positive(),
|
|
21637
|
+
content: z16.string().trim().min(1).max(6e3).optional(),
|
|
21638
|
+
included: z16.boolean().optional(),
|
|
21020
21639
|
destination: importDestinationSchema.optional()
|
|
21021
21640
|
}).strict();
|
|
21022
|
-
var importBatchConfirmSchema =
|
|
21023
|
-
var importPlacementSchema =
|
|
21024
|
-
expectedVersion:
|
|
21641
|
+
var importBatchConfirmSchema = z16.object({ id: z16.uuid(), expectedVersion: z16.number().int().positive() }).strict();
|
|
21642
|
+
var importPlacementSchema = z16.object({
|
|
21643
|
+
expectedVersion: z16.number().int().positive(),
|
|
21025
21644
|
destination: importDestinationSchema
|
|
21026
21645
|
}).strict();
|
|
21027
|
-
var importSuggestionsSchema =
|
|
21028
|
-
groups:
|
|
21029
|
-
|
|
21030
|
-
files:
|
|
21031
|
-
destination:
|
|
21032
|
-
name:
|
|
21033
|
-
reason:
|
|
21034
|
-
evidence:
|
|
21646
|
+
var importSuggestionsSchema = z16.object({
|
|
21647
|
+
groups: z16.array(
|
|
21648
|
+
z16.object({
|
|
21649
|
+
files: z16.array(z16.uuid()).min(1).max(25),
|
|
21650
|
+
destination: z16.array(z16.uuid()).max(1),
|
|
21651
|
+
name: z16.array(z16.string().trim().min(1).max(100)).max(1),
|
|
21652
|
+
reason: z16.string().min(1).max(300),
|
|
21653
|
+
evidence: z16.array(summaryEvidenceSchema).max(6)
|
|
21035
21654
|
}).strict()
|
|
21036
21655
|
).max(25)
|
|
21037
21656
|
}).strict();
|
|
21038
21657
|
|
|
21039
21658
|
// lib/memory/src/tasks.ts
|
|
21040
21659
|
init_define_GROVE_TELEMETRY();
|
|
21660
|
+
init_contracts();
|
|
21041
21661
|
import { createHash as createHash10 } from "node:crypto";
|
|
21042
21662
|
var fingerprint = (value) => createHash10("sha256").update(JSON.stringify(value)).digest("hex");
|
|
21043
21663
|
var Tasks = class {
|
|
@@ -22343,9 +22963,13 @@ var ConversationDocuments = class _ConversationDocuments {
|
|
|
22343
22963
|
}
|
|
22344
22964
|
};
|
|
22345
22965
|
|
|
22966
|
+
// lib/memory/src/conversations.ts
|
|
22967
|
+
init_contracts();
|
|
22968
|
+
init_note_writing();
|
|
22969
|
+
|
|
22346
22970
|
// lib/shared/src/conversations.ts
|
|
22347
22971
|
init_define_GROVE_TELEMETRY();
|
|
22348
|
-
import { z as
|
|
22972
|
+
import { z as z17 } from "zod";
|
|
22349
22973
|
init_models();
|
|
22350
22974
|
|
|
22351
22975
|
// lib/shared/src/ask-tools.ts
|
|
@@ -22366,15 +22990,15 @@ var defaultAskTools = {
|
|
|
22366
22990
|
var askToolIds = Object.keys(askToolCatalog);
|
|
22367
22991
|
|
|
22368
22992
|
// lib/shared/src/conversations.ts
|
|
22369
|
-
var askToolsSchema =
|
|
22993
|
+
var askToolsSchema = z17.object({ exa: z17.boolean(), tavily: z17.boolean(), organize: z17.boolean() }).strict();
|
|
22370
22994
|
var askToolsPatchSchema = askToolsSchema.partial().refine(
|
|
22371
22995
|
(patch) => Object.keys(patch).length > 0,
|
|
22372
22996
|
"Choose at least one tool to update"
|
|
22373
22997
|
);
|
|
22374
|
-
var toolSettingsSchema =
|
|
22998
|
+
var toolSettingsSchema = z17.object({
|
|
22375
22999
|
tools: askToolsSchema,
|
|
22376
|
-
expectedVersion:
|
|
22377
|
-
saveDefault:
|
|
23000
|
+
expectedVersion: z17.number().int().nonnegative(),
|
|
23001
|
+
saveDefault: z17.boolean().optional(),
|
|
22378
23002
|
defaultPatch: askToolsPatchSchema.optional()
|
|
22379
23003
|
}).strict().refine(
|
|
22380
23004
|
({ tools, saveDefault, defaultPatch }) => !defaultPatch || saveDefault && Object.entries(defaultPatch).every(
|
|
@@ -22382,52 +23006,52 @@ var toolSettingsSchema = z16.object({
|
|
|
22382
23006
|
),
|
|
22383
23007
|
"Saved defaults must match the changed conversation tools"
|
|
22384
23008
|
);
|
|
22385
|
-
var researchRequestSchema =
|
|
22386
|
-
provider:
|
|
22387
|
-
query:
|
|
22388
|
-
urls:
|
|
23009
|
+
var researchRequestSchema = z17.object({
|
|
23010
|
+
provider: z17.enum(["exa", "tavily"]),
|
|
23011
|
+
query: z17.string().max(500),
|
|
23012
|
+
urls: z17.array(z17.string().max(2e3)).max(3)
|
|
22389
23013
|
}).strict();
|
|
22390
|
-
var webStatementSchema =
|
|
22391
|
-
text:
|
|
22392
|
-
urls:
|
|
23014
|
+
var webStatementSchema = z17.object({
|
|
23015
|
+
text: z17.string().trim().min(1).max(1200),
|
|
23016
|
+
urls: z17.array(z17.string().max(2e3)).min(1).max(5)
|
|
22393
23017
|
}).strict();
|
|
22394
|
-
var destinationSchema =
|
|
22395
|
-
var organizationProposalSchema =
|
|
22396
|
-
notebooks:
|
|
22397
|
-
|
|
22398
|
-
key:
|
|
22399
|
-
name:
|
|
23018
|
+
var destinationSchema = z17.union([z17.uuid(), z17.string().regex(/^new:[a-z0-9_-]{1,40}$/)]).nullable();
|
|
23019
|
+
var organizationProposalSchema = z17.object({
|
|
23020
|
+
notebooks: z17.array(
|
|
23021
|
+
z17.object({
|
|
23022
|
+
key: z17.string().regex(/^[a-z0-9_-]{1,40}$/),
|
|
23023
|
+
name: z17.string().trim().min(1).max(120),
|
|
22400
23024
|
parent: destinationSchema.default(null)
|
|
22401
23025
|
}).strict()
|
|
22402
23026
|
).max(6).default([]),
|
|
22403
|
-
renames:
|
|
22404
|
-
sourceRefSchema.extend({ name:
|
|
23027
|
+
renames: z17.array(
|
|
23028
|
+
sourceRefSchema.extend({ name: z17.string().trim().min(1).max(120) })
|
|
22405
23029
|
).max(6).default([]),
|
|
22406
|
-
moves:
|
|
22407
|
-
notebookMoves:
|
|
22408
|
-
notes:
|
|
22409
|
-
|
|
22410
|
-
content:
|
|
23030
|
+
moves: z17.array(sourceRefSchema.extend({ destination: destinationSchema })).max(30).default([]),
|
|
23031
|
+
notebookMoves: z17.array(sourceRefSchema.extend({ destination: destinationSchema })).max(6).optional(),
|
|
23032
|
+
notes: z17.array(
|
|
23033
|
+
z17.object({
|
|
23034
|
+
content: z17.string().trim().min(1).max(6e3),
|
|
22411
23035
|
destination: destinationSchema
|
|
22412
23036
|
}).strict()
|
|
22413
23037
|
).max(3).default([])
|
|
22414
23038
|
}).strict();
|
|
22415
|
-
var lifecycleProposalSchema =
|
|
22416
|
-
action:
|
|
22417
|
-
notes:
|
|
22418
|
-
notebooks:
|
|
23039
|
+
var lifecycleProposalSchema = z17.object({
|
|
23040
|
+
action: z17.enum(["archive", "restore", "delete"]),
|
|
23041
|
+
notes: z17.array(sourceRefSchema).max(30).default([]),
|
|
23042
|
+
notebooks: z17.array(sourceRefSchema).max(6).default([])
|
|
22419
23043
|
}).strict();
|
|
22420
|
-
var conversationScopeSchema =
|
|
22421
|
-
projectId:
|
|
22422
|
-
includePersonal:
|
|
23044
|
+
var conversationScopeSchema = z17.object({
|
|
23045
|
+
projectId: z17.uuid().nullable().optional(),
|
|
23046
|
+
includePersonal: z17.boolean().default(false)
|
|
22423
23047
|
}).strict();
|
|
22424
23048
|
var conversationCreateSchema = conversationScopeSchema.extend({
|
|
22425
|
-
id:
|
|
23049
|
+
id: z17.uuid()
|
|
22426
23050
|
});
|
|
22427
|
-
var conversationContextSchema =
|
|
22428
|
-
notes:
|
|
22429
|
-
notebooks:
|
|
22430
|
-
only:
|
|
23051
|
+
var conversationContextSchema = z17.object({
|
|
23052
|
+
notes: z17.array(z17.uuid().transform((id2) => id2.toLowerCase())).max(12),
|
|
23053
|
+
notebooks: z17.array(z17.uuid().transform((id2) => id2.toLowerCase())).max(6),
|
|
23054
|
+
only: z17.boolean()
|
|
22431
23055
|
}).strict().refine(
|
|
22432
23056
|
({ notes, notebooks }) => notes.length + notebooks.length > 0,
|
|
22433
23057
|
"Choose a source"
|
|
@@ -22435,18 +23059,18 @@ var conversationContextSchema = z16.object({
|
|
|
22435
23059
|
({ notes, notebooks }) => new Set(notes).size === notes.length && new Set(notebooks).size === notebooks.length,
|
|
22436
23060
|
"Choose each source once"
|
|
22437
23061
|
);
|
|
22438
|
-
var conversationTurnSchema =
|
|
22439
|
-
id:
|
|
22440
|
-
query:
|
|
22441
|
-
format:
|
|
22442
|
-
expectedVersion:
|
|
22443
|
-
refreshSources:
|
|
23062
|
+
var conversationTurnSchema = z17.object({
|
|
23063
|
+
id: z17.uuid(),
|
|
23064
|
+
query: z17.string().trim().min(1).max(6e3),
|
|
23065
|
+
format: z17.enum(["plain", "markdown"]).default("plain"),
|
|
23066
|
+
expectedVersion: z17.number().int().min(0),
|
|
23067
|
+
refreshSources: z17.boolean().optional(),
|
|
22444
23068
|
context: conversationContextSchema.optional(),
|
|
22445
|
-
documentsVersion:
|
|
23069
|
+
documentsVersion: z17.number().int().nonnegative().optional()
|
|
22446
23070
|
}).strict();
|
|
22447
|
-
var conversationPlanSchema =
|
|
22448
|
-
query:
|
|
22449
|
-
intent:
|
|
23071
|
+
var conversationPlanSchema = z17.object({
|
|
23072
|
+
query: z17.string().trim().min(1).max(1e3),
|
|
23073
|
+
intent: z17.enum([
|
|
22450
23074
|
"answer",
|
|
22451
23075
|
"find",
|
|
22452
23076
|
"edit",
|
|
@@ -22457,50 +23081,50 @@ var conversationPlanSchema = z16.object({
|
|
|
22457
23081
|
"restore",
|
|
22458
23082
|
"delete"
|
|
22459
23083
|
]),
|
|
22460
|
-
references:
|
|
22461
|
-
research:
|
|
22462
|
-
organizeAfter:
|
|
23084
|
+
references: z17.array(z17.uuid()).max(8),
|
|
23085
|
+
research: z17.array(researchRequestSchema).max(2).default([]),
|
|
23086
|
+
organizeAfter: z17.uuid().nullable().default(null)
|
|
22463
23087
|
}).strict();
|
|
22464
|
-
var noteProposalSchema =
|
|
22465
|
-
kind:
|
|
23088
|
+
var noteProposalSchema = z17.object({
|
|
23089
|
+
kind: z17.enum(["edit", "merge", "create"]),
|
|
22466
23090
|
target: sourceRefSchema.nullable(),
|
|
22467
|
-
sources:
|
|
22468
|
-
content:
|
|
23091
|
+
sources: z17.array(sourceRefSchema).max(6),
|
|
23092
|
+
content: z17.string().trim().min(1).max(6e3)
|
|
22469
23093
|
}).strict();
|
|
22470
|
-
var conversationReplySchema =
|
|
22471
|
-
message:
|
|
23094
|
+
var conversationReplySchema = z17.object({
|
|
23095
|
+
message: z17.string().trim().max(2e3),
|
|
22472
23096
|
statements: answerSchema.shape.statements,
|
|
22473
23097
|
proposal: noteProposalSchema.nullable(),
|
|
22474
|
-
webStatements:
|
|
23098
|
+
webStatements: z17.array(webStatementSchema).max(8).default([])
|
|
22475
23099
|
}).strict();
|
|
22476
23100
|
var conversationGenerationSchema = conversationReplySchema.omit({ proposal: true }).extend({
|
|
22477
|
-
documentStatements:
|
|
22478
|
-
lifecycle:
|
|
22479
|
-
organization:
|
|
22480
|
-
proposals:
|
|
23101
|
+
documentStatements: z17.array(documentStatementSchema).max(8).default([]),
|
|
23102
|
+
lifecycle: z17.array(lifecycleProposalSchema).max(1).default([]),
|
|
23103
|
+
organization: z17.array(organizationProposalSchema).max(1).default([]),
|
|
23104
|
+
proposals: z17.array(
|
|
22481
23105
|
noteProposalSchema.extend({
|
|
22482
|
-
target:
|
|
23106
|
+
target: z17.array(sourceRefSchema).max(1)
|
|
22483
23107
|
})
|
|
22484
23108
|
).max(1)
|
|
22485
23109
|
});
|
|
22486
23110
|
function conversationResponseSchema(intent, notes, web, writes) {
|
|
22487
23111
|
const proposal = conversationGenerationSchema.shape.proposals.element;
|
|
22488
23112
|
return conversationGenerationSchema.extend({
|
|
22489
|
-
lifecycle: writes && ["archive", "restore", "delete"].includes(intent) ?
|
|
23113
|
+
lifecycle: writes && ["archive", "restore", "delete"].includes(intent) ? z17.array(
|
|
22490
23114
|
lifecycleProposalSchema.extend({
|
|
22491
|
-
action:
|
|
23115
|
+
action: z17.literal(intent)
|
|
22492
23116
|
})
|
|
22493
|
-
).max(1).default([]) :
|
|
22494
|
-
statements: notes ? conversationReplySchema.shape.statements :
|
|
22495
|
-
webStatements: web ? conversationReplySchema.shape.webStatements :
|
|
22496
|
-
organization: writes && intent === "organize" ? conversationGenerationSchema.shape.organization :
|
|
22497
|
-
proposals: !writes ?
|
|
23117
|
+
).max(1).default([]) : z17.tuple([]).default([]),
|
|
23118
|
+
statements: notes ? conversationReplySchema.shape.statements : z17.tuple([]),
|
|
23119
|
+
webStatements: web ? conversationReplySchema.shape.webStatements : z17.tuple([]).default([]),
|
|
23120
|
+
organization: writes && intent === "organize" ? conversationGenerationSchema.shape.organization : z17.tuple([]).default([]),
|
|
23121
|
+
proposals: !writes ? z17.tuple([]).default([]) : intent === "create" ? z17.array(
|
|
22498
23122
|
proposal.extend({
|
|
22499
|
-
kind:
|
|
22500
|
-
target:
|
|
22501
|
-
sources:
|
|
23123
|
+
kind: z17.literal("create"),
|
|
23124
|
+
target: z17.tuple([]),
|
|
23125
|
+
sources: z17.tuple([])
|
|
22502
23126
|
})
|
|
22503
|
-
).max(1) : notes && (intent === "edit" || intent === "merge") ?
|
|
23127
|
+
).max(1) : notes && (intent === "edit" || intent === "merge") ? z17.array(proposal.extend({ kind: z17.literal(intent) })).max(1) : z17.tuple([]).default([])
|
|
22504
23128
|
});
|
|
22505
23129
|
}
|
|
22506
23130
|
|
|
@@ -22510,6 +23134,7 @@ var inConversationScope = (scope, projectId) => scope.projectId === void 0 || pr
|
|
|
22510
23134
|
|
|
22511
23135
|
// lib/memory/src/conversation-context.ts
|
|
22512
23136
|
init_define_GROVE_TELEMETRY();
|
|
23137
|
+
init_contracts();
|
|
22513
23138
|
async function resolveConversationContext(trx, scope, selection, query) {
|
|
22514
23139
|
if (!selection) return { sources: [], notebooks: [] };
|
|
22515
23140
|
const unavailable6 = () => new GroveError(
|
|
@@ -22762,6 +23387,7 @@ async function applyOrganization(service, principal, trx, turnId, proposal, scop
|
|
|
22762
23387
|
// lib/memory/src/conversation-lifecycle.ts
|
|
22763
23388
|
init_define_GROVE_TELEMETRY();
|
|
22764
23389
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
23390
|
+
init_contracts();
|
|
22765
23391
|
async function lifecyclePreview(service, principal, trx, changes, sources, notebooks, scope) {
|
|
22766
23392
|
if (!changes.notes.length && !changes.notebooks.length)
|
|
22767
23393
|
throw changedSources();
|
|
@@ -24206,6 +24832,7 @@ var Conversations = class {
|
|
|
24206
24832
|
|
|
24207
24833
|
// lib/memory/src/relationships.ts
|
|
24208
24834
|
init_define_GROVE_TELEMETRY();
|
|
24835
|
+
init_contracts();
|
|
24209
24836
|
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
24210
24837
|
var unavailable = () => new GroveError("not_found", "Connection unavailable", 404);
|
|
24211
24838
|
var Relationships = class {
|
|
@@ -24556,32 +25183,7 @@ function semanticMatches(trx, eligible2, embedder, vector, limit) {
|
|
|
24556
25183
|
|
|
24557
25184
|
// lib/memory/src/lexical.ts
|
|
24558
25185
|
init_define_GROVE_TELEMETRY();
|
|
24559
|
-
|
|
24560
|
-
// lib/shared/src/search.ts
|
|
24561
|
-
init_define_GROVE_TELEMETRY();
|
|
24562
|
-
function noteTitle2(content3, organized) {
|
|
24563
|
-
const first = content3.trim().split("\n")[0];
|
|
24564
|
-
const heading = first.match(/^#{1,6}\s+(.+)/)?.[1].trim();
|
|
24565
|
-
if (!heading && organized) return organized;
|
|
24566
|
-
const text5 = (heading || first).slice(0, 110);
|
|
24567
|
-
return /[\uD800-\uDBFF]$/.test(text5) ? text5.slice(0, -1) : text5;
|
|
24568
|
-
}
|
|
24569
|
-
function plainExcerpt(content3, length = 160) {
|
|
24570
|
-
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();
|
|
24571
|
-
return text5.length > length ? `${text5.slice(0, length).trimEnd()}\u2026` : text5;
|
|
24572
|
-
}
|
|
24573
|
-
function searchExpansion(query) {
|
|
24574
|
-
if (!/^[\p{L}\p{N}\s_]+$/u.test(query) || /\bor\b/i.test(query)) return;
|
|
24575
|
-
const tokens = query.match(/[\p{L}\p{N}]+/gu) ?? [];
|
|
24576
|
-
if (!tokens.length || tokens.length > 16 || tokens.some((t) => t.length > 64))
|
|
24577
|
-
return;
|
|
24578
|
-
return {
|
|
24579
|
-
tokens,
|
|
24580
|
-
prefix: tokens.at(-1).length >= 2 ? tokens.map((t, i) => t + (i === tokens.length - 1 ? ":*" : "")).join(" & ") : void 0
|
|
24581
|
-
};
|
|
24582
|
-
}
|
|
24583
|
-
|
|
24584
|
-
// lib/memory/src/lexical.ts
|
|
25186
|
+
init_search();
|
|
24585
25187
|
var searchVersion = "title-prefix-trgm-shortfall40-v1";
|
|
24586
25188
|
function lexicalQuery(trx, eligible2, query, providers, account, semantic) {
|
|
24587
25189
|
const expansion = searchExpansion(query);
|
|
@@ -24723,6 +25325,8 @@ async function relevancePage(trx, query, limit, after) {
|
|
|
24723
25325
|
|
|
24724
25326
|
// lib/memory/src/search-evidence.ts
|
|
24725
25327
|
init_define_GROVE_TELEMETRY();
|
|
25328
|
+
init_contracts();
|
|
25329
|
+
init_search();
|
|
24726
25330
|
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
24727
25331
|
async function searchEvidence(trx, items, query, rows) {
|
|
24728
25332
|
if (!items.length) return {};
|
|
@@ -24833,6 +25437,7 @@ async function admitOperation(owner, principal, run) {
|
|
|
24833
25437
|
// lib/memory/src/assistance.ts
|
|
24834
25438
|
init_define_GROVE_TELEMETRY();
|
|
24835
25439
|
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
25440
|
+
init_contracts();
|
|
24836
25441
|
var missing5 = () => new GroveError("not_found", "Preview unavailable", 404);
|
|
24837
25442
|
var conflict2 = () => new GroveError("preview_changed", "This preview changed. Reopen it.", 409);
|
|
24838
25443
|
var NotebookAssistance = class {
|
|
@@ -25123,11 +25728,12 @@ import {
|
|
|
25123
25728
|
createHash as createHash14,
|
|
25124
25729
|
randomBytes
|
|
25125
25730
|
} from "node:crypto";
|
|
25731
|
+
init_contracts();
|
|
25126
25732
|
|
|
25127
25733
|
// lib/shared/src/writing-assistance.ts
|
|
25128
25734
|
init_define_GROVE_TELEMETRY();
|
|
25129
|
-
import { z as
|
|
25130
|
-
var writingToolSchema =
|
|
25735
|
+
import { z as z18 } from "zod";
|
|
25736
|
+
var writingToolSchema = z18.enum([
|
|
25131
25737
|
"concise",
|
|
25132
25738
|
"verbose",
|
|
25133
25739
|
"rewrite",
|
|
@@ -25156,22 +25762,22 @@ function selectWritingSentence(source3, from, to) {
|
|
|
25156
25762
|
from += selected2.length - selected2.trimStart().length;
|
|
25157
25763
|
return { language: "en", from, to: from + original.length, original };
|
|
25158
25764
|
}
|
|
25159
|
-
var writingContextSchema =
|
|
25160
|
-
previousSentence:
|
|
25161
|
-
nextSentence:
|
|
25162
|
-
sentenceBefore:
|
|
25163
|
-
sentenceAfter:
|
|
25164
|
-
startsSentence:
|
|
25165
|
-
endsSentence:
|
|
25166
|
-
startsParagraph:
|
|
25167
|
-
endsParagraph:
|
|
25765
|
+
var writingContextSchema = z18.object({
|
|
25766
|
+
previousSentence: z18.string().max(writingLimits.contextExcerpt),
|
|
25767
|
+
nextSentence: z18.string().max(writingLimits.contextExcerpt),
|
|
25768
|
+
sentenceBefore: z18.string().max(writingLimits.contextExcerpt),
|
|
25769
|
+
sentenceAfter: z18.string().max(writingLimits.contextExcerpt),
|
|
25770
|
+
startsSentence: z18.boolean(),
|
|
25771
|
+
endsSentence: z18.boolean(),
|
|
25772
|
+
startsParagraph: z18.boolean(),
|
|
25773
|
+
endsParagraph: z18.boolean()
|
|
25168
25774
|
}).strict();
|
|
25169
|
-
var writingRequestSchema =
|
|
25170
|
-
id:
|
|
25171
|
-
sessionId:
|
|
25172
|
-
language:
|
|
25775
|
+
var writingRequestSchema = z18.object({
|
|
25776
|
+
id: z18.uuid(),
|
|
25777
|
+
sessionId: z18.uuid(),
|
|
25778
|
+
language: z18.literal("en"),
|
|
25173
25779
|
tool: writingToolSchema,
|
|
25174
|
-
sentence:
|
|
25780
|
+
sentence: z18.string().min(1).max(writingLimits.sentence).refine(
|
|
25175
25781
|
(text5) => selectWritingSentence(text5, 0, text5.length)?.original === text5,
|
|
25176
25782
|
"Select one English sentence."
|
|
25177
25783
|
),
|
|
@@ -25190,15 +25796,15 @@ var writingRequestSchema = z17.object({
|
|
|
25190
25796
|
message: "Select one word."
|
|
25191
25797
|
});
|
|
25192
25798
|
});
|
|
25193
|
-
var writingAlternativesSchema =
|
|
25194
|
-
alternatives:
|
|
25799
|
+
var writingAlternativesSchema = z18.object({
|
|
25800
|
+
alternatives: z18.array(z18.string().trim().min(1).max(writingLimits.alternative)).min(2).max(writingLimits.alternatives)
|
|
25195
25801
|
}).strict();
|
|
25196
|
-
var writingAvailabilitySchema =
|
|
25197
|
-
available:
|
|
25198
|
-
authorized:
|
|
25199
|
-
consented:
|
|
25200
|
-
policy:
|
|
25201
|
-
provider:
|
|
25802
|
+
var writingAvailabilitySchema = z18.object({
|
|
25803
|
+
available: z18.boolean(),
|
|
25804
|
+
authorized: z18.boolean(),
|
|
25805
|
+
consented: z18.boolean(),
|
|
25806
|
+
policy: z18.string().max(100),
|
|
25807
|
+
provider: z18.string().max(1e3).nullable()
|
|
25202
25808
|
});
|
|
25203
25809
|
|
|
25204
25810
|
// lib/memory/src/writing-jobs.ts
|
|
@@ -25275,7 +25881,7 @@ async function cancelRows(trx, rows, status = "cancelled") {
|
|
|
25275
25881
|
await settleNamedAction(
|
|
25276
25882
|
trx,
|
|
25277
25883
|
row.accountId,
|
|
25278
|
-
"
|
|
25884
|
+
"writing",
|
|
25279
25885
|
operation(row.id),
|
|
25280
25886
|
row.providerStartedAt ? "completed" : "released"
|
|
25281
25887
|
);
|
|
@@ -25429,11 +26035,12 @@ var WritingTools = class {
|
|
|
25429
26035
|
epoch: control.epoch
|
|
25430
26036
|
};
|
|
25431
26037
|
const inputCiphertext = crypt(this.key, row, "input").seal(input);
|
|
26038
|
+
await assertWritingDailyLimit(this.service.db, trx, principal.accountId);
|
|
25432
26039
|
await reserveAction(
|
|
25433
26040
|
this.service.db,
|
|
25434
26041
|
trx,
|
|
25435
26042
|
principal.accountId,
|
|
25436
|
-
"
|
|
26043
|
+
"writing",
|
|
25437
26044
|
operation(input.id)
|
|
25438
26045
|
);
|
|
25439
26046
|
const [saved] = await trx("writing_requests").insert({ ...row, inputCiphertext }).returning("*");
|
|
@@ -25647,18 +26254,19 @@ function cleanupHandlers(db, deleteIdentity, cancelBilling) {
|
|
|
25647
26254
|
|
|
25648
26255
|
// lib/memory/src/files.ts
|
|
25649
26256
|
init_define_GROVE_TELEMETRY();
|
|
26257
|
+
init_contracts();
|
|
25650
26258
|
import { createHash as createHash15, createHmac as createHmac3, timingSafeEqual as timingSafeEqual2 } from "node:crypto";
|
|
25651
26259
|
|
|
25652
26260
|
// lib/shared/src/files.ts
|
|
25653
26261
|
init_define_GROVE_TELEMETRY();
|
|
25654
|
-
import { z as
|
|
25655
|
-
var fileSourceSchema =
|
|
25656
|
-
var fileCursorSchema =
|
|
25657
|
-
var fileSearchSchema =
|
|
25658
|
-
query:
|
|
25659
|
-
kind:
|
|
25660
|
-
sort:
|
|
25661
|
-
view:
|
|
26262
|
+
import { z as z19 } from "zod";
|
|
26263
|
+
var fileSourceSchema = z19.enum(["chat", "import", "media"]);
|
|
26264
|
+
var fileCursorSchema = z19.object({ owner: z19.uuid(), binding: z19.string(), key: z19.string().max(512) }).strict();
|
|
26265
|
+
var fileSearchSchema = z19.object({
|
|
26266
|
+
query: z19.string().trim().max(200).default(""),
|
|
26267
|
+
kind: z19.enum(["document", "image", "recording"]).optional(),
|
|
26268
|
+
sort: z19.enum(["newest", "name", "size"]).default("newest"),
|
|
26269
|
+
view: z19.enum([
|
|
25662
26270
|
"all",
|
|
25663
26271
|
"temporary",
|
|
25664
26272
|
"attention",
|
|
@@ -25666,20 +26274,20 @@ var fileSearchSchema = z18.object({
|
|
|
25666
26274
|
"unfiled",
|
|
25667
26275
|
"history"
|
|
25668
26276
|
]).default("all"),
|
|
25669
|
-
memoryId:
|
|
25670
|
-
projectId:
|
|
25671
|
-
conversationId:
|
|
25672
|
-
after:
|
|
26277
|
+
memoryId: z19.uuid().optional(),
|
|
26278
|
+
projectId: z19.uuid().optional(),
|
|
26279
|
+
conversationId: z19.uuid().optional(),
|
|
26280
|
+
after: z19.string().max(2048).optional()
|
|
25673
26281
|
}).strict();
|
|
25674
|
-
var fileLocationsSchema =
|
|
26282
|
+
var fileLocationsSchema = z19.object({
|
|
25675
26283
|
source: fileSourceSchema,
|
|
25676
|
-
id:
|
|
25677
|
-
after:
|
|
26284
|
+
id: z19.uuid(),
|
|
26285
|
+
after: z19.string().max(2048).optional()
|
|
25678
26286
|
}).strict();
|
|
25679
|
-
var filePositionSchema =
|
|
25680
|
-
value:
|
|
26287
|
+
var filePositionSchema = z19.object({
|
|
26288
|
+
value: z19.string().max(200),
|
|
25681
26289
|
source: fileSourceSchema,
|
|
25682
|
-
id:
|
|
26290
|
+
id: z19.uuid()
|
|
25683
26291
|
}).strict();
|
|
25684
26292
|
|
|
25685
26293
|
// lib/memory/src/files.ts
|
|
@@ -25907,6 +26515,7 @@ var Files = class {
|
|
|
25907
26515
|
// lib/memory/src/speech.ts
|
|
25908
26516
|
init_define_GROVE_TELEMETRY();
|
|
25909
26517
|
import { createHash as createHash16, randomUUID as randomUUID10 } from "node:crypto";
|
|
26518
|
+
init_contracts();
|
|
25910
26519
|
var kinds = ["speech_transcribe", "speech_synthesize"];
|
|
25911
26520
|
var keys = (kind) => kind === "speech_transcribe" ? {
|
|
25912
26521
|
preference: "transcriptionEnabled",
|
|
@@ -26199,14 +26808,17 @@ init_define_GROVE_TELEMETRY();
|
|
|
26199
26808
|
|
|
26200
26809
|
// lib/memory/src/imports.ts
|
|
26201
26810
|
init_define_GROVE_TELEMETRY();
|
|
26811
|
+
init_contracts();
|
|
26202
26812
|
|
|
26203
26813
|
// lib/shared/src/jobs.ts
|
|
26204
26814
|
init_define_GROVE_TELEMETRY();
|
|
26205
|
-
import { z as
|
|
26815
|
+
import { z as z21 } from "zod";
|
|
26206
26816
|
|
|
26207
26817
|
// lib/shared/src/web-capture.ts
|
|
26208
26818
|
init_define_GROVE_TELEMETRY();
|
|
26209
|
-
|
|
26819
|
+
init_contracts();
|
|
26820
|
+
init_limits();
|
|
26821
|
+
import { z as z20 } from "zod";
|
|
26210
26822
|
var trackingParameters = /* @__PURE__ */ new Set([
|
|
26211
26823
|
"utm_source",
|
|
26212
26824
|
"utm_medium",
|
|
@@ -26226,7 +26838,7 @@ function containsControlCharacters(value) {
|
|
|
26226
26838
|
});
|
|
26227
26839
|
}
|
|
26228
26840
|
function normalizeWebUrl(input) {
|
|
26229
|
-
if (typeof input !== "string" || input.length >
|
|
26841
|
+
if (typeof input !== "string" || input.length > WEB_URL_MAX || !/^https?:\/\//i.test(input) || /\s/u.test(input) || containsControlCharacters(input))
|
|
26230
26842
|
throw new Error("Invalid source URL");
|
|
26231
26843
|
let url;
|
|
26232
26844
|
try {
|
|
@@ -26243,58 +26855,69 @@ function normalizeWebUrl(input) {
|
|
|
26243
26855
|
});
|
|
26244
26856
|
if (retained.length !== parts.length) url.search = retained.join("&");
|
|
26245
26857
|
const normalized = url.href;
|
|
26246
|
-
if (normalized.length >
|
|
26858
|
+
if (normalized.length > WEB_URL_MAX)
|
|
26859
|
+
throw new Error("Invalid source URL: too long");
|
|
26247
26860
|
return normalized;
|
|
26248
26861
|
}
|
|
26249
|
-
var webCaptureSchema =
|
|
26250
|
-
url:
|
|
26862
|
+
var webCaptureSchema = z20.object({
|
|
26863
|
+
url: z20.string().max(WEB_URL_MAX).transform((value, ctx) => {
|
|
26251
26864
|
try {
|
|
26252
26865
|
return normalizeWebUrl(value);
|
|
26253
26866
|
} catch {
|
|
26254
26867
|
ctx.addIssue({ code: "custom", message: "Invalid source URL" });
|
|
26255
|
-
return
|
|
26868
|
+
return z20.NEVER;
|
|
26256
26869
|
}
|
|
26257
26870
|
}),
|
|
26258
|
-
title:
|
|
26871
|
+
title: z20.string().max(300).refine((value) => !containsControlCharacters(value), {
|
|
26259
26872
|
message: "Source title must be a single line"
|
|
26260
26873
|
}),
|
|
26261
|
-
capturedAt:
|
|
26874
|
+
capturedAt: z20.iso.datetime()
|
|
26262
26875
|
}).strict();
|
|
26263
|
-
var browserCaptureRequestSchema =
|
|
26264
|
-
operationId:
|
|
26876
|
+
var browserCaptureRequestSchema = z20.object({
|
|
26877
|
+
operationId: z20.uuid(),
|
|
26878
|
+
id: z20.uuid().optional(),
|
|
26879
|
+
expectedVersion: z20.number().int().positive().optional(),
|
|
26880
|
+
editSession: z20.uuid().optional(),
|
|
26265
26881
|
content: rememberSchema.shape.content,
|
|
26266
|
-
projectId:
|
|
26267
|
-
capture:
|
|
26882
|
+
projectId: z20.uuid().nullable(),
|
|
26883
|
+
capture: z20.literal("explicit"),
|
|
26268
26884
|
provenance: webCaptureSchema.optional()
|
|
26269
|
-
}).strict()
|
|
26270
|
-
|
|
26885
|
+
}).strict().refine(
|
|
26886
|
+
(input) => Boolean(input.id) === Boolean(input.expectedVersion),
|
|
26887
|
+
"Updates require both id and expectedVersion"
|
|
26888
|
+
);
|
|
26889
|
+
var browserPageRequestSchema = z20.object({
|
|
26271
26890
|
url: webCaptureSchema.shape.url,
|
|
26272
|
-
projectId:
|
|
26273
|
-
cursor:
|
|
26891
|
+
projectId: z20.uuid().nullable(),
|
|
26892
|
+
cursor: z20.string().max(2048).optional()
|
|
26274
26893
|
}).strict();
|
|
26275
26894
|
|
|
26276
26895
|
// lib/shared/src/jobs.ts
|
|
26277
|
-
var exportRequestSchema =
|
|
26278
|
-
id:
|
|
26279
|
-
projectId:
|
|
26280
|
-
includeDescendants:
|
|
26281
|
-
includeMedia:
|
|
26896
|
+
var exportRequestSchema = z21.object({
|
|
26897
|
+
id: z21.uuid(),
|
|
26898
|
+
projectId: z21.uuid().optional(),
|
|
26899
|
+
includeDescendants: z21.boolean().default(false),
|
|
26900
|
+
includeMedia: z21.boolean().optional()
|
|
26282
26901
|
}).strict();
|
|
26283
|
-
var importRecordSchema =
|
|
26284
|
-
sourceId:
|
|
26285
|
-
content:
|
|
26286
|
-
projectId:
|
|
26902
|
+
var importRecordSchema = z21.object({
|
|
26903
|
+
sourceId: z21.string().min(1).max(200),
|
|
26904
|
+
content: z21.string().min(1).max(6e3),
|
|
26905
|
+
projectId: z21.uuid().nullable().default(null),
|
|
26287
26906
|
webCapture: webCaptureSchema.optional()
|
|
26288
26907
|
}).strict();
|
|
26289
|
-
var importRequestSchema =
|
|
26290
|
-
id:
|
|
26291
|
-
source:
|
|
26292
|
-
records:
|
|
26908
|
+
var importRequestSchema = z21.object({
|
|
26909
|
+
id: z21.uuid(),
|
|
26910
|
+
source: z21.string().regex(/^[a-zA-Z0-9._-]{1,100}$/),
|
|
26911
|
+
records: z21.array(importRecordSchema).min(1).max(100)
|
|
26293
26912
|
}).strict();
|
|
26294
26913
|
|
|
26914
|
+
// lib/memory/src/index.ts
|
|
26915
|
+
init_contracts();
|
|
26916
|
+
|
|
26295
26917
|
// lib/memory/src/connect.ts
|
|
26296
26918
|
init_define_GROVE_TELEMETRY();
|
|
26297
26919
|
import { randomUUID as randomUUID11 } from "node:crypto";
|
|
26920
|
+
init_contracts();
|
|
26298
26921
|
var unavailable5 = () => new GroveError(
|
|
26299
26922
|
"connection_unavailable",
|
|
26300
26923
|
"This connection link is unavailable. Run grove connect again, using the same Grove account in your browser.",
|
|
@@ -26470,6 +27093,8 @@ var ConnectionSetup = class {
|
|
|
26470
27093
|
|
|
26471
27094
|
// lib/memory/src/sharing.ts
|
|
26472
27095
|
init_define_GROVE_TELEMETRY();
|
|
27096
|
+
init_contracts();
|
|
27097
|
+
init_sharing();
|
|
26473
27098
|
import {
|
|
26474
27099
|
createCipheriv as createCipheriv2,
|
|
26475
27100
|
createDecipheriv as createDecipheriv2,
|
|
@@ -26479,77 +27104,6 @@ import {
|
|
|
26479
27104
|
randomUUID as randomUUID12,
|
|
26480
27105
|
timingSafeEqual as timingSafeEqual3
|
|
26481
27106
|
} from "node:crypto";
|
|
26482
|
-
|
|
26483
|
-
// lib/shared/src/sharing.ts
|
|
26484
|
-
init_define_GROVE_TELEMETRY();
|
|
26485
|
-
import { z as z21 } from "zod";
|
|
26486
|
-
|
|
26487
|
-
// lib/shared/src/share-durations.ts
|
|
26488
|
-
init_define_GROVE_TELEMETRY();
|
|
26489
|
-
var shareDurations = {
|
|
26490
|
-
"1h": { label: "1 hour", seconds: 3600 },
|
|
26491
|
-
"4h": { label: "4 hours", seconds: 14400 },
|
|
26492
|
-
"1d": { label: "1 day", seconds: 86400 },
|
|
26493
|
-
"1w": { label: "1 week", seconds: 604800 },
|
|
26494
|
-
"2w": { label: "2 weeks", seconds: 1209600 },
|
|
26495
|
-
"1mo": { label: "1 month", seconds: 2592e3 }
|
|
26496
|
-
};
|
|
26497
|
-
|
|
26498
|
-
// lib/shared/src/sharing.ts
|
|
26499
|
-
var shareTokenSchema = z21.string().regex(/^gsh_[A-Za-z0-9_-]{43}$/);
|
|
26500
|
-
var shareDurationSchema = z21.enum([
|
|
26501
|
-
"1h",
|
|
26502
|
-
"4h",
|
|
26503
|
-
"1d",
|
|
26504
|
-
"1w",
|
|
26505
|
-
"2w",
|
|
26506
|
-
"1mo"
|
|
26507
|
-
]);
|
|
26508
|
-
var shareMutationSchema = z21.object({
|
|
26509
|
-
operationId: operationSchema,
|
|
26510
|
-
expectedVersion: z21.number().int().positive()
|
|
26511
|
-
}).strict();
|
|
26512
|
-
var shareEnableSchema = shareMutationSchema.extend({
|
|
26513
|
-
expectedVersion: z21.number().int().min(0),
|
|
26514
|
-
expectedTargetVersion: z21.number().int().positive(),
|
|
26515
|
-
includeDescendants: z21.boolean().default(false),
|
|
26516
|
-
duration: shareDurationSchema.nullable().optional()
|
|
26517
|
-
});
|
|
26518
|
-
var shareScopeSchema = shareMutationSchema.extend({
|
|
26519
|
-
includeDescendants: z21.boolean().optional(),
|
|
26520
|
-
duration: shareDurationSchema.nullable().optional()
|
|
26521
|
-
}).refine(
|
|
26522
|
-
(value) => value.includeDescendants !== void 0 || value.duration !== void 0,
|
|
26523
|
-
"Choose a sharing setting to change"
|
|
26524
|
-
);
|
|
26525
|
-
var publicShareQuerySchema = z21.object({
|
|
26526
|
-
cursor: z21.string().max(2048).optional(),
|
|
26527
|
-
limit: z21.coerce.number().int().min(1).max(100).default(30)
|
|
26528
|
-
}).strict();
|
|
26529
|
-
var notebook = z21.object({ id: uuidSchema, name: z21.string() }).strict();
|
|
26530
|
-
var publicNoteSchema = z21.object({
|
|
26531
|
-
id: uuidSchema,
|
|
26532
|
-
title: z21.string(),
|
|
26533
|
-
content: z21.string(),
|
|
26534
|
-
updatedAt: z21.string(),
|
|
26535
|
-
linkedNoteIds: z21.array(uuidSchema)
|
|
26536
|
-
}).strict();
|
|
26537
|
-
var publicShareSchema = z21.object({
|
|
26538
|
-
kind: z21.enum(["note", "notebook"]),
|
|
26539
|
-
root: notebook,
|
|
26540
|
-
notebook: notebook.nullable(),
|
|
26541
|
-
note: publicNoteSchema.nullable(),
|
|
26542
|
-
notebooks: z21.array(notebook),
|
|
26543
|
-
notes: z21.array(
|
|
26544
|
-
publicNoteSchema.pick({ id: true, title: true, updatedAt: true })
|
|
26545
|
-
),
|
|
26546
|
-
nextCursor: z21.string().nullable()
|
|
26547
|
-
}).strict();
|
|
26548
|
-
function sharedNoteTitle(content3) {
|
|
26549
|
-
return content3.trim().split("\n")[0].replace(/^#{1,6}\s+/, "").slice(0, 110) || "Untitled note";
|
|
26550
|
-
}
|
|
26551
|
-
|
|
26552
|
-
// lib/memory/src/sharing.ts
|
|
26553
27107
|
var hash3 = (value) => createHash17("sha256").update(value).digest("hex");
|
|
26554
27108
|
var missing7 = () => new GroveError("not_found", "This shared content is unavailable", 404);
|
|
26555
27109
|
var conflict3 = () => new GroveError(
|
|
@@ -26921,213 +27475,26 @@ var Sharing = class {
|
|
|
26921
27475
|
}
|
|
26922
27476
|
};
|
|
26923
27477
|
|
|
26924
|
-
// lib/memory/src/
|
|
26925
|
-
|
|
26926
|
-
import { createHash as createHash18, randomUUID as randomUUID13 } from "node:crypto";
|
|
26927
|
-
var missing8 = () => new GroveError("not_found", "Media is unavailable", 404);
|
|
26928
|
-
var conflict4 = () => new GroveError(
|
|
26929
|
-
"media_changed",
|
|
26930
|
-
"The note or upload changed. Reload and retry.",
|
|
26931
|
-
409
|
|
26932
|
-
);
|
|
26933
|
-
var mediaDescriptor = (row) => ({
|
|
26934
|
-
id: row.id,
|
|
26935
|
-
reference: mediaReference(row.id),
|
|
26936
|
-
mime: row.mime,
|
|
26937
|
-
bytes: row.bytes,
|
|
26938
|
-
width: row.width,
|
|
26939
|
-
height: row.height,
|
|
26940
|
-
durationMs: row.durationMs ?? null
|
|
26941
|
-
});
|
|
26942
|
-
var MediaAttachments = class {
|
|
26943
|
-
constructor(service) {
|
|
26944
|
-
this.service = service;
|
|
26945
|
-
}
|
|
26946
|
-
service;
|
|
26947
|
-
async note(trx, id2, grant) {
|
|
26948
|
-
const note = await trx("memories").where({ id: id2 }).where(
|
|
26949
|
-
(q) => q.whereNull("expiresAt").orWhere("expiresAt", ">", trx.fn.now())
|
|
26950
|
-
).first();
|
|
26951
|
-
if (!note || grant && (note.projectId === null ? !grant.personal : !(grant.allProjects || grant.projectIds.includes(note.projectId))))
|
|
26952
|
-
throw missing8();
|
|
26953
|
-
return note;
|
|
26954
|
-
}
|
|
26955
|
-
async claim(principal, input) {
|
|
26956
|
-
return this.service.access(principal, "admin", async ({ trx, account }) => {
|
|
26957
|
-
const note = await this.note(trx, input.memoryId);
|
|
26958
|
-
if (note.status !== "active") throw missing8();
|
|
26959
|
-
const existing = await trx("media_objects").where({ id: input.id }).first();
|
|
26960
|
-
if (existing && (existing.memoryId !== input.memoryId || existing.mime !== input.mime || existing.bytes !== input.bytes || existing.sha256 !== input.sha256))
|
|
26961
|
-
throw conflict4();
|
|
26962
|
-
if (existing?.status === "ready") return { row: existing, replay: true };
|
|
26963
|
-
if (note.version !== input.version) throw conflict4();
|
|
26964
|
-
if (existing?.status === "pending" && new Date(existing.leaseUntil) > /* @__PURE__ */ new Date())
|
|
26965
|
-
throw conflict4();
|
|
26966
|
-
const quota = await trx("accounts").where({ id: account.id }).first("mediaBytes", "mediaAttempts");
|
|
26967
|
-
if (Number(quota.mediaBytes) + input.bytes > 1024 * 1024 * 1024 || quota.mediaAttempts >= 1e3)
|
|
26968
|
-
throw new GroveError("media_quota", "Media storage limit reached", 429);
|
|
26969
|
-
const leaseId = randomUUID13(), objectKey = mediaObjectKey(account.id, input.id, leaseId);
|
|
26970
|
-
const values = {
|
|
26971
|
-
memoryId: input.memoryId,
|
|
26972
|
-
bytes: input.bytes,
|
|
26973
|
-
mime: input.mime,
|
|
26974
|
-
sha256: input.sha256,
|
|
26975
|
-
status: "pending",
|
|
26976
|
-
leaseId,
|
|
26977
|
-
objectKey,
|
|
26978
|
-
leaseUntil: trx.raw("clock_timestamp()+interval '120 seconds'")
|
|
26979
|
-
};
|
|
26980
|
-
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("*");
|
|
26981
|
-
await trx("media_upload_attempts").insert({
|
|
26982
|
-
accountId: account.id,
|
|
26983
|
-
mediaId: input.id,
|
|
26984
|
-
id: leaseId,
|
|
26985
|
-
objectKey
|
|
26986
|
-
});
|
|
26987
|
-
await trx("accounts").where({ id: account.id }).increment({ mediaBytes: input.bytes, mediaAttempts: 1 });
|
|
26988
|
-
return { row, replay: false };
|
|
26989
|
-
});
|
|
26990
|
-
}
|
|
26991
|
-
async finish(principal, input, leaseId, dimensions) {
|
|
26992
|
-
return this.service.access(principal, "admin", async ({ trx }) => {
|
|
26993
|
-
const note = await this.note(trx, input.memoryId);
|
|
26994
|
-
if (note.status !== "active" || note.version !== input.version)
|
|
26995
|
-
throw conflict4();
|
|
26996
|
-
const [row] = await trx("media_objects").where({
|
|
26997
|
-
id: input.id,
|
|
26998
|
-
memoryId: input.memoryId,
|
|
26999
|
-
leaseId,
|
|
27000
|
-
status: "pending"
|
|
27001
|
-
}).where("leaseUntil", ">", trx.raw("clock_timestamp()")).update({
|
|
27002
|
-
width: dimensions.width,
|
|
27003
|
-
height: dimensions.height,
|
|
27004
|
-
durationMs: dimensions.durationMs ?? null,
|
|
27005
|
-
status: "ready"
|
|
27006
|
-
}).returning("*");
|
|
27007
|
-
if (!row) throw conflict4();
|
|
27008
|
-
await trx("accounts").where({ id: principal.accountId }).increment("exportVersion", 1);
|
|
27009
|
-
return mediaDescriptor(row);
|
|
27010
|
-
});
|
|
27011
|
-
}
|
|
27012
|
-
async fail(principal, id2, leaseId) {
|
|
27013
|
-
return this.service.access(principal, "admin", async ({ trx }) => {
|
|
27014
|
-
await trx("media_objects").where({ id: id2, leaseId, status: "pending" }).update({ status: "failed" });
|
|
27015
|
-
});
|
|
27016
|
-
}
|
|
27017
|
-
async read(principal, memoryId, id2, version2) {
|
|
27018
|
-
return this.service.access(
|
|
27019
|
-
principal,
|
|
27020
|
-
"memory:read",
|
|
27021
|
-
async ({ trx, grant }) => {
|
|
27022
|
-
const note = await this.note(trx, memoryId, grant);
|
|
27023
|
-
const row = await trx("media_objects as o").join("media_revision_bindings as b", function() {
|
|
27024
|
-
this.on("b.accountId", "=", "o.accountId").andOn(
|
|
27025
|
-
"b.mediaId",
|
|
27026
|
-
"=",
|
|
27027
|
-
"o.id"
|
|
27028
|
-
);
|
|
27029
|
-
}).where({
|
|
27030
|
-
"o.id": id2,
|
|
27031
|
-
"o.memoryId": memoryId,
|
|
27032
|
-
"o.status": "ready",
|
|
27033
|
-
"b.memoryId": memoryId,
|
|
27034
|
-
"b.version": version2 ?? note.version
|
|
27035
|
-
}).select("o.*").first();
|
|
27036
|
-
if (!row) throw missing8();
|
|
27037
|
-
return {
|
|
27038
|
-
key: row.objectKey,
|
|
27039
|
-
mime: row.mime,
|
|
27040
|
-
bytes: row.bytes,
|
|
27041
|
-
sha256: row.sha256
|
|
27042
|
-
};
|
|
27043
|
-
}
|
|
27044
|
-
);
|
|
27045
|
-
}
|
|
27046
|
-
async publicRead(token, memoryId, id2) {
|
|
27047
|
-
if (!shareTokenSchema.safeParse(token).success) throw missing8();
|
|
27048
|
-
const admitted = await this.service.db.raw(
|
|
27049
|
-
"SELECT grove_share_admit('global') AS allowed"
|
|
27050
|
-
);
|
|
27051
|
-
if (!admitted.rows[0].allowed)
|
|
27052
|
-
throw new GroveError("rate_limited", "Retry later", 429);
|
|
27053
|
-
const { rows } = await this.service.db.raw(
|
|
27054
|
-
"SELECT grove_public_media(?,?::uuid,?::uuid) AS value",
|
|
27055
|
-
[createHash18("sha256").update(token).digest("hex"), memoryId, id2]
|
|
27056
|
-
);
|
|
27057
|
-
const value = rows[0].value;
|
|
27058
|
-
if (value?.limited)
|
|
27059
|
-
throw new GroveError("rate_limited", "Retry later", 429);
|
|
27060
|
-
if (!value) throw missing8();
|
|
27061
|
-
return value;
|
|
27062
|
-
}
|
|
27063
|
-
async transcript(principal, memoryId, id2) {
|
|
27064
|
-
const object = await this.read(principal, memoryId, id2);
|
|
27065
|
-
if (object.mime !== "audio/wav") throw missing8();
|
|
27066
|
-
return this.service.access(
|
|
27067
|
-
principal,
|
|
27068
|
-
"memory:read",
|
|
27069
|
-
async ({ trx, grant }) => {
|
|
27070
|
-
await this.note(trx, memoryId, grant);
|
|
27071
|
-
const row = await trx("media_transcripts").where({ mediaId: id2 }).select("text", "version").first();
|
|
27072
|
-
return row ?? { text: "", version: 0 };
|
|
27073
|
-
}
|
|
27074
|
-
);
|
|
27075
|
-
}
|
|
27076
|
-
async saveTranscript(principal, memoryId, id2, input) {
|
|
27077
|
-
return this.service.access(principal, "admin", async ({ trx, account }) => {
|
|
27078
|
-
const note = await this.note(trx, memoryId);
|
|
27079
|
-
const object = await trx("media_objects").where({ id: id2, memoryId, mime: "audio/wav", status: "ready" }).first();
|
|
27080
|
-
if (!object || !await trx("media_revision_bindings").where({ mediaId: id2, memoryId, version: note.version }).first())
|
|
27081
|
-
throw missing8();
|
|
27082
|
-
const old = await trx("media_transcripts").where({ mediaId: id2 }).first(), fingerprint2 = createHash18("sha256").update(JSON.stringify(input)).digest("hex");
|
|
27083
|
-
if (old?.operationId === input.operationId) {
|
|
27084
|
-
if (old.fingerprint !== fingerprint2) throw conflict4();
|
|
27085
|
-
return { text: old.text, version: old.version };
|
|
27086
|
-
}
|
|
27087
|
-
if ((old?.version ?? 0) !== input.expectedVersion) throw conflict4();
|
|
27088
|
-
const version2 = input.expectedVersion + 1;
|
|
27089
|
-
await trx("media_transcripts").insert({
|
|
27090
|
-
accountId: account.id,
|
|
27091
|
-
mediaId: id2,
|
|
27092
|
-
text: input.text,
|
|
27093
|
-
version: version2,
|
|
27094
|
-
operationId: input.operationId,
|
|
27095
|
-
fingerprint: fingerprint2
|
|
27096
|
-
}).onConflict(["accountId", "mediaId"]).merge({
|
|
27097
|
-
text: input.text,
|
|
27098
|
-
version: version2,
|
|
27099
|
-
operationId: input.operationId,
|
|
27100
|
-
fingerprint: fingerprint2,
|
|
27101
|
-
updatedAt: trx.fn.now()
|
|
27102
|
-
});
|
|
27103
|
-
await trx("media_transcript_revisions").insert({
|
|
27104
|
-
accountId: account.id,
|
|
27105
|
-
mediaId: id2,
|
|
27106
|
-
version: version2,
|
|
27107
|
-
text: input.text
|
|
27108
|
-
});
|
|
27109
|
-
await trx("accounts").where({ id: account.id }).increment("exportVersion", 1);
|
|
27110
|
-
return { text: input.text, version: version2 };
|
|
27111
|
-
});
|
|
27112
|
-
}
|
|
27113
|
-
};
|
|
27478
|
+
// lib/memory/src/index.ts
|
|
27479
|
+
init_media2();
|
|
27114
27480
|
|
|
27115
27481
|
// lib/memory/src/conversation-history.ts
|
|
27116
27482
|
init_define_GROVE_TELEMETRY();
|
|
27483
|
+
init_contracts();
|
|
27117
27484
|
import { createHash as createHash19, createHmac as createHmac5, timingSafeEqual as timingSafeEqual4 } from "node:crypto";
|
|
27118
27485
|
|
|
27119
27486
|
// lib/shared/src/conversation-history.ts
|
|
27120
27487
|
init_define_GROVE_TELEMETRY();
|
|
27121
|
-
import { z as
|
|
27122
|
-
var conversationHistorySchema =
|
|
27123
|
-
query:
|
|
27124
|
-
after:
|
|
27488
|
+
import { z as z23 } from "zod";
|
|
27489
|
+
var conversationHistorySchema = z23.object({
|
|
27490
|
+
query: z23.string().trim().max(200).default(""),
|
|
27491
|
+
after: z23.string().max(2048).optional()
|
|
27125
27492
|
}).strict();
|
|
27126
|
-
var conversationHistoryCursorSchema =
|
|
27127
|
-
owner:
|
|
27128
|
-
query:
|
|
27129
|
-
id:
|
|
27130
|
-
at:
|
|
27493
|
+
var conversationHistoryCursorSchema = z23.object({
|
|
27494
|
+
owner: z23.uuid(),
|
|
27495
|
+
query: z23.string(),
|
|
27496
|
+
id: z23.uuid(),
|
|
27497
|
+
at: z23.iso.datetime()
|
|
27131
27498
|
});
|
|
27132
27499
|
|
|
27133
27500
|
// lib/memory/src/conversation-history.ts
|
|
@@ -27205,14 +27572,16 @@ async function searchConversationHistory(service, principal, input) {
|
|
|
27205
27572
|
|
|
27206
27573
|
// lib/memory/src/tools.ts
|
|
27207
27574
|
init_define_GROVE_TELEMETRY();
|
|
27575
|
+
init_contracts();
|
|
27208
27576
|
|
|
27209
27577
|
// lib/shared/src/notebook-lifecycle.ts
|
|
27210
27578
|
init_define_GROVE_TELEMETRY();
|
|
27211
|
-
|
|
27212
|
-
|
|
27579
|
+
init_contracts();
|
|
27580
|
+
import { z as z24 } from "zod";
|
|
27581
|
+
var notebookLifecycleSchema = z24.object({
|
|
27213
27582
|
operationId: operationSchema,
|
|
27214
|
-
expectedVersion:
|
|
27215
|
-
fingerprint:
|
|
27583
|
+
expectedVersion: z24.number().int().positive(),
|
|
27584
|
+
fingerprint: z24.string().regex(/^[a-f0-9]{64}$/)
|
|
27216
27585
|
}).strict();
|
|
27217
27586
|
|
|
27218
27587
|
// lib/memory/src/tools.ts
|
|
@@ -27297,6 +27666,23 @@ async function executeMemoryTool(service, principal, tool, value, signal) {
|
|
|
27297
27666
|
notebookLifecycleSchema.parse(input)
|
|
27298
27667
|
);
|
|
27299
27668
|
}
|
|
27669
|
+
case "list_note_media": {
|
|
27670
|
+
const input = memoryTools.list_note_media.schema.parse(value);
|
|
27671
|
+
return service.listNoteMedia(principal, input.memoryId, input.version);
|
|
27672
|
+
}
|
|
27673
|
+
case "describe_note_media": {
|
|
27674
|
+
const input = memoryTools.describe_note_media.schema.parse(value);
|
|
27675
|
+
return service.describeNoteMedia(
|
|
27676
|
+
principal,
|
|
27677
|
+
input.memoryId,
|
|
27678
|
+
input.mediaId,
|
|
27679
|
+
input.version
|
|
27680
|
+
);
|
|
27681
|
+
}
|
|
27682
|
+
case "read_media_transcript": {
|
|
27683
|
+
const input = memoryTools.read_media_transcript.schema.parse(value);
|
|
27684
|
+
return service.readMediaTranscript(principal, input.memoryId, input.mediaId);
|
|
27685
|
+
}
|
|
27300
27686
|
default:
|
|
27301
27687
|
throw new GroveError("not_found", "Unknown Grove tool", 404);
|
|
27302
27688
|
}
|
|
@@ -27304,39 +27690,47 @@ async function executeMemoryTool(service, principal, tool, value, signal) {
|
|
|
27304
27690
|
|
|
27305
27691
|
// lib/memory/src/system-admin.ts
|
|
27306
27692
|
init_define_GROVE_TELEMETRY();
|
|
27693
|
+
init_contracts();
|
|
27307
27694
|
|
|
27308
27695
|
// lib/shared/src/system-admin.ts
|
|
27309
27696
|
init_define_GROVE_TELEMETRY();
|
|
27310
|
-
|
|
27311
|
-
|
|
27697
|
+
init_contracts();
|
|
27698
|
+
import { z as z25 } from "zod";
|
|
27699
|
+
var adminChangeSchema = z25.object({
|
|
27312
27700
|
accountId: uuidSchema,
|
|
27313
27701
|
operationId: uuidSchema,
|
|
27314
|
-
expectedVersion:
|
|
27315
|
-
role:
|
|
27316
|
-
access:
|
|
27317
|
-
reason:
|
|
27702
|
+
expectedVersion: z25.number().int().min(0),
|
|
27703
|
+
role: z25.enum(["user", "system_admin"]),
|
|
27704
|
+
access: z25.enum(["default", "pro", "unlimited"]),
|
|
27705
|
+
reason: z25.string().trim().min(3).max(300)
|
|
27318
27706
|
}).strict();
|
|
27319
|
-
var adminSettingsSchema =
|
|
27320
|
-
captureEnabled:
|
|
27321
|
-
recallEnabled:
|
|
27322
|
-
suspended:
|
|
27323
|
-
supportNote:
|
|
27707
|
+
var adminSettingsSchema = z25.object({
|
|
27708
|
+
captureEnabled: z25.boolean(),
|
|
27709
|
+
recallEnabled: z25.boolean(),
|
|
27710
|
+
suspended: z25.boolean(),
|
|
27711
|
+
supportNote: z25.string().max(500)
|
|
27324
27712
|
}).strict();
|
|
27325
|
-
var adminSupportSchema =
|
|
27713
|
+
var adminSupportSchema = z25.object({
|
|
27326
27714
|
accountId: uuidSchema,
|
|
27327
27715
|
operationId: uuidSchema,
|
|
27328
|
-
expectedVersion:
|
|
27716
|
+
expectedVersion: z25.number().int().min(0),
|
|
27329
27717
|
expectedSettings: adminSettingsSchema,
|
|
27330
27718
|
settings: adminSettingsSchema,
|
|
27331
|
-
reason:
|
|
27719
|
+
reason: z25.string().trim().min(3).max(300)
|
|
27332
27720
|
}).strict();
|
|
27333
|
-
var
|
|
27334
|
-
|
|
27721
|
+
var adminTrialResetSchema = z25.object({
|
|
27722
|
+
accountId: uuidSchema,
|
|
27723
|
+
operationId: uuidSchema,
|
|
27724
|
+
reason: z25.string().trim().min(3).max(300)
|
|
27725
|
+
}).strict();
|
|
27726
|
+
var adminDetailsSchema = z25.object({ accountId: uuidSchema }).strict();
|
|
27727
|
+
var adminBrowseSchema = z25.object({ after: uuidSchema.optional() }).strict();
|
|
27335
27728
|
var usageReportFeatures = [
|
|
27336
27729
|
"recall",
|
|
27337
27730
|
"ask",
|
|
27338
27731
|
"organization",
|
|
27339
27732
|
"assistance",
|
|
27733
|
+
"writing",
|
|
27340
27734
|
"embedding",
|
|
27341
27735
|
"decision",
|
|
27342
27736
|
"generation",
|
|
@@ -27358,9 +27752,9 @@ var emptyUsageReportMetrics = () => Object.fromEntries(
|
|
|
27358
27752
|
}
|
|
27359
27753
|
])
|
|
27360
27754
|
);
|
|
27361
|
-
var adminUsageReportSchema =
|
|
27362
|
-
from:
|
|
27363
|
-
to:
|
|
27755
|
+
var adminUsageReportSchema = z25.object({
|
|
27756
|
+
from: z25.iso.date().optional(),
|
|
27757
|
+
to: z25.iso.date().optional(),
|
|
27364
27758
|
after: uuidSchema.optional()
|
|
27365
27759
|
}).strict().superRefine((input, ctx) => {
|
|
27366
27760
|
if (!!input.from !== !!input.to || input.from && input.to && (input.from > input.to || Date.parse(input.to) - Date.parse(input.from) > 365 * 864e5))
|
|
@@ -27422,6 +27816,12 @@ var SystemAdministration = class {
|
|
|
27422
27816
|
"Keep at least one active system administrator",
|
|
27423
27817
|
409
|
|
27424
27818
|
);
|
|
27819
|
+
if (code2 === "GA007")
|
|
27820
|
+
throw new GroveError(
|
|
27821
|
+
"trial_not_consumed",
|
|
27822
|
+
"This account never used a trial",
|
|
27823
|
+
404
|
|
27824
|
+
);
|
|
27425
27825
|
throw error3;
|
|
27426
27826
|
});
|
|
27427
27827
|
}
|
|
@@ -27519,6 +27919,33 @@ var SystemAdministration = class {
|
|
|
27519
27919
|
)).rows[0].result;
|
|
27520
27920
|
});
|
|
27521
27921
|
}
|
|
27922
|
+
/**
|
|
27923
|
+
* Restore trial eligibility. Never creates, changes, or cancels a Stripe
|
|
27924
|
+
* subscription; it only deletes the single-use consumption record so the
|
|
27925
|
+
* account can start one new trial. The guarded SQL function does the work
|
|
27926
|
+
* because FORCE-RLS tenant rows are invisible to the admin's own tenant
|
|
27927
|
+
* context; GA007 reports an unused trial.
|
|
27928
|
+
*/
|
|
27929
|
+
trialReset(principal, raw) {
|
|
27930
|
+
return this.access(principal, async (trx) => {
|
|
27931
|
+
await trx.raw("SELECT grove_admin_accounts(ARRAY[]::text[])");
|
|
27932
|
+
const input = adminTrialResetSchema.parse(raw);
|
|
27933
|
+
const {
|
|
27934
|
+
rows: [result]
|
|
27935
|
+
} = await trx.raw(
|
|
27936
|
+
"SELECT grove_admin_trial_reset(?::uuid,?::uuid,?) AS result",
|
|
27937
|
+
[input.accountId, input.operationId, input.reason]
|
|
27938
|
+
);
|
|
27939
|
+
const value = result?.result;
|
|
27940
|
+
if (value?.eligible !== true || value?.accountId !== input.accountId)
|
|
27941
|
+
throw new GroveError(
|
|
27942
|
+
"trial_not_consumed",
|
|
27943
|
+
"This account never used a trial",
|
|
27944
|
+
404
|
|
27945
|
+
);
|
|
27946
|
+
return { accountId: input.accountId, eligible: true };
|
|
27947
|
+
});
|
|
27948
|
+
}
|
|
27522
27949
|
};
|
|
27523
27950
|
|
|
27524
27951
|
// lib/memory/src/index.ts
|
|
@@ -27823,7 +28250,21 @@ var MemoryService = class _MemoryService {
|
|
|
27823
28250
|
...input
|
|
27824
28251
|
},
|
|
27825
28252
|
async () => {
|
|
27826
|
-
|
|
28253
|
+
if (input.id) {
|
|
28254
|
+
const target2 = await this.query(trx, grant).findById(input.id).forUpdate();
|
|
28255
|
+
if (!target2 || target2.status !== "active" || target2.expiresAt && new Date(target2.expiresAt) <= /* @__PURE__ */ new Date())
|
|
28256
|
+
throw missing9();
|
|
28257
|
+
}
|
|
28258
|
+
const writer = this.inTransaction(trx);
|
|
28259
|
+
const note2 = input.id ? await writer.updateMemory(principal, {
|
|
28260
|
+
operationId: randomUUID14(),
|
|
28261
|
+
id: input.id,
|
|
28262
|
+
expectedVersion: input.expectedVersion,
|
|
28263
|
+
editSession: input.editSession,
|
|
28264
|
+
content: input.content,
|
|
28265
|
+
projectId: input.projectId,
|
|
28266
|
+
capture: "explicit"
|
|
28267
|
+
}) : await writer.remember(
|
|
27827
28268
|
principal,
|
|
27828
28269
|
rememberSchema.parse({
|
|
27829
28270
|
operationId: randomUUID14(),
|
|
@@ -27833,14 +28274,39 @@ var MemoryService = class _MemoryService {
|
|
|
27833
28274
|
source: { agent: "api" }
|
|
27834
28275
|
})
|
|
27835
28276
|
);
|
|
27836
|
-
if (input.
|
|
27837
|
-
await trx("web_captures").
|
|
28277
|
+
if (input.id)
|
|
28278
|
+
await trx("web_captures").where({
|
|
27838
28279
|
accountId: account.id,
|
|
27839
28280
|
memoryId: note2.id,
|
|
27840
|
-
version: note2.version,
|
|
27841
|
-
provenance: JSON.stringify(input.provenance),
|
|
27842
28281
|
active: true
|
|
27843
|
-
});
|
|
28282
|
+
}).update({ active: false });
|
|
28283
|
+
if (input.provenance) {
|
|
28284
|
+
const retained = await trx("web_captures").where({
|
|
28285
|
+
accountId: account.id,
|
|
28286
|
+
memoryId: note2.id,
|
|
28287
|
+
version: note2.version
|
|
28288
|
+
}).first();
|
|
28289
|
+
if (retained && stable(retained.provenance) !== stable(input.provenance))
|
|
28290
|
+
throw new GroveError(
|
|
28291
|
+
"version_conflict",
|
|
28292
|
+
"Source changed without a new note revision",
|
|
28293
|
+
409
|
|
28294
|
+
);
|
|
28295
|
+
if (retained)
|
|
28296
|
+
await trx("web_captures").where({
|
|
28297
|
+
accountId: account.id,
|
|
28298
|
+
memoryId: note2.id,
|
|
28299
|
+
version: note2.version
|
|
28300
|
+
}).update({ active: true });
|
|
28301
|
+
else
|
|
28302
|
+
await trx("web_captures").insert({
|
|
28303
|
+
accountId: account.id,
|
|
28304
|
+
memoryId: note2.id,
|
|
28305
|
+
version: note2.version,
|
|
28306
|
+
provenance: JSON.stringify(input.provenance),
|
|
28307
|
+
active: true
|
|
28308
|
+
});
|
|
28309
|
+
}
|
|
27844
28310
|
return {
|
|
27845
28311
|
action: "browser_capture",
|
|
27846
28312
|
connectionId: principal.connectionId,
|
|
@@ -27856,6 +28322,12 @@ var MemoryService = class _MemoryService {
|
|
|
27856
28322
|
"This capture is no longer available",
|
|
27857
28323
|
410
|
|
27858
28324
|
);
|
|
28325
|
+
if (note.version !== receipt.version)
|
|
28326
|
+
throw new GroveError(
|
|
28327
|
+
"version_conflict",
|
|
28328
|
+
"The saved version is no longer current. Check its receipt before continuing.",
|
|
28329
|
+
409
|
|
28330
|
+
);
|
|
27859
28331
|
return this.present(trx, note);
|
|
27860
28332
|
}
|
|
27861
28333
|
);
|
|
@@ -28201,6 +28673,28 @@ var MemoryService = class _MemoryService {
|
|
|
28201
28673
|
return this.present(trx, row);
|
|
28202
28674
|
});
|
|
28203
28675
|
}
|
|
28676
|
+
async listNoteMedia(principal, memoryId, version2) {
|
|
28677
|
+
const { MediaAttachments: MediaAttachments2 } = await Promise.resolve().then(() => (init_media2(), media_exports));
|
|
28678
|
+
return new MediaAttachments2(this).listForNote(principal, memoryId, version2);
|
|
28679
|
+
}
|
|
28680
|
+
async describeNoteMedia(principal, memoryId, id2, version2) {
|
|
28681
|
+
const { MediaAttachments: MediaAttachments2 } = await Promise.resolve().then(() => (init_media2(), media_exports));
|
|
28682
|
+
return new MediaAttachments2(this).describeForNote(
|
|
28683
|
+
principal,
|
|
28684
|
+
memoryId,
|
|
28685
|
+
id2,
|
|
28686
|
+
version2
|
|
28687
|
+
);
|
|
28688
|
+
}
|
|
28689
|
+
async readMediaTranscript(principal, memoryId, id2) {
|
|
28690
|
+
const { MediaAttachments: MediaAttachments2 } = await Promise.resolve().then(() => (init_media2(), media_exports));
|
|
28691
|
+
const attachments = new MediaAttachments2(this);
|
|
28692
|
+
const meta = await attachments.describeForNote(principal, memoryId, id2);
|
|
28693
|
+
if (!meta.mime.startsWith("audio/")) throw missing9();
|
|
28694
|
+
const saved = await attachments.transcript(principal, memoryId, id2);
|
|
28695
|
+
const text5 = typeof saved.text === "string" ? saved.text.slice(0, 6e3) : "";
|
|
28696
|
+
return { text: text5, version: saved.version, mediaId: id2, memoryId };
|
|
28697
|
+
}
|
|
28204
28698
|
async moveMemories(principal, raw) {
|
|
28205
28699
|
const input = moveMemoriesSchema.parse(raw);
|
|
28206
28700
|
return this.access(
|
|
@@ -29626,6 +30120,8 @@ var sessionPrincipal = (accountId, subject) => ({
|
|
|
29626
30120
|
|
|
29627
30121
|
// packages/api/src/media-input.ts
|
|
29628
30122
|
init_define_GROVE_TELEMETRY();
|
|
30123
|
+
init_contracts();
|
|
30124
|
+
init_media();
|
|
29629
30125
|
import { Writable } from "node:stream";
|
|
29630
30126
|
import { pipeline } from "node:stream/promises";
|
|
29631
30127
|
async function readMediaBytes(source3, signal, maximum = imageLimits.bytes) {
|
|
@@ -29658,6 +30154,7 @@ async function readMediaBytes(source3, signal, maximum = imageLimits.bytes) {
|
|
|
29658
30154
|
// packages/api/src/billing.ts
|
|
29659
30155
|
init_define_GROVE_TELEMETRY();
|
|
29660
30156
|
import { randomUUID as randomUUID15 } from "node:crypto";
|
|
30157
|
+
init_contracts();
|
|
29661
30158
|
var ongoing = (status) => !["canceled", "incomplete_expired"].includes(status);
|
|
29662
30159
|
var replaceableCheckout = (session, subscriptions) => {
|
|
29663
30160
|
if (session.status === "expired") return true;
|
|
@@ -29682,20 +30179,31 @@ var Billing = class {
|
|
|
29682
30179
|
}
|
|
29683
30180
|
service;
|
|
29684
30181
|
options;
|
|
29685
|
-
checkoutParameters(accountId, customerId, priceId) {
|
|
30182
|
+
checkoutParameters(accountId, customerId, priceId, trialDays) {
|
|
29686
30183
|
return {
|
|
29687
30184
|
mode: "subscription",
|
|
29688
30185
|
customer: customerId,
|
|
29689
30186
|
client_reference_id: accountId,
|
|
29690
30187
|
line_items: [{ price: priceId, quantity: 1 }],
|
|
29691
|
-
subscription_data: {
|
|
30188
|
+
subscription_data: {
|
|
30189
|
+
metadata: { groveAccountId: accountId },
|
|
30190
|
+
...trialDays ? { trial_period_days: trialDays } : {}
|
|
30191
|
+
},
|
|
30192
|
+
// Card-required trials must always collect a payment method; ordinary
|
|
30193
|
+
// checkout keeps Stripe's default behavior.
|
|
30194
|
+
...trialDays ? { payment_method_collection: "always" } : {},
|
|
29692
30195
|
success_url: `${this.options.siteUrl}/app/settings/billing?checkout=success`,
|
|
29693
30196
|
cancel_url: `${this.options.siteUrl}/app/settings/billing?checkout=canceled`
|
|
29694
30197
|
};
|
|
29695
30198
|
}
|
|
29696
|
-
async checkoutSession(accountId, row) {
|
|
30199
|
+
async checkoutSession(accountId, row, trialDays) {
|
|
29697
30200
|
const id2 = row.checkoutId ?? (await this.options.stripe.checkout.sessions.create(
|
|
29698
|
-
this.checkoutParameters(
|
|
30201
|
+
this.checkoutParameters(
|
|
30202
|
+
accountId,
|
|
30203
|
+
row.customerId,
|
|
30204
|
+
row.checkoutPrice,
|
|
30205
|
+
trialDays
|
|
30206
|
+
),
|
|
29699
30207
|
{ idempotencyKey: `grove-checkout-${row.checkoutOperation}` }
|
|
29700
30208
|
)).id;
|
|
29701
30209
|
return this.options.stripe.checkout.sessions.retrieve(id2);
|
|
@@ -29745,6 +30253,29 @@ var Billing = class {
|
|
|
29745
30253
|
);
|
|
29746
30254
|
return price;
|
|
29747
30255
|
}
|
|
30256
|
+
/**
|
|
30257
|
+
* Monthly flag pricing is required; yearly is optional so an unset yearly
|
|
30258
|
+
* variant never breaks the billing page. Checkout still resolves (and
|
|
30259
|
+
* rejects invalid quotes) per interval.
|
|
30260
|
+
*/
|
|
30261
|
+
async flagQuotes(subject) {
|
|
30262
|
+
const pricing = this.options.pricing;
|
|
30263
|
+
const monthly = await pricing.month?.quote(subject);
|
|
30264
|
+
if (!monthly)
|
|
30265
|
+
throw new GroveError(
|
|
30266
|
+
"billing_price_missing",
|
|
30267
|
+
"This subscription option is unavailable",
|
|
30268
|
+
400
|
|
30269
|
+
);
|
|
30270
|
+
const quotes = [monthly];
|
|
30271
|
+
if (pricing.year) {
|
|
30272
|
+
try {
|
|
30273
|
+
quotes.push(await pricing.year.quote(subject));
|
|
30274
|
+
} catch {
|
|
30275
|
+
}
|
|
30276
|
+
}
|
|
30277
|
+
return quotes;
|
|
30278
|
+
}
|
|
29748
30279
|
/** Refresh under the customer row lock. Event arrival order never determines access. */
|
|
29749
30280
|
async sync(trx, accountId, customerId) {
|
|
29750
30281
|
const subscriptions = await this.options.stripe.subscriptions.list({
|
|
@@ -29783,6 +30314,10 @@ var Billing = class {
|
|
|
29783
30314
|
"cancelAtPeriodEnd"
|
|
29784
30315
|
]);
|
|
29785
30316
|
}
|
|
30317
|
+
const trialing = subscriptions.data.find((s) => s.status === "trialing");
|
|
30318
|
+
if (trialing) {
|
|
30319
|
+
await trx("billing_trials").where({ accountId }).whereNull("subscriptionId").update({ subscriptionId: trialing.id });
|
|
30320
|
+
}
|
|
29786
30321
|
await trx("billing_subscriptions").where({ accountId, customerId }).whereNotIn(
|
|
29787
30322
|
"id",
|
|
29788
30323
|
subscriptions.data.map((s) => s.id)
|
|
@@ -29817,6 +30352,13 @@ var Billing = class {
|
|
|
29817
30352
|
cancelAtPeriodEnd: subscription.cancelAtPeriodEnd,
|
|
29818
30353
|
periodEnd: new Date(subscription.periodEnd).toISOString()
|
|
29819
30354
|
} : null,
|
|
30355
|
+
trial: await trialState(trx, principal.accountId).then(
|
|
30356
|
+
(state2) => state2.eligible ? { eligible: true, consumedAt: null } : {
|
|
30357
|
+
eligible: false,
|
|
30358
|
+
consumedAt: state2.consumedAt,
|
|
30359
|
+
resetAt: state2.resetAt
|
|
30360
|
+
}
|
|
30361
|
+
),
|
|
29820
30362
|
usage: await billingUsage(this.service.db, trx, principal.accountId),
|
|
29821
30363
|
resources: await resourceUsage(
|
|
29822
30364
|
this.service.db,
|
|
@@ -29826,7 +30368,7 @@ var Billing = class {
|
|
|
29826
30368
|
};
|
|
29827
30369
|
}
|
|
29828
30370
|
);
|
|
29829
|
-
const prices = this.options.pricing ?
|
|
30371
|
+
const prices = this.options.pricing ? await this.flagQuotes(principal.subject) : enabled ? await Promise.all(
|
|
29830
30372
|
Object.keys(this.options.prices).map(
|
|
29831
30373
|
async (interval) => {
|
|
29832
30374
|
const price = await this.price(interval);
|
|
@@ -29857,13 +30399,16 @@ var Billing = class {
|
|
|
29857
30399
|
);
|
|
29858
30400
|
await trx("billing_customers").insert({ accountId: principal.accountId }).onConflict("accountId").ignore();
|
|
29859
30401
|
});
|
|
29860
|
-
if (this.options.pricing && interval
|
|
30402
|
+
if (this.options.pricing && !this.options.pricing[interval])
|
|
29861
30403
|
throw new GroveError(
|
|
29862
30404
|
"billing_price_missing",
|
|
29863
30405
|
"This subscription option is unavailable",
|
|
29864
30406
|
400
|
|
29865
30407
|
);
|
|
29866
|
-
const price = this.options.pricing ? await this.options.pricing.resolve(
|
|
30408
|
+
const price = this.options.pricing?.[interval] ? await this.options.pricing[interval].resolve(
|
|
30409
|
+
principal.subject,
|
|
30410
|
+
expectedAmount
|
|
30411
|
+
) : await this.price(interval);
|
|
29867
30412
|
await this.service.access(principal, "admin", async ({ trx }) => {
|
|
29868
30413
|
const row = await trx("billing_customers").where({ accountId: principal.accountId }).forUpdate().first();
|
|
29869
30414
|
if (row.checkoutPrice && row.checkoutPrice !== price.id) {
|
|
@@ -29944,6 +30489,140 @@ var Billing = class {
|
|
|
29944
30489
|
);
|
|
29945
30490
|
return result ?? this.checkout(principal, interval, expectedAmount);
|
|
29946
30491
|
}
|
|
30492
|
+
/**
|
|
30493
|
+
* Card-required 7-day Pro trial. Single use per account: consumption is
|
|
30494
|
+
* recorded when the trial checkout is created (same row lock that fences
|
|
30495
|
+
* concurrent checkouts) and only an admin reset restores eligibility.
|
|
30496
|
+
* Abandoned/expired trial checkouts still count as used.
|
|
30497
|
+
*/
|
|
30498
|
+
async startTrial(principal, interval, expectedAmount) {
|
|
30499
|
+
await this.service.access(principal, "admin", async ({ account, trx }) => {
|
|
30500
|
+
if (!await this.options.enabled(account.clerkSubject))
|
|
30501
|
+
throw new GroveError(
|
|
30502
|
+
"billing_disabled",
|
|
30503
|
+
"Subscriptions are not available yet",
|
|
30504
|
+
404
|
|
30505
|
+
);
|
|
30506
|
+
const state = await trialState(trx, principal.accountId);
|
|
30507
|
+
if (!state.eligible)
|
|
30508
|
+
throw new GroveError(
|
|
30509
|
+
"trial_already_used",
|
|
30510
|
+
"This account already used its Pro trial",
|
|
30511
|
+
409
|
|
30512
|
+
);
|
|
30513
|
+
await trx("billing_customers").insert({ accountId: principal.accountId }).onConflict("accountId").ignore();
|
|
30514
|
+
});
|
|
30515
|
+
if (this.options.pricing && !this.options.pricing[interval])
|
|
30516
|
+
throw new GroveError(
|
|
30517
|
+
"billing_price_missing",
|
|
30518
|
+
"This subscription option is unavailable",
|
|
30519
|
+
400
|
|
30520
|
+
);
|
|
30521
|
+
const price = this.options.pricing?.[interval] ? await this.options.pricing[interval].resolve(
|
|
30522
|
+
principal.subject,
|
|
30523
|
+
expectedAmount
|
|
30524
|
+
) : await this.price(interval);
|
|
30525
|
+
await this.service.access(principal, "admin", async ({ trx }) => {
|
|
30526
|
+
const row = await trx("billing_customers").where({ accountId: principal.accountId }).forUpdate().first();
|
|
30527
|
+
if (row.checkoutPrice && row.checkoutPrice !== price.id) {
|
|
30528
|
+
const previous3 = row.customerId ? await this.checkoutSession(principal.accountId, row) : null;
|
|
30529
|
+
const subscriptions = previous3?.status === "complete" ? await this.sync(trx, principal.accountId, row.customerId) : [];
|
|
30530
|
+
if (previous3 && !replaceableCheckout(previous3, subscriptions))
|
|
30531
|
+
throw new GroveError(
|
|
30532
|
+
"checkout_pending",
|
|
30533
|
+
"Finish or let your existing checkout expire before starting a trial",
|
|
30534
|
+
409
|
|
30535
|
+
);
|
|
30536
|
+
await trx("billing_customers").where({ accountId: principal.accountId }).update({
|
|
30537
|
+
checkoutId: null,
|
|
30538
|
+
checkoutPrice: price.id,
|
|
30539
|
+
checkoutOperation: randomUUID15()
|
|
30540
|
+
});
|
|
30541
|
+
}
|
|
30542
|
+
if (!row.checkoutPrice)
|
|
30543
|
+
await trx("billing_customers").where({ accountId: principal.accountId }).update({ checkoutPrice: price.id });
|
|
30544
|
+
});
|
|
30545
|
+
await this.service.access(principal, "admin", async ({ trx }) => {
|
|
30546
|
+
const row = await trx("billing_customers").where({ accountId: principal.accountId }).forUpdate().first();
|
|
30547
|
+
if (!row.customerId) {
|
|
30548
|
+
const customer = await this.options.stripe.customers.create(
|
|
30549
|
+
{ metadata: { groveAccountId: principal.accountId } },
|
|
30550
|
+
{ idempotencyKey: `grove-customer-${principal.accountId}` }
|
|
30551
|
+
);
|
|
30552
|
+
await trx("billing_customers").where({ accountId: principal.accountId }).update({ customerId: customer.id });
|
|
30553
|
+
}
|
|
30554
|
+
});
|
|
30555
|
+
const result = await this.service.access(
|
|
30556
|
+
principal,
|
|
30557
|
+
"admin",
|
|
30558
|
+
async ({ trx, account }) => {
|
|
30559
|
+
if (!await this.options.enabled(account.clerkSubject))
|
|
30560
|
+
throw new GroveError(
|
|
30561
|
+
"billing_disabled",
|
|
30562
|
+
"Subscriptions are not available yet",
|
|
30563
|
+
404
|
|
30564
|
+
);
|
|
30565
|
+
const row = await trx("billing_customers").where({ accountId: principal.accountId }).forUpdate().first();
|
|
30566
|
+
if (row.checkoutPrice !== price.id)
|
|
30567
|
+
throw new GroveError(
|
|
30568
|
+
"checkout_pending",
|
|
30569
|
+
"Your checkout changed. Refresh billing and try again.",
|
|
30570
|
+
409
|
|
30571
|
+
);
|
|
30572
|
+
const state = await trialState(trx, principal.accountId);
|
|
30573
|
+
if (!state.eligible)
|
|
30574
|
+
throw new GroveError(
|
|
30575
|
+
"trial_already_used",
|
|
30576
|
+
"This account already used its Pro trial",
|
|
30577
|
+
409
|
|
30578
|
+
);
|
|
30579
|
+
const customerId = row.customerId;
|
|
30580
|
+
const subscriptions = await this.sync(
|
|
30581
|
+
trx,
|
|
30582
|
+
principal.accountId,
|
|
30583
|
+
customerId
|
|
30584
|
+
);
|
|
30585
|
+
if (subscriptions.some((s) => ongoing(s.status)))
|
|
30586
|
+
throw new GroveError(
|
|
30587
|
+
"subscription_exists",
|
|
30588
|
+
"Manage your existing subscription instead",
|
|
30589
|
+
409
|
|
30590
|
+
);
|
|
30591
|
+
if (row.checkoutId) {
|
|
30592
|
+
const existing = await this.checkoutSession(principal.accountId, row);
|
|
30593
|
+
if (existing.status === "open")
|
|
30594
|
+
throw new GroveError(
|
|
30595
|
+
"checkout_pending",
|
|
30596
|
+
"Finish or let your existing checkout expire before starting a trial",
|
|
30597
|
+
409
|
|
30598
|
+
);
|
|
30599
|
+
}
|
|
30600
|
+
const session = await this.checkoutSession(
|
|
30601
|
+
principal.accountId,
|
|
30602
|
+
row,
|
|
30603
|
+
trialDurationDays
|
|
30604
|
+
);
|
|
30605
|
+
if (replaceableCheckout(session, subscriptions)) {
|
|
30606
|
+
await trx("billing_customers").where({ accountId: principal.accountId }).update({
|
|
30607
|
+
checkoutId: null,
|
|
30608
|
+
checkoutPrice: null,
|
|
30609
|
+
checkoutOperation: randomUUID15()
|
|
30610
|
+
});
|
|
30611
|
+
return null;
|
|
30612
|
+
}
|
|
30613
|
+
if (session.status !== "open")
|
|
30614
|
+
throw new GroveError(
|
|
30615
|
+
"checkout_processing",
|
|
30616
|
+
"Your subscription is processing. Refresh billing shortly.",
|
|
30617
|
+
409
|
|
30618
|
+
);
|
|
30619
|
+
await consumeTrial(trx, principal.accountId, void 0);
|
|
30620
|
+
await trx("billing_customers").where({ accountId: principal.accountId }).update({ checkoutId: session.id });
|
|
30621
|
+
return destination2(session.url, "checkout.stripe.com");
|
|
30622
|
+
}
|
|
30623
|
+
);
|
|
30624
|
+
return result ?? this.startTrial(principal, interval, expectedAmount);
|
|
30625
|
+
}
|
|
29947
30626
|
async portal(principal) {
|
|
29948
30627
|
return this.service.access(principal, "admin", async ({ trx, account }) => {
|
|
29949
30628
|
if (!await this.options.enabled(account.clerkSubject))
|
|
@@ -30008,8 +30687,9 @@ var Billing = class {
|
|
|
30008
30687
|
|
|
30009
30688
|
// packages/api/src/system-admin.ts
|
|
30010
30689
|
init_define_GROVE_TELEMETRY();
|
|
30690
|
+
init_contracts();
|
|
30011
30691
|
import { createClerkClient } from "@clerk/backend";
|
|
30012
|
-
import { z as
|
|
30692
|
+
import { z as z26 } from "zod";
|
|
30013
30693
|
function clerkAdminDirectory(secretKey) {
|
|
30014
30694
|
const clerk = createClerkClient({ secretKey });
|
|
30015
30695
|
return {
|
|
@@ -30045,12 +30725,12 @@ var AdminAccounts = class {
|
|
|
30045
30725
|
administration;
|
|
30046
30726
|
async search(principal, raw) {
|
|
30047
30727
|
await this.administration.accounts(principal, []);
|
|
30048
|
-
const { query } =
|
|
30728
|
+
const { query } = z26.object({ query: z26.string().trim().max(254) }).strict().parse(raw);
|
|
30049
30729
|
let subjects;
|
|
30050
30730
|
if (query.startsWith("user_") && /^user_[A-Za-z0-9_-]{1,128}$/.test(query))
|
|
30051
30731
|
subjects = [query];
|
|
30052
30732
|
else if (query) {
|
|
30053
|
-
if (!
|
|
30733
|
+
if (!z26.email().safeParse(query).success)
|
|
30054
30734
|
throw new GroveError(
|
|
30055
30735
|
"invalid_request",
|
|
30056
30736
|
"Search by exact email or user ID",
|
|
@@ -30103,14 +30783,17 @@ var AdminAccounts = class {
|
|
|
30103
30783
|
|
|
30104
30784
|
// packages/api/src/billing-pricing.ts
|
|
30105
30785
|
init_define_GROVE_TELEMETRY();
|
|
30106
|
-
|
|
30107
|
-
|
|
30786
|
+
init_contracts();
|
|
30787
|
+
var FlagPricing = class {
|
|
30788
|
+
constructor(stripe, productId, interval, dollars) {
|
|
30108
30789
|
this.stripe = stripe;
|
|
30109
30790
|
this.productId = productId;
|
|
30791
|
+
this.interval = interval;
|
|
30110
30792
|
this.dollars = dollars;
|
|
30111
30793
|
}
|
|
30112
30794
|
stripe;
|
|
30113
30795
|
productId;
|
|
30796
|
+
interval;
|
|
30114
30797
|
dollars;
|
|
30115
30798
|
async quote(subject) {
|
|
30116
30799
|
const dollars = await this.dollars(subject);
|
|
@@ -30121,7 +30804,7 @@ var MonthlyPricing = class {
|
|
|
30121
30804
|
"Subscription pricing is unavailable. Try again shortly.",
|
|
30122
30805
|
503
|
|
30123
30806
|
);
|
|
30124
|
-
return { interval:
|
|
30807
|
+
return { interval: this.interval, amount: cents, currency: "usd" };
|
|
30125
30808
|
}
|
|
30126
30809
|
async resolve(subject, expectedAmount) {
|
|
30127
30810
|
const quote = await this.quote(subject);
|
|
@@ -30138,7 +30821,7 @@ var MonthlyPricing = class {
|
|
|
30138
30821
|
"This subscription is unavailable",
|
|
30139
30822
|
503
|
|
30140
30823
|
);
|
|
30141
|
-
const key2 = `grove-pro-${this.productId}-usd
|
|
30824
|
+
const key2 = `grove-pro-${this.productId}-usd-${this.interval}-${quote.amount}`;
|
|
30142
30825
|
const existing = await this.stripe.prices.list({
|
|
30143
30826
|
lookup_keys: [key2],
|
|
30144
30827
|
active: true,
|
|
@@ -30150,7 +30833,7 @@ var MonthlyPricing = class {
|
|
|
30150
30833
|
currency: "usd",
|
|
30151
30834
|
unit_amount: quote.amount,
|
|
30152
30835
|
recurring: {
|
|
30153
|
-
interval:
|
|
30836
|
+
interval: this.interval,
|
|
30154
30837
|
interval_count: 1,
|
|
30155
30838
|
usage_type: "licensed"
|
|
30156
30839
|
},
|
|
@@ -30159,7 +30842,7 @@ var MonthlyPricing = class {
|
|
|
30159
30842
|
},
|
|
30160
30843
|
{ idempotencyKey: key2 }
|
|
30161
30844
|
);
|
|
30162
|
-
if (price.unit_amount !== quote.amount || price.currency !== "usd" || price.product !== this.productId || !price.active || price.recurring?.interval !==
|
|
30845
|
+
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")
|
|
30163
30846
|
throw new GroveError(
|
|
30164
30847
|
"billing_price_invalid",
|
|
30165
30848
|
"Subscription pricing could not be verified",
|
|
@@ -30168,6 +30851,16 @@ var MonthlyPricing = class {
|
|
|
30168
30851
|
return price;
|
|
30169
30852
|
}
|
|
30170
30853
|
};
|
|
30854
|
+
var MonthlyPricing = class extends FlagPricing {
|
|
30855
|
+
constructor(stripe, productId, dollars) {
|
|
30856
|
+
super(stripe, productId, "month", dollars);
|
|
30857
|
+
}
|
|
30858
|
+
};
|
|
30859
|
+
var YearlyPricing = class extends FlagPricing {
|
|
30860
|
+
constructor(stripe, productId, dollars) {
|
|
30861
|
+
super(stripe, productId, "year", dollars);
|
|
30862
|
+
}
|
|
30863
|
+
};
|
|
30171
30864
|
|
|
30172
30865
|
// packages/api/src/app.ts
|
|
30173
30866
|
import { PassThrough, Readable as Readable2 } from "node:stream";
|
|
@@ -46296,14 +46989,16 @@ var closeTelemetry = (timeoutMs = 550) => Promise.allSettled(
|
|
|
46296
46989
|
// packages/api/src/app.ts
|
|
46297
46990
|
import { Hono } from "hono";
|
|
46298
46991
|
import { cors } from "hono/cors";
|
|
46299
|
-
import { z as
|
|
46992
|
+
import { z as z27, ZodError as ZodError2 } from "zod";
|
|
46300
46993
|
import { Webhook } from "svix";
|
|
46301
46994
|
import { WebStandardStreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
|
|
46302
46995
|
|
|
46303
46996
|
// lib/integration-core/src/mcp.ts
|
|
46304
46997
|
init_define_GROVE_TELEMETRY();
|
|
46998
|
+
init_contracts();
|
|
46305
46999
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
46306
47000
|
import { ZodError } from "zod";
|
|
47001
|
+
init_note_writing();
|
|
46307
47002
|
function createMemoryMcp(execute) {
|
|
46308
47003
|
const server = new McpServer(
|
|
46309
47004
|
{ name: "grove", version: "1.0.0" },
|
|
@@ -46362,8 +47057,12 @@ function createMemoryMcp(execute) {
|
|
|
46362
47057
|
return server;
|
|
46363
47058
|
}
|
|
46364
47059
|
|
|
47060
|
+
// packages/api/src/app.ts
|
|
47061
|
+
init_contracts();
|
|
47062
|
+
|
|
46365
47063
|
// packages/api/src/admission.ts
|
|
46366
47064
|
init_define_GROVE_TELEMETRY();
|
|
47065
|
+
init_contracts();
|
|
46367
47066
|
var busy = () => new GroveError("overloaded", "Grove is busy. Try again shortly.", 503);
|
|
46368
47067
|
async function admittedRequest(request2, signal) {
|
|
46369
47068
|
if (!request2.body) return request2;
|
|
@@ -46446,8 +47145,13 @@ var defaultCapacity = {
|
|
|
46446
47145
|
interactiveTimeoutMs: 9e4
|
|
46447
47146
|
};
|
|
46448
47147
|
|
|
47148
|
+
// packages/api/src/app.ts
|
|
47149
|
+
init_sharing();
|
|
47150
|
+
|
|
46449
47151
|
// packages/api/src/media-images.ts
|
|
46450
47152
|
init_define_GROVE_TELEMETRY();
|
|
47153
|
+
init_contracts();
|
|
47154
|
+
init_media();
|
|
46451
47155
|
import { createHash as createHash21 } from "node:crypto";
|
|
46452
47156
|
import sharp from "sharp";
|
|
46453
47157
|
var invalid2 = () => new GroveError(
|
|
@@ -46521,6 +47225,7 @@ async function verifyImage(source3, declaredMime, signal) {
|
|
|
46521
47225
|
|
|
46522
47226
|
// packages/api/src/media-audio.ts
|
|
46523
47227
|
init_define_GROVE_TELEMETRY();
|
|
47228
|
+
init_contracts();
|
|
46524
47229
|
import { createHash as createHash22 } from "node:crypto";
|
|
46525
47230
|
async function verifyAudio(source3, signal) {
|
|
46526
47231
|
const fail = () => new GroveError(
|
|
@@ -46566,6 +47271,7 @@ async function verifyAudio(source3, signal) {
|
|
|
46566
47271
|
|
|
46567
47272
|
// packages/api/src/media-archive.ts
|
|
46568
47273
|
init_define_GROVE_TELEMETRY();
|
|
47274
|
+
init_contracts();
|
|
46569
47275
|
import { createHash as createHash23 } from "node:crypto";
|
|
46570
47276
|
import { Readable } from "node:stream";
|
|
46571
47277
|
function header(name, size) {
|
|
@@ -46703,6 +47409,7 @@ async function noteArchive(service, media, principal, id2, expectedVersion, sign
|
|
|
46703
47409
|
}
|
|
46704
47410
|
|
|
46705
47411
|
// packages/api/src/app.ts
|
|
47412
|
+
init_media();
|
|
46706
47413
|
init_models();
|
|
46707
47414
|
function createApp(deps) {
|
|
46708
47415
|
const app = new Hono();
|
|
@@ -46903,13 +47610,13 @@ function createApp(deps) {
|
|
|
46903
47610
|
400
|
|
46904
47611
|
);
|
|
46905
47612
|
}
|
|
46906
|
-
const payload =
|
|
46907
|
-
type:
|
|
46908
|
-
timestamp:
|
|
46909
|
-
data:
|
|
46910
|
-
id:
|
|
46911
|
-
banned:
|
|
46912
|
-
locked:
|
|
47613
|
+
const payload = z27.object({
|
|
47614
|
+
type: z27.string(),
|
|
47615
|
+
timestamp: z27.number().int(),
|
|
47616
|
+
data: z27.object({
|
|
47617
|
+
id: z27.string().min(1),
|
|
47618
|
+
banned: z27.boolean().optional(),
|
|
47619
|
+
locked: z27.boolean().optional()
|
|
46913
47620
|
})
|
|
46914
47621
|
}).parse(event);
|
|
46915
47622
|
await deps.memories.db.transaction(async (trx) => {
|
|
@@ -47016,6 +47723,16 @@ function createApp(deps) {
|
|
|
47016
47723
|
)
|
|
47017
47724
|
})
|
|
47018
47725
|
);
|
|
47726
|
+
app.post(
|
|
47727
|
+
"/v1/admin/accounts/trial-reset",
|
|
47728
|
+
async (c) => c.json({
|
|
47729
|
+
success: true,
|
|
47730
|
+
data: await admin.administration.trialReset(
|
|
47731
|
+
c.get("principal"),
|
|
47732
|
+
await c.req.json()
|
|
47733
|
+
)
|
|
47734
|
+
})
|
|
47735
|
+
);
|
|
47019
47736
|
app.get(
|
|
47020
47737
|
"/v1/admin/audit",
|
|
47021
47738
|
async (c) => c.json({
|
|
@@ -47042,9 +47759,9 @@ function createApp(deps) {
|
|
|
47042
47759
|
async (c) => c.json({ success: true, data: await billing2().status(c.get("principal")) })
|
|
47043
47760
|
);
|
|
47044
47761
|
app.post("/v1/billing/checkout", async (c) => {
|
|
47045
|
-
const input =
|
|
47046
|
-
interval:
|
|
47047
|
-
expectedAmount:
|
|
47762
|
+
const input = z27.object({
|
|
47763
|
+
interval: z27.enum(["month", "year"]),
|
|
47764
|
+
expectedAmount: z27.number().int().positive().optional()
|
|
47048
47765
|
}).strict().parse(await c.req.json());
|
|
47049
47766
|
return c.json({
|
|
47050
47767
|
success: true,
|
|
@@ -47059,6 +47776,20 @@ function createApp(deps) {
|
|
|
47059
47776
|
"/v1/billing/portal",
|
|
47060
47777
|
async (c) => c.json({ success: true, data: await billing2().portal(c.get("principal")) })
|
|
47061
47778
|
);
|
|
47779
|
+
app.post("/v1/billing/trial", async (c) => {
|
|
47780
|
+
const input = z27.object({
|
|
47781
|
+
interval: z27.enum(["month", "year"]),
|
|
47782
|
+
expectedAmount: z27.number().int().positive().optional()
|
|
47783
|
+
}).strict().parse(await c.req.json());
|
|
47784
|
+
return c.json({
|
|
47785
|
+
success: true,
|
|
47786
|
+
data: await billing2().startTrial(
|
|
47787
|
+
c.get("principal"),
|
|
47788
|
+
input.interval,
|
|
47789
|
+
input.expectedAmount
|
|
47790
|
+
)
|
|
47791
|
+
});
|
|
47792
|
+
});
|
|
47062
47793
|
const body = async (c, schema) => schema.parse(await c.req.json());
|
|
47063
47794
|
const mutation = async (c, schema) => {
|
|
47064
47795
|
const value = await c.req.json();
|
|
@@ -47141,8 +47872,8 @@ function createApp(deps) {
|
|
|
47141
47872
|
importStorage();
|
|
47142
47873
|
const principal = c.get("principal"), conversationId = uuidSchema.parse(c.req.param("conversationId")), id2 = uuidSchema.parse(c.req.param("id"));
|
|
47143
47874
|
await conversationDocuments2.list(principal, conversationId);
|
|
47144
|
-
const length =
|
|
47145
|
-
const hash4 =
|
|
47875
|
+
const length = z27.coerce.number().int().min(1).max(3 * 1024 * 1024).parse(c.req.header("content-length"));
|
|
47876
|
+
const hash4 = z27.string().regex(/^[0-9a-f]{64}$/).parse(c.req.header("x-grove-content-sha256"));
|
|
47146
47877
|
let filename;
|
|
47147
47878
|
try {
|
|
47148
47879
|
filename = decodeURIComponent(c.req.header("x-grove-filename") ?? "");
|
|
@@ -47221,7 +47952,7 @@ function createApp(deps) {
|
|
|
47221
47952
|
c.get("principal"),
|
|
47222
47953
|
uuidSchema.parse(c.req.param("conversationId")),
|
|
47223
47954
|
uuidSchema.parse(c.req.param("id")),
|
|
47224
|
-
|
|
47955
|
+
z27.coerce.number().int().nonnegative().default(0).parse(c.req.query("after"))
|
|
47225
47956
|
)
|
|
47226
47957
|
})
|
|
47227
47958
|
);
|
|
@@ -47260,7 +47991,7 @@ function createApp(deps) {
|
|
|
47260
47991
|
data: await documentImports2.get(
|
|
47261
47992
|
c.get("principal"),
|
|
47262
47993
|
uuidSchema.parse(c.req.param("id")),
|
|
47263
|
-
|
|
47994
|
+
z27.uuid().optional().parse(c.req.query("after"))
|
|
47264
47995
|
)
|
|
47265
47996
|
})
|
|
47266
47997
|
);
|
|
@@ -47268,8 +47999,8 @@ function createApp(deps) {
|
|
|
47268
47999
|
importStorage();
|
|
47269
48000
|
const principal = c.get("principal"), batchId = uuidSchema.parse(c.req.param("batchId")), id2 = uuidSchema.parse(c.req.param("id"));
|
|
47270
48001
|
await documentImports2.get(principal, batchId);
|
|
47271
|
-
const length =
|
|
47272
|
-
const hash4 =
|
|
48002
|
+
const length = z27.coerce.number().int().min(1).max(3 * 1024 * 1024).parse(c.req.header("content-length"));
|
|
48003
|
+
const hash4 = z27.string().regex(/^[0-9a-f]{64}$/).parse(c.req.header("x-grove-content-sha256"));
|
|
47273
48004
|
let filename;
|
|
47274
48005
|
try {
|
|
47275
48006
|
filename = decodeURIComponent(c.req.header("x-grove-filename") ?? "");
|
|
@@ -47386,7 +48117,7 @@ function createApp(deps) {
|
|
|
47386
48117
|
service,
|
|
47387
48118
|
c.get("principal"),
|
|
47388
48119
|
c.req.param("tool"),
|
|
47389
|
-
await mutation(c,
|
|
48120
|
+
await mutation(c, z27.record(z27.string(), z27.unknown())),
|
|
47390
48121
|
c.get("signal")
|
|
47391
48122
|
)
|
|
47392
48123
|
})
|
|
@@ -47398,7 +48129,7 @@ function createApp(deps) {
|
|
|
47398
48129
|
"Media storage is not configured",
|
|
47399
48130
|
503
|
|
47400
48131
|
);
|
|
47401
|
-
const id2 = uuidSchema.parse(c.req.param("id")), version2 = c.req.query("version") ?
|
|
48132
|
+
const id2 = uuidSchema.parse(c.req.param("id")), version2 = c.req.query("version") ? z27.coerce.number().int().positive().parse(c.req.query("version")) : void 0;
|
|
47402
48133
|
const cancelled = new AbortController(), signal = AbortSignal.any([c.get("signal"), cancelled.signal]);
|
|
47403
48134
|
const source3 = await noteArchive(
|
|
47404
48135
|
service,
|
|
@@ -47432,10 +48163,10 @@ function createApp(deps) {
|
|
|
47432
48163
|
const input = {
|
|
47433
48164
|
id: uuidSchema.parse(c.req.param("id")),
|
|
47434
48165
|
memoryId: uuidSchema.parse(c.req.param("memoryId")),
|
|
47435
|
-
version:
|
|
47436
|
-
bytes:
|
|
47437
|
-
mime:
|
|
47438
|
-
sha256:
|
|
48166
|
+
version: z27.coerce.number().int().positive().parse(c.req.header("x-grove-note-version")),
|
|
48167
|
+
bytes: z27.coerce.number().int().min(1).max(imageLimits.bytes).parse(c.req.header("content-length")),
|
|
48168
|
+
mime: z27.enum(mediaMimeTypes).parse(c.req.header("content-type")),
|
|
48169
|
+
sha256: z27.string().regex(/^[0-9a-f]{64}$/).parse(c.req.header("x-grove-content-sha256"))
|
|
47439
48170
|
};
|
|
47440
48171
|
const claim = await attachments.claim(principal, input);
|
|
47441
48172
|
if (claim.replay)
|
|
@@ -47538,7 +48269,7 @@ function createApp(deps) {
|
|
|
47538
48269
|
};
|
|
47539
48270
|
app.get("/v1/memories/:memoryId/media/:id", async (c) => {
|
|
47540
48271
|
const memoryId = uuidSchema.parse(c.req.param("memoryId")), id2 = uuidSchema.parse(c.req.param("id"));
|
|
47541
|
-
const version2 = c.req.query("version") ?
|
|
48272
|
+
const version2 = c.req.query("version") ? z27.coerce.number().int().positive().parse(c.req.query("version")) : void 0;
|
|
47542
48273
|
return mediaResponse(
|
|
47543
48274
|
c,
|
|
47544
48275
|
() => attachments.read(c.get("principal"), memoryId, id2, version2)
|
|
@@ -47595,7 +48326,7 @@ function createApp(deps) {
|
|
|
47595
48326
|
})
|
|
47596
48327
|
);
|
|
47597
48328
|
app.post("/v1/speech/:id/cancel", async (c) => {
|
|
47598
|
-
await mutation(c,
|
|
48329
|
+
await mutation(c, z27.object({}).strict());
|
|
47599
48330
|
return c.json({
|
|
47600
48331
|
success: true,
|
|
47601
48332
|
data: await speech2.cancel(
|
|
@@ -47633,10 +48364,10 @@ function createApp(deps) {
|
|
|
47633
48364
|
uuidSchema.parse(c.req.param("id")),
|
|
47634
48365
|
await body(
|
|
47635
48366
|
c,
|
|
47636
|
-
|
|
47637
|
-
operationId:
|
|
47638
|
-
expectedVersion:
|
|
47639
|
-
text:
|
|
48367
|
+
z27.object({
|
|
48368
|
+
operationId: z27.uuid(),
|
|
48369
|
+
expectedVersion: z27.number().int().min(0),
|
|
48370
|
+
text: z27.string().max(6e3)
|
|
47640
48371
|
}).strict()
|
|
47641
48372
|
)
|
|
47642
48373
|
)
|
|
@@ -47789,7 +48520,7 @@ function createApp(deps) {
|
|
|
47789
48520
|
})
|
|
47790
48521
|
);
|
|
47791
48522
|
app.post("/v1/connect/:id/cancel", async (c) => {
|
|
47792
|
-
await body(c,
|
|
48523
|
+
await body(c, z27.object({}).strict());
|
|
47793
48524
|
return c.json({
|
|
47794
48525
|
success: true,
|
|
47795
48526
|
data: await setup.cancel(
|
|
@@ -47799,7 +48530,7 @@ function createApp(deps) {
|
|
|
47799
48530
|
});
|
|
47800
48531
|
});
|
|
47801
48532
|
app.post("/v1/browser/connect", async (c) => {
|
|
47802
|
-
await body(c,
|
|
48533
|
+
await body(c, z27.object({}).strict());
|
|
47803
48534
|
const principal = c.get("principal");
|
|
47804
48535
|
const identity = await service.me(principal);
|
|
47805
48536
|
const approval = new URL("/app/connections", deps.siteUrl);
|
|
@@ -47832,9 +48563,9 @@ function createApp(deps) {
|
|
|
47832
48563
|
c.get("principal"),
|
|
47833
48564
|
await body(
|
|
47834
48565
|
c,
|
|
47835
|
-
|
|
47836
|
-
policy:
|
|
47837
|
-
accepted:
|
|
48566
|
+
z27.object({
|
|
48567
|
+
policy: z27.string().min(1).max(100),
|
|
48568
|
+
accepted: z27.boolean()
|
|
47838
48569
|
}).strict()
|
|
47839
48570
|
)
|
|
47840
48571
|
)
|
|
@@ -47864,7 +48595,7 @@ function createApp(deps) {
|
|
|
47864
48595
|
})
|
|
47865
48596
|
);
|
|
47866
48597
|
app.post("/v1/browser/writing/requests/:id/cancel", async (c) => {
|
|
47867
|
-
await body(c,
|
|
48598
|
+
await body(c, z27.object({}).strict());
|
|
47868
48599
|
return c.json({
|
|
47869
48600
|
success: true,
|
|
47870
48601
|
data: await writing.cancel(
|
|
@@ -47899,7 +48630,7 @@ function createApp(deps) {
|
|
|
47899
48630
|
success: true,
|
|
47900
48631
|
data: await service.projects(
|
|
47901
48632
|
c.get("principal"),
|
|
47902
|
-
|
|
48633
|
+
z27.enum(["active", "archived"]).parse(c.req.query("status") ?? "active")
|
|
47903
48634
|
)
|
|
47904
48635
|
})
|
|
47905
48636
|
);
|
|
@@ -48000,7 +48731,7 @@ function createApp(deps) {
|
|
|
48000
48731
|
app.post("/v1/models/test", async (c) => {
|
|
48001
48732
|
const input = await body(
|
|
48002
48733
|
c,
|
|
48003
|
-
|
|
48734
|
+
z27.object({ role: z27.enum(["embedding", "decision", "generation"]) }).strict()
|
|
48004
48735
|
);
|
|
48005
48736
|
if (!deps.models)
|
|
48006
48737
|
throw new GroveError(
|
|
@@ -48048,7 +48779,7 @@ function createApp(deps) {
|
|
|
48048
48779
|
app.post("/v1/memories", async (c) => {
|
|
48049
48780
|
const input = await mutation(
|
|
48050
48781
|
c,
|
|
48051
|
-
|
|
48782
|
+
z27.union([rememberSchema, memoryUpdateSchema])
|
|
48052
48783
|
);
|
|
48053
48784
|
return c.json({
|
|
48054
48785
|
success: true,
|
|
@@ -48213,14 +48944,14 @@ function createApp(deps) {
|
|
|
48213
48944
|
data: await service.sourceRevision(
|
|
48214
48945
|
c.get("principal"),
|
|
48215
48946
|
uuidSchema.parse(c.req.param("id")),
|
|
48216
|
-
|
|
48947
|
+
z27.coerce.number().int().positive().max(2147483647).parse(c.req.param("version"))
|
|
48217
48948
|
)
|
|
48218
48949
|
})
|
|
48219
48950
|
);
|
|
48220
48951
|
app.post("/v1/memories/:id/reprocess", async (c) => {
|
|
48221
48952
|
const input = await body(
|
|
48222
48953
|
c,
|
|
48223
|
-
|
|
48954
|
+
z27.object({ expectedVersion: z27.number().int().positive() }).strict()
|
|
48224
48955
|
);
|
|
48225
48956
|
return c.json({
|
|
48226
48957
|
success: true,
|
|
@@ -48324,7 +49055,7 @@ function createApp(deps) {
|
|
|
48324
49055
|
success: true,
|
|
48325
49056
|
data: await service.conversations.list(
|
|
48326
49057
|
c.get("principal"),
|
|
48327
|
-
|
|
49058
|
+
z27.uuid().optional().parse(c.req.query("after"))
|
|
48328
49059
|
)
|
|
48329
49060
|
})
|
|
48330
49061
|
);
|
|
@@ -48371,8 +49102,8 @@ function createApp(deps) {
|
|
|
48371
49102
|
})
|
|
48372
49103
|
);
|
|
48373
49104
|
app.post("/v1/conversations/:id/turns/:turnId/:action", async (c) => {
|
|
48374
|
-
const action =
|
|
48375
|
-
await body(c,
|
|
49105
|
+
const action = z27.enum(["apply", "undo"]).parse(c.req.param("action"));
|
|
49106
|
+
await body(c, z27.object({}).strict());
|
|
48376
49107
|
return c.json({
|
|
48377
49108
|
success: true,
|
|
48378
49109
|
data: await service.conversations.apply(
|
|
@@ -48462,7 +49193,7 @@ function createApp(deps) {
|
|
|
48462
49193
|
app.post("/v1/account/delete", async (c) => {
|
|
48463
49194
|
await body(
|
|
48464
49195
|
c,
|
|
48465
|
-
|
|
49196
|
+
z27.object({ confirm: z27.literal("delete my account") }).strict()
|
|
48466
49197
|
);
|
|
48467
49198
|
return c.json(
|
|
48468
49199
|
{ success: true, data: await service.deleteAccount(c.get("principal")) },
|
|
@@ -48511,7 +49242,7 @@ function createApp(deps) {
|
|
|
48511
49242
|
success: true,
|
|
48512
49243
|
data: await tasks.list(
|
|
48513
49244
|
c.get("principal"),
|
|
48514
|
-
|
|
49245
|
+
z27.uuid().optional().parse(c.req.query("projectId"))
|
|
48515
49246
|
)
|
|
48516
49247
|
})
|
|
48517
49248
|
);
|
|
@@ -48631,6 +49362,7 @@ init_define_GROVE_TELEMETRY();
|
|
|
48631
49362
|
import { createClerkClient as createClerkClient2 } from "@clerk/backend";
|
|
48632
49363
|
import { TokenVerificationError } from "@clerk/backend/errors";
|
|
48633
49364
|
import { createRemoteJWKSet, decodeJwt, jwtVerify, errors } from "jose";
|
|
49365
|
+
init_contracts();
|
|
48634
49366
|
var unauthorized = () => new GroveError("unauthorized", "Sign in to Grove", 401);
|
|
48635
49367
|
function clerkVerifier(env) {
|
|
48636
49368
|
const jwks = createRemoteJWKSet(
|
|
@@ -48787,53 +49519,53 @@ init_define_GROVE_TELEMETRY();
|
|
|
48787
49519
|
|
|
48788
49520
|
// lib/environment/src/index.ts
|
|
48789
49521
|
init_define_GROVE_TELEMETRY();
|
|
48790
|
-
import { z as
|
|
48791
|
-
var origin =
|
|
49522
|
+
import { z as z28 } from "zod";
|
|
49523
|
+
var origin = z28.url().transform((value, ctx) => {
|
|
48792
49524
|
const url = new URL(value);
|
|
48793
49525
|
if (url.username || url.password || url.search || url.hash || url.pathname !== "/" || url.protocol !== "https:" && !(url.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname))) {
|
|
48794
49526
|
ctx.addIssue({
|
|
48795
49527
|
code: "custom",
|
|
48796
49528
|
message: "Use an HTTPS origin (HTTP is allowed on loopback)"
|
|
48797
49529
|
});
|
|
48798
|
-
return
|
|
49530
|
+
return z28.NEVER;
|
|
48799
49531
|
}
|
|
48800
49532
|
return url.origin;
|
|
48801
49533
|
});
|
|
48802
|
-
var allowance = (value) =>
|
|
48803
|
-
var serverSchema =
|
|
48804
|
-
NODE_ENV:
|
|
48805
|
-
PORT:
|
|
48806
|
-
DATABASE_URL:
|
|
48807
|
-
DATABASE_SSL:
|
|
48808
|
-
DATABASE_POOL_MAX:
|
|
48809
|
-
DATABASE_ACQUIRE_TIMEOUT_MS:
|
|
48810
|
-
DATABASE_STATEMENT_TIMEOUT_MS:
|
|
48811
|
-
API_MAX_IN_FLIGHT:
|
|
48812
|
-
API_MAX_QUEUED:
|
|
48813
|
-
API_QUEUE_TIMEOUT_MS:
|
|
48814
|
-
API_REQUEST_TIMEOUT_MS:
|
|
48815
|
-
API_INTERACTIVE_CONCURRENCY:
|
|
48816
|
-
API_INTERACTIVE_TIMEOUT_MS:
|
|
49534
|
+
var allowance = (value) => z28.coerce.number().int().min(0).max(1e9).default(value);
|
|
49535
|
+
var serverSchema = z28.object({
|
|
49536
|
+
NODE_ENV: z28.enum(["development", "test", "production"]).default("development"),
|
|
49537
|
+
PORT: z28.coerce.number().int().min(1).max(65535).default(26080),
|
|
49538
|
+
DATABASE_URL: z28.string().min(1),
|
|
49539
|
+
DATABASE_SSL: z28.enum(["require", "disable"]).default("disable"),
|
|
49540
|
+
DATABASE_POOL_MAX: z28.coerce.number().int().min(1).max(64).default(8),
|
|
49541
|
+
DATABASE_ACQUIRE_TIMEOUT_MS: z28.coerce.number().int().min(100).max(3e4).default(2e3),
|
|
49542
|
+
DATABASE_STATEMENT_TIMEOUT_MS: z28.coerce.number().int().min(100).max(3e4).default(1e4),
|
|
49543
|
+
API_MAX_IN_FLIGHT: z28.coerce.number().int().min(1).max(256).default(32),
|
|
49544
|
+
API_MAX_QUEUED: z28.coerce.number().int().min(0).max(256).default(32),
|
|
49545
|
+
API_QUEUE_TIMEOUT_MS: z28.coerce.number().int().min(1).max(5e3).default(250),
|
|
49546
|
+
API_REQUEST_TIMEOUT_MS: z28.coerce.number().int().min(100).max(6e4).default(1e4),
|
|
49547
|
+
API_INTERACTIVE_CONCURRENCY: z28.coerce.number().int().min(1).max(32).default(4),
|
|
49548
|
+
API_INTERACTIVE_TIMEOUT_MS: z28.coerce.number().int().min(100).max(18e4).default(9e4),
|
|
48817
49549
|
API_ORIGIN: origin,
|
|
48818
49550
|
SITE_URL: origin,
|
|
48819
49551
|
// Public ownership proof, never an account credential. Empty values are omitted below.
|
|
48820
|
-
OPENAI_APPS_CHALLENGE:
|
|
49552
|
+
OPENAI_APPS_CHALLENGE: z28.string().min(1).max(512).refine(
|
|
48821
49553
|
(value) => !/\s/.test(value),
|
|
48822
49554
|
"Use the exact non-whitespace verification token"
|
|
48823
49555
|
).optional(),
|
|
48824
|
-
CLERK_PUBLISHABLE_KEY:
|
|
48825
|
-
CLERK_SECRET_KEY:
|
|
49556
|
+
CLERK_PUBLISHABLE_KEY: z28.string().startsWith("pk_"),
|
|
49557
|
+
CLERK_SECRET_KEY: z28.string().startsWith("sk_"),
|
|
48826
49558
|
CLERK_ISSUER: origin,
|
|
48827
|
-
CLERK_WEBHOOK_SIGNING_SECRET:
|
|
48828
|
-
GROVE_EDITION:
|
|
48829
|
-
BILLING_CONFIGURED:
|
|
48830
|
-
FLAGS:
|
|
48831
|
-
STRIPE_SECRET_KEY:
|
|
48832
|
-
STRIPE_WEBHOOK_SECRET:
|
|
48833
|
-
STRIPE_PRO_PRODUCT_ID:
|
|
48834
|
-
STRIPE_PORTAL_CONFIGURATION_ID:
|
|
48835
|
-
STRIPE_PRO_MONTHLY_PRICE_ID:
|
|
48836
|
-
STRIPE_PRO_YEARLY_PRICE_ID:
|
|
49559
|
+
CLERK_WEBHOOK_SIGNING_SECRET: z28.string().min(1),
|
|
49560
|
+
GROVE_EDITION: z28.enum(["self-hosted", "cloud"]).default("self-hosted"),
|
|
49561
|
+
BILLING_CONFIGURED: z28.enum(["true", "false"]).default("false").transform((value) => value === "true"),
|
|
49562
|
+
FLAGS: z28.string().min(1).optional(),
|
|
49563
|
+
STRIPE_SECRET_KEY: z28.string().regex(/^(sk|rk)_(test|live)_/).optional(),
|
|
49564
|
+
STRIPE_WEBHOOK_SECRET: z28.string().startsWith("whsec_").optional(),
|
|
49565
|
+
STRIPE_PRO_PRODUCT_ID: z28.string().startsWith("prod_").optional(),
|
|
49566
|
+
STRIPE_PORTAL_CONFIGURATION_ID: z28.string().startsWith("bpc_").optional(),
|
|
49567
|
+
STRIPE_PRO_MONTHLY_PRICE_ID: z28.string().startsWith("price_").optional(),
|
|
49568
|
+
STRIPE_PRO_YEARLY_PRICE_ID: z28.string().startsWith("price_").optional(),
|
|
48837
49569
|
BILLING_FREE_GENERATION_DAILY: allowance(
|
|
48838
49570
|
billingLimits.free.generation.daily
|
|
48839
49571
|
),
|
|
@@ -48868,58 +49600,60 @@ var serverSchema = z27.object({
|
|
|
48868
49600
|
resourceLimits.free.organization
|
|
48869
49601
|
),
|
|
48870
49602
|
BILLING_FREE_ASSISTANCE_MONTHLY: allowance(resourceLimits.free.assistance),
|
|
49603
|
+
BILLING_FREE_WRITING_MONTHLY: allowance(resourceLimits.free.writing),
|
|
48871
49604
|
BILLING_PRO_NOTES: allowance(resourceLimits.pro.notes),
|
|
48872
49605
|
BILLING_PRO_NOTEBOOKS: allowance(resourceLimits.pro.notebooks),
|
|
48873
49606
|
BILLING_PRO_RECALL_MONTHLY: allowance(resourceLimits.pro.recall),
|
|
48874
49607
|
BILLING_PRO_ASK_MONTHLY: allowance(resourceLimits.pro.ask),
|
|
48875
49608
|
BILLING_PRO_ORGANIZATION_MONTHLY: allowance(resourceLimits.pro.organization),
|
|
48876
49609
|
BILLING_PRO_ASSISTANCE_MONTHLY: allowance(resourceLimits.pro.assistance),
|
|
49610
|
+
BILLING_PRO_WRITING_MONTHLY: allowance(resourceLimits.pro.writing),
|
|
48877
49611
|
// Reject old deployment settings instead of silently treating characters as time.
|
|
48878
|
-
BILLING_FREE_SYNTHESIS_MONTHLY_CHARACTERS:
|
|
48879
|
-
BILLING_PRO_SYNTHESIS_MONTHLY_CHARACTERS:
|
|
48880
|
-
EMBEDDING_MODE:
|
|
48881
|
-
EMBEDDING_CACHE:
|
|
48882
|
-
EMBEDDING_URL:
|
|
48883
|
-
EMBEDDING_MODEL:
|
|
48884
|
-
EMBEDDING_API_KEY:
|
|
48885
|
-
EMBEDDING_DIMENSIONS:
|
|
48886
|
-
EMBEDDING_QUERY_PREFIX:
|
|
48887
|
-
EMBEDDING_DOCUMENT_PREFIX:
|
|
48888
|
-
EMBEDDING_DISTANCE_THRESHOLD:
|
|
48889
|
-
DECISION_PROVIDER:
|
|
48890
|
-
DECISION_URL:
|
|
48891
|
-
DECISION_MODEL:
|
|
48892
|
-
DECISION_API_KEY:
|
|
48893
|
-
DECISION_PATH:
|
|
48894
|
-
GENERATION_PROVIDER:
|
|
48895
|
-
GENERATION_URL:
|
|
48896
|
-
GENERATION_MODEL:
|
|
48897
|
-
GENERATION_API_KEY:
|
|
48898
|
-
GENERATION_OUTPUT_FORMAT:
|
|
48899
|
-
GENERATION_REASONING_EFFORT:
|
|
48900
|
-
GENERATION_MAX_OUTPUT_TOKENS:
|
|
48901
|
-
DEEPINFRA_API_KEY:
|
|
48902
|
-
MINIMAX_API_KEY:
|
|
48903
|
-
OPENAI_API_KEY:
|
|
48904
|
-
SPEECH_ENABLED:
|
|
48905
|
-
TTS_VOICE:
|
|
48906
|
-
MINIMAX_TTS_ENABLED:
|
|
48907
|
-
SPEECH_PROVIDER_CONCURRENCY:
|
|
48908
|
-
EXA_API_KEY:
|
|
48909
|
-
TAVILY_API_KEY:
|
|
48910
|
-
RESEARCH_DAILY_CALL_LIMIT:
|
|
48911
|
-
RESEARCH_MONTHLY_BUDGET_USD:
|
|
48912
|
-
MODEL_ADMIN_SUBJECTS:
|
|
48913
|
-
MODEL_SETTINGS_KEY:
|
|
48914
|
-
AI_DAILY_REQUEST_LIMIT:
|
|
48915
|
-
AI_CONCURRENCY:
|
|
48916
|
-
INDEXING_CONCURRENCY:
|
|
48917
|
-
EMAIL_CONCURRENCY:
|
|
48918
|
-
MAINTENANCE_CONCURRENCY:
|
|
48919
|
-
BULK_CONCURRENCY:
|
|
48920
|
-
JOB_ACCOUNT_CONCURRENCY:
|
|
48921
|
-
JOB_PROVIDER_CONCURRENCY:
|
|
48922
|
-
WORKER_LANES:
|
|
49612
|
+
BILLING_FREE_SYNTHESIS_MONTHLY_CHARACTERS: z28.string().optional(),
|
|
49613
|
+
BILLING_PRO_SYNTHESIS_MONTHLY_CHARACTERS: z28.string().optional(),
|
|
49614
|
+
EMBEDDING_MODE: z28.enum(["local", "remote", "disabled"]).optional(),
|
|
49615
|
+
EMBEDDING_CACHE: z28.string().default("./data/models"),
|
|
49616
|
+
EMBEDDING_URL: z28.string().optional(),
|
|
49617
|
+
EMBEDDING_MODEL: z28.string().optional(),
|
|
49618
|
+
EMBEDDING_API_KEY: z28.string().optional(),
|
|
49619
|
+
EMBEDDING_DIMENSIONS: z28.coerce.number().int().min(32).max(16e3).optional(),
|
|
49620
|
+
EMBEDDING_QUERY_PREFIX: z28.string().optional(),
|
|
49621
|
+
EMBEDDING_DOCUMENT_PREFIX: z28.string().optional(),
|
|
49622
|
+
EMBEDDING_DISTANCE_THRESHOLD: z28.coerce.number().min(0).max(2).optional(),
|
|
49623
|
+
DECISION_PROVIDER: z28.enum(["system-one", "disabled"]).default("disabled"),
|
|
49624
|
+
DECISION_URL: z28.string().optional(),
|
|
49625
|
+
DECISION_MODEL: z28.string().optional(),
|
|
49626
|
+
DECISION_API_KEY: z28.string().optional(),
|
|
49627
|
+
DECISION_PATH: z28.enum(["/decisions", "/systemone"]).default("/decisions"),
|
|
49628
|
+
GENERATION_PROVIDER: z28.enum(["minimax", "openai-compatible", "disabled"]).default("disabled"),
|
|
49629
|
+
GENERATION_URL: z28.string().optional(),
|
|
49630
|
+
GENERATION_MODEL: z28.string().optional(),
|
|
49631
|
+
GENERATION_API_KEY: z28.string().optional(),
|
|
49632
|
+
GENERATION_OUTPUT_FORMAT: z28.enum(["tool", "json-schema", "json"]).default("tool"),
|
|
49633
|
+
GENERATION_REASONING_EFFORT: z28.enum(["low", "medium", "high", "omit"]).default("low"),
|
|
49634
|
+
GENERATION_MAX_OUTPUT_TOKENS: z28.coerce.number().int().min(256).max(16384).default(4096),
|
|
49635
|
+
DEEPINFRA_API_KEY: z28.string().optional(),
|
|
49636
|
+
MINIMAX_API_KEY: z28.string().optional(),
|
|
49637
|
+
OPENAI_API_KEY: z28.string().optional(),
|
|
49638
|
+
SPEECH_ENABLED: z28.enum(["true", "false"]).default("false").transform((value) => value === "true"),
|
|
49639
|
+
TTS_VOICE: z28.enum(["alloy", "echo", "fable", "onyx", "nova", "shimmer"]).default("alloy"),
|
|
49640
|
+
MINIMAX_TTS_ENABLED: z28.enum(["true", "false"]).default("false").transform((value) => value === "true"),
|
|
49641
|
+
SPEECH_PROVIDER_CONCURRENCY: z28.coerce.number().int().min(1).max(16).default(2),
|
|
49642
|
+
EXA_API_KEY: z28.string().optional(),
|
|
49643
|
+
TAVILY_API_KEY: z28.string().optional(),
|
|
49644
|
+
RESEARCH_DAILY_CALL_LIMIT: z28.coerce.number().int().min(1).max(1e4).default(20),
|
|
49645
|
+
RESEARCH_MONTHLY_BUDGET_USD: z28.coerce.number().min(0).max(1e5).default(100),
|
|
49646
|
+
MODEL_ADMIN_SUBJECTS: z28.string().default(""),
|
|
49647
|
+
MODEL_SETTINGS_KEY: z28.string().regex(/^[0-9a-f]{64}$/i).optional(),
|
|
49648
|
+
AI_DAILY_REQUEST_LIMIT: z28.coerce.number().int().min(1).max(1e6).default(2e3),
|
|
49649
|
+
AI_CONCURRENCY: z28.coerce.number().int().min(1).max(32).default(4),
|
|
49650
|
+
INDEXING_CONCURRENCY: z28.coerce.number().int().min(0).max(32).default(2),
|
|
49651
|
+
EMAIL_CONCURRENCY: z28.coerce.number().int().min(0).max(8).default(1),
|
|
49652
|
+
MAINTENANCE_CONCURRENCY: z28.coerce.number().int().min(0).max(8).default(1),
|
|
49653
|
+
BULK_CONCURRENCY: z28.coerce.number().int().min(0).max(8).default(1),
|
|
49654
|
+
JOB_ACCOUNT_CONCURRENCY: z28.coerce.number().int().min(1).max(8).default(2),
|
|
49655
|
+
JOB_PROVIDER_CONCURRENCY: z28.coerce.number().int().min(1).max(128).default(8),
|
|
49656
|
+
WORKER_LANES: z28.string().default("indexing,enrichment,email,maintenance,bulk").refine(
|
|
48923
49657
|
(value) => value.split(",").every(
|
|
48924
49658
|
(lane) => ["indexing", "enrichment", "email", "maintenance", "bulk"].includes(
|
|
48925
49659
|
lane
|
|
@@ -48927,38 +49661,38 @@ var serverSchema = z27.object({
|
|
|
48927
49661
|
),
|
|
48928
49662
|
"Unknown worker lane"
|
|
48929
49663
|
),
|
|
48930
|
-
WORKER_LEGACY_QUEUE:
|
|
48931
|
-
EXPORT_STORAGE:
|
|
49664
|
+
WORKER_LEGACY_QUEUE: z28.enum(["true", "false"]).default("true").transform((value) => value === "true"),
|
|
49665
|
+
EXPORT_STORAGE: z28.enum(["disabled", "local", "s3"]).optional(),
|
|
48932
49666
|
// Explicit opt-in until the revision-scoped media API is available.
|
|
48933
|
-
MEDIA_STORAGE:
|
|
48934
|
-
MEDIA_DIRECTORY:
|
|
48935
|
-
MEDIA_S3_ENDPOINT:
|
|
48936
|
-
MEDIA_S3_REGION:
|
|
48937
|
-
MEDIA_S3_BUCKET:
|
|
48938
|
-
MEDIA_S3_ACCESS_KEY_ID:
|
|
48939
|
-
MEDIA_S3_SECRET_ACCESS_KEY:
|
|
49667
|
+
MEDIA_STORAGE: z28.enum(["disabled", "local", "s3"]).default("disabled"),
|
|
49668
|
+
MEDIA_DIRECTORY: z28.string().default("./data/media"),
|
|
49669
|
+
MEDIA_S3_ENDPOINT: z28.url().optional(),
|
|
49670
|
+
MEDIA_S3_REGION: z28.string().default("us-east-1"),
|
|
49671
|
+
MEDIA_S3_BUCKET: z28.string().optional(),
|
|
49672
|
+
MEDIA_S3_ACCESS_KEY_ID: z28.string().optional(),
|
|
49673
|
+
MEDIA_S3_SECRET_ACCESS_KEY: z28.string().optional(),
|
|
48940
49674
|
// Exact endpoint/bucket receipt from an operator lifecycle/ACL inspection.
|
|
48941
49675
|
// Spaces scoped keys cannot read these settings; never use an account-wide key in runtime.
|
|
48942
|
-
MEDIA_S3_LIFECYCLE_VERIFIED_FOR:
|
|
48943
|
-
MEDIA_S3_PATH_STYLE:
|
|
48944
|
-
EXPORT_DIRECTORY:
|
|
48945
|
-
EXPORT_S3_ENDPOINT:
|
|
48946
|
-
EXPORT_S3_REGION:
|
|
48947
|
-
EXPORT_S3_BUCKET:
|
|
48948
|
-
EXPORT_S3_ACCESS_KEY_ID:
|
|
48949
|
-
EXPORT_S3_SECRET_ACCESS_KEY:
|
|
48950
|
-
EXPORT_S3_PATH_STYLE:
|
|
48951
|
-
AMQP_URL:
|
|
49676
|
+
MEDIA_S3_LIFECYCLE_VERIFIED_FOR: z28.string().optional(),
|
|
49677
|
+
MEDIA_S3_PATH_STYLE: z28.enum(["true", "false"]).default("false").transform((value) => value === "true"),
|
|
49678
|
+
EXPORT_DIRECTORY: z28.string().default("./data/exports"),
|
|
49679
|
+
EXPORT_S3_ENDPOINT: z28.url().optional(),
|
|
49680
|
+
EXPORT_S3_REGION: z28.string().default("us-east-1"),
|
|
49681
|
+
EXPORT_S3_BUCKET: z28.string().optional(),
|
|
49682
|
+
EXPORT_S3_ACCESS_KEY_ID: z28.string().optional(),
|
|
49683
|
+
EXPORT_S3_SECRET_ACCESS_KEY: z28.string().optional(),
|
|
49684
|
+
EXPORT_S3_PATH_STYLE: z28.enum(["true", "false"]).default("false").transform((value) => value === "true"),
|
|
49685
|
+
AMQP_URL: z28.url().refine(
|
|
48952
49686
|
(value) => new URL(value).protocol === "amqps:",
|
|
48953
49687
|
"Use TLS for the job broker"
|
|
48954
49688
|
).optional(),
|
|
48955
|
-
ORGANIZATION_INTERVAL_SECONDS:
|
|
48956
|
-
RESEND_API_KEY:
|
|
48957
|
-
EMAIL_FROM:
|
|
48958
|
-
CURSOR_SECRET:
|
|
48959
|
-
WRITING_STAGING_KEY:
|
|
48960
|
-
WRITING_PROVIDER_NOTICE:
|
|
48961
|
-
SHARE_LINK_KEY:
|
|
49689
|
+
ORGANIZATION_INTERVAL_SECONDS: z28.coerce.number().int().min(60).max(86400).default(900),
|
|
49690
|
+
RESEND_API_KEY: z28.string().startsWith("re_").optional(),
|
|
49691
|
+
EMAIL_FROM: z28.string().email().default("notifications@mail.usegrove.cloud"),
|
|
49692
|
+
CURSOR_SECRET: z28.string().min(32),
|
|
49693
|
+
WRITING_STAGING_KEY: z28.string().regex(/^[0-9a-f]{64}$/i).optional(),
|
|
49694
|
+
WRITING_PROVIDER_NOTICE: z28.string().trim().min(20).max(1e3).optional(),
|
|
49695
|
+
SHARE_LINK_KEY: z28.string().regex(/^[0-9a-f]{64}$/i).optional()
|
|
48962
49696
|
});
|
|
48963
49697
|
var serverEnvironmentSchema = serverSchema.superRefine((env, ctx) => {
|
|
48964
49698
|
if (env.WRITING_STAGING_KEY && !env.WRITING_PROVIDER_NOTICE)
|
|
@@ -49013,6 +49747,7 @@ import { createClient as createClient2 } from "@vercel/flags-core";
|
|
|
49013
49747
|
init_define_GROVE_TELEMETRY();
|
|
49014
49748
|
import { createCipheriv as createCipheriv3, createDecipheriv as createDecipheriv3, randomBytes as randomBytes4 } from "node:crypto";
|
|
49015
49749
|
init_models();
|
|
49750
|
+
init_contracts();
|
|
49016
49751
|
|
|
49017
49752
|
// packages/api/src/embedding.ts
|
|
49018
49753
|
init_define_GROVE_TELEMETRY();
|
|
@@ -49332,7 +50067,7 @@ function createBilling(env, service) {
|
|
|
49332
50067
|
const enabled = async (subject) => {
|
|
49333
50068
|
const result = await client.evaluate(
|
|
49334
50069
|
billingFlagKey,
|
|
49335
|
-
|
|
50070
|
+
true,
|
|
49336
50071
|
{ user: { id: subject } }
|
|
49337
50072
|
);
|
|
49338
50073
|
return result.value === true;
|
|
@@ -49366,6 +50101,7 @@ function createBilling(env, service) {
|
|
|
49366
50101
|
ask: env[`BILLING_${tier}_ASK_MONTHLY`],
|
|
49367
50102
|
organization: env[`BILLING_${tier}_ORGANIZATION_MONTHLY`],
|
|
49368
50103
|
assistance: env[`BILLING_${tier}_ASSISTANCE_MONTHLY`],
|
|
50104
|
+
writing: env[`BILLING_${tier}_WRITING_MONTHLY`],
|
|
49369
50105
|
concurrency: resourceLimits.free.concurrency
|
|
49370
50106
|
});
|
|
49371
50107
|
configureBillingQuotas(service.db, {
|
|
@@ -49388,14 +50124,24 @@ function createBilling(env, service) {
|
|
|
49388
50124
|
proLimits: limits("PRO"),
|
|
49389
50125
|
proResources: resources("PRO"),
|
|
49390
50126
|
portalConfigurationId: env.STRIPE_PORTAL_CONFIGURATION_ID,
|
|
49391
|
-
pricing: env.STRIPE_PRO_PRODUCT_ID ?
|
|
49392
|
-
|
|
49393
|
-
|
|
49394
|
-
|
|
49395
|
-
|
|
49396
|
-
|
|
49397
|
-
|
|
49398
|
-
|
|
50127
|
+
pricing: env.STRIPE_PRO_PRODUCT_ID ? {
|
|
50128
|
+
month: new MonthlyPricing(
|
|
50129
|
+
stripe,
|
|
50130
|
+
env.STRIPE_PRO_PRODUCT_ID,
|
|
50131
|
+
async (subject) => {
|
|
50132
|
+
const result = await client.evaluate(billingPriceFlagKey, 19.99, { user: { id: subject } });
|
|
50133
|
+
return result.value;
|
|
50134
|
+
}
|
|
50135
|
+
),
|
|
50136
|
+
year: new YearlyPricing(
|
|
50137
|
+
stripe,
|
|
50138
|
+
env.STRIPE_PRO_PRODUCT_ID,
|
|
50139
|
+
async (subject) => {
|
|
50140
|
+
const result = await client.evaluate(billingPriceYearlyFlagKey, null, { user: { id: subject } });
|
|
50141
|
+
return result.value;
|
|
50142
|
+
}
|
|
50143
|
+
)
|
|
50144
|
+
} : void 0
|
|
49399
50145
|
});
|
|
49400
50146
|
service.beforeAccountDeletion = (trx, accountId) => billing2.cancelForDeletion(accountId, trx);
|
|
49401
50147
|
return { billing: billing2, close: () => client.shutdown() };
|
|
@@ -49546,6 +50292,7 @@ function createArtifacts(env) {
|
|
|
49546
50292
|
|
|
49547
50293
|
// packages/api/src/media-store.ts
|
|
49548
50294
|
init_define_GROVE_TELEMETRY();
|
|
50295
|
+
init_media();
|
|
49549
50296
|
import { constants as constants3 } from "node:fs";
|
|
49550
50297
|
import { link, lstat, mkdir as mkdir2, open as open2, realpath, unlink as unlink2 } from "node:fs/promises";
|
|
49551
50298
|
import { randomUUID as randomUUID19 } from "node:crypto";
|