@wowok/agent-mcp 2.3.14 → 2.3.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/dist/config/index.d.ts +1 -0
  2. package/dist/config/index.js +1 -0
  3. package/dist/config/runtime.d.ts +26 -0
  4. package/dist/config/runtime.js +217 -0
  5. package/dist/customer/industry-risks.d.ts +36 -0
  6. package/dist/customer/industry-risks.js +424 -0
  7. package/dist/customer/info-puzzle.d.ts +102 -0
  8. package/dist/customer/info-puzzle.js +312 -0
  9. package/dist/customer/order-monitor.d.ts +75 -0
  10. package/dist/customer/order-monitor.js +327 -0
  11. package/dist/customer/order-strategy.d.ts +36 -0
  12. package/dist/customer/order-strategy.js +373 -0
  13. package/dist/customer/post-purchase.d.ts +42 -0
  14. package/dist/customer/post-purchase.js +350 -0
  15. package/dist/customer/reminder-system.d.ts +42 -0
  16. package/dist/customer/reminder-system.js +295 -0
  17. package/dist/customer/risk-assessment.d.ts +8 -0
  18. package/dist/customer/risk-assessment.js +337 -0
  19. package/dist/customer/types.d.ts +193 -0
  20. package/dist/customer/types.js +13 -0
  21. package/dist/customer/user-preferences.d.ts +67 -0
  22. package/dist/customer/user-preferences.js +451 -0
  23. package/dist/experience/experience-reuse.d.ts +10 -0
  24. package/dist/experience/experience-reuse.js +103 -0
  25. package/dist/experience/index.d.ts +6 -0
  26. package/dist/experience/index.js +5 -0
  27. package/dist/experience/intent-distill.d.ts +3 -0
  28. package/dist/experience/intent-distill.js +83 -0
  29. package/dist/experience/realtime-feedback.d.ts +5 -0
  30. package/dist/experience/realtime-feedback.js +77 -0
  31. package/dist/experience/types.d.ts +50 -0
  32. package/dist/experience/types.js +1 -0
  33. package/dist/experience/user-profile.d.ts +25 -0
  34. package/dist/experience/user-profile.js +171 -0
  35. package/dist/index.js +570 -186
  36. package/dist/knowledge/acquisition-flywheel.d.ts +50 -0
  37. package/dist/knowledge/acquisition-flywheel.js +183 -0
  38. package/dist/knowledge/arbitration-trust.d.ts +24 -0
  39. package/dist/knowledge/arbitration-trust.js +117 -0
  40. package/dist/knowledge/audit-rules.d.ts +28 -0
  41. package/dist/knowledge/audit-rules.js +141 -0
  42. package/dist/knowledge/demand-matching.d.ts +29 -0
  43. package/dist/knowledge/demand-matching.js +132 -0
  44. package/dist/knowledge/dynamic-pricing.d.ts +31 -0
  45. package/dist/knowledge/dynamic-pricing.js +87 -0
  46. package/dist/knowledge/flywheel-loop.d.ts +87 -0
  47. package/dist/knowledge/flywheel-loop.js +378 -0
  48. package/dist/knowledge/glossary.d.ts +18 -0
  49. package/dist/knowledge/glossary.js +209 -0
  50. package/dist/knowledge/index.d.ts +64 -0
  51. package/dist/knowledge/index.js +66 -0
  52. package/dist/knowledge/industry-evolution.d.ts +82 -0
  53. package/dist/knowledge/industry-evolution.js +323 -0
  54. package/dist/knowledge/industry-generalizer.d.ts +17 -0
  55. package/dist/knowledge/industry-generalizer.js +381 -0
  56. package/dist/knowledge/industry-registry.d.ts +49 -0
  57. package/dist/knowledge/industry-registry.js +167 -0
  58. package/dist/knowledge/intent-metrics.d.ts +42 -0
  59. package/dist/knowledge/intent-metrics.js +566 -0
  60. package/dist/knowledge/process-model.d.ts +24 -0
  61. package/dist/knowledge/process-model.js +160 -0
  62. package/dist/knowledge/reputation-rules.d.ts +42 -0
  63. package/dist/knowledge/reputation-rules.js +99 -0
  64. package/dist/knowledge/reward-templates.d.ts +25 -0
  65. package/dist/knowledge/reward-templates.js +125 -0
  66. package/dist/knowledge/safety-rules.d.ts +36 -0
  67. package/dist/knowledge/safety-rules.js +171 -0
  68. package/dist/knowledge/tool-constraints.d.ts +30 -0
  69. package/dist/knowledge/tool-constraints.js +185 -0
  70. package/dist/knowledge/trust-metrics.d.ts +37 -0
  71. package/dist/knowledge/trust-metrics.js +138 -0
  72. package/dist/loop-engineering/diagnose.d.ts +3 -2
  73. package/dist/loop-engineering/diagnose.js +94 -0
  74. package/dist/loop-engineering/improve.d.ts +1 -1
  75. package/dist/loop-engineering/improve.js +52 -1
  76. package/dist/project/graph.d.ts +71 -0
  77. package/dist/project/graph.js +314 -0
  78. package/dist/project/index.d.ts +62 -0
  79. package/dist/project/index.js +167 -0
  80. package/dist/project/namespace.d.ts +62 -0
  81. package/dist/project/namespace.js +181 -0
  82. package/dist/project/query.d.ts +40 -0
  83. package/dist/project/query.js +110 -0
  84. package/dist/safety/confirm-gate.d.ts +15 -0
  85. package/dist/safety/confirm-gate.js +44 -0
  86. package/dist/safety/index.d.ts +3 -0
  87. package/dist/safety/index.js +3 -0
  88. package/dist/safety/preview.d.ts +2 -0
  89. package/dist/safety/preview.js +36 -0
  90. package/dist/schema/call/allocation.d.ts +15 -0
  91. package/dist/schema/call/arbitration.d.ts +111 -96
  92. package/dist/schema/call/base.d.ts +1070 -44
  93. package/dist/schema/call/base.js +69 -1
  94. package/dist/schema/call/bridge.d.ts +709 -52
  95. package/dist/schema/call/bridge.js +13 -2
  96. package/dist/schema/call/contact.d.ts +15 -0
  97. package/dist/schema/call/demand.d.ts +69 -54
  98. package/dist/schema/call/guard.d.ts +125 -80
  99. package/dist/schema/call/handler.d.ts +3 -0
  100. package/dist/schema/call/handler.js +14 -0
  101. package/dist/schema/call/machine.d.ts +830 -800
  102. package/dist/schema/call/order.d.ts +15 -0
  103. package/dist/schema/call/payment.d.ts +15 -0
  104. package/dist/schema/call/permission.d.ts +15 -0
  105. package/dist/schema/call/personal.d.ts +15 -0
  106. package/dist/schema/call/progress.d.ts +15 -0
  107. package/dist/schema/call/proof.d.ts +42 -12
  108. package/dist/schema/call/proof.js +3 -3
  109. package/dist/schema/call/repository.d.ts +91 -76
  110. package/dist/schema/call/reward.d.ts +45 -30
  111. package/dist/schema/call/semantic.d.ts +1 -0
  112. package/dist/schema/call/semantic.js +217 -0
  113. package/dist/schema/call/service.d.ts +407 -392
  114. package/dist/schema/call/treasury.d.ts +15 -0
  115. package/dist/schema/common/index.js +3 -3
  116. package/dist/schema/local/index.d.ts +228 -72
  117. package/dist/schema/local/index.js +33 -6
  118. package/dist/schema/messenger/index.d.ts +668 -50
  119. package/dist/schema/messenger/index.js +9 -0
  120. package/dist/schema/operations.d.ts +1693 -1369
  121. package/dist/schema/operations.js +2 -2
  122. package/dist/schema/query/index.d.ts +1614 -1614
  123. package/dist/schema/query/index.js +30 -27
  124. package/dist/schemas/account_operation.output.json +25 -16
  125. package/dist/schemas/account_operation.schema.json +1 -1
  126. package/dist/schemas/bridge_operation.output.json +520 -0
  127. package/dist/schemas/bridge_operation.schema.json +15 -0
  128. package/dist/schemas/guard2file.schema.json +15 -0
  129. package/dist/schemas/index.json +1 -1
  130. package/dist/schemas/local_info_operation.output.json +23 -0
  131. package/dist/schemas/local_info_operation.schema.json +1 -1
  132. package/dist/schemas/local_mark_operation.output.json +24 -1
  133. package/dist/schemas/local_mark_operation.schema.json +4 -4
  134. package/dist/schemas/machineNode2file.schema.json +15 -0
  135. package/dist/schemas/messenger_operation.output.json +528 -0
  136. package/dist/schemas/onchain_operations.output.json +350 -16
  137. package/dist/schemas/onchain_operations.schema.json +96 -23
  138. package/dist/schemas/onchain_operations_allocation.schema.json +15 -0
  139. package/dist/schemas/onchain_operations_arbitration.schema.json +15 -0
  140. package/dist/schemas/onchain_operations_contact.schema.json +15 -0
  141. package/dist/schemas/onchain_operations_demand.schema.json +15 -0
  142. package/dist/schemas/onchain_operations_gen_passport.schema.json +30 -0
  143. package/dist/schemas/onchain_operations_guard.schema.json +15 -0
  144. package/dist/schemas/onchain_operations_machine.schema.json +81 -23
  145. package/dist/schemas/onchain_operations_order.schema.json +15 -0
  146. package/dist/schemas/onchain_operations_payment.schema.json +15 -0
  147. package/dist/schemas/onchain_operations_permission.schema.json +15 -0
  148. package/dist/schemas/onchain_operations_personal.schema.json +15 -0
  149. package/dist/schemas/onchain_operations_progress.schema.json +15 -0
  150. package/dist/schemas/onchain_operations_repository.schema.json +15 -0
  151. package/dist/schemas/onchain_operations_reward.schema.json +15 -0
  152. package/dist/schemas/onchain_operations_service.schema.json +15 -0
  153. package/dist/schemas/onchain_operations_treasury.schema.json +15 -0
  154. package/dist/schemas/onchain_table_data.output.json +221 -69
  155. package/dist/schemas/onchain_table_data.schema.json +2 -2
  156. package/package.json +2 -2
@@ -0,0 +1,381 @@
1
+ import { getIndustryProfile, listIndustries, registerIndustry, } from "./industry-registry.js";
2
+ const TRAIT_INFERENCE_RULES = [
3
+ { keywords: ["物流", "发货", "配送", "快递", "送货", "delivery", "shipping", "logistics", "ship"],
4
+ trait: "has_logistics", value: true, weight: 0.85 },
5
+ { keywords: ["数字", "在线", "云端", "线上", "digital", "online", "cloud"],
6
+ trait: "has_logistics", value: false, weight: 0.7 },
7
+ { keywords: ["咨询", "沟通", "需求确认", "修改轮次", "consult", "communication", "negotiate"],
8
+ trait: "communication_heavy", value: true, weight: 0.8 },
9
+ { keywords: ["标准品", "现货", "一键下单", "standard", "instant"],
10
+ trait: "communication_heavy", value: false, weight: 0.7 },
11
+ { keywords: ["数字", "文件", "代码", "设计稿", "电子", "在线", "digital", "file", "online"],
12
+ trait: "pure_digital", value: true, weight: 0.8 },
13
+ { keywords: ["实物", "硬件", "设备", "physical", "hardware", "equipment"],
14
+ trait: "pure_digital", value: false, weight: 0.75 },
15
+ { keywords: ["课程", "学期", "周期长", "长期", "项目制", "course", "semester", "long-term", "project"],
16
+ trait: "long_cycle", value: true, weight: 0.75 },
17
+ { keywords: ["即时", "现货", "当天", "instant", "same-day", "immediate"],
18
+ trait: "long_cycle", value: false, weight: 0.8 },
19
+ { keywords: ["租赁", "租用", "押金", "rental", "rent", "deposit", "lease"],
20
+ trait: "deposit_required", value: true, weight: 0.9 },
21
+ { keywords: ["购买", "买断", "purchase", "buy"],
22
+ trait: "deposit_required", value: false, weight: 0.6 },
23
+ { keywords: ["多方", "分段", "多阶段", "多商家", "行程", "multi-party", "segment", "multi-vendor"],
24
+ trait: "multi_tier_allocation", value: true, weight: 0.75 },
25
+ { keywords: ["医疗", "法律", "金融", "保险", "药品", "medical", "legal", "finance", "insurance", "pharma"],
26
+ trait: "regulatory_intensity", value: "high", weight: 0.9 },
27
+ { keywords: ["教育", "食品", "建筑", "education", "food", "construction"],
28
+ trait: "regulatory_intensity", value: "medium", weight: 0.7 },
29
+ { keywords: ["娱乐", "游戏", "数字", "entertainment", "game", "digital"],
30
+ trait: "regulatory_intensity", value: "low", weight: 0.6 },
31
+ { keywords: ["定制", "高价值", "定制化", "custom", "high-value", "bespoke"],
32
+ trait: "trust_sensitivity", value: "high", weight: 0.8 },
33
+ { keywords: ["标准品", "小额", "standard", "low-value"],
34
+ trait: "trust_sensitivity", value: "low", weight: 0.7 },
35
+ { keywords: ["订阅", "会员", "周期性", "subscription", "membership", "recurring"],
36
+ trait: "consumption_frequency", value: "frequent", weight: 0.85 },
37
+ { keywords: ["课程", "学期", "教育", "course", "education"],
38
+ trait: "consumption_frequency", value: "one_time", weight: 0.75 },
39
+ { keywords: ["日常", "频繁", "常用", "daily", "frequent"],
40
+ trait: "consumption_frequency", value: "frequent", weight: 0.75 },
41
+ { keywords: ["小额", "日常", "便利店", "micro", "small-ticket"],
42
+ trait: "avg_ticket_size", value: "micro", weight: 0.7 },
43
+ { keywords: ["零售", "商品", "标准品", "retail", "commodity"],
44
+ trait: "avg_ticket_size", value: "small", weight: 0.7 },
45
+ { keywords: ["定制", "项目", "外包", "custom", "project"],
46
+ trait: "avg_ticket_size", value: "medium", weight: 0.7 },
47
+ { keywords: ["房产", "汽车", "高价值", "奢侈品", "realestate", "luxury", "car"],
48
+ trait: "avg_ticket_size", value: "large", weight: 0.85 },
49
+ ];
50
+ export const DEFAULT_TRAITS = {
51
+ has_logistics: false,
52
+ communication_heavy: false,
53
+ pure_digital: false,
54
+ long_cycle: false,
55
+ deposit_required: false,
56
+ multi_tier_allocation: false,
57
+ regulatory_intensity: "low",
58
+ trust_sensitivity: "medium",
59
+ consumption_frequency: "occasional",
60
+ avg_ticket_size: "small",
61
+ };
62
+ export function inferTraitsFromDescription(description) {
63
+ const text = (description ?? "").toLowerCase();
64
+ const matched = [];
65
+ const traitConfidence = new Map();
66
+ const traitValue = new Map();
67
+ for (const rule of TRAIT_INFERENCE_RULES) {
68
+ const hit = rule.keywords.find((k) => text.includes(k.toLowerCase()));
69
+ if (hit) {
70
+ matched.push(hit);
71
+ const prev = traitConfidence.get(rule.trait) ?? 0;
72
+ if (rule.weight > prev) {
73
+ traitConfidence.set(rule.trait, rule.weight);
74
+ traitValue.set(rule.trait, rule.value);
75
+ }
76
+ }
77
+ }
78
+ const traits = { ...DEFAULT_TRAITS };
79
+ for (const [k, v] of traitValue.entries()) {
80
+ traits[k] = v;
81
+ }
82
+ const hitCount = traitConfidence.size;
83
+ const confidence = Math.min(1, hitCount / 10);
84
+ return {
85
+ traits,
86
+ confidence,
87
+ matched_keywords: Array.from(new Set(matched)),
88
+ trait_confidence: Object.fromEntries(traitConfidence),
89
+ };
90
+ }
91
+ export function findSimilarIndustries(traits, limit) {
92
+ const all = listIndustries({ source: "builtin" });
93
+ const results = [];
94
+ for (const profile of all) {
95
+ const other = profile.traits;
96
+ let score = 0;
97
+ const matched = [];
98
+ const booleanKeys = [
99
+ "has_logistics", "communication_heavy", "pure_digital",
100
+ "long_cycle", "deposit_required", "multi_tier_allocation",
101
+ ];
102
+ for (const k of booleanKeys) {
103
+ if (traits[k] === other[k]) {
104
+ score += 1;
105
+ matched.push(k);
106
+ }
107
+ }
108
+ const enumKeys = [
109
+ "regulatory_intensity", "trust_sensitivity",
110
+ "consumption_frequency", "avg_ticket_size",
111
+ ];
112
+ for (const k of enumKeys) {
113
+ if (traits[k] === other[k]) {
114
+ score += 1;
115
+ matched.push(k);
116
+ }
117
+ }
118
+ results.push({
119
+ industry: profile.name,
120
+ similarity: score / 10,
121
+ matched_traits: matched,
122
+ });
123
+ }
124
+ results.sort((a, b) => b.similarity - a.similarity);
125
+ return typeof limit === "number" ? results.slice(0, Math.max(0, limit)) : results;
126
+ }
127
+ const FALLBACK_RISK_CHECK_RULES = [
128
+ {
129
+ trait_key: "deposit_required", trait_value: true,
130
+ check: {
131
+ id: "fb_deposit_lock", description: "押金锁定期安全(押金不可被商家随时撤回)",
132
+ weight: 30,
133
+ passed: (p) => p?.fund_safety?.lock_duration_safe ?? false,
134
+ advice: "⚠️ 锁定期不安全:押金可能被随时撤回,建议要求锁定期 ≥ 7 天。",
135
+ },
136
+ need: {
137
+ id: "need_deposit_lock", tier: "personalized",
138
+ description: "押金锁定期安全",
139
+ satisfied: (p) => p?.fund_safety?.lock_duration_safe ?? false,
140
+ advice: "押金锁定期不安全。",
141
+ },
142
+ },
143
+ {
144
+ trait_key: "has_logistics", trait_value: true,
145
+ check: {
146
+ id: "fb_logistics_track", description: "物流 Guard 配置(发货/收货验证)",
147
+ weight: 25,
148
+ passed: (p) => p?.workflow_analysis?.has_milestone_nodes ?? false,
149
+ advice: "⚠️ 无物流 Guard:发货与收货状态无第三方验证。",
150
+ },
151
+ },
152
+ {
153
+ trait_key: "pure_digital", trait_value: true,
154
+ check: {
155
+ id: "fb_wip_verified", description: "WIP hash 验证(数字交付物可溯源)",
156
+ weight: 25,
157
+ passed: (p) => p?.service_basics?.wip_verified === true,
158
+ advice: "⚠️ WIP 未验证:数字交付物无法溯源。",
159
+ },
160
+ },
161
+ {
162
+ trait_key: "long_cycle", trait_value: true,
163
+ check: {
164
+ id: "fb_milestone", description: "里程碑节点(分阶段验收)",
165
+ weight: 25,
166
+ passed: (p) => p?.workflow_analysis?.has_milestone_nodes ?? false,
167
+ advice: "⚠️ 无里程碑节点:长周期项目缺少分阶段验收。",
168
+ },
169
+ },
170
+ {
171
+ trait_key: "regulatory_intensity", trait_value: "high",
172
+ check: {
173
+ id: "fb_compliance", description: "合规配置(仲裁 + 赔偿金)",
174
+ weight: 30,
175
+ passed: (p) => (p?.workflow_analysis?.has_arbitration_path ?? false) &&
176
+ (p?.service_basics?.compensation_fund_balance ?? 0n) > 0n,
177
+ advice: "🔴 合规要求未满足:高监管行业必须配置仲裁与赔偿金。",
178
+ },
179
+ },
180
+ {
181
+ trait_key: "multi_tier_allocation", trait_value: true,
182
+ check: {
183
+ id: "fb_multi_tier_fair", description: "多层分账公平性(每个 segment 有对应 Allocator)",
184
+ weight: 20,
185
+ passed: (p) => (p?.workflow_analysis?.total_nodes ?? 0) >= 3,
186
+ advice: "⚠️ 多层分账需配置对应节点与 Allocator,否则资金分配不透明。",
187
+ },
188
+ },
189
+ ];
190
+ function buildFallbackFlywheel(name, traits) {
191
+ const sellingPoints = ["资金托管 + 流程透明"];
192
+ if (traits.deposit_required)
193
+ sellingPoints.push("押金托管 + 锁定期保障");
194
+ if (traits.has_logistics)
195
+ sellingPoints.push("物流 Guard 验证");
196
+ if (traits.pure_digital)
197
+ sellingPoints.push("WIP 数字交付物溯源");
198
+ if (traits.regulatory_intensity === "high")
199
+ sellingPoints.push("合规仲裁 + 赔偿金保障");
200
+ const keyActions = [
201
+ { action: "设置首单 Reward", purpose: "吸引新客户", mutableField: "rewards", metricToWatch: "新客下单率" },
202
+ { action: "配置 compensation_fund", purpose: "提升信任分", mutableField: "compensation_fund", metricToWatch: "信任分" },
203
+ ];
204
+ if (traits.long_cycle) {
205
+ keyActions.push({ action: "里程碑 Reward", purpose: "激励完成长周期项目", mutableField: "rewards", metricToWatch: "完单率" });
206
+ }
207
+ if (traits.consumption_frequency === "frequent") {
208
+ keyActions.push({ action: "忠诚度 Reward", purpose: "提升复购", mutableField: "rewards", metricToWatch: "复购率" });
209
+ }
210
+ return {
211
+ industry: name,
212
+ trustSellingPoints: sellingPoints,
213
+ keyActions,
214
+ rewardStrategy: "首单奖励 + 推荐返现" + (traits.consumption_frequency === "frequent" ? " + 忠诚度奖励" : ""),
215
+ discountStrategy: traits.long_cycle ? "长期合作折扣 + 阶梯优惠" : "首单折扣 + 满减",
216
+ trustDescription: sellingPoints.join(" + "),
217
+ };
218
+ }
219
+ function buildFallbackPreferenceTemplate(traits) {
220
+ return {
221
+ max_acceptable_cycle: traits.long_cycle ? 90 : 14,
222
+ response_time_expectation: traits.communication_heavy ? 4 : 12,
223
+ require_arbitration: traits.regulatory_intensity !== "low" || traits.trust_sensitivity === "high",
224
+ require_compensation_fund: traits.trust_sensitivity === "high" || traits.deposit_required,
225
+ risk_appetite: traits.trust_sensitivity === "high" ? "conservative" : "balanced",
226
+ delivery_speed_priority: traits.has_logistics && traits.consumption_frequency === "frequent" ? "urgent" : "normal",
227
+ after_sales_expectation: traits.trust_sensitivity === "high" ? "full" : "basic",
228
+ };
229
+ }
230
+ export function synthesizeProfile(traits, name) {
231
+ const similar = findSimilarIndustries(traits, 1);
232
+ const bestMatch = similar[0];
233
+ const reuseBasis = bestMatch && bestMatch.similarity >= 0.6
234
+ ? getIndustryProfile(bestMatch.industry)
235
+ : undefined;
236
+ const industryName = name ?? `custom_${Date.now().toString(36)}`;
237
+ const displayName = name ?? `自定义行业`;
238
+ const flywheel = reuseBasis
239
+ ? { ...reuseBasis.flywheel, industry: industryName }
240
+ : buildFallbackFlywheel(industryName, traits);
241
+ const preferenceTemplate = reuseBasis
242
+ ? {
243
+ ...reuseBasis.preference_template,
244
+ max_acceptable_cycle: traits.long_cycle
245
+ ? Math.max(reuseBasis.preference_template.max_acceptable_cycle, 90)
246
+ : reuseBasis.preference_template.max_acceptable_cycle,
247
+ require_compensation_fund: traits.trust_sensitivity === "high"
248
+ ? true
249
+ : reuseBasis.preference_template.require_compensation_fund,
250
+ }
251
+ : buildFallbackPreferenceTemplate(traits);
252
+ const riskChecks = [];
253
+ const needs = [];
254
+ for (const rule of FALLBACK_RISK_CHECK_RULES) {
255
+ if (traits[rule.trait_key] === rule.trait_value) {
256
+ riskChecks.push({ ...rule.check, industry: industryName });
257
+ if (rule.need) {
258
+ needs.push({ ...rule.need });
259
+ }
260
+ }
261
+ }
262
+ if (riskChecks.length === 0) {
263
+ riskChecks.push({
264
+ id: "fb_basic_arbitration",
265
+ industry: industryName,
266
+ description: "配置仲裁(基础纠纷解决)",
267
+ weight: 100,
268
+ passed: (p) => p?.workflow_analysis?.has_arbitration_path ?? false,
269
+ advice: "⚠️ 未配置仲裁:基础纠纷无解决通道。",
270
+ });
271
+ }
272
+ return {
273
+ name: industryName,
274
+ display_name: displayName,
275
+ traits,
276
+ source: "inferred",
277
+ version: "v1",
278
+ flywheel,
279
+ risk_checks: riskChecks,
280
+ preference_template: preferenceTemplate,
281
+ needs,
282
+ confidence: bestMatch?.similarity ?? 0.3,
283
+ evolution: {
284
+ version: 1,
285
+ last_updated: Date.now(),
286
+ signal_count: 0,
287
+ pending_suggestions: 0,
288
+ },
289
+ };
290
+ }
291
+ export function composeIndustries(names, newName) {
292
+ if (!names || names.length === 0)
293
+ return undefined;
294
+ const profiles = [];
295
+ for (const n of names) {
296
+ const p = getIndustryProfile(n);
297
+ if (!p)
298
+ return undefined;
299
+ profiles.push(p);
300
+ }
301
+ const composedTraits = {
302
+ has_logistics: profiles.some((p) => p.traits.has_logistics),
303
+ communication_heavy: profiles.some((p) => p.traits.communication_heavy),
304
+ pure_digital: profiles.every((p) => p.traits.pure_digital),
305
+ long_cycle: profiles.some((p) => p.traits.long_cycle),
306
+ deposit_required: profiles.some((p) => p.traits.deposit_required),
307
+ multi_tier_allocation: profiles.some((p) => p.traits.multi_tier_allocation),
308
+ regulatory_intensity: pickStrictest(profiles.map((p) => p.traits.regulatory_intensity), ["low", "medium", "high"]),
309
+ trust_sensitivity: pickStrictest(profiles.map((p) => p.traits.trust_sensitivity), ["low", "medium", "high"]),
310
+ consumption_frequency: pickStrictest(profiles.map((p) => p.traits.consumption_frequency), ["one_time", "occasional", "frequent"]),
311
+ avg_ticket_size: pickStrictest(profiles.map((p) => p.traits.avg_ticket_size), ["micro", "small", "medium", "large"]),
312
+ };
313
+ const newNameResolved = newName ?? `composed_${names.join("_and_")}`;
314
+ const sellingPoints = Array.from(new Set(profiles.flatMap((p) => p.flywheel.trustSellingPoints)));
315
+ const keyActions = Array.from(new Set(profiles.flatMap((p) => p.flywheel.keyActions)));
316
+ const flywheel = {
317
+ industry: newNameResolved,
318
+ trustSellingPoints: sellingPoints,
319
+ keyActions,
320
+ rewardStrategy: profiles.map((p) => p.flywheel.rewardStrategy).join(" + "),
321
+ discountStrategy: profiles.map((p) => p.flywheel.discountStrategy).join(" + "),
322
+ trustDescription: profiles.map((p) => p.flywheel.trustDescription).join(" + "),
323
+ };
324
+ const riskCheckMap = new Map();
325
+ for (const p of profiles) {
326
+ for (const c of p.risk_checks) {
327
+ if (!riskCheckMap.has(c.id)) {
328
+ riskCheckMap.set(c.id, { ...c, industry: newNameResolved });
329
+ }
330
+ }
331
+ }
332
+ const needMap = new Map();
333
+ for (const p of profiles) {
334
+ for (const n of p.needs) {
335
+ if (!needMap.has(n.id)) {
336
+ needMap.set(n.id, { ...n });
337
+ }
338
+ }
339
+ }
340
+ const prefTpl = {
341
+ max_acceptable_cycle: Math.max(...profiles.map((p) => p.preference_template.max_acceptable_cycle)),
342
+ response_time_expectation: Math.min(...profiles.map((p) => p.preference_template.response_time_expectation)),
343
+ require_arbitration: profiles.some((p) => p.preference_template.require_arbitration),
344
+ require_compensation_fund: profiles.some((p) => p.preference_template.require_compensation_fund),
345
+ risk_appetite: pickStrictest(profiles.map((p) => p.preference_template.risk_appetite), ["aggressive", "balanced", "conservative"]),
346
+ delivery_speed_priority: pickStrictest(profiles.map((p) => p.preference_template.delivery_speed_priority), ["flexible", "normal", "urgent"]),
347
+ after_sales_expectation: pickStrictest(profiles.map((p) => p.preference_template.after_sales_expectation), ["minimal", "basic", "full"]),
348
+ };
349
+ const composed = {
350
+ name: newNameResolved,
351
+ display_name: newName ?? `组合行业(${names.join("+")})`,
352
+ traits: composedTraits,
353
+ source: "composed",
354
+ version: "v1",
355
+ flywheel,
356
+ risk_checks: Array.from(riskCheckMap.values()),
357
+ preference_template: prefTpl,
358
+ needs: Array.from(needMap.values()),
359
+ parent_industries: [...names],
360
+ evolution: {
361
+ version: 1,
362
+ last_updated: Date.now(),
363
+ signal_count: 0,
364
+ pending_suggestions: 0,
365
+ },
366
+ };
367
+ registerIndustry(composed);
368
+ return composed;
369
+ }
370
+ function pickStrictest(values, strictness) {
371
+ let maxIdx = 0;
372
+ let result = values[0] ?? strictness[0];
373
+ for (const v of values) {
374
+ const idx = strictness.indexOf(v);
375
+ if (idx >= 0 && idx > maxIdx) {
376
+ maxIdx = idx;
377
+ result = v;
378
+ }
379
+ }
380
+ return result;
381
+ }
@@ -0,0 +1,49 @@
1
+ import type { AcquisitionFlywheel } from "./acquisition-flywheel.js";
2
+ import type { IndustryRiskCheck, IndustryNeed } from "../customer/industry-risks.js";
3
+ import type { IndustryTemplate } from "../customer/user-preferences.js";
4
+ export interface IndustryTraits {
5
+ has_logistics: boolean;
6
+ communication_heavy: boolean;
7
+ pure_digital: boolean;
8
+ long_cycle: boolean;
9
+ deposit_required: boolean;
10
+ multi_tier_allocation: boolean;
11
+ regulatory_intensity: "low" | "medium" | "high";
12
+ trust_sensitivity: "low" | "medium" | "high";
13
+ consumption_frequency: "one_time" | "occasional" | "frequent";
14
+ avg_ticket_size: "micro" | "small" | "medium" | "large";
15
+ }
16
+ export type IndustrySource = "builtin" | "inferred" | "composed" | "custom";
17
+ export interface IndustryEvolutionMeta {
18
+ version: number;
19
+ last_updated: number;
20
+ signal_count: number;
21
+ pending_suggestions: number;
22
+ last_health_score?: number;
23
+ }
24
+ export interface IndustryProfile {
25
+ name: string;
26
+ display_name: string;
27
+ traits: IndustryTraits;
28
+ source: IndustrySource;
29
+ version: string;
30
+ flywheel: AcquisitionFlywheel;
31
+ risk_checks: IndustryRiskCheck[];
32
+ preference_template: IndustryTemplate;
33
+ needs: IndustryNeed[];
34
+ evolution?: IndustryEvolutionMeta;
35
+ confidence?: number;
36
+ parent_industries?: string[];
37
+ }
38
+ export type ExtendedIndustry = "freelance" | "rental" | "education" | "travel" | "subscription" | "retail" | "general" | "custom";
39
+ export declare const INDUSTRY_REGISTRY_VERSION = 1;
40
+ export declare function getIndustryProfile(name: string): IndustryProfile | undefined;
41
+ export declare function listIndustries(filter?: {
42
+ source?: IndustrySource;
43
+ }): IndustryProfile[];
44
+ export declare function registerIndustry(profile: IndustryProfile): boolean;
45
+ export declare function getIndustryTraits(name: string): IndustryTraits | undefined;
46
+ export declare function resolveIndustryName(alias: string): string | undefined;
47
+ export declare function getRegistrySize(): number;
48
+ export declare function _resetRegistryForTest(): void;
49
+ export declare function listBuiltinIndustryNames(): string[];
@@ -0,0 +1,167 @@
1
+ import { getFlywheelForIndustry, listIndustries as listFlywheelIndustries } from "./acquisition-flywheel.js";
2
+ import { getIndustryRiskChecks, getIndustryNeeds } from "../customer/industry-risks.js";
3
+ import { getIndustryTemplate, SUPPORTED_INDUSTRIES } from "../customer/user-preferences.js";
4
+ const BUILTIN_TRAITS = {
5
+ freelance: {
6
+ has_logistics: false, communication_heavy: true, pure_digital: true,
7
+ long_cycle: false, deposit_required: false, multi_tier_allocation: false,
8
+ regulatory_intensity: "low", trust_sensitivity: "high",
9
+ consumption_frequency: "occasional", avg_ticket_size: "medium",
10
+ },
11
+ rental: {
12
+ has_logistics: true, communication_heavy: false, pure_digital: false,
13
+ long_cycle: false, deposit_required: true, multi_tier_allocation: false,
14
+ regulatory_intensity: "low", trust_sensitivity: "high",
15
+ consumption_frequency: "occasional", avg_ticket_size: "medium",
16
+ },
17
+ education: {
18
+ has_logistics: false, communication_heavy: true, pure_digital: false,
19
+ long_cycle: true, deposit_required: false, multi_tier_allocation: false,
20
+ regulatory_intensity: "medium", trust_sensitivity: "high",
21
+ consumption_frequency: "one_time", avg_ticket_size: "large",
22
+ },
23
+ travel: {
24
+ has_logistics: true, communication_heavy: true, pure_digital: false,
25
+ long_cycle: false, deposit_required: false, multi_tier_allocation: true,
26
+ regulatory_intensity: "medium", trust_sensitivity: "high",
27
+ consumption_frequency: "one_time", avg_ticket_size: "large",
28
+ },
29
+ subscription: {
30
+ has_logistics: false, communication_heavy: false, pure_digital: true,
31
+ long_cycle: false, deposit_required: false, multi_tier_allocation: false,
32
+ regulatory_intensity: "low", trust_sensitivity: "medium",
33
+ consumption_frequency: "frequent", avg_ticket_size: "small",
34
+ },
35
+ retail: {
36
+ has_logistics: true, communication_heavy: false, pure_digital: false,
37
+ long_cycle: false, deposit_required: false, multi_tier_allocation: false,
38
+ regulatory_intensity: "low", trust_sensitivity: "medium",
39
+ consumption_frequency: "frequent", avg_ticket_size: "small",
40
+ },
41
+ };
42
+ const BUILTIN_DISPLAY_NAMES = {
43
+ freelance: "自由职业",
44
+ rental: "租赁",
45
+ education: "教育",
46
+ travel: "旅行",
47
+ subscription: "订阅",
48
+ retail: "零售",
49
+ general: "通用",
50
+ custom: "自定义",
51
+ };
52
+ const INDUSTRY_ALIASES = {
53
+ "自由职业": "freelance",
54
+ "外包": "freelance",
55
+ "设计": "freelance",
56
+ "开发": "freelance",
57
+ "咨询": "freelance",
58
+ "租赁": "rental",
59
+ "租用": "rental",
60
+ "出租": "rental",
61
+ "教育": "education",
62
+ "课程": "education",
63
+ "培训": "education",
64
+ "旅行": "travel",
65
+ "旅游": "travel",
66
+ "行程": "travel",
67
+ "订阅": "subscription",
68
+ "会员": "subscription",
69
+ "零售": "retail",
70
+ "电商": "retail",
71
+ "商品": "retail",
72
+ "通用": "general",
73
+ "自定义": "custom",
74
+ "freelancer": "freelance",
75
+ "gig": "freelance",
76
+ "rent": "rental",
77
+ "lease": "rental",
78
+ "course": "education",
79
+ "edu": "education",
80
+ "trip": "travel",
81
+ "tour": "travel",
82
+ "subscribe": "subscription",
83
+ "membership": "subscription",
84
+ "shop": "retail",
85
+ "ecommerce": "retail",
86
+ "general_industry": "general",
87
+ };
88
+ export const INDUSTRY_REGISTRY_VERSION = 1;
89
+ const registry = new Map();
90
+ function seedBuiltinProfile(name) {
91
+ const traits = BUILTIN_TRAITS[name];
92
+ if (!traits)
93
+ return undefined;
94
+ const flywheel = getFlywheelForIndustry(name);
95
+ if (!flywheel)
96
+ return undefined;
97
+ const riskChecks = getIndustryRiskChecks(name);
98
+ const needs = getIndustryNeeds(name);
99
+ const preferenceTemplate = getIndustryTemplate(name);
100
+ return {
101
+ name,
102
+ display_name: BUILTIN_DISPLAY_NAMES[name] ?? name,
103
+ traits,
104
+ source: "builtin",
105
+ version: "v1",
106
+ flywheel,
107
+ risk_checks: riskChecks,
108
+ preference_template: preferenceTemplate,
109
+ needs,
110
+ };
111
+ }
112
+ function seedBuiltinIndustries() {
113
+ for (const name of SUPPORTED_INDUSTRIES) {
114
+ const profile = seedBuiltinProfile(name);
115
+ if (profile) {
116
+ registry.set(name, profile);
117
+ }
118
+ }
119
+ }
120
+ seedBuiltinIndustries();
121
+ export function getIndustryProfile(name) {
122
+ const p = registry.get(name);
123
+ return p ? JSON.parse(JSON.stringify(p)) : undefined;
124
+ }
125
+ export function listIndustries(filter) {
126
+ const all = Array.from(registry.values());
127
+ if (filter?.source) {
128
+ return all.filter((p) => p.source === filter.source);
129
+ }
130
+ return all;
131
+ }
132
+ export function registerIndustry(profile) {
133
+ if (!profile.name || !profile.traits || !profile.flywheel)
134
+ return false;
135
+ registry.set(profile.name, profile);
136
+ return true;
137
+ }
138
+ export function getIndustryTraits(name) {
139
+ return registry.get(name)?.traits;
140
+ }
141
+ export function resolveIndustryName(alias) {
142
+ if (!alias || typeof alias !== "string")
143
+ return undefined;
144
+ const trimmed = alias.trim();
145
+ if (!trimmed)
146
+ return undefined;
147
+ const lower = trimmed.toLowerCase();
148
+ if (INDUSTRY_ALIASES[trimmed])
149
+ return INDUSTRY_ALIASES[trimmed];
150
+ if (INDUSTRY_ALIASES[lower])
151
+ return INDUSTRY_ALIASES[lower];
152
+ if (registry.has(trimmed))
153
+ return trimmed;
154
+ if (registry.has(lower))
155
+ return lower;
156
+ return undefined;
157
+ }
158
+ export function getRegistrySize() {
159
+ return registry.size;
160
+ }
161
+ export function _resetRegistryForTest() {
162
+ registry.clear();
163
+ seedBuiltinIndustries();
164
+ }
165
+ export function listBuiltinIndustryNames() {
166
+ return listFlywheelIndustries();
167
+ }
@@ -0,0 +1,42 @@
1
+ import type { IndustryMetrics, IndustryHealthReport, IndustryUpdateSuggestion } from "./industry-evolution.js";
2
+ export type BusinessIntent = "default" | "growth" | "retention" | "compliance" | "efficiency" | "trust_building" | "custom";
3
+ export type MetricDimension = "completed_rate" | "dispute_rate" | "refund_rate" | "repeat_buyer_rate" | "cycle_efficiency" | "arbitration_coverage" | "compensation_coverage" | "milestone_adoption" | "review_openness";
4
+ export interface IntentMetricSpec {
5
+ intent: BusinessIntent;
6
+ display_name: string;
7
+ weights: Partial<Record<MetricDimension, number>>;
8
+ healthy_thresholds: Partial<Record<MetricDimension, number>>;
9
+ suggestion_triggers: IntentSuggestionTrigger[];
10
+ level_thresholds?: {
11
+ thriving?: number;
12
+ healthy?: number;
13
+ stressed?: number;
14
+ };
15
+ role_advice_routing?: Record<"user" | "merchant" | "arbitrator", string[]>;
16
+ }
17
+ export interface IntentSuggestionTrigger {
18
+ metric: MetricDimension;
19
+ operator: ">=" | "<=" | ">" | "<" | "==";
20
+ threshold: number;
21
+ suggestion_type: IndustryUpdateSuggestion["suggestion_type"];
22
+ field: string;
23
+ suggested_value: unknown;
24
+ evidence_template: string;
25
+ confidence: number;
26
+ priority: IndustryUpdateSuggestion["priority"];
27
+ target_roles?: Array<"user" | "merchant" | "arbitrator">;
28
+ }
29
+ export declare const BUILTIN_INTENT_SPECS: Record<BusinessIntent, IntentMetricSpec>;
30
+ export declare function registerIntentProfile(spec: IntentMetricSpec): boolean;
31
+ export declare function getIntentProfile(intent: BusinessIntent): IntentMetricSpec | undefined;
32
+ export declare function listIntents(): BusinessIntent[];
33
+ export declare function _resetIntentRegistryForTest(): void;
34
+ export declare function evaluateIndustryHealthByIntent(industry: string, metrics: IndustryMetrics, intent?: BusinessIntent): IndustryHealthReport;
35
+ export declare function suggestIndustryUpdateByIntent(industry: string, metrics: IndustryMetrics, intent?: BusinessIntent): IndustryUpdateSuggestion[];
36
+ export declare function evaluateIndustryHealthMultiIntent(industry: string, metrics: IndustryMetrics, intents: Array<{
37
+ intent: BusinessIntent;
38
+ weight: number;
39
+ }>): IndustryHealthReport;
40
+ export type AdviceRole = "user" | "merchant" | "arbitrator";
41
+ export declare function getRoleAdvice(intent: BusinessIntent, role: AdviceRole): string[];
42
+ export declare function filterSuggestionsByRole(suggestions: IndustryUpdateSuggestion[], role: AdviceRole, triggers?: IntentSuggestionTrigger[]): IndustryUpdateSuggestion[];