DevOS v1 + Phase 2: unified resource model, infra ops, website deployment, AI chat ops
- Monorepo: NestJS API (Fastify) + React web (antd/ProComponents) + shared packages - PostgreSQL/Prisma (unified resources, relations graph, audit, events, jobs) - Auth/RBAC/workspace isolation, credential vault (AES-256-GCM) - Servers/SSH, Docker discovery & lifecycle, Job Center - Websites & deployments (git provider credential clone, env, health verification) - Domains/DNS (Cloudflare adapter), certificates (TLS probe), monitoring - Automation (cron/event/webhook HMAC + notifications), AI Gateway, MCP (29 tools) - AI chat window (LLM function-calling + rules fallback, SSE streaming, approvals) - Notes: Vditor WYSIWYG markdown editor, non-blocking autosave - Tests: 35 unit/security tests; UI audit clean (desktop+mobile, deep links)
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "@devos/types",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "tsc -p tsconfig.json"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,276 @@
|
||||
/**
|
||||
* # @devos/types
|
||||
* 前后端共享的领域类型与常量定义。
|
||||
* 该包不依赖任何运行时库,仅类型与枚举。
|
||||
*/
|
||||
|
||||
/** # 资源类型枚举
|
||||
* DevOS 统一资源模型支持的资源类型(V1 子集 + 预留)。
|
||||
*/
|
||||
export const RESOURCE_TYPES = [
|
||||
"SERVER",
|
||||
"DOMAIN",
|
||||
"WEBSITE",
|
||||
"REPOSITORY",
|
||||
"CERTIFICATE",
|
||||
"DATABASE",
|
||||
"CONTAINER",
|
||||
"EMAIL_ACCOUNT",
|
||||
"PROJECT",
|
||||
"TASK",
|
||||
"NOTE",
|
||||
"DOCUMENT",
|
||||
"BACKUP",
|
||||
"DEPLOYMENT",
|
||||
"MONITOR",
|
||||
"CREDENTIAL",
|
||||
"AUTOMATION",
|
||||
"AI_RUN",
|
||||
] as const;
|
||||
export type ResourceType = (typeof RESOURCE_TYPES)[number];
|
||||
|
||||
/** # 资源状态枚举 */
|
||||
export const RESOURCE_STATUSES = [
|
||||
"PENDING",
|
||||
"ACTIVE",
|
||||
"ERROR",
|
||||
"OFFLINE",
|
||||
"ARCHIVED",
|
||||
"UNKNOWN",
|
||||
] as const;
|
||||
export type ResourceStatus = (typeof RESOURCE_STATUSES)[number];
|
||||
|
||||
/** # 工作区角色 */
|
||||
export const WORKSPACE_ROLES = ["OWNER", "ADMIN", "MEMBER", "VIEWER"] as const;
|
||||
export type WorkspaceRole = (typeof WORKSPACE_ROLES)[number];
|
||||
|
||||
/** # 风险等级 */
|
||||
export const RISK_LEVELS = ["LOW", "MEDIUM", "HIGH", "CRITICAL"] as const;
|
||||
export type RiskLevel = (typeof RISK_LEVELS)[number];
|
||||
|
||||
/** # 审计主体类型 */
|
||||
export const ACTOR_TYPES = ["USER", "SYSTEM", "AGENT", "MCP"] as const;
|
||||
export type ActorType = (typeof ACTOR_TYPES)[number];
|
||||
|
||||
/** # 任务状态(job 状态机) */
|
||||
export const JOB_STATUSES = [
|
||||
"PENDING",
|
||||
"RUNNING",
|
||||
"SUCCEEDED",
|
||||
"FAILED",
|
||||
"CANCELLED",
|
||||
"DEAD",
|
||||
] as const;
|
||||
export type JobStatus = (typeof JOB_STATUSES)[number];
|
||||
|
||||
/** # 部署状态 */
|
||||
export const DEPLOYMENT_STATUSES = [
|
||||
"QUEUED",
|
||||
"RUNNING",
|
||||
"SUCCEEDED",
|
||||
"FAILED",
|
||||
"CANCELLED",
|
||||
] as const;
|
||||
export type DeploymentStatus = (typeof DEPLOYMENT_STATUSES)[number];
|
||||
|
||||
/** # 触发器类型 */
|
||||
export const TRIGGER_TYPES = ["MANUAL", "CRON", "EVENT", "WEBHOOK"] as const;
|
||||
export type TriggerType = (typeof TRIGGER_TYPES)[number];
|
||||
|
||||
/** # 规范事件名常量
|
||||
* 事件命名遵循 `<resource>.<verb>` / `<domain>.<verb>` 约定。
|
||||
*/
|
||||
export const EVENTS = {
|
||||
deploymentCreated: "deployment.created",
|
||||
deploymentStarted: "deployment.started",
|
||||
deploymentSuccess: "deployment.success",
|
||||
deploymentFailed: "deployment.failed",
|
||||
serverOnline: "server.online",
|
||||
serverOffline: "server.offline",
|
||||
websiteDown: "website.down",
|
||||
websiteRecovered: "website.recovered",
|
||||
containerRestarted: "container.restarted",
|
||||
taskCreated: "task.created",
|
||||
taskCompleted: "task.completed",
|
||||
} as const;
|
||||
export type EventName = (typeof EVENTS)[keyof typeof EVENTS] | (string & {});
|
||||
|
||||
/** # API 错误码 */
|
||||
export const ERROR_CODES = {
|
||||
VALIDATION_ERROR: "VALIDATION_ERROR",
|
||||
UNAUTHORIZED: "UNAUTHORIZED",
|
||||
FORBIDDEN: "FORBIDDEN",
|
||||
RESOURCE_NOT_FOUND: "RESOURCE_NOT_FOUND",
|
||||
CONFLICT: "CONFLICT",
|
||||
RATE_LIMITED: "RATE_LIMITED",
|
||||
INTERNAL_ERROR: "INTERNAL_ERROR",
|
||||
UPSTREAM_FAILURE: "UPSTREAM_FAILURE",
|
||||
TIMEOUT: "TIMEOUT",
|
||||
} as const;
|
||||
export type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
|
||||
|
||||
/** # API 统一错误结构 */
|
||||
export interface ApiErrorBody {
|
||||
error: {
|
||||
code: ErrorCode | string;
|
||||
message: string;
|
||||
requestId: string;
|
||||
details?: unknown;
|
||||
};
|
||||
}
|
||||
|
||||
/** # 资源通用视图(API 返回) */
|
||||
export interface ResourceView {
|
||||
id: string;
|
||||
workspaceId: string;
|
||||
type: ResourceType;
|
||||
name: string;
|
||||
provider: string | null;
|
||||
status: ResourceStatus;
|
||||
metadata: Record<string, unknown>;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
/** # 服务器视图 */
|
||||
export interface ServerView {
|
||||
id: string;
|
||||
resourceId: string;
|
||||
workspaceId: string;
|
||||
name: string;
|
||||
host: string;
|
||||
port: number;
|
||||
username: string;
|
||||
authType: string;
|
||||
provider: string;
|
||||
status: ResourceStatus;
|
||||
osInfo: string | null;
|
||||
lastSeenAt: string | null;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
/** # 容器视图 */
|
||||
export interface ContainerView {
|
||||
id: string;
|
||||
containerId: string;
|
||||
name: string;
|
||||
image: string;
|
||||
state: string;
|
||||
ports: Record<string, unknown> | null;
|
||||
serverId: string;
|
||||
}
|
||||
|
||||
/** # 网站视图 */
|
||||
export interface WebsiteView {
|
||||
id: string;
|
||||
resourceId: string;
|
||||
workspaceId: string;
|
||||
name: string;
|
||||
primaryDomain: string | null;
|
||||
serverId: string | null;
|
||||
repositoryUrl: string | null;
|
||||
deployType: string;
|
||||
port: number;
|
||||
healthPath: string;
|
||||
status: ResourceStatus;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
/** # 部署视图 */
|
||||
export interface DeploymentView {
|
||||
id: string;
|
||||
resourceId: string;
|
||||
websiteId: string;
|
||||
status: DeploymentStatus;
|
||||
trigger: string;
|
||||
progress: number;
|
||||
commit: string | null;
|
||||
createdAt: string;
|
||||
finishedAt: string | null;
|
||||
}
|
||||
|
||||
/** # 域名视图 */
|
||||
export interface DomainView {
|
||||
id: string;
|
||||
resourceId: string;
|
||||
workspaceId: string;
|
||||
name: string;
|
||||
provider: string;
|
||||
status: ResourceStatus;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
/** # 域名记录视图 */
|
||||
export interface DomainRecordView {
|
||||
id: string;
|
||||
type: string;
|
||||
name: string;
|
||||
value: string;
|
||||
ttl: number;
|
||||
proxied: boolean;
|
||||
}
|
||||
|
||||
/** # 健康检查响应 */
|
||||
export interface HealthView {
|
||||
status: "ok";
|
||||
service: string;
|
||||
version: string;
|
||||
time: string;
|
||||
}
|
||||
|
||||
/** # 认证用户视图 */
|
||||
export interface AuthUserView {
|
||||
id: string;
|
||||
email: string;
|
||||
name: string | null;
|
||||
activeWorkspaceId: string | null;
|
||||
workspaces: { id: string; name: string; slug: string; role: WorkspaceRole }[];
|
||||
}
|
||||
|
||||
// ============ Phase 2 常量 ============
|
||||
|
||||
/** # 规范关系类型(有向,Phase 2 标准化) **/
|
||||
export const RELATION_TYPES = {
|
||||
projectHasRepository: "PROJECT_HAS_REPOSITORY",
|
||||
projectHasWebsite: "PROJECT_HAS_WEBSITE",
|
||||
projectHasServer: "PROJECT_HAS_SERVER",
|
||||
projectHasTask: "PROJECT_HAS_TASK",
|
||||
projectHasNote: "PROJECT_HAS_NOTE",
|
||||
projectHasDomain: "PROJECT_HAS_DOMAIN",
|
||||
websiteDeployedToServer: "WEBSITE_DEPLOYED_TO_SERVER",
|
||||
websiteUsesDomain: "WEBSITE_USES_DOMAIN",
|
||||
websiteHasDeployment: "WEBSITE_HAS_DEPLOYMENT",
|
||||
websiteHasMonitor: "WEBSITE_HAS_MONITOR",
|
||||
websiteHasCertificate: "WEBSITE_HAS_CERTIFICATE",
|
||||
deploymentFromRepository: "DEPLOYMENT_FROM_REPOSITORY",
|
||||
deploymentToServer: "DEPLOYMENT_TO_SERVER",
|
||||
serverHasContainer: "SERVER_HAS_CONTAINER",
|
||||
} as const;
|
||||
export type RelationType = (typeof RELATION_TYPES)[keyof typeof RELATION_TYPES];
|
||||
|
||||
/** # 任务状态 **/
|
||||
export const TASK_STATUSES = ["BACKLOG", "TODO", "DOING", "REVIEW", "DONE"] as const;
|
||||
export type TaskStatus = (typeof TASK_STATUSES)[number];
|
||||
|
||||
/** # 任务优先级 **/
|
||||
export const TASK_PRIORITIES = ["LOW", "MEDIUM", "HIGH", "URGENT"] as const;
|
||||
export type TaskPriority = (typeof TASK_PRIORITIES)[number];
|
||||
|
||||
/** # 部署环境 **/
|
||||
export const ENVIRONMENTS = ["development", "staging", "production"] as const;
|
||||
export type DeployEnvironment = (typeof ENVIRONMENTS)[number];
|
||||
|
||||
/** # Git 提供商 **/
|
||||
export const GIT_PROVIDERS = ["GITHUB", "GITLAB", "GITEA"] as const;
|
||||
export type GitProvider = (typeof GIT_PROVIDERS)[number];
|
||||
|
||||
/** # 新增动作类型(自动化 Phase F) **/
|
||||
export const AUTOMATION_ACTION_TYPES = [
|
||||
"LOG",
|
||||
"WEBHOOK",
|
||||
"DEPLOY_WEBSITE",
|
||||
"CONTAINER_RESTART",
|
||||
"TASK_CREATE",
|
||||
"NOTE_CREATE",
|
||||
"NOTIFICATION_SEND",
|
||||
] as const;
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"rootDir": "src",
|
||||
"declaration": true
|
||||
},
|
||||
"include": ["src/**/*.ts"]
|
||||
}
|
||||
Reference in New Issue
Block a user