mirror of
https://github.com/docmost/docmost.git
synced 2026-08-27 08:47:06 +08:00
* feat(ai): add AI_VECTOR_DRIVER and turbopuffer configuration * feat(ai): carry workspace and target space ids on vector lifecycle events * feat(ai): add vector driver interface and turbopuffer request helpers * feat(ai): add pgvector driver behind the vector driver interface * refactor(ai): route vector reads and writes through the vector driver * feat(ai): add turbopuffer vector driver * feat(ai): rebuild turbopuffer namespaces when the embedding model changes * feat(ai): warm the vector namespace cache on session start * fix(ai): harden turbopuffer misconfiguration and reset failure paths * fix(ai): collapse blank-line runs in extracted page text * fix(ai): skip full re-embed when ai search is re-enabled within the delete grace window * sync * fix(ai): store real embedding dimensions instead of serialized vector length * fix(ai): filter search hits by the page's current space at query time * fix(ai): retry the page moved-to-space vector patch job * sync * feat(ai): pre-warm the vector namespace * fix(ai): pass AI_VECTOR_DRIVER through the client build config
113 lines
2.8 KiB
TypeScript
113 lines
2.8 KiB
TypeScript
import bytes from "bytes";
|
|
import { castToBoolean } from "@/lib/utils.tsx";
|
|
import { AvatarIconType } from "@/features/attachments/types/attachment.types.ts";
|
|
import { sanitizeUrl } from "@docmost/editor-ext";
|
|
|
|
declare global {
|
|
interface Window {
|
|
CONFIG?: Record<string, string>;
|
|
}
|
|
}
|
|
|
|
export function getAppName(): string {
|
|
return "Docmost";
|
|
}
|
|
|
|
export function getAppUrl(): string {
|
|
return `${window.location.protocol}//${window.location.host}`;
|
|
}
|
|
|
|
export function getServerAppUrl(): string {
|
|
return getConfigValue("APP_URL");
|
|
}
|
|
|
|
export function getBackendUrl(): string {
|
|
return getAppUrl() + "/api";
|
|
}
|
|
|
|
export function getCollaborationUrl(): string {
|
|
const baseUrl =
|
|
getConfigValue("COLLAB_URL") ||
|
|
(import.meta.env.DEV ? process.env.APP_URL : getAppUrl());
|
|
|
|
const collabUrl = new URL("/collab", baseUrl);
|
|
collabUrl.protocol = collabUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
return collabUrl.toString();
|
|
}
|
|
|
|
export function getSubdomainHost(): string {
|
|
return getConfigValue("SUBDOMAIN_HOST");
|
|
}
|
|
|
|
export function isCloud(): boolean {
|
|
return castToBoolean(getConfigValue("CLOUD"));
|
|
}
|
|
|
|
export function getAiVectorDriver(): string {
|
|
return getConfigValue("AI_VECTOR_DRIVER");
|
|
}
|
|
|
|
export function getAvatarUrl(
|
|
avatarUrl: string,
|
|
type: AvatarIconType = AvatarIconType.AVATAR,
|
|
) {
|
|
if (!avatarUrl) return null;
|
|
if (avatarUrl?.startsWith("http")) return avatarUrl;
|
|
|
|
return getBackendUrl() + `/attachments/img/${type}/` + encodeURI(avatarUrl);
|
|
}
|
|
|
|
export function getSpaceUrl(spaceSlug: string) {
|
|
return "/s/" + spaceSlug;
|
|
}
|
|
|
|
export function getFileUrl(src: string) {
|
|
if (!src) return src;
|
|
if (src.startsWith("http")) return src;
|
|
if (src.startsWith("/api/")) {
|
|
// Remove the '/api' prefix
|
|
return getBackendUrl() + src.substring(4);
|
|
}
|
|
if (src.startsWith("/files/")) {
|
|
return getBackendUrl() + src;
|
|
}
|
|
return sanitizeUrl(src);
|
|
}
|
|
|
|
export function getFileUploadSizeLimit() {
|
|
const limit = getConfigValue("FILE_UPLOAD_SIZE_LIMIT", "50mb");
|
|
return bytes(limit);
|
|
}
|
|
|
|
export function getFileImportSizeLimit() {
|
|
const limit = getConfigValue("FILE_IMPORT_SIZE_LIMIT", "200mb");
|
|
return bytes(limit);
|
|
}
|
|
|
|
export function getDrawioUrl() {
|
|
return getConfigValue("DRAWIO_URL", "https://embed.diagrams.net");
|
|
}
|
|
|
|
export function getBillingTrialDays() {
|
|
return getConfigValue("BILLING_TRIAL_DAYS");
|
|
}
|
|
|
|
export function getPostHogHost() {
|
|
return getConfigValue("POSTHOG_HOST");
|
|
}
|
|
|
|
export function isPostHogEnabled(): boolean {
|
|
return Boolean(getPostHogHost() && getPostHogKey());
|
|
}
|
|
|
|
export function getPostHogKey() {
|
|
return getConfigValue("POSTHOG_KEY");
|
|
}
|
|
|
|
function getConfigValue(key: string, defaultValue: string = undefined): string {
|
|
const rawValue = import.meta.env.DEV
|
|
? process?.env?.[key]
|
|
: window?.CONFIG?.[key];
|
|
return rawValue ?? defaultValue;
|
|
}
|