117 lines
4.3 KiB
TypeScript
117 lines
4.3 KiB
TypeScript
import { z } from 'zod';
|
|
import { EntityIdSchema, HttpUrlSchema, IanaTimezoneSchema } from './common.js';
|
|
|
|
export const ThemeIdSchema = z.enum([
|
|
'phosphor-green',
|
|
'amber-term',
|
|
'nord-dark',
|
|
'gruvbox-dark',
|
|
'paper-light',
|
|
'solarized-dark',
|
|
'tokyo-night',
|
|
'high-contrast',
|
|
]);
|
|
|
|
export const THEME_IDS = ThemeIdSchema.options;
|
|
|
|
export const ThrottleModeSchema = z.enum(['low-resource', 'balanced', 'unthrottled']);
|
|
|
|
export const StepUpPolicySchema = z.enum([
|
|
'off',
|
|
'every-action',
|
|
'5m',
|
|
'15m',
|
|
'1h',
|
|
'24h',
|
|
'session',
|
|
]);
|
|
|
|
export const StepUpMethodSchema = z.enum(['totp', 'password', 'both', 'passkey']);
|
|
|
|
export const SecuritySettingsSchema = z.object({
|
|
requireTotpOnLogin: z.boolean().default(true),
|
|
passwordMode: z.enum(['any', 'all']).default('any'),
|
|
totpMode: z.enum(['any', 'all']).default('any'),
|
|
stepUpPolicy: StepUpPolicySchema.default('15m'),
|
|
stepUpMethod: StepUpMethodSchema.default('totp'),
|
|
elevateOnLogin: z.boolean().default(false),
|
|
keepElevationOnSafeMode: z.boolean().default(true),
|
|
enableEmergencySecretsBackup: z.boolean().default(false),
|
|
allowSameOriginProxy: z.boolean().default(false),
|
|
egressAllowedCidrs: z.array(z.string().min(1).max(64)).max(64).default([]),
|
|
sessionTtlHours: z.number().int().min(1).max(720).default(168),
|
|
sessionIdleTimeoutMin: z.number().int().min(0).max(10080).default(60),
|
|
});
|
|
|
|
export const SettingsSchema = z.object({
|
|
version: z.literal(1).default(1),
|
|
theme: ThemeIdSchema.default('phosphor-green'),
|
|
defaultMobileSafeMode: z.boolean().default(true),
|
|
rawRetentionHours: z.number().int().min(1).max(720).default(48),
|
|
rollupRetentionDays: z.number().int().min(1).max(3650).default(30),
|
|
auditRetentionDays: z.number().int().min(1).max(3650).default(90),
|
|
workflowRunRetentionDays: z.number().int().min(1).max(3650).default(30),
|
|
alertEventRetentionDays: z.number().int().min(1).max(3650).default(30),
|
|
configRevisionLimit: z.number().int().min(5).max(500).default(50),
|
|
ptyScrollbackBytes: z.number().int().min(16384).max(2097152).default(262144),
|
|
ptyIdleTtlSec: z.number().int().min(60).max(604800).default(43200),
|
|
sshKeepaliveMs: z.number().int().min(5000).max(120000).default(15000),
|
|
sshReadyTimeoutMs: z.number().int().min(3000).max(120000).default(15000),
|
|
runtime: z
|
|
.object({
|
|
throttleMode: ThrottleModeSchema.default('low-resource'),
|
|
})
|
|
.default({ throttleMode: 'low-resource' }),
|
|
scheduledBackup: z
|
|
.object({
|
|
enabled: z.boolean().default(false),
|
|
cron: z.string().min(1).default('0 3 * * *'),
|
|
timezone: IanaTimezoneSchema.default('UTC'),
|
|
destination: z.enum(['local', 'sftp']).default('local'),
|
|
localDir: z.string().min(1).max(128).default('backups'),
|
|
remoteServerId: EntityIdSchema.optional(),
|
|
remotePath: z.string().min(1).max(256).optional(),
|
|
retentionCount: z.number().int().min(1).max(100).default(7),
|
|
passphraseSecretRef: EntityIdSchema.optional(),
|
|
})
|
|
.default({
|
|
enabled: false,
|
|
cron: '0 3 * * *',
|
|
timezone: 'UTC',
|
|
destination: 'local',
|
|
localDir: 'backups',
|
|
retentionCount: 7,
|
|
}),
|
|
metrics: z
|
|
.object({
|
|
prometheusEnabled: z.boolean().default(false),
|
|
prometheusSecretRef: EntityIdSchema.optional(),
|
|
})
|
|
.default({ prometheusEnabled: false }),
|
|
security: SecuritySettingsSchema.default({}),
|
|
ai: z
|
|
.object({
|
|
enabled: z.boolean().default(false),
|
|
baseUrl: HttpUrlSchema.default('http://127.0.0.1:11434'),
|
|
model: z.string().min(1).default('qwen2.5-coder:7b'),
|
|
secretRef: EntityIdSchema.optional(),
|
|
maxContextChars: z.number().int().min(1000).max(128000).default(16000),
|
|
timeoutSec: z.number().int().min(5).max(300).default(90),
|
|
maxTokens: z.number().int().min(64).max(32768).default(2048),
|
|
})
|
|
.default({
|
|
enabled: false,
|
|
baseUrl: 'http://127.0.0.1:11434',
|
|
model: 'qwen2.5-coder:7b',
|
|
maxContextChars: 16000,
|
|
timeoutSec: 90,
|
|
maxTokens: 2048,
|
|
}),
|
|
});
|
|
|
|
export type ThemeId = z.infer<typeof ThemeIdSchema>;
|
|
export type ThrottleMode = z.infer<typeof ThrottleModeSchema>;
|
|
export type StepUpPolicy = z.infer<typeof StepUpPolicySchema>;
|
|
export type StepUpMethod = z.infer<typeof StepUpMethodSchema>;
|
|
export type SecuritySettings = z.infer<typeof SecuritySettingsSchema>;
|
|
export type SettingsConfig = z.infer<typeof SettingsSchema>;
|