mirror of
https://github.com/docmost/docmost.git
synced 2026-08-25 15:57:11 +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
389 lines
9.5 KiB
TypeScript
389 lines
9.5 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { ConfigService } from '@nestjs/config';
|
|
import ms, { StringValue } from 'ms';
|
|
|
|
@Injectable()
|
|
export class EnvironmentService {
|
|
constructor(private configService: ConfigService) {}
|
|
|
|
getNodeEnv(): string {
|
|
return this.configService.get<string>('NODE_ENV', 'development');
|
|
}
|
|
|
|
isDevelopment(): boolean {
|
|
return this.getNodeEnv() === 'development';
|
|
}
|
|
|
|
getAppUrl(): string {
|
|
const rawUrl =
|
|
this.configService.get<string>('APP_URL') ||
|
|
`http://localhost:${this.getPort()}`;
|
|
|
|
const { origin } = new URL(rawUrl);
|
|
return origin;
|
|
}
|
|
|
|
isHttps(): boolean {
|
|
const appUrl = this.configService.get<string>('APP_URL');
|
|
try {
|
|
const url = new URL(appUrl);
|
|
return url.protocol === 'https:';
|
|
} catch (error) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
getSubdomainHost(): string {
|
|
return this.configService.get<string>('SUBDOMAIN_HOST');
|
|
}
|
|
|
|
getPort(): number {
|
|
return parseInt(this.configService.get<string>('PORT', '3000'));
|
|
}
|
|
|
|
getAppSecret(): string {
|
|
return this.configService.get<string>('APP_SECRET');
|
|
}
|
|
|
|
getDatabaseURL(): string {
|
|
return this.configService.get<string>('DATABASE_URL');
|
|
}
|
|
|
|
getDatabaseMaxPool(): number {
|
|
return parseInt(this.configService.get<string>('DATABASE_MAX_POOL', '10'));
|
|
}
|
|
|
|
getRedisUrl(): string {
|
|
return this.configService.get<string>(
|
|
'REDIS_URL',
|
|
'redis://localhost:6379',
|
|
);
|
|
}
|
|
|
|
getJwtTokenExpiresIn(): string {
|
|
return this.configService.get<string>('JWT_TOKEN_EXPIRES_IN', '90d');
|
|
}
|
|
|
|
getCookieExpiresIn(): Date {
|
|
const expiresInStr = this.getJwtTokenExpiresIn();
|
|
let msUntilExpiry: number;
|
|
try {
|
|
msUntilExpiry = ms(expiresInStr as StringValue);
|
|
} catch (err) {
|
|
msUntilExpiry = ms('90d');
|
|
}
|
|
return new Date(Date.now() + msUntilExpiry);
|
|
}
|
|
|
|
getGotenbergUrl(): string | undefined {
|
|
return this.configService.get<string>('GOTENBERG_URL');
|
|
}
|
|
|
|
getStorageDriver(): string {
|
|
return this.configService.get<string>('STORAGE_DRIVER', 'local');
|
|
}
|
|
|
|
getFileUploadSizeLimit(): string {
|
|
return this.configService.get<string>('FILE_UPLOAD_SIZE_LIMIT', '50mb');
|
|
}
|
|
|
|
getFileImportSizeLimit(): string {
|
|
return this.configService.get<string>('FILE_IMPORT_SIZE_LIMIT', '200mb');
|
|
}
|
|
|
|
getAwsS3AccessKeyId(): string {
|
|
return this.configService.get<string>('AWS_S3_ACCESS_KEY_ID');
|
|
}
|
|
|
|
getAwsS3SecretAccessKey(): string {
|
|
return this.configService.get<string>('AWS_S3_SECRET_ACCESS_KEY');
|
|
}
|
|
|
|
getAwsS3Region(): string {
|
|
return this.configService.get<string>('AWS_S3_REGION');
|
|
}
|
|
|
|
getAwsS3Bucket(): string {
|
|
return this.configService.get<string>('AWS_S3_BUCKET');
|
|
}
|
|
|
|
getAwsS3Endpoint(): string {
|
|
return this.configService.get<string>('AWS_S3_ENDPOINT');
|
|
}
|
|
|
|
getAwsS3ForcePathStyle(): boolean {
|
|
const forcePathStyle = this.configService
|
|
.get<string>('AWS_S3_FORCE_PATH_STYLE', 'false')
|
|
.toLowerCase();
|
|
return forcePathStyle === 'true';
|
|
}
|
|
|
|
getAwsS3Url(): string {
|
|
return this.configService.get<string>('AWS_S3_URL');
|
|
}
|
|
|
|
getAzureStorageAccountName(): string {
|
|
return this.configService.get<string>('AZURE_STORAGE_ACCOUNT_NAME');
|
|
}
|
|
|
|
getAzureStorageContainer(): string {
|
|
return this.configService.get<string>('AZURE_STORAGE_CONTAINER');
|
|
}
|
|
|
|
getAzureStorageAccountKey(): string {
|
|
return this.configService.get<string>('AZURE_STORAGE_ACCOUNT_KEY');
|
|
}
|
|
|
|
getAzureStorageEndpoint(): string {
|
|
return this.configService.get<string>('AZURE_STORAGE_ENDPOINT');
|
|
}
|
|
|
|
getAzureStorageUrl(): string {
|
|
return this.configService.get<string>('AZURE_STORAGE_URL');
|
|
}
|
|
|
|
getMailDriver(): string {
|
|
return this.configService.get<string>('MAIL_DRIVER', 'log');
|
|
}
|
|
|
|
getMailFromAddress(): string {
|
|
return this.configService.get<string>('MAIL_FROM_ADDRESS');
|
|
}
|
|
|
|
getMailFromName(): string {
|
|
return this.configService.get<string>('MAIL_FROM_NAME', 'Docmost');
|
|
}
|
|
|
|
getMailBlockedRecipientDomains(): string[] {
|
|
const raw = this.configService.get<string>(
|
|
'MAIL_BLOCKED_RECIPIENT_DOMAINS',
|
|
'',
|
|
);
|
|
return raw
|
|
.split(',')
|
|
.map((d) => d.trim().toLowerCase())
|
|
.filter(Boolean);
|
|
}
|
|
|
|
getSmtpHost(): string {
|
|
return this.configService.get<string>('SMTP_HOST');
|
|
}
|
|
|
|
getSmtpPort(): number {
|
|
return parseInt(this.configService.get<string>('SMTP_PORT'));
|
|
}
|
|
|
|
getSmtpSecure(): boolean {
|
|
const secure = this.configService
|
|
.get<string>('SMTP_SECURE', 'false')
|
|
.toLowerCase();
|
|
return secure === 'true';
|
|
}
|
|
|
|
getSmtpIgnoreTLS(): boolean {
|
|
const ignoretls = this.configService
|
|
.get<string>('SMTP_IGNORETLS', 'false')
|
|
.toLowerCase();
|
|
return ignoretls === 'true';
|
|
}
|
|
|
|
getSmtpUsername(): string {
|
|
return this.configService.get<string>('SMTP_USERNAME');
|
|
}
|
|
|
|
getSmtpPassword(): string {
|
|
return this.configService.get<string>('SMTP_PASSWORD');
|
|
}
|
|
|
|
getPostmarkToken(): string {
|
|
return this.configService.get<string>('POSTMARK_TOKEN');
|
|
}
|
|
|
|
getDrawioUrl(): string {
|
|
return this.configService.get<string>('DRAWIO_URL');
|
|
}
|
|
|
|
isCloud(): boolean {
|
|
const cloudConfig = this.configService
|
|
.get<string>('CLOUD', 'false')
|
|
.toLowerCase();
|
|
return cloudConfig === 'true';
|
|
}
|
|
|
|
isSelfHosted(): boolean {
|
|
return !this.isCloud();
|
|
}
|
|
|
|
getStripePublishableKey(): string {
|
|
return this.configService.get<string>('STRIPE_PUBLISHABLE_KEY');
|
|
}
|
|
|
|
getStripeSecretKey(): string {
|
|
return this.configService.get<string>('STRIPE_SECRET_KEY');
|
|
}
|
|
|
|
getStripeWebhookSecret(): string {
|
|
return this.configService.get<string>('STRIPE_WEBHOOK_SECRET');
|
|
}
|
|
|
|
getBillingTrialDays(): number {
|
|
return parseInt(this.configService.get<string>('BILLING_TRIAL_DAYS', '14'));
|
|
}
|
|
|
|
getCollabUrl(): string {
|
|
return this.configService.get<string>('COLLAB_URL');
|
|
}
|
|
|
|
isCollabDisableRedis(): boolean {
|
|
const isStandalone = this.configService
|
|
.get<string>('COLLAB_DISABLE_REDIS', 'false')
|
|
.toLowerCase();
|
|
return isStandalone === 'true';
|
|
}
|
|
|
|
isDisableTelemetry(): boolean {
|
|
const disable = this.configService
|
|
.get<string>('DISABLE_TELEMETRY', 'false')
|
|
.toLowerCase();
|
|
return disable === 'true';
|
|
}
|
|
|
|
getPostHogHost(): string {
|
|
return this.configService.get<string>('POSTHOG_HOST');
|
|
}
|
|
|
|
getPostHogKey(): string {
|
|
return this.configService.get<string>('POSTHOG_KEY');
|
|
}
|
|
|
|
getSearchDriver(): string {
|
|
return this.configService
|
|
.get<string>('SEARCH_DRIVER', 'database')
|
|
.toLowerCase();
|
|
}
|
|
|
|
getTypesenseUrl(): string {
|
|
return this.configService
|
|
.get<string>('TYPESENSE_URL', 'http://localhost:8108')
|
|
.toLowerCase();
|
|
}
|
|
|
|
getTypesenseApiKey(): string {
|
|
return this.configService.get<string>('TYPESENSE_API_KEY');
|
|
}
|
|
|
|
getTypesenseLocale(): string {
|
|
return this.configService
|
|
.get<string>('TYPESENSE_LOCALE', 'en')
|
|
.toLowerCase();
|
|
}
|
|
|
|
getAiDriver(): string {
|
|
return this.configService.get<string>('AI_DRIVER');
|
|
}
|
|
|
|
getAiEmbeddingModel(): string {
|
|
return this.configService.get<string>('AI_EMBEDDING_MODEL');
|
|
}
|
|
|
|
getAiCompletionModel(): string {
|
|
return this.configService.get<string>('AI_COMPLETION_MODEL');
|
|
}
|
|
|
|
getAiChatModel(): string {
|
|
return (
|
|
this.configService.get<string>('AI_CHAT_MODEL') ||
|
|
this.configService.get<string>('AI_COMPLETION_MODEL')
|
|
);
|
|
}
|
|
|
|
getAiEmbeddingDimension(): number {
|
|
return parseInt(
|
|
this.configService.get<string>('AI_EMBEDDING_DIMENSION'),
|
|
10,
|
|
);
|
|
}
|
|
|
|
getAiEmbeddingSupportsMrl(): boolean | undefined {
|
|
const val = this.configService.get<string>('AI_EMBEDDING_SUPPORTS_MRL');
|
|
if (val === undefined || val === null || val === '') return undefined;
|
|
return val === 'true';
|
|
}
|
|
|
|
getAiVectorDriver(): string {
|
|
return this.configService
|
|
.get<string>('AI_VECTOR_DRIVER', 'pgvector')
|
|
.toLowerCase();
|
|
}
|
|
|
|
getTurbopufferApiKey(): string {
|
|
return this.configService.get<string>('TURBOPUFFER_API_KEY');
|
|
}
|
|
|
|
getTurbopufferRegion(): string {
|
|
return this.configService.get<string>('TURBOPUFFER_REGION');
|
|
}
|
|
|
|
getTurbopufferBaseUrl(): string {
|
|
return this.configService.get<string>('TURBOPUFFER_BASE_URL');
|
|
}
|
|
|
|
getTurbopufferNamespacePrefix(): string {
|
|
return this.configService.get<string>(
|
|
'TURBOPUFFER_NAMESPACE_PREFIX',
|
|
'docmost',
|
|
);
|
|
}
|
|
|
|
getOpenAiApiKey(): string {
|
|
return this.configService.get<string>('OPENAI_API_KEY');
|
|
}
|
|
|
|
getOpenAiApiUrl(): string {
|
|
return this.configService.get<string>('OPENAI_API_URL');
|
|
}
|
|
|
|
getGeminiApiKey(): string {
|
|
return this.configService.get<string>('GEMINI_API_KEY');
|
|
}
|
|
|
|
getOllamaApiUrl(): string {
|
|
return this.configService.get<string>(
|
|
'OLLAMA_API_URL',
|
|
'http://localhost:11434',
|
|
);
|
|
}
|
|
|
|
getEventStoreDriver(): string {
|
|
return this.configService
|
|
.get<string>('EVENT_STORE_DRIVER', 'postgres')
|
|
.toLowerCase();
|
|
}
|
|
|
|
getClickHouseUrl(): string {
|
|
return this.configService.get<string>('CLICKHOUSE_URL');
|
|
}
|
|
|
|
getSamlDisableRequestedAuthnContext(): boolean {
|
|
const disabled = this.configService
|
|
.get<string>('SAML_DISABLE_REQUESTED_AUTHN_CONTEXT', 'false')
|
|
.toLowerCase();
|
|
return disabled === 'true';
|
|
}
|
|
|
|
isIframeEmbedAllowed(): boolean {
|
|
const allowed = this.configService
|
|
.get<string>('IFRAME_EMBED_ALLOWED', 'false')
|
|
.toLowerCase();
|
|
return allowed === 'true';
|
|
}
|
|
|
|
getIframeAllowedOrigins(): string[] {
|
|
const raw = this.configService.get<string>('IFRAME_ALLOWED_ORIGINS', '');
|
|
return raw
|
|
.split(',')
|
|
.map((o) => o.trim())
|
|
.filter(Boolean);
|
|
}
|
|
}
|