@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.
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.js +1 -0
- package/dist/config/runtime.d.ts +26 -0
- package/dist/config/runtime.js +217 -0
- package/dist/customer/industry-risks.d.ts +36 -0
- package/dist/customer/industry-risks.js +424 -0
- package/dist/customer/info-puzzle.d.ts +102 -0
- package/dist/customer/info-puzzle.js +312 -0
- package/dist/customer/order-monitor.d.ts +75 -0
- package/dist/customer/order-monitor.js +327 -0
- package/dist/customer/order-strategy.d.ts +36 -0
- package/dist/customer/order-strategy.js +373 -0
- package/dist/customer/post-purchase.d.ts +42 -0
- package/dist/customer/post-purchase.js +350 -0
- package/dist/customer/reminder-system.d.ts +42 -0
- package/dist/customer/reminder-system.js +295 -0
- package/dist/customer/risk-assessment.d.ts +8 -0
- package/dist/customer/risk-assessment.js +337 -0
- package/dist/customer/types.d.ts +193 -0
- package/dist/customer/types.js +13 -0
- package/dist/customer/user-preferences.d.ts +67 -0
- package/dist/customer/user-preferences.js +451 -0
- package/dist/experience/experience-reuse.d.ts +10 -0
- package/dist/experience/experience-reuse.js +103 -0
- package/dist/experience/index.d.ts +6 -0
- package/dist/experience/index.js +5 -0
- package/dist/experience/intent-distill.d.ts +3 -0
- package/dist/experience/intent-distill.js +83 -0
- package/dist/experience/realtime-feedback.d.ts +5 -0
- package/dist/experience/realtime-feedback.js +77 -0
- package/dist/experience/types.d.ts +50 -0
- package/dist/experience/types.js +1 -0
- package/dist/experience/user-profile.d.ts +25 -0
- package/dist/experience/user-profile.js +171 -0
- package/dist/index.js +570 -186
- package/dist/knowledge/acquisition-flywheel.d.ts +50 -0
- package/dist/knowledge/acquisition-flywheel.js +183 -0
- package/dist/knowledge/arbitration-trust.d.ts +24 -0
- package/dist/knowledge/arbitration-trust.js +117 -0
- package/dist/knowledge/audit-rules.d.ts +28 -0
- package/dist/knowledge/audit-rules.js +141 -0
- package/dist/knowledge/demand-matching.d.ts +29 -0
- package/dist/knowledge/demand-matching.js +132 -0
- package/dist/knowledge/dynamic-pricing.d.ts +31 -0
- package/dist/knowledge/dynamic-pricing.js +87 -0
- package/dist/knowledge/flywheel-loop.d.ts +87 -0
- package/dist/knowledge/flywheel-loop.js +378 -0
- package/dist/knowledge/glossary.d.ts +18 -0
- package/dist/knowledge/glossary.js +209 -0
- package/dist/knowledge/index.d.ts +64 -0
- package/dist/knowledge/index.js +66 -0
- package/dist/knowledge/industry-evolution.d.ts +82 -0
- package/dist/knowledge/industry-evolution.js +323 -0
- package/dist/knowledge/industry-generalizer.d.ts +17 -0
- package/dist/knowledge/industry-generalizer.js +381 -0
- package/dist/knowledge/industry-registry.d.ts +49 -0
- package/dist/knowledge/industry-registry.js +167 -0
- package/dist/knowledge/intent-metrics.d.ts +42 -0
- package/dist/knowledge/intent-metrics.js +566 -0
- package/dist/knowledge/process-model.d.ts +24 -0
- package/dist/knowledge/process-model.js +160 -0
- package/dist/knowledge/reputation-rules.d.ts +42 -0
- package/dist/knowledge/reputation-rules.js +99 -0
- package/dist/knowledge/reward-templates.d.ts +25 -0
- package/dist/knowledge/reward-templates.js +125 -0
- package/dist/knowledge/safety-rules.d.ts +36 -0
- package/dist/knowledge/safety-rules.js +171 -0
- package/dist/knowledge/tool-constraints.d.ts +30 -0
- package/dist/knowledge/tool-constraints.js +185 -0
- package/dist/knowledge/trust-metrics.d.ts +37 -0
- package/dist/knowledge/trust-metrics.js +138 -0
- package/dist/loop-engineering/diagnose.d.ts +3 -2
- package/dist/loop-engineering/diagnose.js +94 -0
- package/dist/loop-engineering/improve.d.ts +1 -1
- package/dist/loop-engineering/improve.js +52 -1
- package/dist/project/graph.d.ts +71 -0
- package/dist/project/graph.js +314 -0
- package/dist/project/index.d.ts +62 -0
- package/dist/project/index.js +167 -0
- package/dist/project/namespace.d.ts +62 -0
- package/dist/project/namespace.js +181 -0
- package/dist/project/query.d.ts +40 -0
- package/dist/project/query.js +110 -0
- package/dist/safety/confirm-gate.d.ts +15 -0
- package/dist/safety/confirm-gate.js +44 -0
- package/dist/safety/index.d.ts +3 -0
- package/dist/safety/index.js +3 -0
- package/dist/safety/preview.d.ts +2 -0
- package/dist/safety/preview.js +36 -0
- package/dist/schema/call/allocation.d.ts +15 -0
- package/dist/schema/call/arbitration.d.ts +111 -96
- package/dist/schema/call/base.d.ts +1070 -44
- package/dist/schema/call/base.js +69 -1
- package/dist/schema/call/bridge.d.ts +709 -52
- package/dist/schema/call/bridge.js +13 -2
- package/dist/schema/call/contact.d.ts +15 -0
- package/dist/schema/call/demand.d.ts +69 -54
- package/dist/schema/call/guard.d.ts +125 -80
- package/dist/schema/call/handler.d.ts +3 -0
- package/dist/schema/call/handler.js +14 -0
- package/dist/schema/call/machine.d.ts +830 -800
- package/dist/schema/call/order.d.ts +15 -0
- package/dist/schema/call/payment.d.ts +15 -0
- package/dist/schema/call/permission.d.ts +15 -0
- package/dist/schema/call/personal.d.ts +15 -0
- package/dist/schema/call/progress.d.ts +15 -0
- package/dist/schema/call/proof.d.ts +42 -12
- package/dist/schema/call/proof.js +3 -3
- package/dist/schema/call/repository.d.ts +91 -76
- package/dist/schema/call/reward.d.ts +45 -30
- package/dist/schema/call/semantic.d.ts +1 -0
- package/dist/schema/call/semantic.js +217 -0
- package/dist/schema/call/service.d.ts +407 -392
- package/dist/schema/call/treasury.d.ts +15 -0
- package/dist/schema/common/index.js +3 -3
- package/dist/schema/local/index.d.ts +228 -72
- package/dist/schema/local/index.js +33 -6
- package/dist/schema/messenger/index.d.ts +668 -50
- package/dist/schema/messenger/index.js +9 -0
- package/dist/schema/operations.d.ts +1693 -1369
- package/dist/schema/operations.js +2 -2
- package/dist/schema/query/index.d.ts +1614 -1614
- package/dist/schema/query/index.js +30 -27
- package/dist/schemas/account_operation.output.json +25 -16
- package/dist/schemas/account_operation.schema.json +1 -1
- package/dist/schemas/bridge_operation.output.json +520 -0
- package/dist/schemas/bridge_operation.schema.json +15 -0
- package/dist/schemas/guard2file.schema.json +15 -0
- package/dist/schemas/index.json +1 -1
- package/dist/schemas/local_info_operation.output.json +23 -0
- package/dist/schemas/local_info_operation.schema.json +1 -1
- package/dist/schemas/local_mark_operation.output.json +24 -1
- package/dist/schemas/local_mark_operation.schema.json +4 -4
- package/dist/schemas/machineNode2file.schema.json +15 -0
- package/dist/schemas/messenger_operation.output.json +528 -0
- package/dist/schemas/onchain_operations.output.json +350 -16
- package/dist/schemas/onchain_operations.schema.json +96 -23
- package/dist/schemas/onchain_operations_allocation.schema.json +15 -0
- package/dist/schemas/onchain_operations_arbitration.schema.json +15 -0
- package/dist/schemas/onchain_operations_contact.schema.json +15 -0
- package/dist/schemas/onchain_operations_demand.schema.json +15 -0
- package/dist/schemas/onchain_operations_gen_passport.schema.json +30 -0
- package/dist/schemas/onchain_operations_guard.schema.json +15 -0
- package/dist/schemas/onchain_operations_machine.schema.json +81 -23
- package/dist/schemas/onchain_operations_order.schema.json +15 -0
- package/dist/schemas/onchain_operations_payment.schema.json +15 -0
- package/dist/schemas/onchain_operations_permission.schema.json +15 -0
- package/dist/schemas/onchain_operations_personal.schema.json +15 -0
- package/dist/schemas/onchain_operations_progress.schema.json +15 -0
- package/dist/schemas/onchain_operations_repository.schema.json +15 -0
- package/dist/schemas/onchain_operations_reward.schema.json +15 -0
- package/dist/schemas/onchain_operations_service.schema.json +15 -0
- package/dist/schemas/onchain_operations_treasury.schema.json +15 -0
- package/dist/schemas/onchain_table_data.output.json +221 -69
- package/dist/schemas/onchain_table_data.schema.json +2 -2
- package/package.json +2 -2
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
import { CUSTOMER_INTELLIGENCE_VERSION } from "./types.js";
|
|
2
|
+
export const SUPPORTED_INDUSTRIES = [
|
|
3
|
+
"freelance", "rental", "education", "travel", "subscription", "retail",
|
|
4
|
+
];
|
|
5
|
+
const INDUSTRY_TEMPLATES = {
|
|
6
|
+
freelance: {
|
|
7
|
+
max_acceptable_cycle: 30, response_time_expectation: 4,
|
|
8
|
+
require_arbitration: true, require_compensation_fund: true,
|
|
9
|
+
risk_appetite: "balanced", delivery_speed_priority: "normal",
|
|
10
|
+
after_sales_expectation: "full",
|
|
11
|
+
},
|
|
12
|
+
rental: {
|
|
13
|
+
max_acceptable_cycle: 7, response_time_expectation: 8,
|
|
14
|
+
require_arbitration: true, require_compensation_fund: true,
|
|
15
|
+
risk_appetite: "conservative", delivery_speed_priority: "normal",
|
|
16
|
+
after_sales_expectation: "full",
|
|
17
|
+
},
|
|
18
|
+
education: {
|
|
19
|
+
max_acceptable_cycle: 90, response_time_expectation: 24,
|
|
20
|
+
require_arbitration: true, require_compensation_fund: true,
|
|
21
|
+
risk_appetite: "conservative", delivery_speed_priority: "flexible",
|
|
22
|
+
after_sales_expectation: "full",
|
|
23
|
+
},
|
|
24
|
+
travel: {
|
|
25
|
+
max_acceptable_cycle: 14, response_time_expectation: 2,
|
|
26
|
+
require_arbitration: true, require_compensation_fund: true,
|
|
27
|
+
risk_appetite: "conservative", delivery_speed_priority: "urgent",
|
|
28
|
+
after_sales_expectation: "full",
|
|
29
|
+
},
|
|
30
|
+
subscription: {
|
|
31
|
+
max_acceptable_cycle: 30, response_time_expectation: 24,
|
|
32
|
+
require_arbitration: false, require_compensation_fund: false,
|
|
33
|
+
risk_appetite: "aggressive", delivery_speed_priority: "normal",
|
|
34
|
+
after_sales_expectation: "basic",
|
|
35
|
+
},
|
|
36
|
+
retail: {
|
|
37
|
+
max_acceptable_cycle: 7, response_time_expectation: 8,
|
|
38
|
+
require_arbitration: true, require_compensation_fund: true,
|
|
39
|
+
risk_appetite: "balanced", delivery_speed_priority: "normal",
|
|
40
|
+
after_sales_expectation: "full",
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
const BASE_DEFAULTS = {
|
|
44
|
+
price_sensitivity: "medium",
|
|
45
|
+
value_orientation: "balanced",
|
|
46
|
+
discount_sensitivity: 0.3,
|
|
47
|
+
delivery_speed_priority: "normal",
|
|
48
|
+
max_acceptable_cycle: 14,
|
|
49
|
+
response_time_expectation: 8,
|
|
50
|
+
merchant_preference: "neutral",
|
|
51
|
+
min_order_history: 3,
|
|
52
|
+
bargain_hunting: 0.3,
|
|
53
|
+
reward_seeking: false,
|
|
54
|
+
referral_participation: false,
|
|
55
|
+
communication_style: "friendly",
|
|
56
|
+
transparency_demand: 0.5,
|
|
57
|
+
after_sales_expectation: "basic",
|
|
58
|
+
risk_appetite: "balanced",
|
|
59
|
+
min_trust_score: 50,
|
|
60
|
+
require_arbitration: true,
|
|
61
|
+
require_compensation_fund: true,
|
|
62
|
+
preferred_industries: [],
|
|
63
|
+
preferred_tokens: ["0x2::wow::WOW"],
|
|
64
|
+
preferred_merchants: [],
|
|
65
|
+
};
|
|
66
|
+
export function getDefaultPreferences(industry) {
|
|
67
|
+
if (!industry || !INDUSTRY_TEMPLATES[industry]) {
|
|
68
|
+
return { ...BASE_DEFAULTS };
|
|
69
|
+
}
|
|
70
|
+
const tpl = INDUSTRY_TEMPLATES[industry];
|
|
71
|
+
return {
|
|
72
|
+
...BASE_DEFAULTS,
|
|
73
|
+
max_acceptable_cycle: tpl.max_acceptable_cycle,
|
|
74
|
+
response_time_expectation: tpl.response_time_expectation,
|
|
75
|
+
require_arbitration: tpl.require_arbitration,
|
|
76
|
+
require_compensation_fund: tpl.require_compensation_fund,
|
|
77
|
+
risk_appetite: tpl.risk_appetite,
|
|
78
|
+
delivery_speed_priority: tpl.delivery_speed_priority,
|
|
79
|
+
after_sales_expectation: tpl.after_sales_expectation,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
export function getIndustryTemplate(industry) {
|
|
83
|
+
return { ...INDUSTRY_TEMPLATES[industry] };
|
|
84
|
+
}
|
|
85
|
+
export function inferPreferences(history, basePrefs) {
|
|
86
|
+
const prefs = { ...(basePrefs ?? getDefaultPreferences()) };
|
|
87
|
+
const confidence = {};
|
|
88
|
+
const signals = [];
|
|
89
|
+
if (history.length < 3) {
|
|
90
|
+
signals.push(`history=${history.length} < 3,沿用默认偏好`);
|
|
91
|
+
return { preferences: prefs, confidence, signals };
|
|
92
|
+
}
|
|
93
|
+
const lowPricePicks = history.filter((h) => h.avg_market_price > 0n && h.price < (h.avg_market_price * 90n) / 100n);
|
|
94
|
+
if (lowPricePicks.length >= 3) {
|
|
95
|
+
prefs.price_sensitivity = "high";
|
|
96
|
+
prefs.value_orientation = "budget";
|
|
97
|
+
confidence.price_sensitivity = 0.8;
|
|
98
|
+
confidence.value_orientation = 0.7;
|
|
99
|
+
signals.push(`连续 ${lowPricePicks.length} 次选择低于均价 10%+ 的 Service → price_sensitivity=high`);
|
|
100
|
+
}
|
|
101
|
+
else if (lowPricePicks.length >= 1) {
|
|
102
|
+
prefs.price_sensitivity = "medium";
|
|
103
|
+
confidence.price_sensitivity = 0.5;
|
|
104
|
+
signals.push(`${lowPricePicks.length} 次低价选择 → price_sensitivity=medium`);
|
|
105
|
+
}
|
|
106
|
+
const discountUsers = history.filter((h) => h.used_discount);
|
|
107
|
+
if (discountUsers.length >= 2) {
|
|
108
|
+
prefs.discount_sensitivity = 0.8;
|
|
109
|
+
confidence.discount_sensitivity = 0.85;
|
|
110
|
+
signals.push(`使用折扣 ${discountUsers.length} 次 → discount_sensitivity=0.8`);
|
|
111
|
+
}
|
|
112
|
+
if (history.some((h) => h.used_referral)) {
|
|
113
|
+
prefs.referral_participation = true;
|
|
114
|
+
confidence.referral_participation = 1.0;
|
|
115
|
+
signals.push("使用过推荐码 → referral_participation=true");
|
|
116
|
+
}
|
|
117
|
+
if (discountUsers.length >= 2 || history.some((h) => h.used_referral)) {
|
|
118
|
+
prefs.reward_seeking = true;
|
|
119
|
+
confidence.reward_seeking = 0.75;
|
|
120
|
+
signals.push("Reward 行为检测到 → reward_seeking=true");
|
|
121
|
+
}
|
|
122
|
+
const bargainSignals = discountUsers.length + (history.some((h) => h.used_referral) ? 1 : 0);
|
|
123
|
+
if (bargainSignals >= 3) {
|
|
124
|
+
prefs.bargain_hunting = 0.8;
|
|
125
|
+
confidence.bargain_hunting = 0.8;
|
|
126
|
+
}
|
|
127
|
+
else if (bargainSignals >= 1) {
|
|
128
|
+
prefs.bargain_hunting = 0.5;
|
|
129
|
+
confidence.bargain_hunting = 0.6;
|
|
130
|
+
}
|
|
131
|
+
const industryCounts = new Map();
|
|
132
|
+
for (const h of history) {
|
|
133
|
+
if (h.industry) {
|
|
134
|
+
industryCounts.set(h.industry, (industryCounts.get(h.industry) ?? 0) + 1);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const preferredIndustries = Array.from(industryCounts.entries())
|
|
138
|
+
.filter(([, c]) => c >= 1)
|
|
139
|
+
.sort((a, b) => b[1] - a[1])
|
|
140
|
+
.slice(0, 3)
|
|
141
|
+
.map(([ind]) => ind);
|
|
142
|
+
if (preferredIndustries.length > 0) {
|
|
143
|
+
prefs.preferred_industries = preferredIndustries;
|
|
144
|
+
confidence.preferred_industries = Math.min(1, (industryCounts.get(preferredIndustries[0]) ?? 0) / 5);
|
|
145
|
+
signals.push(`偏好行业:${preferredIndustries.join(", ")}`);
|
|
146
|
+
}
|
|
147
|
+
const arbPicks = history.filter((h) => h.has_arbitration);
|
|
148
|
+
if (arbPicks.length >= 3 && arbPicks.length === history.length) {
|
|
149
|
+
prefs.require_arbitration = true;
|
|
150
|
+
confidence.require_arbitration = 0.85;
|
|
151
|
+
signals.push("100% 历史订单选择有仲裁的 Service → require_arbitration=true (confirmed)");
|
|
152
|
+
}
|
|
153
|
+
else if (arbPicks.length < history.length / 2) {
|
|
154
|
+
prefs.require_arbitration = false;
|
|
155
|
+
confidence.require_arbitration = 0.5;
|
|
156
|
+
signals.push(`${arbPicks.length}/${history.length} 订单有仲裁 → require_arbitration=false`);
|
|
157
|
+
}
|
|
158
|
+
const compPicks = history.filter((h) => h.has_compensation);
|
|
159
|
+
if (compPicks.length >= 3 && compPicks.length === history.length) {
|
|
160
|
+
prefs.require_compensation_fund = true;
|
|
161
|
+
confidence.require_compensation_fund = 0.85;
|
|
162
|
+
signals.push("100% 历史订单有赔偿金 → require_compensation_fund=true (confirmed)");
|
|
163
|
+
}
|
|
164
|
+
else if (compPicks.length < history.length / 2) {
|
|
165
|
+
prefs.require_compensation_fund = false;
|
|
166
|
+
confidence.require_compensation_fund = 0.5;
|
|
167
|
+
}
|
|
168
|
+
const riskScores = history
|
|
169
|
+
.map((h) => h.risk_score_at_purchase)
|
|
170
|
+
.filter((s) => typeof s === "number");
|
|
171
|
+
if (riskScores.length >= 5) {
|
|
172
|
+
const minRisk = Math.min(...riskScores);
|
|
173
|
+
if (minRisk >= 70) {
|
|
174
|
+
prefs.risk_appetite = "conservative";
|
|
175
|
+
prefs.min_trust_score = 70;
|
|
176
|
+
confidence.risk_appetite = 0.8;
|
|
177
|
+
confidence.min_trust_score = 0.7;
|
|
178
|
+
signals.push(`历史订单最低风险分 ${minRisk} ≥ 70 → risk_appetite=conservative`);
|
|
179
|
+
}
|
|
180
|
+
else if (minRisk < 50) {
|
|
181
|
+
prefs.risk_appetite = "aggressive";
|
|
182
|
+
prefs.min_trust_score = Math.max(0, minRisk - 10);
|
|
183
|
+
confidence.risk_appetite = 0.7;
|
|
184
|
+
signals.push(`历史订单最低风险分 ${minRisk} < 50 → risk_appetite=aggressive`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const messengerUsers = history.filter((h) => h.used_messenger);
|
|
188
|
+
if (messengerUsers.length >= 2) {
|
|
189
|
+
const avgMsgs = messengerUsers.reduce((s, h) => s + (h.messenger_messages ?? 0), 0) / messengerUsers.length;
|
|
190
|
+
if (avgMsgs >= 10) {
|
|
191
|
+
prefs.communication_style = "formal";
|
|
192
|
+
confidence.communication_style = 0.6;
|
|
193
|
+
signals.push(`平均 ${avgMsgs.toFixed(1)} 条 Messenger 消息 → communication_style=formal`);
|
|
194
|
+
}
|
|
195
|
+
else if (avgMsgs <= 3) {
|
|
196
|
+
prefs.communication_style = "casual";
|
|
197
|
+
confidence.communication_style = 0.5;
|
|
198
|
+
signals.push(`平均 ${avgMsgs.toFixed(1)} 条 Messenger 消息 → communication_style=casual`);
|
|
199
|
+
}
|
|
200
|
+
prefs.transparency_demand = Math.min(1, avgMsgs / 20);
|
|
201
|
+
confidence.transparency_demand = 0.6;
|
|
202
|
+
}
|
|
203
|
+
const disputedCount = history.filter((h) => h.has_dispute).length;
|
|
204
|
+
if (disputedCount > 0) {
|
|
205
|
+
prefs.transparency_demand = Math.max(prefs.transparency_demand, 0.7);
|
|
206
|
+
prefs.after_sales_expectation = "full";
|
|
207
|
+
confidence.transparency_demand = Math.max(confidence.transparency_demand ?? 0, 0.7);
|
|
208
|
+
confidence.after_sales_expectation = 0.7;
|
|
209
|
+
signals.push(`${disputedCount} 次争议 → transparency_demand 提升,after_sales=full`);
|
|
210
|
+
}
|
|
211
|
+
const merchantCounts = new Map();
|
|
212
|
+
for (const h of history) {
|
|
213
|
+
if (h.service_owner) {
|
|
214
|
+
merchantCounts.set(h.service_owner, (merchantCounts.get(h.service_owner) ?? 0) + 1);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
prefs.preferred_merchants = Array.from(merchantCounts.entries())
|
|
218
|
+
.filter(([, c]) => c >= 2)
|
|
219
|
+
.sort((a, b) => b[1] - a[1])
|
|
220
|
+
.slice(0, 5)
|
|
221
|
+
.map(([m]) => m);
|
|
222
|
+
if (prefs.preferred_merchants.length > 0) {
|
|
223
|
+
confidence.preferred_merchants = 0.8;
|
|
224
|
+
signals.push(`惠顾 ${prefs.preferred_merchants.length} 个商家 ≥2 次`);
|
|
225
|
+
}
|
|
226
|
+
return { preferences: prefs, confidence, signals };
|
|
227
|
+
}
|
|
228
|
+
export function matchServiceToPreferences(service, prefs) {
|
|
229
|
+
const matches = [];
|
|
230
|
+
const mismatches = [];
|
|
231
|
+
const warnings = [];
|
|
232
|
+
let score = 0;
|
|
233
|
+
let maxScore = 0;
|
|
234
|
+
maxScore += 25;
|
|
235
|
+
if (prefs.budget_range) {
|
|
236
|
+
if (service.price >= prefs.budget_range.min && service.price <= prefs.budget_range.max) {
|
|
237
|
+
score += 20;
|
|
238
|
+
matches.push("价格在预算区间内");
|
|
239
|
+
}
|
|
240
|
+
else if (service.price < prefs.budget_range.min) {
|
|
241
|
+
score += 15;
|
|
242
|
+
matches.push("价格低于预算下限");
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
mismatches.push("价格超出预算上限");
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
else if (service.avg_market_price && service.avg_market_price > 0n) {
|
|
249
|
+
const ratio = Number((service.price * 100n) / service.avg_market_price) / 100;
|
|
250
|
+
if (prefs.price_sensitivity === "high") {
|
|
251
|
+
if (ratio <= 0.9) {
|
|
252
|
+
score += 25;
|
|
253
|
+
matches.push(`价格低于均价 ${(1 - ratio) * 100 | 0}%(高敏感度用户加分)`);
|
|
254
|
+
}
|
|
255
|
+
else if (ratio <= 1.1) {
|
|
256
|
+
score += 15;
|
|
257
|
+
matches.push("价格与均价持平");
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
mismatches.push(`价格高于均价 ${((ratio - 1) * 100 | 0)}%(高敏感度用户)`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
else if (prefs.price_sensitivity === "low") {
|
|
264
|
+
score += 20;
|
|
265
|
+
matches.push("低价格敏感度");
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
if (ratio <= 1.0) {
|
|
269
|
+
score += 20;
|
|
270
|
+
matches.push("价格不高于均价");
|
|
271
|
+
}
|
|
272
|
+
else if (ratio <= 1.2) {
|
|
273
|
+
score += 12;
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
mismatches.push("价格显著高于均价");
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
score += 12;
|
|
282
|
+
}
|
|
283
|
+
maxScore += 15;
|
|
284
|
+
const cycle = service.estimated_cycle_days ?? 0;
|
|
285
|
+
if (cycle > 0) {
|
|
286
|
+
if (cycle <= prefs.max_acceptable_cycle) {
|
|
287
|
+
score += 10;
|
|
288
|
+
matches.push(`交付周期 ${cycle}天 ≤ 期望 ${prefs.max_acceptable_cycle}天`);
|
|
289
|
+
if (prefs.delivery_speed_priority === "urgent" && cycle <= Math.max(1, prefs.max_acceptable_cycle / 3)) {
|
|
290
|
+
score += 5;
|
|
291
|
+
matches.push("紧急交付需求得到满足");
|
|
292
|
+
}
|
|
293
|
+
else if (prefs.delivery_speed_priority === "urgent") {
|
|
294
|
+
warnings.push("紧急交付需求但周期较长");
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
mismatches.push(`交付周期 ${cycle}天 > 期望 ${prefs.max_acceptable_cycle}天`);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
score += 7;
|
|
303
|
+
}
|
|
304
|
+
maxScore += 10;
|
|
305
|
+
if (prefs.preferred_region) {
|
|
306
|
+
if (service.merchant_region && service.merchant_region === prefs.preferred_region) {
|
|
307
|
+
score += 10;
|
|
308
|
+
matches.push(`商家地域 ${service.merchant_region} 与偏好一致`);
|
|
309
|
+
}
|
|
310
|
+
else if (service.merchant_region) {
|
|
311
|
+
mismatches.push(`商家地域 ${service.merchant_region} 与偏好 ${prefs.preferred_region} 不符`);
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
score += 5;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
score += 7;
|
|
319
|
+
}
|
|
320
|
+
maxScore += 10;
|
|
321
|
+
if (service.merchant_order_history_count >= prefs.min_order_history) {
|
|
322
|
+
score += 7;
|
|
323
|
+
matches.push(`商家历史 ${service.merchant_order_history_count} 单 ≥ 要求 ${prefs.min_order_history} 单`);
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
mismatches.push(`商家历史 ${service.merchant_order_history_count} 单 < 要求 ${prefs.min_order_history} 单`);
|
|
327
|
+
}
|
|
328
|
+
if (prefs.merchant_preference !== "neutral") {
|
|
329
|
+
if (service.merchant_age === prefs.merchant_preference) {
|
|
330
|
+
score += 3;
|
|
331
|
+
matches.push(`商家类型 ${service.merchant_age} 符合偏好`);
|
|
332
|
+
}
|
|
333
|
+
else if (service.merchant_age !== "unknown") {
|
|
334
|
+
mismatches.push(`商家类型 ${service.merchant_age} ≠ 偏好 ${prefs.merchant_preference}`);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
score += 3;
|
|
339
|
+
}
|
|
340
|
+
maxScore += 15;
|
|
341
|
+
let bargainScore = 0;
|
|
342
|
+
if (service.has_reward_activity) {
|
|
343
|
+
bargainScore += 8;
|
|
344
|
+
matches.push("有 Reward 活动");
|
|
345
|
+
}
|
|
346
|
+
if (service.has_discount) {
|
|
347
|
+
bargainScore += 7;
|
|
348
|
+
matches.push("有折扣");
|
|
349
|
+
}
|
|
350
|
+
if (prefs.bargain_hunting >= 0.7 && bargainScore === 0) {
|
|
351
|
+
mismatches.push("用户高 bargain_hunting 但无 Reward/折扣");
|
|
352
|
+
}
|
|
353
|
+
else if (prefs.bargain_hunting < 0.3) {
|
|
354
|
+
if (bargainScore === 0)
|
|
355
|
+
bargainScore = 10;
|
|
356
|
+
else
|
|
357
|
+
bargainScore = Math.min(bargainScore, 5);
|
|
358
|
+
}
|
|
359
|
+
else if (prefs.bargain_hunting < 0.7 && bargainScore === 0) {
|
|
360
|
+
bargainScore = 5;
|
|
361
|
+
}
|
|
362
|
+
score += bargainScore;
|
|
363
|
+
maxScore += 10;
|
|
364
|
+
if (service.after_sales_support_level === prefs.after_sales_expectation) {
|
|
365
|
+
score += 5;
|
|
366
|
+
matches.push(`售后支持 ${service.after_sales_support_level} 符合期望`);
|
|
367
|
+
}
|
|
368
|
+
else if ((prefs.after_sales_expectation === "full" && service.after_sales_support_level === "basic") ||
|
|
369
|
+
(prefs.after_sales_expectation === "full" && service.after_sales_support_level === "minimal") ||
|
|
370
|
+
(prefs.after_sales_expectation === "basic" && service.after_sales_support_level === "minimal")) {
|
|
371
|
+
mismatches.push(`售后支持 ${service.after_sales_support_level} < 期望 ${prefs.after_sales_expectation}`);
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
score += 3;
|
|
375
|
+
}
|
|
376
|
+
if (prefs.transparency_demand >= 0.7 && service.requires_messenger) {
|
|
377
|
+
score += 5;
|
|
378
|
+
matches.push("商家支持 Messenger 沟通(高透明度需求)");
|
|
379
|
+
}
|
|
380
|
+
else if (prefs.transparency_demand >= 0.7 && !service.requires_messenger) {
|
|
381
|
+
mismatches.push("高透明度需求但商家无 Messenger");
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
score += 3;
|
|
385
|
+
}
|
|
386
|
+
maxScore += 15;
|
|
387
|
+
if (service.risk_score >= prefs.min_trust_score) {
|
|
388
|
+
score += 8;
|
|
389
|
+
matches.push(`风险分 ${service.risk_score} ≥ 要求 ${prefs.min_trust_score}`);
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
mismatches.push(`风险分 ${service.risk_score} < 要求 ${prefs.min_trust_score}`);
|
|
393
|
+
}
|
|
394
|
+
if (prefs.require_arbitration) {
|
|
395
|
+
if (service.has_arbitration) {
|
|
396
|
+
score += 4;
|
|
397
|
+
matches.push("配置了仲裁");
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
mismatches.push("用户要求仲裁但 Service 未配置");
|
|
401
|
+
warnings.push("⚠️ 无仲裁:用户偏好要求必备仲裁");
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
score += 4;
|
|
406
|
+
}
|
|
407
|
+
if (prefs.require_compensation_fund) {
|
|
408
|
+
if (service.has_compensation_fund) {
|
|
409
|
+
score += 3;
|
|
410
|
+
matches.push("有赔偿金");
|
|
411
|
+
}
|
|
412
|
+
else {
|
|
413
|
+
mismatches.push("用户要求赔偿金但 Service 无");
|
|
414
|
+
warnings.push("⚠️ 无赔偿金:用户偏好要求必备");
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
score += 3;
|
|
419
|
+
}
|
|
420
|
+
const normalized = maxScore > 0 ? Math.round((score / maxScore) * 100) : 0;
|
|
421
|
+
return { score: normalized, matches, mismatches, warnings };
|
|
422
|
+
}
|
|
423
|
+
export function mergePreferences(inferred, manual) {
|
|
424
|
+
return { ...inferred, ...manual };
|
|
425
|
+
}
|
|
426
|
+
export function validatePreferences(prefs) {
|
|
427
|
+
const issues = [];
|
|
428
|
+
if (prefs.budget_range && prefs.budget_range.min > prefs.budget_range.max) {
|
|
429
|
+
issues.push("budget_range.min > budget_range.max");
|
|
430
|
+
}
|
|
431
|
+
if (prefs.discount_sensitivity < 0 || prefs.discount_sensitivity > 1) {
|
|
432
|
+
issues.push("discount_sensitivity must be in [0,1]");
|
|
433
|
+
}
|
|
434
|
+
if (prefs.bargain_hunting < 0 || prefs.bargain_hunting > 1) {
|
|
435
|
+
issues.push("bargain_hunting must be in [0,1]");
|
|
436
|
+
}
|
|
437
|
+
if (prefs.transparency_demand < 0 || prefs.transparency_demand > 1) {
|
|
438
|
+
issues.push("transparency_demand must be in [0,1]");
|
|
439
|
+
}
|
|
440
|
+
if (prefs.min_trust_score < 0 || prefs.min_trust_score > 100) {
|
|
441
|
+
issues.push("min_trust_score must be in [0,100]");
|
|
442
|
+
}
|
|
443
|
+
if (prefs.max_acceptable_cycle < 0) {
|
|
444
|
+
issues.push("max_acceptable_cycle must be ≥ 0");
|
|
445
|
+
}
|
|
446
|
+
if (prefs.response_time_expectation < 0) {
|
|
447
|
+
issues.push("response_time_expectation must be ≥ 0");
|
|
448
|
+
}
|
|
449
|
+
return issues;
|
|
450
|
+
}
|
|
451
|
+
export { CUSTOMER_INTELLIGENCE_VERSION };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { UserIntentSignature, ExperienceMatch } from "./types.js";
|
|
2
|
+
export declare function recordSignature(sig: UserIntentSignature): void;
|
|
3
|
+
export declare function findMatches(intent: string, operation_type: string, data: any, limit?: number): ExperienceMatch[];
|
|
4
|
+
export declare function getHistory(intent?: string): UserIntentSignature[];
|
|
5
|
+
export declare function clearHistory(): void;
|
|
6
|
+
export declare function getHistoryStats(): {
|
|
7
|
+
total: number;
|
|
8
|
+
by_outcome: Record<string, number>;
|
|
9
|
+
by_intent: Record<string, number>;
|
|
10
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { extractSignals } from "./intent-distill.js";
|
|
2
|
+
const MAX_HISTORY = 200;
|
|
3
|
+
const history = [];
|
|
4
|
+
export function recordSignature(sig) {
|
|
5
|
+
try {
|
|
6
|
+
history.push(sig);
|
|
7
|
+
if (history.length > MAX_HISTORY) {
|
|
8
|
+
history.shift();
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function findMatches(intent, operation_type, data, limit = 3) {
|
|
15
|
+
try {
|
|
16
|
+
const currentSignals = extractSignals(operation_type, data);
|
|
17
|
+
const now = Date.now();
|
|
18
|
+
const scored = history
|
|
19
|
+
.map((sig) => {
|
|
20
|
+
const relevance = computeRelevance(sig, intent, currentSignals, now);
|
|
21
|
+
return { signature: sig, relevance };
|
|
22
|
+
})
|
|
23
|
+
.filter((s) => s.relevance > 0.3)
|
|
24
|
+
.sort((a, b) => b.relevance - a.relevance)
|
|
25
|
+
.slice(0, limit);
|
|
26
|
+
return scored.map((s) => formatMatch(s.signature, s.relevance));
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function computeRelevance(sig, currentIntent, currentSignals, now) {
|
|
33
|
+
let score = 0;
|
|
34
|
+
if (sig.intent === currentIntent) {
|
|
35
|
+
score += 0.5;
|
|
36
|
+
}
|
|
37
|
+
else if (sig.intent.startsWith(currentIntent.split("_")[0])) {
|
|
38
|
+
score += 0.2;
|
|
39
|
+
}
|
|
40
|
+
const sigKeys = Object.keys(sig.signals);
|
|
41
|
+
if (sigKeys.length > 0) {
|
|
42
|
+
const overlap = sigKeys.filter((k) => {
|
|
43
|
+
const sigVal = JSON.stringify(sig.signals[k]);
|
|
44
|
+
const curVal = JSON.stringify(currentSignals[k]);
|
|
45
|
+
return sigVal === curVal;
|
|
46
|
+
}).length;
|
|
47
|
+
score += (overlap / sigKeys.length) * 0.3;
|
|
48
|
+
}
|
|
49
|
+
const ageDays = (now - sig.timestamp) / (1000 * 60 * 60 * 24);
|
|
50
|
+
const decay = Math.exp(-ageDays / 30);
|
|
51
|
+
score *= decay;
|
|
52
|
+
return Math.min(1, score);
|
|
53
|
+
}
|
|
54
|
+
function formatMatch(sig, relevance) {
|
|
55
|
+
const advice = buildAdvice(sig);
|
|
56
|
+
const avoid = buildAvoid(sig);
|
|
57
|
+
return {
|
|
58
|
+
signature: sig,
|
|
59
|
+
relevance,
|
|
60
|
+
advice,
|
|
61
|
+
avoid,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function buildAdvice(sig) {
|
|
65
|
+
if (sig.outcome === "success") {
|
|
66
|
+
if (sig.recovery_path && sig.recovery_path.length > 0) {
|
|
67
|
+
return `Last ${sig.intent} succeeded (after ${sig.recovery_path.length} recovery steps), you can follow the same path.`;
|
|
68
|
+
}
|
|
69
|
+
return `Last ${sig.intent} succeeded, parameter configuration is valid.`;
|
|
70
|
+
}
|
|
71
|
+
if (sig.outcome === "failed" && sig.error_code) {
|
|
72
|
+
return `Last ${sig.intent} failed (${sig.error_code}), please check the relevant parameters.`;
|
|
73
|
+
}
|
|
74
|
+
return `Last ${sig.intent} partially succeeded, check result completeness.`;
|
|
75
|
+
}
|
|
76
|
+
function buildAvoid(sig) {
|
|
77
|
+
const avoid = [];
|
|
78
|
+
if (sig.outcome !== "success" && sig.error_code) {
|
|
79
|
+
avoid.push(`Avoid triggering ${sig.error_code} error`);
|
|
80
|
+
}
|
|
81
|
+
if (sig.recovery_path && sig.recovery_path.length > 0) {
|
|
82
|
+
avoid.push(`Note: last time required ${sig.recovery_path.length} recovery steps to succeed`);
|
|
83
|
+
}
|
|
84
|
+
return avoid;
|
|
85
|
+
}
|
|
86
|
+
export function getHistory(intent) {
|
|
87
|
+
if (intent) {
|
|
88
|
+
return history.filter((h) => h.intent === intent);
|
|
89
|
+
}
|
|
90
|
+
return [...history];
|
|
91
|
+
}
|
|
92
|
+
export function clearHistory() {
|
|
93
|
+
history.length = 0;
|
|
94
|
+
}
|
|
95
|
+
export function getHistoryStats() {
|
|
96
|
+
const byOutcome = {};
|
|
97
|
+
const byIntent = {};
|
|
98
|
+
for (const h of history) {
|
|
99
|
+
byOutcome[h.outcome] = (byOutcome[h.outcome] ?? 0) + 1;
|
|
100
|
+
byIntent[h.intent] = (byIntent[h.intent] ?? 0) + 1;
|
|
101
|
+
}
|
|
102
|
+
return { total: history.length, by_outcome: byOutcome, by_intent: byIntent };
|
|
103
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { distillIntent, extractSignals } from "./intent-distill.js";
|
|
2
|
+
import { getProfile, updateFromOperation, resetProfile, getProfileStats } from "./user-profile.js";
|
|
3
|
+
import { findMatches, recordSignature, getHistory, clearHistory, getHistoryStats } from "./experience-reuse.js";
|
|
4
|
+
import { getExperienceFeedback, recordOperationOutcome, EXPERIENCE_LAYER_VERSION } from "./realtime-feedback.js";
|
|
5
|
+
import type { DistilledIntent, ExperienceMatch, ExperienceFeedback, UserProfile, UserIntentSignature } from "./types.js";
|
|
6
|
+
export { distillIntent, extractSignals, getProfile, updateFromOperation, resetProfile, getProfileStats, findMatches, recordSignature, getHistory, clearHistory, getHistoryStats, getExperienceFeedback, recordOperationOutcome, EXPERIENCE_LAYER_VERSION, type DistilledIntent, type ExperienceMatch, type ExperienceFeedback, type UserProfile, type UserIntentSignature, };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { distillIntent, extractSignals, } from "./intent-distill.js";
|
|
2
|
+
import { getProfile, updateFromOperation, resetProfile, getProfileStats, } from "./user-profile.js";
|
|
3
|
+
import { findMatches, recordSignature, getHistory, clearHistory, getHistoryStats, } from "./experience-reuse.js";
|
|
4
|
+
import { getExperienceFeedback, recordOperationOutcome, EXPERIENCE_LAYER_VERSION, } from "./realtime-feedback.js";
|
|
5
|
+
export { distillIntent, extractSignals, getProfile, updateFromOperation, resetProfile, getProfileStats, findMatches, recordSignature, getHistory, clearHistory, getHistoryStats, getExperienceFeedback, recordOperationOutcome, EXPERIENCE_LAYER_VERSION, };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const URGENCY_RULES = [
|
|
2
|
+
{ operation_type: "payment", urgency: "critical" },
|
|
3
|
+
{ operation_type: "service", signals: (d) => d?.publish === true, urgency: "critical" },
|
|
4
|
+
{ operation_type: "arbitration", signals: (d) => d?.arb === true || d?.arb_operation === "raise", urgency: "critical" },
|
|
5
|
+
{ operation_type: "reward", urgency: "high" },
|
|
6
|
+
{ operation_type: "allocation", urgency: "high" },
|
|
7
|
+
{ operation_type: "treasury", urgency: "high" },
|
|
8
|
+
{ operation_type: "order", urgency: "high" },
|
|
9
|
+
{ operation_type: "service", urgency: "normal" },
|
|
10
|
+
{ operation_type: "machine", urgency: "normal" },
|
|
11
|
+
{ operation_type: "guard", urgency: "normal" },
|
|
12
|
+
{ operation_type: "permission", urgency: "normal" },
|
|
13
|
+
{ operation_type: "progress", urgency: "normal" },
|
|
14
|
+
{ operation_type: "repository", urgency: "normal" },
|
|
15
|
+
{ operation_type: "personal", urgency: "normal" },
|
|
16
|
+
{ operation_type: "contact", urgency: "normal" },
|
|
17
|
+
{ operation_type: "demand", urgency: "normal" },
|
|
18
|
+
{ operation_type: "query_toolkit", urgency: "low" },
|
|
19
|
+
{ operation_type: "onchain_events", urgency: "low" },
|
|
20
|
+
{ operation_type: "onchain_table_data", urgency: "low" },
|
|
21
|
+
{ operation_type: "account_balance", urgency: "low" },
|
|
22
|
+
{ operation_type: "mark_query", urgency: "low" },
|
|
23
|
+
{ operation_type: "local_info", urgency: "low" },
|
|
24
|
+
];
|
|
25
|
+
const SCENARIO_RULES = [
|
|
26
|
+
{ signals: (d) => typeof d?.description === "string" && /freelance|自由职业|设计|开发|外包/i.test(d.description), scenario: "freelance" },
|
|
27
|
+
{ signals: (d) => typeof d?.description === "string" && /rental|租赁|出租/i.test(d.description), scenario: "rental" },
|
|
28
|
+
{ signals: (d) => typeof d?.description === "string" && /course|课程|教育|培训/i.test(d.description), scenario: "education" },
|
|
29
|
+
{ signals: (d) => typeof d?.description === "string" && /travel|旅游|旅行/i.test(d.description), scenario: "travel" },
|
|
30
|
+
{ signals: (d) => typeof d?.description === "string" && /subscri|订阅|会员/i.test(d.description), scenario: "subscription" },
|
|
31
|
+
{ signals: (d) => typeof d?.namedNew?.name === "string" && /shop|store|店|铺/i.test(d.namedNew.name), scenario: "retail" },
|
|
32
|
+
];
|
|
33
|
+
const SECONDARY_INTENT_RULES = [
|
|
34
|
+
{ signals: (d) => d?.publish === true, intent: "immutable_commit" },
|
|
35
|
+
{ signals: (d) => d?.amount?.amount !== undefined && BigInt(d.amount.amount) > 100000000000n, intent: "large_amount" },
|
|
36
|
+
{ signals: (d) => d?.replaceExistName === true, intent: "force_claim_name" },
|
|
37
|
+
{ signals: (d) => d?.arb !== undefined, intent: "dispute_resolution" },
|
|
38
|
+
{ signals: (d) => d?.onChain === true, intent: "public_identity" },
|
|
39
|
+
];
|
|
40
|
+
export function distillIntent(operation_type, data, baseIntent) {
|
|
41
|
+
const urgencyRules = URGENCY_RULES.filter((r) => r.operation_type === operation_type);
|
|
42
|
+
const signaled = urgencyRules.find((r) => r.signals && r.signals(data));
|
|
43
|
+
const urgency = (signaled ?? urgencyRules.find((r) => !r.signals))?.urgency ?? "normal";
|
|
44
|
+
const scenarioRule = SCENARIO_RULES.find((r) => r.signals(data));
|
|
45
|
+
const scenario = scenarioRule?.scenario;
|
|
46
|
+
const secondary_intents = SECONDARY_INTENT_RULES
|
|
47
|
+
.filter((r) => r.signals(data))
|
|
48
|
+
.map((r) => r.intent);
|
|
49
|
+
let confidence = 0.8;
|
|
50
|
+
if (scenario)
|
|
51
|
+
confidence = Math.min(1, confidence + 0.1);
|
|
52
|
+
if (secondary_intents.length > 0)
|
|
53
|
+
confidence = Math.min(1, confidence + 0.05);
|
|
54
|
+
if (baseIntent === operation_type)
|
|
55
|
+
confidence -= 0.15;
|
|
56
|
+
return {
|
|
57
|
+
primary_intent: baseIntent,
|
|
58
|
+
secondary_intents,
|
|
59
|
+
confidence: Math.max(0, confidence),
|
|
60
|
+
urgency,
|
|
61
|
+
scenario,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export function extractSignals(operation_type, data) {
|
|
65
|
+
const signals = {};
|
|
66
|
+
if (!data || typeof data !== "object")
|
|
67
|
+
return signals;
|
|
68
|
+
const keys = ["publish", "amount", "price", "arb", "service", "machine", "order", "reward", "guard", "permission", "replaceExistName", "onChain", "type_parameter"];
|
|
69
|
+
for (const k of keys) {
|
|
70
|
+
if (data[k] !== undefined) {
|
|
71
|
+
signals[k] = data[k];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (operation_type === "service") {
|
|
75
|
+
if (data.namedNew?.name)
|
|
76
|
+
signals.name = data.namedNew.name;
|
|
77
|
+
}
|
|
78
|
+
if (operation_type === "payment" || operation_type === "reward") {
|
|
79
|
+
if (data.amount?.amount)
|
|
80
|
+
signals.amount_value = data.amount.amount;
|
|
81
|
+
}
|
|
82
|
+
return signals;
|
|
83
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ExperienceFeedback } from "./types.js";
|
|
2
|
+
import { EXPERIENCE_LAYER_VERSION } from "./types.js";
|
|
3
|
+
export { EXPERIENCE_LAYER_VERSION };
|
|
4
|
+
export declare function getExperienceFeedback(operation_type: string, data: any, baseIntent: string): ExperienceFeedback | undefined;
|
|
5
|
+
export declare function recordOperationOutcome(operation_type: string, data: any, baseIntent: string, outcome: "success" | "failed" | "partial", errorCode?: string, referencedObjects?: string[]): void;
|