feat: 能力插件元数据与运行时消费闭环
This commit is contained in:
1 parent
076c6124c8
commit
bb0709b8cc
26 files changed
+2188
-267
No files matched your search
@@ -17,6 +17,7 @@ export type {
|
||||
BrandUpdate,
|
||||
} from "./types/brand.js";
|
||||
export type { CapabilityInstallation } from "./types/capability.js";
|
||||
export type { CapabilityMetadata } from "./types/capability.js";
|
||||
export type { ApiErrorBody } from "./types/common.js";
|
||||
export type { BrandFieldDefinition } from "./types/field.js";
|
||||
export type { InquiryForm, InquirySubmission } from "./types/inquiry.js";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { BrandTemplateKey, RuntimeWorkspace } from "@personal-brand/types";
|
||||
import type { RequestFn } from "../client/request.js";
|
||||
import type { BrandProfile } from "../types/brand.js";
|
||||
import type { CapabilityInstallation } from "../types/capability.js";
|
||||
import type { CapabilityWithMetadata } from "../types/capability.js";
|
||||
import type { BrandFieldDefinition } from "../types/field.js";
|
||||
import type { Offering } from "../types/offering.js";
|
||||
import type { AdminTemplateContent } from "../types/template.js";
|
||||
@@ -55,18 +55,18 @@ export interface TemplateMethods {
|
||||
offerings: Offering[];
|
||||
forms: unknown[];
|
||||
templateContent: AdminTemplateContent | null;
|
||||
capabilities?: CapabilityWithMetadata[];
|
||||
}>;
|
||||
getAdminPreviewWorkspace(): Promise<RuntimeWorkspace>;
|
||||
installAdminTemplate(templateKey: BrandTemplateKey): Promise<unknown>;
|
||||
listAdminCapabilities(): Promise<CapabilityInstallation[]>;
|
||||
listAdminCapabilities(): Promise<CapabilityWithMetadata[]>;
|
||||
updateAdminCapability(
|
||||
key: string,
|
||||
body: {
|
||||
capabilityVersion: string;
|
||||
status: CapabilityInstallation["status"];
|
||||
status: CapabilityWithMetadata["status"];
|
||||
config?: Record<string, unknown>;
|
||||
},
|
||||
): Promise<CapabilityInstallation>;
|
||||
): Promise<CapabilityWithMetadata>;
|
||||
previewAdminSampleContent(): Promise<{
|
||||
templateKey: string;
|
||||
alreadyImported: boolean;
|
||||
|
||||
@@ -1,4 +1,17 @@
|
||||
export interface CapabilityInstallation {
|
||||
export interface CapabilityMetadata {
|
||||
displayName?: string;
|
||||
description?: string;
|
||||
impact?: string;
|
||||
optional?: boolean;
|
||||
disablePolicy?: "allowed" | "disabled";
|
||||
allowedPages?: string[];
|
||||
requiredModules?: string[];
|
||||
purposeBindings?: string[];
|
||||
entryNavigationKey?: string;
|
||||
configFields?: Array<{ key: string; label: string; input: string; required: boolean }>;
|
||||
}
|
||||
|
||||
export interface CapabilityInstallation extends CapabilityMetadata {
|
||||
id: string | null;
|
||||
capabilityKey: string;
|
||||
capabilityVersion: string;
|
||||
@@ -7,3 +20,5 @@ export interface CapabilityInstallation {
|
||||
updatedAt: string | null;
|
||||
source?: "template" | "brand";
|
||||
}
|
||||
|
||||
export type CapabilityWithMetadata = CapabilityInstallation;
|
||||
@@ -13,6 +13,33 @@ export interface CapabilityDefinition {
|
||||
workflowKey?: string;
|
||||
}
|
||||
|
||||
export type CapabilityDisablePolicy = "allowed" | "disabled";
|
||||
|
||||
export interface CapabilityMetadata {
|
||||
displayName: string;
|
||||
description: string;
|
||||
impact: string;
|
||||
optional: boolean;
|
||||
disablePolicy: CapabilityDisablePolicy;
|
||||
allowedPages: readonly string[];
|
||||
requiredModules: readonly string[];
|
||||
purposeBindings: readonly string[];
|
||||
entryNavigationKey?: string;
|
||||
}
|
||||
|
||||
export type CapabilityConfigFieldKey = "entryLabel" | "submitHint" | "disabledHint";
|
||||
|
||||
export interface CapabilityConfigField {
|
||||
key: CapabilityConfigFieldKey;
|
||||
label: string;
|
||||
input: "text";
|
||||
required: boolean;
|
||||
}
|
||||
|
||||
export interface CapabilityMetadataDefinition extends CapabilityMetadata {
|
||||
configFields: readonly CapabilityConfigField[];
|
||||
}
|
||||
|
||||
export const workflowRegistry = {
|
||||
"booking.basic": {
|
||||
key: "booking.basic",
|
||||
@@ -29,11 +56,84 @@ export const workflowRegistry = {
|
||||
} as const satisfies Record<string, WorkflowDefinition>;
|
||||
|
||||
export const capabilityRegistry = {
|
||||
offerings: { key: "offerings", version: "1.0.0" },
|
||||
inquiry: { key: "inquiry", version: "1.0.0" },
|
||||
offerings: {
|
||||
key: "offerings",
|
||||
version: "1.0.0",
|
||||
displayName: "业务提供项",
|
||||
description: "展示品牌的服务与产品。",
|
||||
impact: "停用会移除业务提供项展示入口。",
|
||||
optional: false,
|
||||
disablePolicy: "disabled",
|
||||
allowedPages: ["home", "offerings", "detail"],
|
||||
requiredModules: ["offering-list", "offering-detail"],
|
||||
purposeBindings: [],
|
||||
},
|
||||
inquiry: {
|
||||
key: "inquiry",
|
||||
version: "1.0.0",
|
||||
displayName: "通用咨询",
|
||||
description: "接收客户的一对一合作咨询。",
|
||||
impact: "停用后所有通用咨询表单都无法提交。",
|
||||
optional: false,
|
||||
disablePolicy: "allowed",
|
||||
allowedPages: ["inquiry", "success"],
|
||||
requiredModules: ["inquiry", "records", "success-summary"],
|
||||
purposeBindings: ["inquiry"],
|
||||
entryNavigationKey: "inquiry",
|
||||
},
|
||||
booking: { key: "booking", version: "1.0.0", workflowKey: "booking.basic" },
|
||||
"quote-request": { key: "quote-request", version: "1.0.0" },
|
||||
} as const satisfies Record<CapabilityKey, CapabilityDefinition>;
|
||||
"quote-request": {
|
||||
key: "quote-request",
|
||||
version: "1.0.0",
|
||||
displayName: "报价咨询",
|
||||
description: "可选安装的报价请求链路。",
|
||||
impact: "安装后可提交报价咨询;移除后报价表单不再接收提交。",
|
||||
optional: true,
|
||||
disablePolicy: "allowed",
|
||||
allowedPages: ["inquiry", "success"],
|
||||
requiredModules: ["inquiry", "records", "success-summary"],
|
||||
purposeBindings: ["quote-request"],
|
||||
},
|
||||
} as const satisfies Record<CapabilityKey, CapabilityDefinition & Partial<CapabilityMetadata>>;
|
||||
|
||||
export const capabilityConfigFields = {
|
||||
entryLabel: { key: "entryLabel", label: "入口文案", input: "text", required: false },
|
||||
submitHint: { key: "submitHint", label: "提交提示", input: "text", required: false },
|
||||
disabledHint: { key: "disabledHint", label: "停用提示", input: "text", required: false },
|
||||
} as const satisfies Record<CapabilityConfigFieldKey, CapabilityConfigField>;
|
||||
|
||||
export function capabilityMetadata(key: CapabilityKey): CapabilityMetadataDefinition | null {
|
||||
const definition = capabilityRegistry[key];
|
||||
if (!("disablePolicy" in definition)) return null;
|
||||
return { ...definition, configFields: Object.values(capabilityConfigFields) };
|
||||
}
|
||||
|
||||
export function validateCapabilityConfig(
|
||||
capabilityKey: CapabilityKey,
|
||||
config: unknown,
|
||||
): Record<string, string> | null {
|
||||
if (config === undefined || config === null) return {};
|
||||
if (typeof config !== "object" || Array.isArray(config)) return null;
|
||||
const metadata = capabilityMetadata(capabilityKey);
|
||||
if (!metadata) return {};
|
||||
const source = config as Record<string, unknown>;
|
||||
if (Object.keys(source).some((key) => !metadata.configFields.some((field) => field.key === key)))
|
||||
return null;
|
||||
const errors: Record<string, string> = {};
|
||||
for (const [key, value] of Object.entries(source)) {
|
||||
const field = capabilityConfigFields[key as CapabilityConfigFieldKey];
|
||||
const message =
|
||||
value === undefined || value === null || (typeof value === "string" && !value.trim())
|
||||
? "不能为空"
|
||||
: typeof value !== "string"
|
||||
? "必须是字符串"
|
||||
: value.length > 80
|
||||
? "不能超过 80 个字符"
|
||||
: "";
|
||||
if (message) errors[key] = `${field?.label ?? key}${message}`;
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
export const capabilityPlugins = {
|
||||
inquiry: {
|
||||
@@ -44,6 +144,8 @@ export const capabilityPlugins = {
|
||||
requiredModules: ["inquiry", "records", "success-summary"],
|
||||
apiContract: "/customer/inquiry-submissions",
|
||||
configSchema: "capability.inquiry.v1",
|
||||
purposeBindings: ["inquiry"],
|
||||
entryNavigationKey: "inquiry",
|
||||
},
|
||||
"quote-request": {
|
||||
key: "quote-request",
|
||||
@@ -53,5 +155,6 @@ export const capabilityPlugins = {
|
||||
requiredModules: ["inquiry", "records", "success-summary"],
|
||||
apiContract: "/customer/inquiry-submissions",
|
||||
configSchema: "capability.quote-request.v1",
|
||||
purposeBindings: ["quote-request"],
|
||||
},
|
||||
} as const;
|
||||
@@ -4,6 +4,7 @@ import Taro from "@tarojs/taro";
|
||||
import type { TemplateProps } from "../../../apps/taro/src/runtime/template";
|
||||
import { navigate } from "../../../apps/taro/src/runtime/navigation";
|
||||
import { presentation, offering, slot, text, rows } from "../../../apps/taro/src/runtime/content";
|
||||
import { inquiryPluginState, pluginStateText } from "../../../apps/taro/src/runtime/plugins";
|
||||
import type { RuntimeWorkspace } from "@personal-brand/types";
|
||||
import "./style.css";
|
||||
const asset = (name: string) =>
|
||||
@@ -30,9 +31,17 @@ function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
{p.stallTime && <Text className="notice-time">{p.stallTime}</Text>}
|
||||
</View>
|
||||
<View className="actions" data-editor-target="food.home.actions">
|
||||
<Button className="home-action" onClick={() => navigate("inquiry")}>
|
||||
{p.primaryAction || "咨询 / 预订"}
|
||||
</Button>
|
||||
{inquiryPluginState(workspace).enabled ? (
|
||||
<Button className="home-action" onClick={() => navigate("inquiry")}>
|
||||
{pluginStateText(workspace, "inquiry", "entryLabel") ||
|
||||
p.primaryAction ||
|
||||
"咨询 / 预订"}
|
||||
</Button>
|
||||
) : (
|
||||
<Text className="home-action disabled">
|
||||
{inquiryPluginState(workspace).disabledHint || "咨询 / 预订暂不可用"}
|
||||
</Text>
|
||||
)}
|
||||
<Button className="home-action muted" onClick={() => navigate("offerings")}>
|
||||
{p.secondaryAction || "查看餐品"}
|
||||
</Button>
|
||||
@@ -222,13 +231,25 @@ function Service({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
)}
|
||||
<Text>{text(process.config.refundNote)}</Text>
|
||||
</View>
|
||||
<Button
|
||||
data-editor-target="food.service.process-action"
|
||||
className="process-action"
|
||||
onClick={() => navigate("inquiry")}
|
||||
>
|
||||
{p.processAction || "立即咨询"} →
|
||||
</Button>
|
||||
{inquiryPluginState(workspace).enabled ? (
|
||||
<Button
|
||||
data-editor-target="food.service.process-action"
|
||||
className="process-action"
|
||||
onClick={() => navigate("inquiry")}
|
||||
>
|
||||
{pluginStateText(workspace, "inquiry", "entryLabel") ||
|
||||
p.processAction ||
|
||||
"立即咨询"}{" "}
|
||||
→
|
||||
</Button>
|
||||
) : (
|
||||
<Text
|
||||
data-editor-target="food.service.process-action"
|
||||
className="process-action disabled"
|
||||
>
|
||||
{inquiryPluginState(workspace).disabledHint || "咨询暂不可用"}
|
||||
</Text>
|
||||
)}
|
||||
</View>
|
||||
</View>
|
||||
)}
|
||||
@@ -476,9 +497,15 @@ function OfferingList({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
<View className="empty-state">没有找到相关餐品,换个词试试</View>
|
||||
)}
|
||||
</View>
|
||||
<Button className="menu-cta" onClick={() => navigate("inquiry")}>
|
||||
咨询 / 预订
|
||||
</Button>
|
||||
{inquiryPluginState(workspace).enabled ? (
|
||||
<Button className="menu-cta" onClick={() => navigate("inquiry")}>
|
||||
{pluginStateText(workspace, "inquiry", "entryLabel") || "咨询 / 预订"}
|
||||
</Button>
|
||||
) : (
|
||||
<Text className="menu-cta disabled">
|
||||
{inquiryPluginState(workspace).disabledHint || "咨询 / 预订暂不可用"}
|
||||
</Text>
|
||||
)}
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
@@ -567,9 +594,15 @@ function Detail({ workspace, id }: { workspace: RuntimeWorkspace; id?: string })
|
||||
</View>
|
||||
</View>
|
||||
<View className="bar" data-editor-target="acheng-campus-food.detail.action">
|
||||
<Button onClick={() => navigate("inquiry", { offeringId: item.id })}>
|
||||
{p.inquiryAction || "咨询 / 提前预订"}
|
||||
</Button>
|
||||
{inquiryPluginState(workspace).enabled ? (
|
||||
<Button onClick={() => navigate("inquiry", { offeringId: item.id })}>
|
||||
{pluginStateText(workspace, "inquiry", "entryLabel") ||
|
||||
p.inquiryAction ||
|
||||
"咨询 / 提前预订"}
|
||||
</Button>
|
||||
) : (
|
||||
<Text>{inquiryPluginState(workspace).disabledHint || "咨询 / 提前预订暂不可用"}</Text>
|
||||
)}
|
||||
<Text>{p.inquiryHint}</Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
text,
|
||||
rows,
|
||||
} from "../../../apps/taro/src/runtime/content";
|
||||
import { inquiryPluginState, pluginStateText } from "../../../apps/taro/src/runtime/plugins";
|
||||
import "./style.css";
|
||||
function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
const b = workspace.brand;
|
||||
@@ -277,7 +278,16 @@ function List({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
</View>
|
||||
))}
|
||||
<Text className="subtitle">{p.closingText}</Text>
|
||||
{p.closingAction && <Button onClick={() => navigate("inquiry")}>{p.closingAction}</Button>}
|
||||
{p.closingAction &&
|
||||
(inquiryPluginState(workspace).enabled ? (
|
||||
<Button onClick={() => navigate("inquiry")}>
|
||||
{pluginStateText(workspace, "inquiry", "entryLabel") || p.closingAction}
|
||||
</Button>
|
||||
) : (
|
||||
<Text>
|
||||
{inquiryPluginState(workspace).disabledHint || `${p.closingAction}暂不可用`}
|
||||
</Text>
|
||||
))}
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
@@ -366,9 +376,13 @@ function Detail({ workspace, id }: { workspace: RuntimeWorkspace; id?: string })
|
||||
</View>
|
||||
</View>
|
||||
<View className="bar" data-editor-target="linjing-editorial.detail.action">
|
||||
<Button onClick={() => navigate("inquiry", { offeringId: item.id })}>
|
||||
{p.inquiryAction}
|
||||
</Button>
|
||||
{inquiryPluginState(workspace).enabled ? (
|
||||
<Button onClick={() => navigate("inquiry", { offeringId: item.id })}>
|
||||
{pluginStateText(workspace, "inquiry", "entryLabel") || p.inquiryAction || "咨询"}
|
||||
</Button>
|
||||
) : (
|
||||
<Text>{inquiryPluginState(workspace).disabledHint || "咨询暂不可用"}</Text>
|
||||
)}
|
||||
<Text>{p.inquiryHint}</Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
@@ -68,6 +68,18 @@ export interface RuntimeCapability {
|
||||
version: string;
|
||||
config: Record<string, unknown>;
|
||||
status: "enabled" | "disabled" | "degraded";
|
||||
metadata?: {
|
||||
displayName?: string;
|
||||
description?: string;
|
||||
impact?: string;
|
||||
optional?: boolean;
|
||||
disablePolicy?: "allowed" | "disabled";
|
||||
allowedPages?: readonly string[];
|
||||
requiredModules?: readonly string[];
|
||||
purposeBindings?: readonly string[];
|
||||
entryNavigationKey?: string;
|
||||
configFields?: readonly { key: string; label: string; input: string; required: boolean }[];
|
||||
};
|
||||
}
|
||||
|
||||
export interface TrustPresentation {
|
||||
@@ -94,6 +106,8 @@ export interface CapabilityPluginManifest {
|
||||
requiredModules: readonly string[];
|
||||
apiContract: string;
|
||||
configSchema: string;
|
||||
purposeBindings?: readonly string[];
|
||||
entryNavigationKey?: string;
|
||||
}
|
||||
|
||||
export interface RuntimeWorkspace {
|
||||
|
||||
Reference in new issue
Block a user