feat: 建立模板运行时契约骨架

This commit is contained in:
que01 committed 2026-09-22 17:17:40 +08:00
1 parent 6c3eb3bfca
commit 40b08b5e1d
3 files changed
+168

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
# 模板运行时实施进度
关联决策:`docs/adr/0005-template-runtime-and-stitch-pipeline.md`
## 当前分支
`feat/template-runtime-platform`
## 阶段状态
### Phase 0:冻结林境门作基线
- [x] 静态小程序提交基线版本 `8489c8c`。
- [ ] 固定各页面测试 fixture 和截图基准。
- [ ] 清理远程图片依赖或建立本地资源清单。
### Phase 1:Runtime Workspace
- [x] 新增共享 `TemplateManifest`、`ModuleManifest`、`CapabilityManifest` 类型。
- [x] 新增 `RuntimeWorkspace`、Offering、Inquiry 和 Capability 运行时类型。
- [x] 新增模板声明的基础校验函数。
- [ ] 在 API 增加运行时工作空间 DTO 和公开接口。
- [ ] 增加 API 授权、品牌隔离和 schema 版本测试。
- [ ] 让 Admin 与小程序读取同一运行时契约。
### 后续阶段
- [ ] Phase 2:标准模块库。
- [ ] Phase 3:模板中心、安装快照、升级和回滚。
- [ ] Phase 4:Capability Plugin。
- [ ] Phase 5:林境门作与第二行业双模板验证。
- [ ] Phase 6:Stitch 到 Manifest 的转换流水线。
## 当前交付门槛
在 Phase 1 的 API 契约、测试和客户端消费完成前,不新增第二个行业页面,也不继续扩展行业专属固定 WXML。
+2
View File
@@ -38,3 +38,5 @@ export interface PublicOffering {
categoryKey?: string;
config?: Record<string, unknown> | null;
}
export * from "./runtime-workspace.js";
+130
View File
@@ -0,0 +1,130 @@
export type ManifestCategory = "industry" | "visual" | "hybrid";
export type WorkspaceModuleType =
| "brand-hero"
| "founder-card"
| "trust-proof"
| "offering-list"
| "offering-detail"
| "gallery"
| "timeline"
| "faq"
| "contact"
| "inquiry"
| "records"
| "custom";
export interface ThemeManifest {
colors: Record<string, string>;
typography?: Record<string, string>;
spacing?: Record<string, string>;
radius?: Record<string, string>;
}
export interface TemplateManifest {
templateKey: string;
version: string;
category: ManifestCategory;
displayName: string;
requiredModules: string[];
optionalModules: string[];
offeringSchema: string;
inquirySchemas: string[];
requiredCapabilities: string[];
optionalCapabilities: string[];
theme: ThemeManifest;
}
export interface ModuleManifest {
key: string;
version: string;
type: WorkspaceModuleType;
propsSchema: string;
dataSource?: string;
variant?: string;
visibilityRules?: VisibilityRule[];
}
export interface VisibilityRule {
field: string;
operator: "equals" | "not-equals" | "exists" | "in";
value?: string | number | boolean | string[];
}
export interface CapabilityManifest {
key: string;
version: string;
permissions: string[];
apiContract: string;
requiredModules: string[];
supportedWorkflows: string[];
}
export interface RuntimeModule extends ModuleManifest {
config: Record<string, unknown>;
source: "core" | "template" | "custom";
}
export interface RuntimeOffering {
id: string;
name: string;
summary: string;
enabled: boolean;
schemaKey: string;
schemaVersion: string;
sections: Array<{
key: string;
type: "text" | "image-list" | "timeline" | "faq" | "specification";
config: Record<string, unknown>;
}>;
}
export interface RuntimeInquiryField {
key: string;
label: string;
type: "text" | "tel" | "number" | "select" | "radio" | "checkbox" | "textarea" | "date";
required: boolean;
options?: Array<{ label: string; value: string }>;
visibleWhen?: VisibilityRule[];
}
export interface RuntimeInquiryForm {
key: string;
version: string;
purpose: "inquiry" | "booking" | "quote-request";
target: "brand" | "offering";
submissionAction: "create-inquiry" | "create-booking" | "create-quote";
fields: RuntimeInquiryField[];
}
export interface RuntimeCapability {
key: string;
version: string;
config: Record<string, unknown>;
status: "enabled" | "disabled" | "degraded";
}
export interface RuntimeWorkspace {
schemaVersion: string;
brand: Record<string, unknown>;
navigation: {
tabs: Array<{ key: string; label: string; page: string }>;
};
modules: RuntimeModule[];
offerings: RuntimeOffering[];
inquiryForms: RuntimeInquiryForm[];
capabilities: RuntimeCapability[];
theme: ThemeManifest;
}
export function validateTemplateManifest(manifest: TemplateManifest): string[] {
const errors: string[] = [];
if (!manifest.templateKey.trim()) errors.push("templateKey is required");
if (!manifest.version.trim()) errors.push("version is required");
if (!manifest.displayName.trim()) errors.push("displayName is required");
if (!manifest.offeringSchema.trim()) errors.push("offeringSchema is required");
if (!manifest.theme || Object.keys(manifest.theme.colors).length === 0) {
errors.push("theme.colors must not be empty");
}
return errors;
}