export type KdProduct = "unknown" | "flagship" | "xinghan" | "cangqiong" | "enterprise"; export type KdPlatform = "unknown" | "cosmic" | "enterprise-csharp" | "enterprise-python"; export type KdTechStack = "unknown" | "java-bos" | "java-cosmic" | "csharp-bos" | "python-bos" | "ksql"; export type KdLanguage = "unknown" | "java" | "csharp" | "python" | "sql"; export type KnowledgeScope = "common" | "flagship" | "enterprise" | "enterprise-python" | "cosmic" | "xinghan" | "cangqiong"; export interface ProductProfile { product: KdProduct; displayName: string; platform: KdPlatform; techStack: KdTechStack; language: KdLanguage; knowledgeScope: KnowledgeScope; requiresMetadataVerification: boolean; notes: string[]; } const PROFILES: Record = { unknown: { product: "unknown", displayName: "unknown", platform: "unknown", techStack: "unknown", language: "unknown", knowledgeScope: "common", requiresMetadataVerification: true, notes: ["尚未选择产品;禁止假设插件技术栈、BOS/Cosmic 平台规则或 KSQL/SQL 交付规则。"], }, flagship: { product: "flagship", displayName: "金蝶星空旗舰版", platform: "cosmic", techStack: "java-cosmic", language: "java", knowledgeScope: "flagship", requiresMetadataVerification: true, notes: [ "星空旗舰版基于苍穹/Cosmic 平台。使用平台元数据、插件生命周期、SDK 和后置检查约束,但接口可能存在旗舰版差异。", "当前工作区存在 code/ 目录时,产品代码必须放在 code/ 下。", "创建或编辑代码前,必须检查 code/ 下真实项目结构,并跟随其实际布局;可能按云、按应用组织,也可能不分模块。", ], }, xinghan: { product: "xinghan", displayName: "金蝶星瀚", platform: "cosmic", techStack: "java-cosmic", language: "java", knowledgeScope: "xinghan", requiresMetadataVerification: true, notes: ["星瀚基于苍穹/Cosmic 平台。默认按平台 Java 插件处理,但接口可能存在星瀚差异。"], }, cangqiong: { product: "cangqiong", displayName: "金蝶苍穹", platform: "cosmic", techStack: "java-cosmic", language: "java", knowledgeScope: "cangqiong", requiresMetadataVerification: true, notes: ["Cosmic 在 KCode 中按苍穹平台语境处理。使用苍穹/Cosmic 平台插件、SDK、元数据、KSQL/SQL 和生命周期规则。"], }, enterprise: { product: "enterprise", displayName: "金蝶企业版", platform: "enterprise-csharp", techStack: "csharp-bos", language: "csharp", knowledgeScope: "enterprise", requiresMetadataVerification: true, notes: ["使用企业版 C# 技术栈。Java 插件规则和 Cosmic API 不适用。"], }, }; const PRODUCT_ALIASES: Array<[RegExp, KdProduct]> = [ [/企业版|enterprise|csharp|c#|\.net/i, "enterprise"], [/星瀚|xinghan/i, "xinghan"], [/苍穹|cangqiong/i, "cangqiong"], [/cosmic|云苍穹/i, "cangqiong"], [/星空旗舰版|星空旗舰|旗舰版|旗舰|flagship/i, "flagship"], ]; const ENTERPRISE_PYTHON_PATTERN = /(?:python|py)\s*(?:插件|plugin)|(?:python|py).*?(?:插件|plugin)|ironpython|(?:企业版|enterprise|星空|金蝶云星空|BOS).*?python\s*脚本|python\s*脚本.*?(?:企业版|enterprise|星空|金蝶云星空|BOS)/i; function enterprisePythonProfile(): ProductProfile { return { ...PROFILES.enterprise, platform: "enterprise-python", techStack: "python-bos", language: "python", knowledgeScope: "enterprise-python", notes: [ "只有用户明确要求 Python 插件或 IronPython 脚本时,才使用金蝶云企业版 / BOS IronPython 插件模式。", "企业版默认插件开发仍按 C# 处理,除非用户明确要求 Python 插件。", "Python 插件通过 BOS 中的 IronPython 运行,并调用 Kingdee.BOS .NET 程序集;编码前必须确认插件类型、事件、FormId、字段标识和注册步骤。", ], }; } export function profileForProduct(product: KdProduct | undefined): ProductProfile { return PROFILES[product ?? "unknown"] ?? PROFILES.unknown; } export function resolveProductProfile(input: string | undefined): ProductProfile { const text = input?.trim(); if (!text) return profileForProduct("unknown"); if (ENTERPRISE_PYTHON_PATTERN.test(text)) return enterprisePythonProfile(); for (const [pattern, product] of PRODUCT_ALIASES) { if (pattern.test(text)) return profileForProduct(product); } return profileForProduct("unknown"); } export function normalizeProduct(value: string | undefined): KdProduct { return resolveProductProfile(value).product; } export function isKnownProduct(product: KdProduct | undefined): boolean { return Boolean(product && product !== "unknown"); } export function formatProductProfile(profile: ProductProfile | undefined): string { const resolved = profile ?? profileForProduct("unknown"); return `${resolved.product}/${resolved.platform}/${resolved.techStack}/${resolved.language}`; }