@miniaxolotl/grove-server 1.11.23 → 1.11.28
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 +54 -1
- package/dist/bootstrap.js.map +4 -4
- package/dist/migrate.js +54 -1
- package/dist/migrate.js.map +4 -4
- package/dist/server.js +761 -290
- package/dist/server.js.map +4 -4
- package/dist/telemetry-build.json +1 -1
- package/dist/worker.js +265 -101
- package/dist/worker.js.map +4 -4
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -18,7 +18,7 @@ var __export = (target2, all2) => {
|
|
|
18
18
|
var define_GROVE_TELEMETRY_default;
|
|
19
19
|
var init_define_GROVE_TELEMETRY = __esm({
|
|
20
20
|
"<define:__GROVE_TELEMETRY__>"() {
|
|
21
|
-
define_GROVE_TELEMETRY_default = { enabled: true, revision: "
|
|
21
|
+
define_GROVE_TELEMETRY_default = { enabled: true, revision: "d6b98466a41776dca9beb1ab0d039dc1029d8b79", version: "1.11.28", 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
|
|
|
@@ -465,7 +465,7 @@ var init_share_durations = __esm({
|
|
|
465
465
|
});
|
|
466
466
|
|
|
467
467
|
// lib/shared/src/sharing.ts
|
|
468
|
-
import { z as
|
|
468
|
+
import { z as z24 } from "zod";
|
|
469
469
|
function sharedNoteTitle(content3) {
|
|
470
470
|
return noteTitle2(content3) || "Untitled note";
|
|
471
471
|
}
|
|
@@ -478,8 +478,8 @@ var init_sharing = __esm({
|
|
|
478
478
|
init_search();
|
|
479
479
|
init_limits();
|
|
480
480
|
init_share_durations();
|
|
481
|
-
shareTokenSchema =
|
|
482
|
-
shareDurationSchema =
|
|
481
|
+
shareTokenSchema = z24.string().regex(/^gsh_[A-Za-z0-9_-]{43}$/);
|
|
482
|
+
shareDurationSchema = z24.enum([
|
|
483
483
|
"1h",
|
|
484
484
|
"4h",
|
|
485
485
|
"1d",
|
|
@@ -487,45 +487,45 @@ var init_sharing = __esm({
|
|
|
487
487
|
"2w",
|
|
488
488
|
"1mo"
|
|
489
489
|
]);
|
|
490
|
-
shareMutationSchema =
|
|
490
|
+
shareMutationSchema = z24.object({
|
|
491
491
|
operationId: operationSchema,
|
|
492
|
-
expectedVersion:
|
|
492
|
+
expectedVersion: z24.number().int().positive()
|
|
493
493
|
}).strict();
|
|
494
494
|
shareEnableSchema = shareMutationSchema.extend({
|
|
495
|
-
expectedVersion:
|
|
496
|
-
expectedTargetVersion:
|
|
497
|
-
includeDescendants:
|
|
495
|
+
expectedVersion: z24.number().int().min(0),
|
|
496
|
+
expectedTargetVersion: z24.number().int().positive(),
|
|
497
|
+
includeDescendants: z24.boolean().default(false),
|
|
498
498
|
duration: shareDurationSchema.nullable().optional()
|
|
499
499
|
});
|
|
500
500
|
shareScopeSchema = shareMutationSchema.extend({
|
|
501
|
-
includeDescendants:
|
|
501
|
+
includeDescendants: z24.boolean().optional(),
|
|
502
502
|
duration: shareDurationSchema.nullable().optional()
|
|
503
503
|
}).refine(
|
|
504
504
|
(value) => value.includeDescendants !== void 0 || value.duration !== void 0,
|
|
505
505
|
"Choose a sharing setting to change"
|
|
506
506
|
);
|
|
507
|
-
publicShareQuerySchema =
|
|
508
|
-
cursor:
|
|
509
|
-
limit:
|
|
507
|
+
publicShareQuerySchema = z24.object({
|
|
508
|
+
cursor: z24.string().max(SHARE_CURSOR_MAX).optional(),
|
|
509
|
+
limit: z24.coerce.number().int().min(1).max(100).default(30)
|
|
510
510
|
}).strict();
|
|
511
|
-
notebook =
|
|
512
|
-
publicNoteSchema =
|
|
511
|
+
notebook = z24.object({ id: uuidSchema, name: z24.string() }).strict();
|
|
512
|
+
publicNoteSchema = z24.object({
|
|
513
513
|
id: uuidSchema,
|
|
514
|
-
title:
|
|
515
|
-
content:
|
|
516
|
-
updatedAt:
|
|
517
|
-
linkedNoteIds:
|
|
514
|
+
title: z24.string(),
|
|
515
|
+
content: z24.string(),
|
|
516
|
+
updatedAt: z24.string(),
|
|
517
|
+
linkedNoteIds: z24.array(uuidSchema)
|
|
518
518
|
}).strict();
|
|
519
|
-
publicShareSchema =
|
|
520
|
-
kind:
|
|
519
|
+
publicShareSchema = z24.object({
|
|
520
|
+
kind: z24.enum(["note", "notebook"]),
|
|
521
521
|
root: notebook,
|
|
522
522
|
notebook: notebook.nullable(),
|
|
523
523
|
note: publicNoteSchema.nullable(),
|
|
524
|
-
notebooks:
|
|
525
|
-
notes:
|
|
524
|
+
notebooks: z24.array(notebook),
|
|
525
|
+
notes: z24.array(
|
|
526
526
|
publicNoteSchema.pick({ id: true, title: true, updatedAt: true })
|
|
527
527
|
),
|
|
528
|
-
nextCursor:
|
|
528
|
+
nextCursor: z24.string().nullable()
|
|
529
529
|
}).strict();
|
|
530
530
|
}
|
|
531
531
|
});
|
|
@@ -536,7 +536,7 @@ __export(media_exports, {
|
|
|
536
536
|
MediaAttachments: () => MediaAttachments,
|
|
537
537
|
mediaDescriptor: () => mediaDescriptor
|
|
538
538
|
});
|
|
539
|
-
import { createHash as createHash18, randomUUID as
|
|
539
|
+
import { createHash as createHash18, randomUUID as randomUUID14 } from "node:crypto";
|
|
540
540
|
var missing8, conflict4, mediaDescriptor, MediaAttachments;
|
|
541
541
|
var init_media2 = __esm({
|
|
542
542
|
"lib/memory/src/media.ts"() {
|
|
@@ -590,7 +590,7 @@ var init_media2 = __esm({
|
|
|
590
590
|
const quota = await trx("accounts").where({ id: account.id }).first("mediaBytes", "mediaAttempts");
|
|
591
591
|
if (Number(quota.mediaBytes) + input.bytes > 1024 * 1024 * 1024 || quota.mediaAttempts >= 1e3)
|
|
592
592
|
throw new GroveError("media_quota", "Media storage limit reached", 429);
|
|
593
|
-
const leaseId =
|
|
593
|
+
const leaseId = randomUUID14(), objectKey = mediaObjectKey(account.id, input.id, leaseId);
|
|
594
594
|
const values = {
|
|
595
595
|
memoryId: input.memoryId,
|
|
596
596
|
bytes: input.bytes,
|
|
@@ -2621,6 +2621,32 @@ var dailyNotes = {
|
|
|
2621
2621
|
}
|
|
2622
2622
|
};
|
|
2623
2623
|
|
|
2624
|
+
// lib/database/src/cache-retention-migration.ts
|
|
2625
|
+
init_define_GROVE_TELEMETRY();
|
|
2626
|
+
var cacheRetention = {
|
|
2627
|
+
name: "20261118_043_cache_retention",
|
|
2628
|
+
async up(db) {
|
|
2629
|
+
const { rows } = await db.raw(
|
|
2630
|
+
"SELECT pg_get_functiondef('grove_schedule_cleanup()'::regprocedure) AS definition"
|
|
2631
|
+
);
|
|
2632
|
+
const definition2 = rows[0].definition;
|
|
2633
|
+
const anchor = "OR EXISTS(SELECT 1 FROM rate_buckets r";
|
|
2634
|
+
if (definition2.split(anchor).length !== 2)
|
|
2635
|
+
throw new Error("Unsupported retention scheduler baseline");
|
|
2636
|
+
await db.raw(
|
|
2637
|
+
definition2.replace(
|
|
2638
|
+
anchor,
|
|
2639
|
+
`OR EXISTS(SELECT 1 FROM ai_cache c WHERE c.account_id=a.id AND c.expires_at<=now())
|
|
2640
|
+
OR EXISTS(SELECT 1 FROM ai_provider_backoff b WHERE b.account_id=a.id AND b.retry_at<now()-interval '1 day')
|
|
2641
|
+
${anchor}`
|
|
2642
|
+
)
|
|
2643
|
+
);
|
|
2644
|
+
},
|
|
2645
|
+
async down() {
|
|
2646
|
+
throw new Error("Use a forward migration");
|
|
2647
|
+
}
|
|
2648
|
+
};
|
|
2649
|
+
|
|
2624
2650
|
// lib/database/src/writing-allowance-migration.ts
|
|
2625
2651
|
init_define_GROVE_TELEMETRY();
|
|
2626
2652
|
var writingAllowance = {
|
|
@@ -4849,6 +4875,33 @@ var aiPreferences = {
|
|
|
4849
4875
|
}
|
|
4850
4876
|
};
|
|
4851
4877
|
|
|
4878
|
+
// lib/database/src/proofing-migration.ts
|
|
4879
|
+
init_define_GROVE_TELEMETRY();
|
|
4880
|
+
var proofingConsents = {
|
|
4881
|
+
name: "20261118_044_proofing_consent",
|
|
4882
|
+
async up(db) {
|
|
4883
|
+
await db.raw(`CREATE TABLE proofing_consents (
|
|
4884
|
+
account_id uuid NOT NULL REFERENCES accounts(id) ON DELETE CASCADE,
|
|
4885
|
+
scope text NOT NULL CHECK(scope='grove-note-editor'),
|
|
4886
|
+
version integer NOT NULL CHECK(version>0),
|
|
4887
|
+
generation uuid NOT NULL,
|
|
4888
|
+
automatic boolean NOT NULL,
|
|
4889
|
+
updated_at timestamptz NOT NULL DEFAULT now(),
|
|
4890
|
+
revoked_at timestamptz,
|
|
4891
|
+
CHECK(revoked_at IS NULL OR NOT automatic),
|
|
4892
|
+
PRIMARY KEY(account_id,scope)
|
|
4893
|
+
);
|
|
4894
|
+
ALTER TABLE proofing_consents ENABLE ROW LEVEL SECURITY;
|
|
4895
|
+
ALTER TABLE proofing_consents FORCE ROW LEVEL SECURITY;
|
|
4896
|
+
CREATE POLICY tenant ON proofing_consents USING(account_id=nullif(current_setting('grove.account_id',true),'')::uuid);
|
|
4897
|
+
GRANT SELECT, INSERT, UPDATE ON proofing_consents TO grove_runtime;
|
|
4898
|
+
GRANT SELECT, DELETE ON proofing_consents TO grove_worker;`);
|
|
4899
|
+
},
|
|
4900
|
+
async down() {
|
|
4901
|
+
throw new Error("Use a forward migration");
|
|
4902
|
+
}
|
|
4903
|
+
};
|
|
4904
|
+
|
|
4852
4905
|
// lib/database/src/queue-migration.ts
|
|
4853
4906
|
init_define_GROVE_TELEMETRY();
|
|
4854
4907
|
|
|
@@ -6361,7 +6414,9 @@ var migrations = [
|
|
|
6361
6414
|
nativeSharing,
|
|
6362
6415
|
billingTrial,
|
|
6363
6416
|
writingAllowance,
|
|
6364
|
-
dailyNotes
|
|
6417
|
+
dailyNotes,
|
|
6418
|
+
cacheRetention,
|
|
6419
|
+
proofingConsents
|
|
6365
6420
|
];
|
|
6366
6421
|
var migrationSource = {
|
|
6367
6422
|
getMigrations: async () => migrations,
|
|
@@ -6481,6 +6536,12 @@ async function probeDatabase(db) {
|
|
|
6481
6536
|
);
|
|
6482
6537
|
await db.raw("SELECT policy, version FROM writing_consents LIMIT 0");
|
|
6483
6538
|
await db.raw("SELECT connection_id FROM writing_cancellations LIMIT 0");
|
|
6539
|
+
await db.raw(
|
|
6540
|
+
"SELECT account_id, local_date, memory_id FROM daily_notes LIMIT 0"
|
|
6541
|
+
);
|
|
6542
|
+
await db.raw(
|
|
6543
|
+
"SELECT scope, version, generation, automatic, revoked_at FROM proofing_consents LIMIT 0"
|
|
6544
|
+
);
|
|
6484
6545
|
}
|
|
6485
6546
|
var MemoryModel = class extends Model {
|
|
6486
6547
|
static tableName = "memories";
|
|
@@ -6504,7 +6565,7 @@ var MemoryModel = class extends Model {
|
|
|
6504
6565
|
|
|
6505
6566
|
// packages/api/src/app.ts
|
|
6506
6567
|
init_define_GROVE_TELEMETRY();
|
|
6507
|
-
import { randomUUID as
|
|
6568
|
+
import { randomUUID as randomUUID19, createHash as createHash24 } from "node:crypto";
|
|
6508
6569
|
|
|
6509
6570
|
// lib/memory/src/index.ts
|
|
6510
6571
|
init_define_GROVE_TELEMETRY();
|
|
@@ -6512,7 +6573,7 @@ import {
|
|
|
6512
6573
|
createHash as createHash20,
|
|
6513
6574
|
createHmac as createHmac6,
|
|
6514
6575
|
randomBytes as randomBytes3,
|
|
6515
|
-
randomUUID as
|
|
6576
|
+
randomUUID as randomUUID15,
|
|
6516
6577
|
timingSafeEqual as timingSafeEqual5
|
|
6517
6578
|
} from "node:crypto";
|
|
6518
6579
|
|
|
@@ -21981,14 +22042,16 @@ async function owned2(trx, id2) {
|
|
|
21981
22042
|
return row;
|
|
21982
22043
|
}
|
|
21983
22044
|
async function expireDocumentDrafts(trx) {
|
|
21984
|
-
const
|
|
22045
|
+
const limit = 20;
|
|
22046
|
+
const expired = trx("document_import_batches").select("id").where("expiresAt", "<=", trx.fn.now()).where({ draftsCleared: false }).whereIn("status", ["uploading", "preparing", "ready", "cancelled"]).orderBy("id").limit(limit);
|
|
21985
22047
|
await trx("document_import_files").whereIn("batchId", expired).where({ originalReady: false }).whereNotNull("staging").update({ staging: null });
|
|
21986
22048
|
await trx("document_import_notes").whereIn("batchId", expired).whereNull("memoryId").whereNot("content", "[Expired import draft]").update({
|
|
21987
22049
|
content: "[Expired import draft]",
|
|
21988
22050
|
included: false,
|
|
21989
22051
|
suggestion: null
|
|
21990
22052
|
});
|
|
21991
|
-
await trx("document_import_batches").whereIn("id", expired).update({ draftsCleared: true });
|
|
22053
|
+
const processed = await trx("document_import_batches").whereIn("id", expired).update({ draftsCleared: true });
|
|
22054
|
+
return { processed, fullPage: processed === limit };
|
|
21992
22055
|
}
|
|
21993
22056
|
var DocumentImports = class {
|
|
21994
22057
|
constructor(service) {
|
|
@@ -22478,8 +22541,9 @@ var available = (q) => q.whereNull("removedAt").where(
|
|
|
22478
22541
|
(sub) => sub.where("accepted", true).orWhere("expiresAt", ">", q.client.raw("now()"))
|
|
22479
22542
|
);
|
|
22480
22543
|
async function expireConversationDocuments(trx) {
|
|
22481
|
-
const
|
|
22482
|
-
|
|
22544
|
+
const limit = 25;
|
|
22545
|
+
const docs = await trx("conversation_documents").where({ accepted: false }).whereNull("removedAt").where("expiresAt", "<=", trx.fn.now()).orderBy("id").limit(limit).select("id", "conversationId");
|
|
22546
|
+
if (!docs.length) return { processed: 0, fullPage: false };
|
|
22483
22547
|
await trx("conversation_document_chunks").whereIn(
|
|
22484
22548
|
"documentId",
|
|
22485
22549
|
docs.map((d) => d.id)
|
|
@@ -22497,6 +22561,7 @@ async function expireConversationDocuments(trx) {
|
|
|
22497
22561
|
"id",
|
|
22498
22562
|
docs.map((d) => d.conversationId)
|
|
22499
22563
|
).increment("documentsVersion", 1);
|
|
22564
|
+
return { processed: docs.length, fullPage: docs.length === limit };
|
|
22500
22565
|
}
|
|
22501
22566
|
async function documentSnapshot(trx, conversationId, query) {
|
|
22502
22567
|
const chat = await documentChat(trx, conversationId);
|
|
@@ -23167,20 +23232,20 @@ init_define_GROVE_TELEMETRY();
|
|
|
23167
23232
|
init_contracts();
|
|
23168
23233
|
async function resolveConversationContext(trx, scope, selection, query) {
|
|
23169
23234
|
if (!selection) return { sources: [], notebooks: [] };
|
|
23170
|
-
const
|
|
23235
|
+
const unavailable7 = () => new GroveError(
|
|
23171
23236
|
"context_unavailable",
|
|
23172
23237
|
"A selected source is unavailable in this conversation. Remove it or choose it again.",
|
|
23173
23238
|
409
|
|
23174
23239
|
);
|
|
23175
23240
|
const books = await trx("projects").whereIn("id", selection.notebooks).where({ status: "active" }).select("id", "version");
|
|
23176
23241
|
if (books.length !== selection.notebooks.length || books.some((book) => !inConversationScope(scope, book.id)))
|
|
23177
|
-
throw
|
|
23242
|
+
throw unavailable7();
|
|
23178
23243
|
const active4 = () => trx("memories").where({ status: "active" }).where(
|
|
23179
23244
|
(q) => q.whereNull("expiresAt").orWhere("expiresAt", ">", trx.fn.now())
|
|
23180
23245
|
);
|
|
23181
23246
|
const pins = await active4().whereIn("id", selection.notes).select("id", "version", "projectId");
|
|
23182
23247
|
if (pins.length !== selection.notes.length || pins.some((pin) => !inConversationScope(scope, pin.projectId)))
|
|
23183
|
-
throw
|
|
23248
|
+
throw unavailable7();
|
|
23184
23249
|
const members = active4().whereIn("projectId", selection.notebooks).whereNotIn("id", selection.notes);
|
|
23185
23250
|
const count2 = await members.clone().count("id as count").first();
|
|
23186
23251
|
const notebookEligible = Number(count2?.count ?? 0);
|
|
@@ -26220,6 +26285,7 @@ function cleanupHandlers(db, deleteIdentity, cancelBilling) {
|
|
|
26220
26285
|
return rows.length;
|
|
26221
26286
|
};
|
|
26222
26287
|
const count2 = await deleteBatch(table);
|
|
26288
|
+
const proofing = table === "notebook_expiries" ? await deleteBatch("proofing_consents") : 0;
|
|
26223
26289
|
const daily = table === "notebook_expiries" ? await deleteBatch("daily_notes") : 0;
|
|
26224
26290
|
const research = table === "inference_usage" ? await trx("research_account_usage").select("day").limit(batchSize) : [];
|
|
26225
26291
|
if (research.length)
|
|
@@ -26232,7 +26298,7 @@ function cleanupHandlers(db, deleteIdentity, cancelBilling) {
|
|
|
26232
26298
|
cursor: {
|
|
26233
26299
|
stage: count2 === batchSize || daily === batchSize || research.length === batchSize || cache === batchSize ? stage : stage + 1
|
|
26234
26300
|
},
|
|
26235
|
-
processed: Number(task.processed) + count2 + daily + research.length + cache
|
|
26301
|
+
processed: Number(task.processed) + count2 + daily + proofing + research.length + cache
|
|
26236
26302
|
};
|
|
26237
26303
|
});
|
|
26238
26304
|
return;
|
|
@@ -26262,8 +26328,8 @@ function cleanupHandlers(db, deleteIdentity, cancelBilling) {
|
|
|
26262
26328
|
const retention_cleanup = async (task, signal) => {
|
|
26263
26329
|
await taskTransaction(db, task, async (trx) => {
|
|
26264
26330
|
signal.throwIfAborted();
|
|
26265
|
-
await expireDocumentDrafts(trx);
|
|
26266
|
-
await expireConversationDocuments(trx);
|
|
26331
|
+
const drafts = await expireDocumentDrafts(trx);
|
|
26332
|
+
const uploads = await expireConversationDocuments(trx);
|
|
26267
26333
|
const writingExpired = await expireWriting(trx);
|
|
26268
26334
|
const expired = await trx("memories").where("purgeAt", "<=", trx.fn.now()).select("id").orderBy("id").limit(batchSize);
|
|
26269
26335
|
if (expired.length) {
|
|
@@ -26279,8 +26345,8 @@ function cleanupHandlers(db, deleteIdentity, cancelBilling) {
|
|
|
26279
26345
|
await trx("rate_buckets").whereIn("minute", buckets).delete();
|
|
26280
26346
|
const cache = await pruneCache(trx, true);
|
|
26281
26347
|
return {
|
|
26282
|
-
processed: Number(task.processed) + expired.length + cache + writingExpired,
|
|
26283
|
-
complete: expired.length < batchSize && buckets.length < batchSize && writingExpired < batchSize && cache < batchSize
|
|
26348
|
+
processed: Number(task.processed) + expired.length + cache + writingExpired + drafts.processed + uploads.processed,
|
|
26349
|
+
complete: !drafts.fullPage && !uploads.fullPage && expired.length < batchSize && buckets.length < batchSize && writingExpired < batchSize && cache < batchSize
|
|
26284
26350
|
};
|
|
26285
26351
|
});
|
|
26286
26352
|
};
|
|
@@ -26838,6 +26904,222 @@ var SpeechJobs = class {
|
|
|
26838
26904
|
}
|
|
26839
26905
|
};
|
|
26840
26906
|
|
|
26907
|
+
// lib/memory/src/proofing-consents.ts
|
|
26908
|
+
init_define_GROVE_TELEMETRY();
|
|
26909
|
+
init_contracts();
|
|
26910
|
+
import { randomUUID as randomUUID11 } from "node:crypto";
|
|
26911
|
+
|
|
26912
|
+
// lib/shared/src/proofing-contract.ts
|
|
26913
|
+
init_define_GROVE_TELEMETRY();
|
|
26914
|
+
import { z as z21 } from "zod";
|
|
26915
|
+
|
|
26916
|
+
// lib/shared/src/writing-settings.ts
|
|
26917
|
+
init_define_GROVE_TELEMETRY();
|
|
26918
|
+
import { z as z20 } from "zod";
|
|
26919
|
+
|
|
26920
|
+
// lib/shared/src/writing-markdown.ts
|
|
26921
|
+
init_define_GROVE_TELEMETRY();
|
|
26922
|
+
function projectWritingText(source3) {
|
|
26923
|
+
const ranges = [];
|
|
26924
|
+
const mark = (from, to) => {
|
|
26925
|
+
if (to > from) ranges.push({ from, to });
|
|
26926
|
+
};
|
|
26927
|
+
for (const match of source3.matchAll(/^(?: {4}|\t)[^\r\n]*/gm))
|
|
26928
|
+
mark(match.index, match.index + match[0].length);
|
|
26929
|
+
if (/[`~[<]/.test(source3)) {
|
|
26930
|
+
const bom = Number(source3.startsWith("\uFEFF"));
|
|
26931
|
+
const pending = [fromMarkdown(source3)];
|
|
26932
|
+
while (pending.length) {
|
|
26933
|
+
const node3 = pending.pop();
|
|
26934
|
+
const from = node3.position.start.offset + bom, to = node3.position.end.offset + bom;
|
|
26935
|
+
if (["code", "inlineCode", "html", "definition"].includes(node3.type)) {
|
|
26936
|
+
mark(from, to);
|
|
26937
|
+
continue;
|
|
26938
|
+
}
|
|
26939
|
+
if (node3.type === "link" || node3.type === "linkReference") {
|
|
26940
|
+
const first = node3.children[0]?.position, last = node3.children.at(-1)?.position;
|
|
26941
|
+
if (!first || !last || source3[from] === "<") {
|
|
26942
|
+
mark(from, to);
|
|
26943
|
+
continue;
|
|
26944
|
+
}
|
|
26945
|
+
mark(from, first.start.offset + bom);
|
|
26946
|
+
mark(last.end.offset + bom, to);
|
|
26947
|
+
}
|
|
26948
|
+
if (node3.type === "image" || node3.type === "imageReference") {
|
|
26949
|
+
const label = /^!\[((?:\\.|[^\]\\])*)\]/.exec(source3.slice(from, to));
|
|
26950
|
+
if (!label) mark(from, to);
|
|
26951
|
+
else {
|
|
26952
|
+
mark(from, from + 2);
|
|
26953
|
+
mark(from + 2 + label[1].length, to);
|
|
26954
|
+
}
|
|
26955
|
+
}
|
|
26956
|
+
if ("children" in node3)
|
|
26957
|
+
for (const child of node3.children) pending.push(child);
|
|
26958
|
+
}
|
|
26959
|
+
}
|
|
26960
|
+
for (const match of source3.matchAll(
|
|
26961
|
+
/https?:\/\/[^\s<>]+|\b[\w.+-]+@[\w.-]+\.[a-z]{2,}\b|\b[\p{L}\d]+(?:[_/][\p{L}\d]+)+\b/giu
|
|
26962
|
+
))
|
|
26963
|
+
mark(match.index, match.index + match[0].length);
|
|
26964
|
+
const protectedSpans = [];
|
|
26965
|
+
for (const span of ranges.sort((a, b) => a.from - b.from)) {
|
|
26966
|
+
const prev = protectedSpans.at(-1);
|
|
26967
|
+
if (prev && prev.to >= span.from) prev.to = Math.max(prev.to, span.to);
|
|
26968
|
+
else protectedSpans.push(span);
|
|
26969
|
+
}
|
|
26970
|
+
let text5 = "", cursor = 0;
|
|
26971
|
+
for (const { from, to } of protectedSpans) {
|
|
26972
|
+
text5 += source3.slice(cursor, from) + source3.slice(from, to).replace(/[^\r\n]/g, " ");
|
|
26973
|
+
cursor = to;
|
|
26974
|
+
}
|
|
26975
|
+
return { text: text5 + source3.slice(cursor), protectedSpans };
|
|
26976
|
+
}
|
|
26977
|
+
|
|
26978
|
+
// lib/shared/src/writing-settings.ts
|
|
26979
|
+
var writingRules = [
|
|
26980
|
+
"brackets",
|
|
26981
|
+
"quotes",
|
|
26982
|
+
"articles",
|
|
26983
|
+
"repetition",
|
|
26984
|
+
"spacing",
|
|
26985
|
+
"capitalization",
|
|
26986
|
+
"redundancy",
|
|
26987
|
+
"agreement",
|
|
26988
|
+
"plurals",
|
|
26989
|
+
"confusion"
|
|
26990
|
+
];
|
|
26991
|
+
var personalWordLimit = 1e3;
|
|
26992
|
+
var ruleSchema = z20.object({
|
|
26993
|
+
brackets: z20.boolean().default(true),
|
|
26994
|
+
quotes: z20.boolean().default(true),
|
|
26995
|
+
articles: z20.boolean().default(true),
|
|
26996
|
+
repetition: z20.boolean().default(true),
|
|
26997
|
+
spacing: z20.boolean().default(true),
|
|
26998
|
+
capitalization: z20.boolean().default(true),
|
|
26999
|
+
redundancy: z20.boolean().default(true),
|
|
27000
|
+
agreement: z20.boolean().default(true),
|
|
27001
|
+
plurals: z20.boolean().default(true),
|
|
27002
|
+
confusion: z20.boolean().default(true)
|
|
27003
|
+
}).strict();
|
|
27004
|
+
var writingSettingsSchema = z20.object({
|
|
27005
|
+
language: z20.literal("en").default("en"),
|
|
27006
|
+
enabled: z20.boolean().default(true),
|
|
27007
|
+
spelling: z20.boolean().default(true),
|
|
27008
|
+
grammar: z20.boolean().default(true),
|
|
27009
|
+
aiRewrites: z20.boolean().default(true),
|
|
27010
|
+
automatic: z20.boolean().default(true),
|
|
27011
|
+
highlights: z20.boolean().default(true),
|
|
27012
|
+
rules: ruleSchema.default(() => ruleSchema.parse({})),
|
|
27013
|
+
words: z20.array(
|
|
27014
|
+
z20.string().min(1).max(80).regex(/^[\p{L}\p{M}]+(?:['’‐‑-][\p{L}\p{M}]+)*$/u)
|
|
27015
|
+
).max(personalWordLimit).default([])
|
|
27016
|
+
}).strict();
|
|
27017
|
+
var writingPatchSchema = z20.object({
|
|
27018
|
+
language: z20.literal("en").optional(),
|
|
27019
|
+
enabled: z20.boolean().optional(),
|
|
27020
|
+
spelling: z20.boolean().optional(),
|
|
27021
|
+
grammar: z20.boolean().optional(),
|
|
27022
|
+
aiRewrites: z20.boolean().optional(),
|
|
27023
|
+
automatic: z20.boolean().optional(),
|
|
27024
|
+
highlights: z20.boolean().optional(),
|
|
27025
|
+
rules: z20.partialRecord(z20.enum(writingRules), z20.boolean()).optional(),
|
|
27026
|
+
words: writingSettingsSchema.shape.words.removeDefault().optional()
|
|
27027
|
+
}).strict();
|
|
27028
|
+
|
|
27029
|
+
// lib/shared/src/proofing-contract.ts
|
|
27030
|
+
var proofingScope = "grove-note-editor";
|
|
27031
|
+
var proofingVersion = 1;
|
|
27032
|
+
var consentFields = z21.strictObject({
|
|
27033
|
+
enabled: z21.boolean(),
|
|
27034
|
+
automatic: z21.boolean()
|
|
27035
|
+
});
|
|
27036
|
+
var validConsent = (value) => value.enabled || !value.automatic;
|
|
27037
|
+
var proofingConsentSchema = consentFields.refine(validConsent);
|
|
27038
|
+
var proofingConsentStatusSchema = consentFields.extend({ available: z21.boolean().optional() }).refine(validConsent);
|
|
27039
|
+
var rule = z21.enum(["spelling", ...writingRules]);
|
|
27040
|
+
var proofingCheckSchema = z21.strictObject({
|
|
27041
|
+
text: z21.string().min(1).max(1500).refine(
|
|
27042
|
+
(text5) => !/[\r\n]\s*[\r\n]|\u2029/u.test(text5.replaceAll("\r\n", "\n")) && !/[\p{Cs}]/u.test(text5)
|
|
27043
|
+
),
|
|
27044
|
+
revision: z21.int().nonnegative(),
|
|
27045
|
+
rules: z21.record(rule, z21.boolean())
|
|
27046
|
+
});
|
|
27047
|
+
var proofingResultSchema = z21.strictObject({
|
|
27048
|
+
revision: z21.int().nonnegative(),
|
|
27049
|
+
complete: z21.boolean(),
|
|
27050
|
+
issues: z21.array(
|
|
27051
|
+
z21.strictObject({
|
|
27052
|
+
id: z21.string().max(80),
|
|
27053
|
+
rule,
|
|
27054
|
+
message: rule,
|
|
27055
|
+
from: z21.int().nonnegative(),
|
|
27056
|
+
to: z21.int().max(1500),
|
|
27057
|
+
original: z21.string().max(160),
|
|
27058
|
+
replacements: z21.array(z21.string().max(100)).max(3)
|
|
27059
|
+
})
|
|
27060
|
+
).max(50)
|
|
27061
|
+
});
|
|
27062
|
+
|
|
27063
|
+
// lib/memory/src/proofing-consents.ts
|
|
27064
|
+
var ProofingConsents = class {
|
|
27065
|
+
constructor(service) {
|
|
27066
|
+
this.service = service;
|
|
27067
|
+
}
|
|
27068
|
+
service;
|
|
27069
|
+
// access() rechecks account lifecycle and the authoritative session revocation
|
|
27070
|
+
// even when this is the second access within one already-admitted request.
|
|
27071
|
+
state(principal, next) {
|
|
27072
|
+
if (principal.type !== "session" || !principal.sessionId)
|
|
27073
|
+
throw new GroveError(
|
|
27074
|
+
"forbidden",
|
|
27075
|
+
"A signed-in editor session is required",
|
|
27076
|
+
403
|
|
27077
|
+
);
|
|
27078
|
+
return this.service.access(
|
|
27079
|
+
principal,
|
|
27080
|
+
next ? "admin" : null,
|
|
27081
|
+
async ({ trx, account }) => {
|
|
27082
|
+
const key2 = { accountId: account.id, scope: proofingScope };
|
|
27083
|
+
const old = await trx("proofing_consents").where(key2).first();
|
|
27084
|
+
const current = old?.version === proofingVersion;
|
|
27085
|
+
const enabled = current && !old.revokedAt;
|
|
27086
|
+
const consent = {
|
|
27087
|
+
enabled,
|
|
27088
|
+
automatic: enabled && old.automatic === true
|
|
27089
|
+
};
|
|
27090
|
+
if (!next || (!old || current) && consent.enabled === next.enabled && consent.automatic === next.automatic)
|
|
27091
|
+
return {
|
|
27092
|
+
consent,
|
|
27093
|
+
generation: enabled ? String(old.generation) : null
|
|
27094
|
+
};
|
|
27095
|
+
const generation = randomUUID11();
|
|
27096
|
+
await trx("proofing_consents").insert({
|
|
27097
|
+
...key2,
|
|
27098
|
+
version: proofingVersion,
|
|
27099
|
+
automatic: next.automatic,
|
|
27100
|
+
generation,
|
|
27101
|
+
updatedAt: trx.fn.now(),
|
|
27102
|
+
revokedAt: next.enabled ? null : trx.fn.now()
|
|
27103
|
+
}).onConflict(["accountId", "scope"]).merge();
|
|
27104
|
+
return { consent: next, generation: next.enabled ? generation : null };
|
|
27105
|
+
}
|
|
27106
|
+
);
|
|
27107
|
+
}
|
|
27108
|
+
async settings(principal, next) {
|
|
27109
|
+
return (await this.state(principal, next)).consent;
|
|
27110
|
+
}
|
|
27111
|
+
async grant(principal, mode, expected) {
|
|
27112
|
+
const { generation, consent } = await this.state(principal);
|
|
27113
|
+
if (!generation || mode === "automatic" && !consent.automatic || expected && expected !== generation)
|
|
27114
|
+
throw new GroveError(
|
|
27115
|
+
"proofing_consent_required",
|
|
27116
|
+
"Review Enhanced grammar in Writing settings.",
|
|
27117
|
+
403
|
|
27118
|
+
);
|
|
27119
|
+
return generation;
|
|
27120
|
+
}
|
|
27121
|
+
};
|
|
27122
|
+
|
|
26841
27123
|
// lib/memory/src/exports.ts
|
|
26842
27124
|
init_define_GROVE_TELEMETRY();
|
|
26843
27125
|
|
|
@@ -26847,13 +27129,13 @@ init_contracts();
|
|
|
26847
27129
|
|
|
26848
27130
|
// lib/shared/src/jobs.ts
|
|
26849
27131
|
init_define_GROVE_TELEMETRY();
|
|
26850
|
-
import { z as
|
|
27132
|
+
import { z as z23 } from "zod";
|
|
26851
27133
|
|
|
26852
27134
|
// lib/shared/src/web-capture.ts
|
|
26853
27135
|
init_define_GROVE_TELEMETRY();
|
|
26854
27136
|
init_contracts();
|
|
26855
27137
|
init_limits();
|
|
26856
|
-
import { z as
|
|
27138
|
+
import { z as z22 } from "zod";
|
|
26857
27139
|
var trackingParameters = /* @__PURE__ */ new Set([
|
|
26858
27140
|
"utm_source",
|
|
26859
27141
|
"utm_medium",
|
|
@@ -26894,56 +27176,56 @@ function normalizeWebUrl(input) {
|
|
|
26894
27176
|
throw new Error("Invalid source URL: too long");
|
|
26895
27177
|
return normalized;
|
|
26896
27178
|
}
|
|
26897
|
-
var webCaptureSchema =
|
|
26898
|
-
url:
|
|
27179
|
+
var webCaptureSchema = z22.object({
|
|
27180
|
+
url: z22.string().max(WEB_URL_MAX).transform((value, ctx) => {
|
|
26899
27181
|
try {
|
|
26900
27182
|
return normalizeWebUrl(value);
|
|
26901
27183
|
} catch {
|
|
26902
27184
|
ctx.addIssue({ code: "custom", message: "Invalid source URL" });
|
|
26903
|
-
return
|
|
27185
|
+
return z22.NEVER;
|
|
26904
27186
|
}
|
|
26905
27187
|
}),
|
|
26906
|
-
title:
|
|
27188
|
+
title: z22.string().max(300).refine((value) => !containsControlCharacters(value), {
|
|
26907
27189
|
message: "Source title must be a single line"
|
|
26908
27190
|
}),
|
|
26909
|
-
capturedAt:
|
|
27191
|
+
capturedAt: z22.iso.datetime()
|
|
26910
27192
|
}).strict();
|
|
26911
|
-
var browserCaptureRequestSchema =
|
|
26912
|
-
operationId:
|
|
26913
|
-
id:
|
|
26914
|
-
expectedVersion:
|
|
26915
|
-
editSession:
|
|
27193
|
+
var browserCaptureRequestSchema = z22.object({
|
|
27194
|
+
operationId: z22.uuid(),
|
|
27195
|
+
id: z22.uuid().optional(),
|
|
27196
|
+
expectedVersion: z22.number().int().positive().optional(),
|
|
27197
|
+
editSession: z22.uuid().optional(),
|
|
26916
27198
|
content: rememberSchema.shape.content,
|
|
26917
|
-
projectId:
|
|
26918
|
-
capture:
|
|
27199
|
+
projectId: z22.uuid().nullable(),
|
|
27200
|
+
capture: z22.literal("explicit"),
|
|
26919
27201
|
provenance: webCaptureSchema.optional()
|
|
26920
27202
|
}).strict().refine(
|
|
26921
27203
|
(input) => Boolean(input.id) === Boolean(input.expectedVersion),
|
|
26922
27204
|
"Updates require both id and expectedVersion"
|
|
26923
27205
|
);
|
|
26924
|
-
var browserPageRequestSchema =
|
|
27206
|
+
var browserPageRequestSchema = z22.object({
|
|
26925
27207
|
url: webCaptureSchema.shape.url,
|
|
26926
|
-
projectId:
|
|
26927
|
-
cursor:
|
|
27208
|
+
projectId: z22.uuid().nullable(),
|
|
27209
|
+
cursor: z22.string().max(2048).optional()
|
|
26928
27210
|
}).strict();
|
|
26929
27211
|
|
|
26930
27212
|
// lib/shared/src/jobs.ts
|
|
26931
|
-
var exportRequestSchema =
|
|
26932
|
-
id:
|
|
26933
|
-
projectId:
|
|
26934
|
-
includeDescendants:
|
|
26935
|
-
includeMedia:
|
|
27213
|
+
var exportRequestSchema = z23.object({
|
|
27214
|
+
id: z23.uuid(),
|
|
27215
|
+
projectId: z23.uuid().optional(),
|
|
27216
|
+
includeDescendants: z23.boolean().default(false),
|
|
27217
|
+
includeMedia: z23.boolean().optional()
|
|
26936
27218
|
}).strict();
|
|
26937
|
-
var importRecordSchema =
|
|
26938
|
-
sourceId:
|
|
26939
|
-
content:
|
|
26940
|
-
projectId:
|
|
27219
|
+
var importRecordSchema = z23.object({
|
|
27220
|
+
sourceId: z23.string().min(1).max(200),
|
|
27221
|
+
content: z23.string().min(1).max(6e3),
|
|
27222
|
+
projectId: z23.uuid().nullable().default(null),
|
|
26941
27223
|
webCapture: webCaptureSchema.optional()
|
|
26942
27224
|
}).strict();
|
|
26943
|
-
var importRequestSchema =
|
|
26944
|
-
id:
|
|
26945
|
-
source:
|
|
26946
|
-
records:
|
|
27225
|
+
var importRequestSchema = z23.object({
|
|
27226
|
+
id: z23.uuid(),
|
|
27227
|
+
source: z23.string().regex(/^[a-zA-Z0-9._-]{1,100}$/),
|
|
27228
|
+
records: z23.array(importRecordSchema).min(1).max(100)
|
|
26947
27229
|
}).strict();
|
|
26948
27230
|
|
|
26949
27231
|
// lib/memory/src/index.ts
|
|
@@ -26951,7 +27233,7 @@ init_contracts();
|
|
|
26951
27233
|
|
|
26952
27234
|
// lib/memory/src/connect.ts
|
|
26953
27235
|
init_define_GROVE_TELEMETRY();
|
|
26954
|
-
import { randomUUID as
|
|
27236
|
+
import { randomUUID as randomUUID12 } from "node:crypto";
|
|
26955
27237
|
init_contracts();
|
|
26956
27238
|
var unavailable5 = () => new GroveError(
|
|
26957
27239
|
"connection_unavailable",
|
|
@@ -27009,7 +27291,7 @@ var ConnectionSetup = class {
|
|
|
27009
27291
|
);
|
|
27010
27292
|
const attempt = {
|
|
27011
27293
|
...input,
|
|
27012
|
-
id:
|
|
27294
|
+
id: randomUUID12(),
|
|
27013
27295
|
connectionId: connection.id,
|
|
27014
27296
|
clientId: connection.clientId,
|
|
27015
27297
|
status: hasAccess ? "approved" : "pending",
|
|
@@ -27136,7 +27418,7 @@ import {
|
|
|
27136
27418
|
createHash as createHash17,
|
|
27137
27419
|
createHmac as createHmac4,
|
|
27138
27420
|
randomBytes as randomBytes2,
|
|
27139
|
-
randomUUID as
|
|
27421
|
+
randomUUID as randomUUID13,
|
|
27140
27422
|
timingSafeEqual as timingSafeEqual3
|
|
27141
27423
|
} from "node:crypto";
|
|
27142
27424
|
var hash3 = (value) => createHash17("sha256").update(value).digest("hex");
|
|
@@ -27357,7 +27639,7 @@ var Sharing = class {
|
|
|
27357
27639
|
return existing;
|
|
27358
27640
|
}
|
|
27359
27641
|
const identity = {
|
|
27360
|
-
id: existing?.id ??
|
|
27642
|
+
id: existing?.id ?? randomUUID13(),
|
|
27361
27643
|
accountId
|
|
27362
27644
|
};
|
|
27363
27645
|
const fields = {
|
|
@@ -27520,16 +27802,16 @@ import { createHash as createHash19, createHmac as createHmac5, timingSafeEqual
|
|
|
27520
27802
|
|
|
27521
27803
|
// lib/shared/src/conversation-history.ts
|
|
27522
27804
|
init_define_GROVE_TELEMETRY();
|
|
27523
|
-
import { z as
|
|
27524
|
-
var conversationHistorySchema =
|
|
27525
|
-
query:
|
|
27526
|
-
after:
|
|
27805
|
+
import { z as z25 } from "zod";
|
|
27806
|
+
var conversationHistorySchema = z25.object({
|
|
27807
|
+
query: z25.string().trim().max(200).default(""),
|
|
27808
|
+
after: z25.string().max(2048).optional()
|
|
27527
27809
|
}).strict();
|
|
27528
|
-
var conversationHistoryCursorSchema =
|
|
27529
|
-
owner:
|
|
27530
|
-
query:
|
|
27531
|
-
id:
|
|
27532
|
-
at:
|
|
27810
|
+
var conversationHistoryCursorSchema = z25.object({
|
|
27811
|
+
owner: z25.uuid(),
|
|
27812
|
+
query: z25.string(),
|
|
27813
|
+
id: z25.uuid(),
|
|
27814
|
+
at: z25.iso.datetime()
|
|
27533
27815
|
});
|
|
27534
27816
|
|
|
27535
27817
|
// lib/memory/src/conversation-history.ts
|
|
@@ -27612,11 +27894,11 @@ init_contracts();
|
|
|
27612
27894
|
// lib/shared/src/notebook-lifecycle.ts
|
|
27613
27895
|
init_define_GROVE_TELEMETRY();
|
|
27614
27896
|
init_contracts();
|
|
27615
|
-
import { z as
|
|
27616
|
-
var notebookLifecycleSchema =
|
|
27897
|
+
import { z as z26 } from "zod";
|
|
27898
|
+
var notebookLifecycleSchema = z26.object({
|
|
27617
27899
|
operationId: operationSchema,
|
|
27618
|
-
expectedVersion:
|
|
27619
|
-
fingerprint:
|
|
27900
|
+
expectedVersion: z26.number().int().positive(),
|
|
27901
|
+
fingerprint: z26.string().regex(/^[a-f0-9]{64}$/)
|
|
27620
27902
|
}).strict();
|
|
27621
27903
|
|
|
27622
27904
|
// lib/memory/src/tools.ts
|
|
@@ -27730,36 +28012,36 @@ init_contracts();
|
|
|
27730
28012
|
// lib/shared/src/system-admin.ts
|
|
27731
28013
|
init_define_GROVE_TELEMETRY();
|
|
27732
28014
|
init_contracts();
|
|
27733
|
-
import { z as
|
|
27734
|
-
var adminChangeSchema =
|
|
28015
|
+
import { z as z27 } from "zod";
|
|
28016
|
+
var adminChangeSchema = z27.object({
|
|
27735
28017
|
accountId: uuidSchema,
|
|
27736
28018
|
operationId: uuidSchema,
|
|
27737
|
-
expectedVersion:
|
|
27738
|
-
role:
|
|
27739
|
-
access:
|
|
27740
|
-
reason:
|
|
28019
|
+
expectedVersion: z27.number().int().min(0),
|
|
28020
|
+
role: z27.enum(["user", "system_admin"]),
|
|
28021
|
+
access: z27.enum(["default", "pro", "unlimited"]),
|
|
28022
|
+
reason: z27.string().trim().min(3).max(300)
|
|
27741
28023
|
}).strict();
|
|
27742
|
-
var adminSettingsSchema =
|
|
27743
|
-
captureEnabled:
|
|
27744
|
-
recallEnabled:
|
|
27745
|
-
suspended:
|
|
27746
|
-
supportNote:
|
|
28024
|
+
var adminSettingsSchema = z27.object({
|
|
28025
|
+
captureEnabled: z27.boolean(),
|
|
28026
|
+
recallEnabled: z27.boolean(),
|
|
28027
|
+
suspended: z27.boolean(),
|
|
28028
|
+
supportNote: z27.string().max(500)
|
|
27747
28029
|
}).strict();
|
|
27748
|
-
var adminSupportSchema =
|
|
28030
|
+
var adminSupportSchema = z27.object({
|
|
27749
28031
|
accountId: uuidSchema,
|
|
27750
28032
|
operationId: uuidSchema,
|
|
27751
|
-
expectedVersion:
|
|
28033
|
+
expectedVersion: z27.number().int().min(0),
|
|
27752
28034
|
expectedSettings: adminSettingsSchema,
|
|
27753
28035
|
settings: adminSettingsSchema,
|
|
27754
|
-
reason:
|
|
28036
|
+
reason: z27.string().trim().min(3).max(300)
|
|
27755
28037
|
}).strict();
|
|
27756
|
-
var adminTrialResetSchema =
|
|
28038
|
+
var adminTrialResetSchema = z27.object({
|
|
27757
28039
|
accountId: uuidSchema,
|
|
27758
28040
|
operationId: uuidSchema,
|
|
27759
|
-
reason:
|
|
28041
|
+
reason: z27.string().trim().min(3).max(300)
|
|
27760
28042
|
}).strict();
|
|
27761
|
-
var adminDetailsSchema =
|
|
27762
|
-
var adminBrowseSchema =
|
|
28043
|
+
var adminDetailsSchema = z27.object({ accountId: uuidSchema }).strict();
|
|
28044
|
+
var adminBrowseSchema = z27.object({ after: uuidSchema.optional() }).strict();
|
|
27763
28045
|
var usageReportFeatures = [
|
|
27764
28046
|
"recall",
|
|
27765
28047
|
"ask",
|
|
@@ -27787,9 +28069,9 @@ var emptyUsageReportMetrics = () => Object.fromEntries(
|
|
|
27787
28069
|
}
|
|
27788
28070
|
])
|
|
27789
28071
|
);
|
|
27790
|
-
var adminUsageReportSchema =
|
|
27791
|
-
from:
|
|
27792
|
-
to:
|
|
28072
|
+
var adminUsageReportSchema = z27.object({
|
|
28073
|
+
from: z27.iso.date().optional(),
|
|
28074
|
+
to: z27.iso.date().optional(),
|
|
27793
28075
|
after: uuidSchema.optional()
|
|
27794
28076
|
}).strict().superRefine((input, ctx) => {
|
|
27795
28077
|
if (!!input.from !== !!input.to || input.from && input.to && (input.from > input.to || Date.parse(input.to) - Date.parse(input.from) > 365 * 864e5))
|
|
@@ -28320,7 +28602,7 @@ var MemoryService = class _MemoryService {
|
|
|
28320
28602
|
}
|
|
28321
28603
|
const writer = this.inTransaction(trx);
|
|
28322
28604
|
const note2 = input.id ? await writer.updateMemory(principal, {
|
|
28323
|
-
operationId:
|
|
28605
|
+
operationId: randomUUID15(),
|
|
28324
28606
|
id: input.id,
|
|
28325
28607
|
expectedVersion: input.expectedVersion,
|
|
28326
28608
|
editSession: input.editSession,
|
|
@@ -28330,7 +28612,7 @@ var MemoryService = class _MemoryService {
|
|
|
28330
28612
|
}) : await writer.remember(
|
|
28331
28613
|
principal,
|
|
28332
28614
|
rememberSchema.parse({
|
|
28333
|
-
operationId:
|
|
28615
|
+
operationId: randomUUID15(),
|
|
28334
28616
|
content: input.content,
|
|
28335
28617
|
projectId: input.projectId,
|
|
28336
28618
|
capture: "explicit",
|
|
@@ -28703,7 +28985,7 @@ var MemoryService = class _MemoryService {
|
|
|
28703
28985
|
version: input.expectedVersion + 1
|
|
28704
28986
|
}) : await MemoryModel.query(trx).insertAndFetch({
|
|
28705
28987
|
...values,
|
|
28706
|
-
id:
|
|
28988
|
+
id: randomUUID15(),
|
|
28707
28989
|
status: input.archived ? "archived" : "active"
|
|
28708
28990
|
});
|
|
28709
28991
|
if (localDate)
|
|
@@ -28795,7 +29077,7 @@ var MemoryService = class _MemoryService {
|
|
|
28795
29077
|
const domain2 = this.inTransaction(trx);
|
|
28796
29078
|
for (const item of input.items)
|
|
28797
29079
|
await domain2.updateMemory(principal, {
|
|
28798
|
-
operationId:
|
|
29080
|
+
operationId: randomUUID15(),
|
|
28799
29081
|
...item,
|
|
28800
29082
|
projectId: input.projectId,
|
|
28801
29083
|
capture: "explicit"
|
|
@@ -28989,7 +29271,7 @@ var MemoryService = class _MemoryService {
|
|
|
28989
29271
|
trx,
|
|
28990
29272
|
principal.accountId,
|
|
28991
29273
|
metric,
|
|
28992
|
-
|
|
29274
|
+
randomUUID15(),
|
|
28993
29275
|
1
|
|
28994
29276
|
);
|
|
28995
29277
|
}
|
|
@@ -29975,7 +30257,7 @@ ${input.query}`.slice(-1e3) : input.query;
|
|
|
29975
30257
|
}).returning("*");
|
|
29976
30258
|
}
|
|
29977
30259
|
if (!options.key) return { connection };
|
|
29978
|
-
const id2 =
|
|
30260
|
+
const id2 = randomUUID15();
|
|
29979
30261
|
const secret = `grv_${id2}_${randomBytes3(32).toString("base64url")}`;
|
|
29980
30262
|
await trx("api_keys").insert({
|
|
29981
30263
|
id: id2,
|
|
@@ -30088,7 +30370,7 @@ ${input.query}`.slice(-1e3) : input.query;
|
|
|
30088
30370
|
throw new GroveError("not_found", "Project not found", 404);
|
|
30089
30371
|
if (refresh && this.providers.generation && account[briefPreference(scope)]) {
|
|
30090
30372
|
const target2 = briefTarget(scope);
|
|
30091
|
-
const usageOperation = `brief:${
|
|
30373
|
+
const usageOperation = `brief:${randomUUID15()}`;
|
|
30092
30374
|
await reserveAction(
|
|
30093
30375
|
this.db,
|
|
30094
30376
|
trx,
|
|
@@ -30202,6 +30484,143 @@ var sessionPrincipal = (accountId, subject) => ({
|
|
|
30202
30484
|
capabilities: [...capabilities]
|
|
30203
30485
|
});
|
|
30204
30486
|
|
|
30487
|
+
// packages/api/src/proofing.ts
|
|
30488
|
+
init_define_GROVE_TELEMETRY();
|
|
30489
|
+
init_contracts();
|
|
30490
|
+
import { z as z28 } from "zod";
|
|
30491
|
+
var families = /* @__PURE__ */ new Map([
|
|
30492
|
+
["YOUR_YOU_2", "confusion"],
|
|
30493
|
+
["WHO_S_NN_VB", "confusion"],
|
|
30494
|
+
["ITS_TO_IT_S", "confusion"],
|
|
30495
|
+
["IT_IS", "confusion"],
|
|
30496
|
+
["FEWER_LESS", "confusion"],
|
|
30497
|
+
["BETWEEN_YOU_AND_I", "agreement"],
|
|
30498
|
+
["MORFOLOGIK_RULE_EN_US", "spelling"]
|
|
30499
|
+
]);
|
|
30500
|
+
var upstreamSchema = z28.object({
|
|
30501
|
+
warnings: z28.object({ incompleteResults: z28.boolean() }).optional(),
|
|
30502
|
+
matches: z28.array(
|
|
30503
|
+
z28.object({
|
|
30504
|
+
rule: z28.object({ id: z28.string() }),
|
|
30505
|
+
offset: z28.int(),
|
|
30506
|
+
length: z28.int(),
|
|
30507
|
+
replacements: z28.array(z28.object({ value: z28.string() }))
|
|
30508
|
+
})
|
|
30509
|
+
)
|
|
30510
|
+
});
|
|
30511
|
+
var unavailable6 = () => new GroveError(
|
|
30512
|
+
"proofing_unavailable",
|
|
30513
|
+
"Enhanced grammar is temporarily unavailable.",
|
|
30514
|
+
503
|
|
30515
|
+
);
|
|
30516
|
+
var maxBytes2 = 64 * 1024;
|
|
30517
|
+
async function upstreamJson(response) {
|
|
30518
|
+
if (!response.ok || !/^application\/json(?:\s*;|$)/i.test(
|
|
30519
|
+
response.headers.get("content-type") ?? ""
|
|
30520
|
+
) || Number(response.headers.get("content-length")) > maxBytes2 || !response.body)
|
|
30521
|
+
throw unavailable6();
|
|
30522
|
+
const reader = response.body.getReader();
|
|
30523
|
+
let size = 0, json = "";
|
|
30524
|
+
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
30525
|
+
try {
|
|
30526
|
+
for (; ; ) {
|
|
30527
|
+
const { done, value } = await reader.read();
|
|
30528
|
+
if (done) break;
|
|
30529
|
+
size += value.byteLength;
|
|
30530
|
+
if (size > maxBytes2) throw unavailable6();
|
|
30531
|
+
json += decoder.decode(value, { stream: true });
|
|
30532
|
+
}
|
|
30533
|
+
return upstreamSchema.parse(JSON.parse(json + decoder.decode()));
|
|
30534
|
+
} finally {
|
|
30535
|
+
reader.releaseLock();
|
|
30536
|
+
}
|
|
30537
|
+
}
|
|
30538
|
+
function proofingEndpoint(origin2) {
|
|
30539
|
+
if (origin2 && URL.canParse(origin2)) {
|
|
30540
|
+
const url = new URL(origin2);
|
|
30541
|
+
if (["http:", "https:"].includes(url.protocol) && ["languagetool", "localhost", "127.0.0.1", "[::1]"].includes(
|
|
30542
|
+
url.hostname
|
|
30543
|
+
) && !url.username && !url.password && url.href === url.origin + "/")
|
|
30544
|
+
return new URL("/v2/check", url);
|
|
30545
|
+
}
|
|
30546
|
+
}
|
|
30547
|
+
function languageTool(origin2) {
|
|
30548
|
+
const endpoint2 = proofingEndpoint(origin2);
|
|
30549
|
+
return async (input, signal) => {
|
|
30550
|
+
signal.throwIfAborted();
|
|
30551
|
+
const ids = [...families].filter(([, family]) => input.rules[family]).map(([id2]) => id2);
|
|
30552
|
+
const projection = projectWritingText(input.text);
|
|
30553
|
+
const result = {
|
|
30554
|
+
revision: input.revision,
|
|
30555
|
+
complete: true,
|
|
30556
|
+
issues: []
|
|
30557
|
+
};
|
|
30558
|
+
if (!ids.length || !projection.text.trim()) return result;
|
|
30559
|
+
if (!endpoint2) throw unavailable6();
|
|
30560
|
+
const controller = new AbortController();
|
|
30561
|
+
const timer = setTimeout(() => controller.abort(), 2500);
|
|
30562
|
+
try {
|
|
30563
|
+
const response = await fetch(endpoint2, {
|
|
30564
|
+
method: "POST",
|
|
30565
|
+
redirect: "error",
|
|
30566
|
+
credentials: "omit",
|
|
30567
|
+
cache: "no-store",
|
|
30568
|
+
signal: AbortSignal.any([controller.signal, signal]),
|
|
30569
|
+
headers: { accept: "application/json" },
|
|
30570
|
+
body: new URLSearchParams({
|
|
30571
|
+
text: projection.text,
|
|
30572
|
+
language: "en-US",
|
|
30573
|
+
level: "default",
|
|
30574
|
+
enabledOnly: "true",
|
|
30575
|
+
enabledRules: ids.join(",")
|
|
30576
|
+
})
|
|
30577
|
+
});
|
|
30578
|
+
const data = await upstreamJson(response);
|
|
30579
|
+
result.complete = !data.warnings?.incompleteResults;
|
|
30580
|
+
for (const match of data.matches) {
|
|
30581
|
+
const rule2 = families.get(match.rule.id), from = match.offset, to = from + match.length;
|
|
30582
|
+
if (!rule2 || !input.rules[rule2] || from < 0 || match.length < 1 || match.length > 160 || to > input.text.length || projection.protectedSpans.some(
|
|
30583
|
+
(span) => from < span.to && to > span.from
|
|
30584
|
+
))
|
|
30585
|
+
continue;
|
|
30586
|
+
const original = input.text.slice(from, to);
|
|
30587
|
+
if (!original.trim() || new RegExp("\\p{Cs}", "u").test(original)) continue;
|
|
30588
|
+
const replacements = [
|
|
30589
|
+
...new Set(
|
|
30590
|
+
match.replacements.map((r) => r.value).filter(
|
|
30591
|
+
(v) => v.length <= 100 && !/[\p{C}\r\n]/u.test(v) && v !== original
|
|
30592
|
+
)
|
|
30593
|
+
)
|
|
30594
|
+
].slice(0, 3);
|
|
30595
|
+
if (match.rule.id === "ITS_TO_IT_S" && original === "its" && /[\p{L},;:]\s+$/u.test(projection.text.slice(0, from)))
|
|
30596
|
+
replacements.sort(
|
|
30597
|
+
(a, b) => Number(b === "it's") - Number(a === "it's")
|
|
30598
|
+
);
|
|
30599
|
+
if (!replacements.length) continue;
|
|
30600
|
+
if (result.issues.length === 50) {
|
|
30601
|
+
result.complete = false;
|
|
30602
|
+
break;
|
|
30603
|
+
}
|
|
30604
|
+
result.issues.push({
|
|
30605
|
+
id: `${rule2}:${from}:${to}`,
|
|
30606
|
+
rule: rule2,
|
|
30607
|
+
message: rule2,
|
|
30608
|
+
from,
|
|
30609
|
+
to,
|
|
30610
|
+
original,
|
|
30611
|
+
replacements
|
|
30612
|
+
});
|
|
30613
|
+
}
|
|
30614
|
+
return result;
|
|
30615
|
+
} catch {
|
|
30616
|
+
throw unavailable6();
|
|
30617
|
+
} finally {
|
|
30618
|
+
clearTimeout(timer);
|
|
30619
|
+
controller.abort();
|
|
30620
|
+
}
|
|
30621
|
+
};
|
|
30622
|
+
}
|
|
30623
|
+
|
|
30205
30624
|
// packages/api/src/media-input.ts
|
|
30206
30625
|
init_define_GROVE_TELEMETRY();
|
|
30207
30626
|
init_contracts();
|
|
@@ -30237,7 +30656,7 @@ async function readMediaBytes(source3, signal, maximum = imageLimits.bytes) {
|
|
|
30237
30656
|
|
|
30238
30657
|
// packages/api/src/billing.ts
|
|
30239
30658
|
init_define_GROVE_TELEMETRY();
|
|
30240
|
-
import { randomUUID as
|
|
30659
|
+
import { randomUUID as randomUUID16 } from "node:crypto";
|
|
30241
30660
|
init_contracts();
|
|
30242
30661
|
var ongoing = (status) => !["canceled", "incomplete_expired"].includes(status);
|
|
30243
30662
|
var replaceableCheckout = (session, subscriptions) => {
|
|
@@ -30507,7 +30926,7 @@ var Billing = class {
|
|
|
30507
30926
|
await trx("billing_customers").where({ accountId: principal.accountId }).update({
|
|
30508
30927
|
checkoutId: null,
|
|
30509
30928
|
checkoutPrice: price.id,
|
|
30510
|
-
checkoutOperation:
|
|
30929
|
+
checkoutOperation: randomUUID16()
|
|
30511
30930
|
});
|
|
30512
30931
|
}
|
|
30513
30932
|
if (!row.checkoutPrice)
|
|
@@ -30557,7 +30976,7 @@ var Billing = class {
|
|
|
30557
30976
|
await trx("billing_customers").where({ accountId: principal.accountId }).update({
|
|
30558
30977
|
checkoutId: null,
|
|
30559
30978
|
checkoutPrice: null,
|
|
30560
|
-
checkoutOperation:
|
|
30979
|
+
checkoutOperation: randomUUID16()
|
|
30561
30980
|
});
|
|
30562
30981
|
return null;
|
|
30563
30982
|
}
|
|
@@ -30620,7 +31039,7 @@ var Billing = class {
|
|
|
30620
31039
|
await trx("billing_customers").where({ accountId: principal.accountId }).update({
|
|
30621
31040
|
checkoutId: null,
|
|
30622
31041
|
checkoutPrice: price.id,
|
|
30623
|
-
checkoutOperation:
|
|
31042
|
+
checkoutOperation: randomUUID16()
|
|
30624
31043
|
});
|
|
30625
31044
|
}
|
|
30626
31045
|
if (!row.checkoutPrice)
|
|
@@ -30690,7 +31109,7 @@ var Billing = class {
|
|
|
30690
31109
|
await trx("billing_customers").where({ accountId: principal.accountId }).update({
|
|
30691
31110
|
checkoutId: null,
|
|
30692
31111
|
checkoutPrice: null,
|
|
30693
|
-
checkoutOperation:
|
|
31112
|
+
checkoutOperation: randomUUID16()
|
|
30694
31113
|
});
|
|
30695
31114
|
return null;
|
|
30696
31115
|
}
|
|
@@ -30773,7 +31192,7 @@ var Billing = class {
|
|
|
30773
31192
|
init_define_GROVE_TELEMETRY();
|
|
30774
31193
|
init_contracts();
|
|
30775
31194
|
import { createClerkClient } from "@clerk/backend";
|
|
30776
|
-
import { z as
|
|
31195
|
+
import { z as z29 } from "zod";
|
|
30777
31196
|
function clerkAdminDirectory(secretKey) {
|
|
30778
31197
|
const clerk = createClerkClient({ secretKey });
|
|
30779
31198
|
return {
|
|
@@ -30809,12 +31228,12 @@ var AdminAccounts = class {
|
|
|
30809
31228
|
administration;
|
|
30810
31229
|
async search(principal, raw) {
|
|
30811
31230
|
await this.administration.accounts(principal, []);
|
|
30812
|
-
const { query } =
|
|
31231
|
+
const { query } = z29.object({ query: z29.string().trim().max(254) }).strict().parse(raw);
|
|
30813
31232
|
let subjects;
|
|
30814
31233
|
if (query.startsWith("user_") && /^user_[A-Za-z0-9_-]{1,128}$/.test(query))
|
|
30815
31234
|
subjects = [query];
|
|
30816
31235
|
else if (query) {
|
|
30817
|
-
if (!
|
|
31236
|
+
if (!z29.email().safeParse(query).success)
|
|
30818
31237
|
throw new GroveError(
|
|
30819
31238
|
"invalid_request",
|
|
30820
31239
|
"Search by exact email or user ID",
|
|
@@ -30952,7 +31371,7 @@ import { pipeline as pipeline2 } from "node:stream/promises";
|
|
|
30952
31371
|
|
|
30953
31372
|
// lib/telemetry/src/index.ts
|
|
30954
31373
|
init_define_GROVE_TELEMETRY();
|
|
30955
|
-
import { createHmac as createHmac7, randomUUID as
|
|
31374
|
+
import { createHmac as createHmac7, randomUUID as randomUUID18 } from "node:crypto";
|
|
30956
31375
|
import { performance as performance2 } from "node:perf_hooks";
|
|
30957
31376
|
|
|
30958
31377
|
// node_modules/.pnpm/posthog-node@5.56.2_@opentelemetry+api@1.10.0/node_modules/posthog-node/dist/entrypoints/index.node.mjs
|
|
@@ -46624,7 +47043,7 @@ function safeMetric(metric, identity) {
|
|
|
46624
47043
|
|
|
46625
47044
|
// lib/telemetry/src/preference.ts
|
|
46626
47045
|
init_define_GROVE_TELEMETRY();
|
|
46627
|
-
import { randomUUID as
|
|
47046
|
+
import { randomUUID as randomUUID17 } from "node:crypto";
|
|
46628
47047
|
import {
|
|
46629
47048
|
chmodSync,
|
|
46630
47049
|
closeSync,
|
|
@@ -46675,7 +47094,7 @@ function installationIdentity(directory = telemetryDirectory()) {
|
|
|
46675
47094
|
try {
|
|
46676
47095
|
const fd = openSync(path2, "wx", 384);
|
|
46677
47096
|
try {
|
|
46678
|
-
writeFileSync(fd, `${
|
|
47097
|
+
writeFileSync(fd, `${randomUUID17()}
|
|
46679
47098
|
`);
|
|
46680
47099
|
} finally {
|
|
46681
47100
|
closeSync(fd);
|
|
@@ -47050,7 +47469,7 @@ function telemetry(surface) {
|
|
|
47050
47469
|
const server = surface === "api" || surface === "worker";
|
|
47051
47470
|
const enabled = build.enabled && !environmentDisabled() && (!server || process.env.GROVE_TELEMETRY_ENABLED === "true");
|
|
47052
47471
|
const directory = telemetryDirectory();
|
|
47053
|
-
const identity = enabled ? server ?
|
|
47472
|
+
const identity = enabled ? server ? randomUUID18() : installationIdentity(directory) : "";
|
|
47054
47473
|
reporter = new Reporter({
|
|
47055
47474
|
...build,
|
|
47056
47475
|
enabled,
|
|
@@ -47073,7 +47492,7 @@ var closeTelemetry = (timeoutMs = 550) => Promise.allSettled(
|
|
|
47073
47492
|
// packages/api/src/app.ts
|
|
47074
47493
|
import { Hono } from "hono";
|
|
47075
47494
|
import { cors } from "hono/cors";
|
|
47076
|
-
import { z as
|
|
47495
|
+
import { z as z30, ZodError as ZodError2 } from "zod";
|
|
47077
47496
|
import { Webhook } from "svix";
|
|
47078
47497
|
import { WebStandardStreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
|
|
47079
47498
|
|
|
@@ -47148,9 +47567,8 @@ init_contracts();
|
|
|
47148
47567
|
init_define_GROVE_TELEMETRY();
|
|
47149
47568
|
init_contracts();
|
|
47150
47569
|
var busy = () => new GroveError("overloaded", "Grove is busy. Try again shortly.", 503);
|
|
47151
|
-
async function admittedRequest(request2, signal) {
|
|
47570
|
+
async function admittedRequest(request2, signal, maximum = 128 * 1024) {
|
|
47152
47571
|
if (!request2.body) return request2;
|
|
47153
|
-
const maximum = 128 * 1024;
|
|
47154
47572
|
const tooLarge2 = () => new GroveError("too_large", "Request body is too large", 413);
|
|
47155
47573
|
if (Number(request2.headers.get("content-length")) > maximum) throw tooLarge2();
|
|
47156
47574
|
let size = 0;
|
|
@@ -47497,6 +47915,13 @@ init_media();
|
|
|
47497
47915
|
init_models();
|
|
47498
47916
|
function createApp(deps) {
|
|
47499
47917
|
const app = new Hono();
|
|
47918
|
+
const proofing = new ProofingConsents(deps.memories);
|
|
47919
|
+
const checkParagraph = languageTool(deps.languageToolUrl);
|
|
47920
|
+
const proofingLane = new Admission(1, 0, 0);
|
|
47921
|
+
const liveSession = (principal) => {
|
|
47922
|
+
if (!principal.sessionExpiresAt || principal.sessionExpiresAt <= Date.now())
|
|
47923
|
+
throw new GroveError("unauthorized", "Sign in to Grove", 401);
|
|
47924
|
+
};
|
|
47500
47925
|
const writing = new WritingTools(
|
|
47501
47926
|
deps.memories,
|
|
47502
47927
|
deps.writingStagingKey,
|
|
@@ -47519,7 +47944,7 @@ function createApp(deps) {
|
|
|
47519
47944
|
capacity.queueTimeoutMs
|
|
47520
47945
|
);
|
|
47521
47946
|
app.use("*", async (c, next) => {
|
|
47522
|
-
c.set("requestId",
|
|
47947
|
+
c.set("requestId", randomUUID19());
|
|
47523
47948
|
c.header("X-Request-ID", c.get("requestId"));
|
|
47524
47949
|
c.header("Cache-Control", "private, no-store");
|
|
47525
47950
|
c.header("X-Content-Type-Options", "nosniff");
|
|
@@ -47528,7 +47953,7 @@ function createApp(deps) {
|
|
|
47528
47953
|
c.header("X-Robots-Tag", "noindex, nofollow, noarchive");
|
|
47529
47954
|
const started = performance.now();
|
|
47530
47955
|
await next();
|
|
47531
|
-
if (requestCollectionAllowed(c.req.raw.headers) && !c.req.path.startsWith("/health/"))
|
|
47956
|
+
if (requestCollectionAllowed(c.req.raw.headers) && !c.req.path.startsWith("/v1/proofing/") && !c.req.path.startsWith("/health/"))
|
|
47532
47957
|
deps.telemetry?.operation(
|
|
47533
47958
|
"http_request",
|
|
47534
47959
|
started,
|
|
@@ -47646,9 +48071,15 @@ function createApp(deps) {
|
|
|
47646
48071
|
c.set("signal", signal);
|
|
47647
48072
|
c.set("finish", finish);
|
|
47648
48073
|
try {
|
|
47649
|
-
|
|
48074
|
+
const isCheck = c.req.path === "/v1/proofing/check";
|
|
48075
|
+
release2 = await (isCheck ? proofingLane : long ? interactive : foreground).acquire(signal);
|
|
47650
48076
|
await withMemoryOperation(async () => {
|
|
47651
|
-
if (!mediaUpload)
|
|
48077
|
+
if (!mediaUpload)
|
|
48078
|
+
c.req.raw = await admittedRequest(
|
|
48079
|
+
c.req.raw,
|
|
48080
|
+
signal,
|
|
48081
|
+
isCheck ? 16384 : c.req.path === "/v1/proofing/consent" ? 512 : void 0
|
|
48082
|
+
);
|
|
47652
48083
|
await next();
|
|
47653
48084
|
if (!c.get("streaming") && !c.error) signal.throwIfAborted();
|
|
47654
48085
|
}, signal);
|
|
@@ -47694,13 +48125,13 @@ function createApp(deps) {
|
|
|
47694
48125
|
400
|
|
47695
48126
|
);
|
|
47696
48127
|
}
|
|
47697
|
-
const payload =
|
|
47698
|
-
type:
|
|
47699
|
-
timestamp:
|
|
47700
|
-
data:
|
|
47701
|
-
id:
|
|
47702
|
-
banned:
|
|
47703
|
-
locked:
|
|
48128
|
+
const payload = z30.object({
|
|
48129
|
+
type: z30.string(),
|
|
48130
|
+
timestamp: z30.number().int(),
|
|
48131
|
+
data: z30.object({
|
|
48132
|
+
id: z30.string().min(1),
|
|
48133
|
+
banned: z30.boolean().optional(),
|
|
48134
|
+
locked: z30.boolean().optional()
|
|
47704
48135
|
})
|
|
47705
48136
|
}).parse(event);
|
|
47706
48137
|
await deps.memories.db.transaction(async (trx) => {
|
|
@@ -47733,6 +48164,18 @@ function createApp(deps) {
|
|
|
47733
48164
|
throw new GroveError("forbidden", "Origin is not allowed", 403);
|
|
47734
48165
|
c.set("principal", principal);
|
|
47735
48166
|
c.get("signal").throwIfAborted();
|
|
48167
|
+
if (c.req.path.startsWith("/v1/proofing/")) {
|
|
48168
|
+
if (origin2 !== deps.siteUrl)
|
|
48169
|
+
throw new GroveError("forbidden", "Editor origin is required", 403);
|
|
48170
|
+
if (principal.type !== "session" || !principal.sessionId)
|
|
48171
|
+
throw new GroveError(
|
|
48172
|
+
"forbidden",
|
|
48173
|
+
"A signed-in editor session is required",
|
|
48174
|
+
403
|
|
48175
|
+
);
|
|
48176
|
+
liveSession(principal);
|
|
48177
|
+
return next();
|
|
48178
|
+
}
|
|
47736
48179
|
await deps.models?.refresh();
|
|
47737
48180
|
const sink = deps.telemetry?.forIdentity(
|
|
47738
48181
|
accountIdentity(c.get("principal").accountId),
|
|
@@ -47843,9 +48286,9 @@ function createApp(deps) {
|
|
|
47843
48286
|
async (c) => c.json({ success: true, data: await billing2().status(c.get("principal")) })
|
|
47844
48287
|
);
|
|
47845
48288
|
app.post("/v1/billing/checkout", async (c) => {
|
|
47846
|
-
const input =
|
|
47847
|
-
interval:
|
|
47848
|
-
expectedAmount:
|
|
48289
|
+
const input = z30.object({
|
|
48290
|
+
interval: z30.enum(["month", "year"]),
|
|
48291
|
+
expectedAmount: z30.number().int().positive().optional()
|
|
47849
48292
|
}).strict().parse(await c.req.json());
|
|
47850
48293
|
return c.json({
|
|
47851
48294
|
success: true,
|
|
@@ -47861,9 +48304,9 @@ function createApp(deps) {
|
|
|
47861
48304
|
async (c) => c.json({ success: true, data: await billing2().portal(c.get("principal")) })
|
|
47862
48305
|
);
|
|
47863
48306
|
app.post("/v1/billing/trial", async (c) => {
|
|
47864
|
-
const input =
|
|
47865
|
-
interval:
|
|
47866
|
-
expectedAmount:
|
|
48307
|
+
const input = z30.object({
|
|
48308
|
+
interval: z30.enum(["month", "year"]),
|
|
48309
|
+
expectedAmount: z30.number().int().positive().optional()
|
|
47867
48310
|
}).strict().parse(await c.req.json());
|
|
47868
48311
|
return c.json({
|
|
47869
48312
|
success: true,
|
|
@@ -47875,6 +48318,31 @@ function createApp(deps) {
|
|
|
47875
48318
|
});
|
|
47876
48319
|
});
|
|
47877
48320
|
const body = async (c, schema) => schema.parse(await c.req.json());
|
|
48321
|
+
const configured = !!proofingEndpoint(deps.languageToolUrl);
|
|
48322
|
+
function requireChecker() {
|
|
48323
|
+
if (!configured) throw new GroveError("proofing_disabled", "Enhanced grammar is not configured.", 503);
|
|
48324
|
+
}
|
|
48325
|
+
app.get("/v1/proofing/consent", async (c) => {
|
|
48326
|
+
const consent = await proofing.settings(c.get("principal"));
|
|
48327
|
+
return c.json(configured ? consent : { ...consent, available: false });
|
|
48328
|
+
});
|
|
48329
|
+
app.put("/v1/proofing/consent", async (c) => {
|
|
48330
|
+
const value = await body(c, proofingConsentSchema);
|
|
48331
|
+
if (value.enabled) requireChecker();
|
|
48332
|
+
const consent = await proofing.settings(c.get("principal"), value);
|
|
48333
|
+
return c.json(configured ? consent : { ...consent, available: false });
|
|
48334
|
+
});
|
|
48335
|
+
app.post("/v1/proofing/check", async (c) => {
|
|
48336
|
+
requireChecker();
|
|
48337
|
+
const principal = c.get("principal"), input = await body(c, proofingCheckSchema);
|
|
48338
|
+
const mode = z30.enum(["manual", "automatic"]).parse(c.req.header("x-grove-proofing-mode") ?? "manual");
|
|
48339
|
+
const generation = await proofing.grant(principal, mode);
|
|
48340
|
+
liveSession(principal);
|
|
48341
|
+
const result = await checkParagraph(input, c.get("signal"));
|
|
48342
|
+
await proofing.grant(principal, mode, generation);
|
|
48343
|
+
liveSession(principal);
|
|
48344
|
+
return c.json(result);
|
|
48345
|
+
});
|
|
47878
48346
|
const mutation = async (c, schema) => {
|
|
47879
48347
|
const value = await c.req.json();
|
|
47880
48348
|
const key2 = c.req.header("idempotency-key");
|
|
@@ -47956,8 +48424,8 @@ function createApp(deps) {
|
|
|
47956
48424
|
importStorage();
|
|
47957
48425
|
const principal = c.get("principal"), conversationId = uuidSchema.parse(c.req.param("conversationId")), id2 = uuidSchema.parse(c.req.param("id"));
|
|
47958
48426
|
await conversationDocuments2.list(principal, conversationId);
|
|
47959
|
-
const length =
|
|
47960
|
-
const hash4 =
|
|
48427
|
+
const length = z30.coerce.number().int().min(1).max(3 * 1024 * 1024).parse(c.req.header("content-length"));
|
|
48428
|
+
const hash4 = z30.string().regex(/^[0-9a-f]{64}$/).parse(c.req.header("x-grove-content-sha256"));
|
|
47961
48429
|
let filename;
|
|
47962
48430
|
try {
|
|
47963
48431
|
filename = decodeURIComponent(c.req.header("x-grove-filename") ?? "");
|
|
@@ -48036,7 +48504,7 @@ function createApp(deps) {
|
|
|
48036
48504
|
c.get("principal"),
|
|
48037
48505
|
uuidSchema.parse(c.req.param("conversationId")),
|
|
48038
48506
|
uuidSchema.parse(c.req.param("id")),
|
|
48039
|
-
|
|
48507
|
+
z30.coerce.number().int().nonnegative().default(0).parse(c.req.query("after"))
|
|
48040
48508
|
)
|
|
48041
48509
|
})
|
|
48042
48510
|
);
|
|
@@ -48075,7 +48543,7 @@ function createApp(deps) {
|
|
|
48075
48543
|
data: await documentImports2.get(
|
|
48076
48544
|
c.get("principal"),
|
|
48077
48545
|
uuidSchema.parse(c.req.param("id")),
|
|
48078
|
-
|
|
48546
|
+
z30.uuid().optional().parse(c.req.query("after"))
|
|
48079
48547
|
)
|
|
48080
48548
|
})
|
|
48081
48549
|
);
|
|
@@ -48083,8 +48551,8 @@ function createApp(deps) {
|
|
|
48083
48551
|
importStorage();
|
|
48084
48552
|
const principal = c.get("principal"), batchId = uuidSchema.parse(c.req.param("batchId")), id2 = uuidSchema.parse(c.req.param("id"));
|
|
48085
48553
|
await documentImports2.get(principal, batchId);
|
|
48086
|
-
const length =
|
|
48087
|
-
const hash4 =
|
|
48554
|
+
const length = z30.coerce.number().int().min(1).max(3 * 1024 * 1024).parse(c.req.header("content-length"));
|
|
48555
|
+
const hash4 = z30.string().regex(/^[0-9a-f]{64}$/).parse(c.req.header("x-grove-content-sha256"));
|
|
48088
48556
|
let filename;
|
|
48089
48557
|
try {
|
|
48090
48558
|
filename = decodeURIComponent(c.req.header("x-grove-filename") ?? "");
|
|
@@ -48201,7 +48669,7 @@ function createApp(deps) {
|
|
|
48201
48669
|
service,
|
|
48202
48670
|
c.get("principal"),
|
|
48203
48671
|
c.req.param("tool"),
|
|
48204
|
-
await mutation(c,
|
|
48672
|
+
await mutation(c, z30.record(z30.string(), z30.unknown())),
|
|
48205
48673
|
c.get("signal")
|
|
48206
48674
|
)
|
|
48207
48675
|
})
|
|
@@ -48213,7 +48681,7 @@ function createApp(deps) {
|
|
|
48213
48681
|
"Media storage is not configured",
|
|
48214
48682
|
503
|
|
48215
48683
|
);
|
|
48216
|
-
const id2 = uuidSchema.parse(c.req.param("id")), version2 = c.req.query("version") ?
|
|
48684
|
+
const id2 = uuidSchema.parse(c.req.param("id")), version2 = c.req.query("version") ? z30.coerce.number().int().positive().parse(c.req.query("version")) : void 0;
|
|
48217
48685
|
const cancelled = new AbortController(), signal = AbortSignal.any([c.get("signal"), cancelled.signal]);
|
|
48218
48686
|
const source3 = await noteArchive(
|
|
48219
48687
|
service,
|
|
@@ -48247,10 +48715,10 @@ function createApp(deps) {
|
|
|
48247
48715
|
const input = {
|
|
48248
48716
|
id: uuidSchema.parse(c.req.param("id")),
|
|
48249
48717
|
memoryId: uuidSchema.parse(c.req.param("memoryId")),
|
|
48250
|
-
version:
|
|
48251
|
-
bytes:
|
|
48252
|
-
mime:
|
|
48253
|
-
sha256:
|
|
48718
|
+
version: z30.coerce.number().int().positive().parse(c.req.header("x-grove-note-version")),
|
|
48719
|
+
bytes: z30.coerce.number().int().min(1).max(imageLimits.bytes).parse(c.req.header("content-length")),
|
|
48720
|
+
mime: z30.enum(mediaMimeTypes).parse(c.req.header("content-type")),
|
|
48721
|
+
sha256: z30.string().regex(/^[0-9a-f]{64}$/).parse(c.req.header("x-grove-content-sha256"))
|
|
48254
48722
|
};
|
|
48255
48723
|
const claim = await attachments.claim(principal, input);
|
|
48256
48724
|
if (claim.replay)
|
|
@@ -48353,7 +48821,7 @@ function createApp(deps) {
|
|
|
48353
48821
|
};
|
|
48354
48822
|
app.get("/v1/memories/:memoryId/media/:id", async (c) => {
|
|
48355
48823
|
const memoryId = uuidSchema.parse(c.req.param("memoryId")), id2 = uuidSchema.parse(c.req.param("id"));
|
|
48356
|
-
const version2 = c.req.query("version") ?
|
|
48824
|
+
const version2 = c.req.query("version") ? z30.coerce.number().int().positive().parse(c.req.query("version")) : void 0;
|
|
48357
48825
|
return mediaResponse(
|
|
48358
48826
|
c,
|
|
48359
48827
|
() => attachments.read(c.get("principal"), memoryId, id2, version2)
|
|
@@ -48410,7 +48878,7 @@ function createApp(deps) {
|
|
|
48410
48878
|
})
|
|
48411
48879
|
);
|
|
48412
48880
|
app.post("/v1/speech/:id/cancel", async (c) => {
|
|
48413
|
-
await mutation(c,
|
|
48881
|
+
await mutation(c, z30.object({}).strict());
|
|
48414
48882
|
return c.json({
|
|
48415
48883
|
success: true,
|
|
48416
48884
|
data: await speech2.cancel(
|
|
@@ -48448,10 +48916,10 @@ function createApp(deps) {
|
|
|
48448
48916
|
uuidSchema.parse(c.req.param("id")),
|
|
48449
48917
|
await body(
|
|
48450
48918
|
c,
|
|
48451
|
-
|
|
48452
|
-
operationId:
|
|
48453
|
-
expectedVersion:
|
|
48454
|
-
text:
|
|
48919
|
+
z30.object({
|
|
48920
|
+
operationId: z30.uuid(),
|
|
48921
|
+
expectedVersion: z30.number().int().min(0),
|
|
48922
|
+
text: z30.string().max(6e3)
|
|
48455
48923
|
}).strict()
|
|
48456
48924
|
)
|
|
48457
48925
|
)
|
|
@@ -48604,7 +49072,7 @@ function createApp(deps) {
|
|
|
48604
49072
|
})
|
|
48605
49073
|
);
|
|
48606
49074
|
app.post("/v1/connect/:id/cancel", async (c) => {
|
|
48607
|
-
await body(c,
|
|
49075
|
+
await body(c, z30.object({}).strict());
|
|
48608
49076
|
return c.json({
|
|
48609
49077
|
success: true,
|
|
48610
49078
|
data: await setup.cancel(
|
|
@@ -48614,7 +49082,7 @@ function createApp(deps) {
|
|
|
48614
49082
|
});
|
|
48615
49083
|
});
|
|
48616
49084
|
app.post("/v1/browser/connect", async (c) => {
|
|
48617
|
-
await body(c,
|
|
49085
|
+
await body(c, z30.object({}).strict());
|
|
48618
49086
|
const principal = c.get("principal");
|
|
48619
49087
|
const identity = await service.me(principal);
|
|
48620
49088
|
const approval = new URL("/app/connections", deps.siteUrl);
|
|
@@ -48647,9 +49115,9 @@ function createApp(deps) {
|
|
|
48647
49115
|
c.get("principal"),
|
|
48648
49116
|
await body(
|
|
48649
49117
|
c,
|
|
48650
|
-
|
|
48651
|
-
policy:
|
|
48652
|
-
accepted:
|
|
49118
|
+
z30.object({
|
|
49119
|
+
policy: z30.string().min(1).max(100),
|
|
49120
|
+
accepted: z30.boolean()
|
|
48653
49121
|
}).strict()
|
|
48654
49122
|
)
|
|
48655
49123
|
)
|
|
@@ -48679,7 +49147,7 @@ function createApp(deps) {
|
|
|
48679
49147
|
})
|
|
48680
49148
|
);
|
|
48681
49149
|
app.post("/v1/browser/writing/requests/:id/cancel", async (c) => {
|
|
48682
|
-
await body(c,
|
|
49150
|
+
await body(c, z30.object({}).strict());
|
|
48683
49151
|
return c.json({
|
|
48684
49152
|
success: true,
|
|
48685
49153
|
data: await writing.cancel(
|
|
@@ -48714,7 +49182,7 @@ function createApp(deps) {
|
|
|
48714
49182
|
success: true,
|
|
48715
49183
|
data: await service.projects(
|
|
48716
49184
|
c.get("principal"),
|
|
48717
|
-
|
|
49185
|
+
z30.enum(["active", "archived"]).parse(c.req.query("status") ?? "active")
|
|
48718
49186
|
)
|
|
48719
49187
|
})
|
|
48720
49188
|
);
|
|
@@ -48815,7 +49283,7 @@ function createApp(deps) {
|
|
|
48815
49283
|
app.post("/v1/models/test", async (c) => {
|
|
48816
49284
|
const input = await body(
|
|
48817
49285
|
c,
|
|
48818
|
-
|
|
49286
|
+
z30.object({ role: z30.enum(["embedding", "decision", "generation"]) }).strict()
|
|
48819
49287
|
);
|
|
48820
49288
|
if (!deps.models)
|
|
48821
49289
|
throw new GroveError(
|
|
@@ -48881,7 +49349,7 @@ function createApp(deps) {
|
|
|
48881
49349
|
app.post("/v1/memories", async (c) => {
|
|
48882
49350
|
const input = await mutation(
|
|
48883
49351
|
c,
|
|
48884
|
-
|
|
49352
|
+
z30.union([rememberSchema, memoryUpdateSchema])
|
|
48885
49353
|
);
|
|
48886
49354
|
return c.json({
|
|
48887
49355
|
success: true,
|
|
@@ -49046,14 +49514,14 @@ function createApp(deps) {
|
|
|
49046
49514
|
data: await service.sourceRevision(
|
|
49047
49515
|
c.get("principal"),
|
|
49048
49516
|
uuidSchema.parse(c.req.param("id")),
|
|
49049
|
-
|
|
49517
|
+
z30.coerce.number().int().positive().max(2147483647).parse(c.req.param("version"))
|
|
49050
49518
|
)
|
|
49051
49519
|
})
|
|
49052
49520
|
);
|
|
49053
49521
|
app.post("/v1/memories/:id/reprocess", async (c) => {
|
|
49054
49522
|
const input = await body(
|
|
49055
49523
|
c,
|
|
49056
|
-
|
|
49524
|
+
z30.object({ expectedVersion: z30.number().int().positive() }).strict()
|
|
49057
49525
|
);
|
|
49058
49526
|
return c.json({
|
|
49059
49527
|
success: true,
|
|
@@ -49157,7 +49625,7 @@ function createApp(deps) {
|
|
|
49157
49625
|
success: true,
|
|
49158
49626
|
data: await service.conversations.list(
|
|
49159
49627
|
c.get("principal"),
|
|
49160
|
-
|
|
49628
|
+
z30.uuid().optional().parse(c.req.query("after"))
|
|
49161
49629
|
)
|
|
49162
49630
|
})
|
|
49163
49631
|
);
|
|
@@ -49204,8 +49672,8 @@ function createApp(deps) {
|
|
|
49204
49672
|
})
|
|
49205
49673
|
);
|
|
49206
49674
|
app.post("/v1/conversations/:id/turns/:turnId/:action", async (c) => {
|
|
49207
|
-
const action =
|
|
49208
|
-
await body(c,
|
|
49675
|
+
const action = z30.enum(["apply", "undo"]).parse(c.req.param("action"));
|
|
49676
|
+
await body(c, z30.object({}).strict());
|
|
49209
49677
|
return c.json({
|
|
49210
49678
|
success: true,
|
|
49211
49679
|
data: await service.conversations.apply(
|
|
@@ -49295,7 +49763,7 @@ function createApp(deps) {
|
|
|
49295
49763
|
app.post("/v1/account/delete", async (c) => {
|
|
49296
49764
|
await body(
|
|
49297
49765
|
c,
|
|
49298
|
-
|
|
49766
|
+
z30.object({ confirm: z30.literal("delete my account") }).strict()
|
|
49299
49767
|
);
|
|
49300
49768
|
return c.json(
|
|
49301
49769
|
{ success: true, data: await service.deleteAccount(c.get("principal")) },
|
|
@@ -49344,7 +49812,7 @@ function createApp(deps) {
|
|
|
49344
49812
|
success: true,
|
|
49345
49813
|
data: await tasks.list(
|
|
49346
49814
|
c.get("principal"),
|
|
49347
|
-
|
|
49815
|
+
z30.uuid().optional().parse(c.req.query("projectId"))
|
|
49348
49816
|
)
|
|
49349
49817
|
})
|
|
49350
49818
|
);
|
|
@@ -49495,7 +49963,8 @@ function clerkVerifier(env) {
|
|
|
49495
49963
|
return {
|
|
49496
49964
|
subject: payload.sub,
|
|
49497
49965
|
type: "session",
|
|
49498
|
-
sessionId: payload.sid
|
|
49966
|
+
sessionId: payload.sid,
|
|
49967
|
+
sessionExpiresAt: payload.exp * 1e3
|
|
49499
49968
|
};
|
|
49500
49969
|
}
|
|
49501
49970
|
const access2 = await clerk.idPOAuthAccessToken.verify(token, {
|
|
@@ -49580,7 +50049,8 @@ var Authentication = class {
|
|
|
49580
50049
|
if (identity.type === "session")
|
|
49581
50050
|
return {
|
|
49582
50051
|
...sessionPrincipal(account.id, identity.subject),
|
|
49583
|
-
sessionId: identity.sessionId
|
|
50052
|
+
sessionId: identity.sessionId,
|
|
50053
|
+
sessionExpiresAt: identity.sessionExpiresAt
|
|
49584
50054
|
};
|
|
49585
50055
|
if (!identity.clientId || !Number.isFinite(identity.issuedAt) || !identity.scopes?.includes("openid"))
|
|
49586
50056
|
throw unauthorized();
|
|
@@ -49621,53 +50091,53 @@ init_define_GROVE_TELEMETRY();
|
|
|
49621
50091
|
|
|
49622
50092
|
// lib/environment/src/index.ts
|
|
49623
50093
|
init_define_GROVE_TELEMETRY();
|
|
49624
|
-
import { z as
|
|
49625
|
-
var origin =
|
|
50094
|
+
import { z as z31 } from "zod";
|
|
50095
|
+
var origin = z31.url().transform((value, ctx) => {
|
|
49626
50096
|
const url = new URL(value);
|
|
49627
50097
|
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))) {
|
|
49628
50098
|
ctx.addIssue({
|
|
49629
50099
|
code: "custom",
|
|
49630
50100
|
message: "Use an HTTPS origin (HTTP is allowed on loopback)"
|
|
49631
50101
|
});
|
|
49632
|
-
return
|
|
50102
|
+
return z31.NEVER;
|
|
49633
50103
|
}
|
|
49634
50104
|
return url.origin;
|
|
49635
50105
|
});
|
|
49636
|
-
var allowance = (value) =>
|
|
49637
|
-
var serverSchema =
|
|
49638
|
-
NODE_ENV:
|
|
49639
|
-
PORT:
|
|
49640
|
-
DATABASE_URL:
|
|
49641
|
-
DATABASE_SSL:
|
|
49642
|
-
DATABASE_POOL_MAX:
|
|
49643
|
-
DATABASE_ACQUIRE_TIMEOUT_MS:
|
|
49644
|
-
DATABASE_STATEMENT_TIMEOUT_MS:
|
|
49645
|
-
API_MAX_IN_FLIGHT:
|
|
49646
|
-
API_MAX_QUEUED:
|
|
49647
|
-
API_QUEUE_TIMEOUT_MS:
|
|
49648
|
-
API_REQUEST_TIMEOUT_MS:
|
|
49649
|
-
API_INTERACTIVE_CONCURRENCY:
|
|
49650
|
-
API_INTERACTIVE_TIMEOUT_MS:
|
|
50106
|
+
var allowance = (value) => z31.coerce.number().int().min(0).max(1e9).default(value);
|
|
50107
|
+
var serverSchema = z31.object({
|
|
50108
|
+
NODE_ENV: z31.enum(["development", "test", "production"]).default("development"),
|
|
50109
|
+
PORT: z31.coerce.number().int().min(1).max(65535).default(26080),
|
|
50110
|
+
DATABASE_URL: z31.string().min(1),
|
|
50111
|
+
DATABASE_SSL: z31.enum(["require", "disable"]).default("disable"),
|
|
50112
|
+
DATABASE_POOL_MAX: z31.coerce.number().int().min(1).max(64).default(8),
|
|
50113
|
+
DATABASE_ACQUIRE_TIMEOUT_MS: z31.coerce.number().int().min(100).max(3e4).default(2e3),
|
|
50114
|
+
DATABASE_STATEMENT_TIMEOUT_MS: z31.coerce.number().int().min(100).max(3e4).default(1e4),
|
|
50115
|
+
API_MAX_IN_FLIGHT: z31.coerce.number().int().min(1).max(256).default(32),
|
|
50116
|
+
API_MAX_QUEUED: z31.coerce.number().int().min(0).max(256).default(32),
|
|
50117
|
+
API_QUEUE_TIMEOUT_MS: z31.coerce.number().int().min(1).max(5e3).default(250),
|
|
50118
|
+
API_REQUEST_TIMEOUT_MS: z31.coerce.number().int().min(100).max(6e4).default(1e4),
|
|
50119
|
+
API_INTERACTIVE_CONCURRENCY: z31.coerce.number().int().min(1).max(32).default(4),
|
|
50120
|
+
API_INTERACTIVE_TIMEOUT_MS: z31.coerce.number().int().min(100).max(18e4).default(9e4),
|
|
49651
50121
|
API_ORIGIN: origin,
|
|
49652
50122
|
SITE_URL: origin,
|
|
49653
50123
|
// Public ownership proof, never an account credential. Empty values are omitted below.
|
|
49654
|
-
OPENAI_APPS_CHALLENGE:
|
|
50124
|
+
OPENAI_APPS_CHALLENGE: z31.string().min(1).max(512).refine(
|
|
49655
50125
|
(value) => !/\s/.test(value),
|
|
49656
50126
|
"Use the exact non-whitespace verification token"
|
|
49657
50127
|
).optional(),
|
|
49658
|
-
CLERK_PUBLISHABLE_KEY:
|
|
49659
|
-
CLERK_SECRET_KEY:
|
|
50128
|
+
CLERK_PUBLISHABLE_KEY: z31.string().startsWith("pk_"),
|
|
50129
|
+
CLERK_SECRET_KEY: z31.string().startsWith("sk_"),
|
|
49660
50130
|
CLERK_ISSUER: origin,
|
|
49661
|
-
CLERK_WEBHOOK_SIGNING_SECRET:
|
|
49662
|
-
GROVE_EDITION:
|
|
49663
|
-
BILLING_CONFIGURED:
|
|
49664
|
-
FLAGS:
|
|
49665
|
-
STRIPE_SECRET_KEY:
|
|
49666
|
-
STRIPE_WEBHOOK_SECRET:
|
|
49667
|
-
STRIPE_PRO_PRODUCT_ID:
|
|
49668
|
-
STRIPE_PORTAL_CONFIGURATION_ID:
|
|
49669
|
-
STRIPE_PRO_MONTHLY_PRICE_ID:
|
|
49670
|
-
STRIPE_PRO_YEARLY_PRICE_ID:
|
|
50131
|
+
CLERK_WEBHOOK_SIGNING_SECRET: z31.string().min(1),
|
|
50132
|
+
GROVE_EDITION: z31.enum(["self-hosted", "cloud"]).default("self-hosted"),
|
|
50133
|
+
BILLING_CONFIGURED: z31.enum(["true", "false"]).default("false").transform((value) => value === "true"),
|
|
50134
|
+
FLAGS: z31.string().min(1).optional(),
|
|
50135
|
+
STRIPE_SECRET_KEY: z31.string().regex(/^(sk|rk)_(test|live)_/).optional(),
|
|
50136
|
+
STRIPE_WEBHOOK_SECRET: z31.string().startsWith("whsec_").optional(),
|
|
50137
|
+
STRIPE_PRO_PRODUCT_ID: z31.string().startsWith("prod_").optional(),
|
|
50138
|
+
STRIPE_PORTAL_CONFIGURATION_ID: z31.string().startsWith("bpc_").optional(),
|
|
50139
|
+
STRIPE_PRO_MONTHLY_PRICE_ID: z31.string().startsWith("price_").optional(),
|
|
50140
|
+
STRIPE_PRO_YEARLY_PRICE_ID: z31.string().startsWith("price_").optional(),
|
|
49671
50141
|
BILLING_FREE_GENERATION_DAILY: allowance(
|
|
49672
50142
|
billingLimits.free.generation.daily
|
|
49673
50143
|
),
|
|
@@ -49711,51 +50181,51 @@ var serverSchema = z28.object({
|
|
|
49711
50181
|
BILLING_PRO_ASSISTANCE_MONTHLY: allowance(resourceLimits.pro.assistance),
|
|
49712
50182
|
BILLING_PRO_WRITING_MONTHLY: allowance(resourceLimits.pro.writing),
|
|
49713
50183
|
// Reject old deployment settings instead of silently treating characters as time.
|
|
49714
|
-
BILLING_FREE_SYNTHESIS_MONTHLY_CHARACTERS:
|
|
49715
|
-
BILLING_PRO_SYNTHESIS_MONTHLY_CHARACTERS:
|
|
49716
|
-
EMBEDDING_MODE:
|
|
49717
|
-
EMBEDDING_CACHE:
|
|
49718
|
-
EMBEDDING_URL:
|
|
49719
|
-
EMBEDDING_MODEL:
|
|
49720
|
-
EMBEDDING_API_KEY:
|
|
49721
|
-
EMBEDDING_DIMENSIONS:
|
|
49722
|
-
EMBEDDING_QUERY_PREFIX:
|
|
49723
|
-
EMBEDDING_DOCUMENT_PREFIX:
|
|
49724
|
-
EMBEDDING_DISTANCE_THRESHOLD:
|
|
49725
|
-
DECISION_PROVIDER:
|
|
49726
|
-
DECISION_URL:
|
|
49727
|
-
DECISION_MODEL:
|
|
49728
|
-
DECISION_API_KEY:
|
|
49729
|
-
DECISION_PATH:
|
|
49730
|
-
GENERATION_PROVIDER:
|
|
49731
|
-
GENERATION_URL:
|
|
49732
|
-
GENERATION_MODEL:
|
|
49733
|
-
GENERATION_API_KEY:
|
|
49734
|
-
GENERATION_OUTPUT_FORMAT:
|
|
49735
|
-
GENERATION_REASONING_EFFORT:
|
|
49736
|
-
GENERATION_MAX_OUTPUT_TOKENS:
|
|
49737
|
-
DEEPINFRA_API_KEY:
|
|
49738
|
-
MINIMAX_API_KEY:
|
|
49739
|
-
OPENAI_API_KEY:
|
|
49740
|
-
SPEECH_ENABLED:
|
|
49741
|
-
TTS_VOICE:
|
|
49742
|
-
MINIMAX_TTS_ENABLED:
|
|
49743
|
-
SPEECH_PROVIDER_CONCURRENCY:
|
|
49744
|
-
EXA_API_KEY:
|
|
49745
|
-
TAVILY_API_KEY:
|
|
49746
|
-
RESEARCH_DAILY_CALL_LIMIT:
|
|
49747
|
-
RESEARCH_MONTHLY_BUDGET_USD:
|
|
49748
|
-
MODEL_ADMIN_SUBJECTS:
|
|
49749
|
-
MODEL_SETTINGS_KEY:
|
|
49750
|
-
AI_DAILY_REQUEST_LIMIT:
|
|
49751
|
-
AI_CONCURRENCY:
|
|
49752
|
-
INDEXING_CONCURRENCY:
|
|
49753
|
-
EMAIL_CONCURRENCY:
|
|
49754
|
-
MAINTENANCE_CONCURRENCY:
|
|
49755
|
-
BULK_CONCURRENCY:
|
|
49756
|
-
JOB_ACCOUNT_CONCURRENCY:
|
|
49757
|
-
JOB_PROVIDER_CONCURRENCY:
|
|
49758
|
-
WORKER_LANES:
|
|
50184
|
+
BILLING_FREE_SYNTHESIS_MONTHLY_CHARACTERS: z31.string().optional(),
|
|
50185
|
+
BILLING_PRO_SYNTHESIS_MONTHLY_CHARACTERS: z31.string().optional(),
|
|
50186
|
+
EMBEDDING_MODE: z31.enum(["local", "remote", "disabled"]).optional(),
|
|
50187
|
+
EMBEDDING_CACHE: z31.string().default("./data/models"),
|
|
50188
|
+
EMBEDDING_URL: z31.string().optional(),
|
|
50189
|
+
EMBEDDING_MODEL: z31.string().optional(),
|
|
50190
|
+
EMBEDDING_API_KEY: z31.string().optional(),
|
|
50191
|
+
EMBEDDING_DIMENSIONS: z31.coerce.number().int().min(32).max(16e3).optional(),
|
|
50192
|
+
EMBEDDING_QUERY_PREFIX: z31.string().optional(),
|
|
50193
|
+
EMBEDDING_DOCUMENT_PREFIX: z31.string().optional(),
|
|
50194
|
+
EMBEDDING_DISTANCE_THRESHOLD: z31.coerce.number().min(0).max(2).optional(),
|
|
50195
|
+
DECISION_PROVIDER: z31.enum(["system-one", "disabled"]).default("disabled"),
|
|
50196
|
+
DECISION_URL: z31.string().optional(),
|
|
50197
|
+
DECISION_MODEL: z31.string().optional(),
|
|
50198
|
+
DECISION_API_KEY: z31.string().optional(),
|
|
50199
|
+
DECISION_PATH: z31.enum(["/decisions", "/systemone"]).default("/decisions"),
|
|
50200
|
+
GENERATION_PROVIDER: z31.enum(["minimax", "openai-compatible", "disabled"]).default("disabled"),
|
|
50201
|
+
GENERATION_URL: z31.string().optional(),
|
|
50202
|
+
GENERATION_MODEL: z31.string().optional(),
|
|
50203
|
+
GENERATION_API_KEY: z31.string().optional(),
|
|
50204
|
+
GENERATION_OUTPUT_FORMAT: z31.enum(["tool", "json-schema", "json"]).default("tool"),
|
|
50205
|
+
GENERATION_REASONING_EFFORT: z31.enum(["low", "medium", "high", "omit"]).default("low"),
|
|
50206
|
+
GENERATION_MAX_OUTPUT_TOKENS: z31.coerce.number().int().min(256).max(16384).default(4096),
|
|
50207
|
+
DEEPINFRA_API_KEY: z31.string().optional(),
|
|
50208
|
+
MINIMAX_API_KEY: z31.string().optional(),
|
|
50209
|
+
OPENAI_API_KEY: z31.string().optional(),
|
|
50210
|
+
SPEECH_ENABLED: z31.enum(["true", "false"]).default("false").transform((value) => value === "true"),
|
|
50211
|
+
TTS_VOICE: z31.enum(["alloy", "echo", "fable", "onyx", "nova", "shimmer"]).default("alloy"),
|
|
50212
|
+
MINIMAX_TTS_ENABLED: z31.enum(["true", "false"]).default("false").transform((value) => value === "true"),
|
|
50213
|
+
SPEECH_PROVIDER_CONCURRENCY: z31.coerce.number().int().min(1).max(16).default(2),
|
|
50214
|
+
EXA_API_KEY: z31.string().optional(),
|
|
50215
|
+
TAVILY_API_KEY: z31.string().optional(),
|
|
50216
|
+
RESEARCH_DAILY_CALL_LIMIT: z31.coerce.number().int().min(1).max(1e4).default(20),
|
|
50217
|
+
RESEARCH_MONTHLY_BUDGET_USD: z31.coerce.number().min(0).max(1e5).default(100),
|
|
50218
|
+
MODEL_ADMIN_SUBJECTS: z31.string().default(""),
|
|
50219
|
+
MODEL_SETTINGS_KEY: z31.string().regex(/^[0-9a-f]{64}$/i).optional(),
|
|
50220
|
+
AI_DAILY_REQUEST_LIMIT: z31.coerce.number().int().min(1).max(1e6).default(2e3),
|
|
50221
|
+
AI_CONCURRENCY: z31.coerce.number().int().min(1).max(32).default(4),
|
|
50222
|
+
INDEXING_CONCURRENCY: z31.coerce.number().int().min(0).max(32).default(2),
|
|
50223
|
+
EMAIL_CONCURRENCY: z31.coerce.number().int().min(0).max(8).default(1),
|
|
50224
|
+
MAINTENANCE_CONCURRENCY: z31.coerce.number().int().min(0).max(8).default(1),
|
|
50225
|
+
BULK_CONCURRENCY: z31.coerce.number().int().min(0).max(8).default(1),
|
|
50226
|
+
JOB_ACCOUNT_CONCURRENCY: z31.coerce.number().int().min(1).max(8).default(2),
|
|
50227
|
+
JOB_PROVIDER_CONCURRENCY: z31.coerce.number().int().min(1).max(128).default(8),
|
|
50228
|
+
WORKER_LANES: z31.string().default("indexing,enrichment,email,maintenance,bulk").refine(
|
|
49759
50229
|
(value) => value.split(",").every(
|
|
49760
50230
|
(lane) => ["indexing", "enrichment", "email", "maintenance", "bulk"].includes(
|
|
49761
50231
|
lane
|
|
@@ -49763,38 +50233,38 @@ var serverSchema = z28.object({
|
|
|
49763
50233
|
),
|
|
49764
50234
|
"Unknown worker lane"
|
|
49765
50235
|
),
|
|
49766
|
-
WORKER_LEGACY_QUEUE:
|
|
49767
|
-
EXPORT_STORAGE:
|
|
50236
|
+
WORKER_LEGACY_QUEUE: z31.enum(["true", "false"]).default("true").transform((value) => value === "true"),
|
|
50237
|
+
EXPORT_STORAGE: z31.enum(["disabled", "local", "s3"]).optional(),
|
|
49768
50238
|
// Explicit opt-in until the revision-scoped media API is available.
|
|
49769
|
-
MEDIA_STORAGE:
|
|
49770
|
-
MEDIA_DIRECTORY:
|
|
49771
|
-
MEDIA_S3_ENDPOINT:
|
|
49772
|
-
MEDIA_S3_REGION:
|
|
49773
|
-
MEDIA_S3_BUCKET:
|
|
49774
|
-
MEDIA_S3_ACCESS_KEY_ID:
|
|
49775
|
-
MEDIA_S3_SECRET_ACCESS_KEY:
|
|
50239
|
+
MEDIA_STORAGE: z31.enum(["disabled", "local", "s3"]).default("disabled"),
|
|
50240
|
+
MEDIA_DIRECTORY: z31.string().default("./data/media"),
|
|
50241
|
+
MEDIA_S3_ENDPOINT: z31.url().optional(),
|
|
50242
|
+
MEDIA_S3_REGION: z31.string().default("us-east-1"),
|
|
50243
|
+
MEDIA_S3_BUCKET: z31.string().optional(),
|
|
50244
|
+
MEDIA_S3_ACCESS_KEY_ID: z31.string().optional(),
|
|
50245
|
+
MEDIA_S3_SECRET_ACCESS_KEY: z31.string().optional(),
|
|
49776
50246
|
// Exact endpoint/bucket receipt from an operator lifecycle/ACL inspection.
|
|
49777
50247
|
// Spaces scoped keys cannot read these settings; never use an account-wide key in runtime.
|
|
49778
|
-
MEDIA_S3_LIFECYCLE_VERIFIED_FOR:
|
|
49779
|
-
MEDIA_S3_PATH_STYLE:
|
|
49780
|
-
EXPORT_DIRECTORY:
|
|
49781
|
-
EXPORT_S3_ENDPOINT:
|
|
49782
|
-
EXPORT_S3_REGION:
|
|
49783
|
-
EXPORT_S3_BUCKET:
|
|
49784
|
-
EXPORT_S3_ACCESS_KEY_ID:
|
|
49785
|
-
EXPORT_S3_SECRET_ACCESS_KEY:
|
|
49786
|
-
EXPORT_S3_PATH_STYLE:
|
|
49787
|
-
AMQP_URL:
|
|
50248
|
+
MEDIA_S3_LIFECYCLE_VERIFIED_FOR: z31.string().optional(),
|
|
50249
|
+
MEDIA_S3_PATH_STYLE: z31.enum(["true", "false"]).default("false").transform((value) => value === "true"),
|
|
50250
|
+
EXPORT_DIRECTORY: z31.string().default("./data/exports"),
|
|
50251
|
+
EXPORT_S3_ENDPOINT: z31.url().optional(),
|
|
50252
|
+
EXPORT_S3_REGION: z31.string().default("us-east-1"),
|
|
50253
|
+
EXPORT_S3_BUCKET: z31.string().optional(),
|
|
50254
|
+
EXPORT_S3_ACCESS_KEY_ID: z31.string().optional(),
|
|
50255
|
+
EXPORT_S3_SECRET_ACCESS_KEY: z31.string().optional(),
|
|
50256
|
+
EXPORT_S3_PATH_STYLE: z31.enum(["true", "false"]).default("false").transform((value) => value === "true"),
|
|
50257
|
+
AMQP_URL: z31.url().refine(
|
|
49788
50258
|
(value) => new URL(value).protocol === "amqps:",
|
|
49789
50259
|
"Use TLS for the job broker"
|
|
49790
50260
|
).optional(),
|
|
49791
|
-
ORGANIZATION_INTERVAL_SECONDS:
|
|
49792
|
-
RESEND_API_KEY:
|
|
49793
|
-
EMAIL_FROM:
|
|
49794
|
-
CURSOR_SECRET:
|
|
49795
|
-
WRITING_STAGING_KEY:
|
|
49796
|
-
WRITING_PROVIDER_NOTICE:
|
|
49797
|
-
SHARE_LINK_KEY:
|
|
50261
|
+
ORGANIZATION_INTERVAL_SECONDS: z31.coerce.number().int().min(60).max(86400).default(900),
|
|
50262
|
+
RESEND_API_KEY: z31.string().startsWith("re_").optional(),
|
|
50263
|
+
EMAIL_FROM: z31.string().email().default("notifications@mail.usegrove.cloud"),
|
|
50264
|
+
CURSOR_SECRET: z31.string().min(32),
|
|
50265
|
+
WRITING_STAGING_KEY: z31.string().regex(/^[0-9a-f]{64}$/i).optional(),
|
|
50266
|
+
WRITING_PROVIDER_NOTICE: z31.string().trim().min(20).max(1e3).optional(),
|
|
50267
|
+
SHARE_LINK_KEY: z31.string().regex(/^[0-9a-f]{64}$/i).optional()
|
|
49798
50268
|
});
|
|
49799
50269
|
var serverEnvironmentSchema = serverSchema.superRefine((env, ctx) => {
|
|
49800
50270
|
if (env.WRITING_STAGING_KEY && !env.WRITING_PROVIDER_NOTICE)
|
|
@@ -50397,7 +50867,7 @@ init_define_GROVE_TELEMETRY();
|
|
|
50397
50867
|
init_media();
|
|
50398
50868
|
import { constants as constants3 } from "node:fs";
|
|
50399
50869
|
import { link, lstat, mkdir as mkdir2, open as open2, realpath, unlink as unlink2 } from "node:fs/promises";
|
|
50400
|
-
import { randomUUID as
|
|
50870
|
+
import { randomUUID as randomUUID20 } from "node:crypto";
|
|
50401
50871
|
import { dirname as dirname4, resolve as resolve3, sep as sep4 } from "node:path";
|
|
50402
50872
|
import { Readable as Readable4 } from "node:stream";
|
|
50403
50873
|
import {
|
|
@@ -50458,7 +50928,7 @@ function localMedia(root) {
|
|
|
50458
50928
|
const publish = async (key2, image, signal) => {
|
|
50459
50929
|
signal.throwIfAborted();
|
|
50460
50930
|
const target2 = await directories(key2, true);
|
|
50461
|
-
const temporary = `${target2}.${
|
|
50931
|
+
const temporary = `${target2}.${randomUUID20()}.partial`;
|
|
50462
50932
|
const file = await open2(
|
|
50463
50933
|
temporary,
|
|
50464
50934
|
constants3.O_CREAT | constants3.O_EXCL | constants3.O_WRONLY | constants3.O_NOFOLLOW,
|
|
@@ -50544,7 +51014,7 @@ function s3Media(client, bucket, spacesLifecycleVerified = false) {
|
|
|
50544
51014
|
{ abortSignal: signal }
|
|
50545
51015
|
);
|
|
50546
51016
|
if (lifecycle.Rules?.some(
|
|
50547
|
-
(
|
|
51017
|
+
(rule2) => rule2.Status === "Enabled" && (rule2.Expiration || rule2.NoncurrentVersionExpiration)
|
|
50548
51018
|
))
|
|
50549
51019
|
throw new Error("media_bucket_must_not_expire_source");
|
|
50550
51020
|
} catch (error3) {
|
|
@@ -50552,7 +51022,7 @@ function s3Media(client, bucket, spacesLifecycleVerified = false) {
|
|
|
50552
51022
|
if (name !== "NoSuchLifecycleConfiguration" && !(name === "AccessDenied" && spacesLifecycleVerified))
|
|
50553
51023
|
throw error3;
|
|
50554
51024
|
}
|
|
50555
|
-
const probe = `media-probes/${
|
|
51025
|
+
const probe = `media-probes/${randomUUID20()}`;
|
|
50556
51026
|
try {
|
|
50557
51027
|
const put = (body) => client.send(
|
|
50558
51028
|
new PutObjectCommand2({
|
|
@@ -50813,6 +51283,7 @@ async function startServer() {
|
|
|
50813
51283
|
telemetry: reporter,
|
|
50814
51284
|
shareLinkKey: env.SHARE_LINK_KEY,
|
|
50815
51285
|
writingStagingKey: env.WRITING_STAGING_KEY,
|
|
51286
|
+
languageToolUrl: process.env.LANGUAGETOOL_URL,
|
|
50816
51287
|
writingProviderNotice: env.WRITING_PROVIDER_NOTICE,
|
|
50817
51288
|
capacity: {
|
|
50818
51289
|
concurrency: env.API_MAX_IN_FLIGHT,
|