@wowok/agent-mcp 2.3.14 → 2.3.18
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/index.d.ts +9 -0
- package/dist/customer/index.js +9 -0
- package/dist/customer/industry-risks.d.ts +40 -0
- package/dist/customer/industry-risks.js +438 -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 +70 -0
- package/dist/customer/user-preferences.js +460 -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 +94 -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 +842 -371
- package/dist/knowledge/acquisition-flywheel.d.ts +53 -0
- package/dist/knowledge/acquisition-flywheel.js +192 -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/guard-ledger.d.ts +19 -0
- package/dist/knowledge/guard-ledger.js +219 -0
- package/dist/knowledge/guard-puzzle.d.ts +93 -0
- package/dist/knowledge/guard-puzzle.js +278 -0
- package/dist/knowledge/guard-risk.d.ts +60 -0
- package/dist/knowledge/guard-risk.js +474 -0
- package/dist/knowledge/guard-translation.d.ts +46 -0
- package/dist/knowledge/guard-translation.js +487 -0
- package/dist/knowledge/index.d.ts +77 -0
- package/dist/knowledge/index.js +79 -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 +48 -0
- package/dist/knowledge/industry-registry.js +187 -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 +232 -0
- package/dist/knowledge/tool-constraints.d.ts +30 -0
- package/dist/knowledge/tool-constraints.js +175 -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 +17 -0
- package/dist/safety/confirm-gate.js +88 -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 +39 -14
- package/dist/schema/call/arbitration.d.ts +187 -162
- package/dist/schema/call/base.d.ts +1971 -87
- package/dist/schema/call/base.js +135 -3
- package/dist/schema/call/bridge-handler.js +15 -2
- package/dist/schema/call/bridge.d.ts +1478 -53
- package/dist/schema/call/bridge.js +50 -2
- package/dist/schema/call/contact.d.ts +25 -0
- package/dist/schema/call/demand.d.ts +79 -54
- package/dist/schema/call/guard.d.ts +125 -50
- package/dist/schema/call/handler.d.ts +3 -0
- package/dist/schema/call/handler.js +60 -14
- package/dist/schema/call/machine.d.ts +988 -938
- package/dist/schema/call/order.d.ts +25 -0
- package/dist/schema/call/payment.d.ts +25 -0
- package/dist/schema/call/permission.d.ts +244 -219
- package/dist/schema/call/personal.d.ts +25 -0
- package/dist/schema/call/progress.d.ts +25 -0
- package/dist/schema/call/proof.d.ts +62 -12
- package/dist/schema/call/proof.js +3 -3
- package/dist/schema/call/repository.d.ts +101 -76
- package/dist/schema/call/reward.d.ts +55 -30
- package/dist/schema/call/semantic.d.ts +10 -2
- package/dist/schema/call/semantic.js +616 -11
- package/dist/schema/call/service.d.ts +442 -417
- package/dist/schema/call/treasury.d.ts +25 -0
- package/dist/schema/common/index.js +3 -3
- package/dist/schema/config/index.d.ts +18 -0
- package/dist/schema/config/index.js +17 -0
- package/dist/schema/index.d.ts +6 -0
- package/dist/schema/index.js +5 -0
- package/dist/schema/local/index.d.ts +237 -81
- package/dist/schema/local/index.js +42 -6
- package/dist/schema/messenger/index.d.ts +1018 -79
- package/dist/schema/messenger/index.js +26 -17
- package/dist/schema/operations.d.ts +3192 -1746
- package/dist/schema/operations.js +93 -98
- package/dist/schema/project/index.d.ts +21 -0
- package/dist/schema/project/index.js +32 -0
- package/dist/schema/query/index.d.ts +2762 -1856
- package/dist/schema/query/index.js +38 -35
- package/dist/schema/schema-query/index.d.ts +33 -0
- package/dist/schema/schema-query/index.js +36 -0
- package/dist/schema/schema-version.d.ts +25 -0
- package/dist/schema/schema-version.js +76 -0
- package/dist/schema/trust/index.d.ts +407 -0
- package/dist/schema/trust/index.js +113 -0
- 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 +744 -0
- package/dist/schemas/bridge_operation.schema.json +82 -8
- package/dist/schemas/config_operation.output.json +18 -0
- package/dist/schemas/config_operation.schema.json +34 -0
- package/dist/schemas/guard-node-schema.json +82 -0
- package/dist/schemas/guard2file.schema.json +23 -0
- package/dist/schemas/index.json +19 -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 +23 -0
- package/dist/schemas/messenger_operation.output.json +752 -0
- package/dist/schemas/onchain_events.output.json +718 -0
- package/dist/schemas/onchain_operations.output.json +627 -18
- package/dist/schemas/onchain_operations.schema.json +115 -39
- package/dist/schemas/onchain_operations_allocation.schema.json +23 -0
- package/dist/schemas/onchain_operations_arbitration.schema.json +23 -0
- package/dist/schemas/onchain_operations_contact.schema.json +23 -0
- package/dist/schemas/onchain_operations_demand.schema.json +23 -0
- package/dist/schemas/onchain_operations_gen_passport.schema.json +46 -0
- package/dist/schemas/onchain_operations_guard.schema.json +26 -16
- package/dist/schemas/onchain_operations_machine.schema.json +89 -23
- package/dist/schemas/onchain_operations_order.schema.json +23 -0
- package/dist/schemas/onchain_operations_payment.schema.json +23 -0
- package/dist/schemas/onchain_operations_permission.schema.json +23 -0
- package/dist/schemas/onchain_operations_personal.schema.json +23 -0
- package/dist/schemas/onchain_operations_progress.schema.json +23 -0
- package/dist/schemas/onchain_operations_repository.schema.json +23 -0
- package/dist/schemas/onchain_operations_reward.schema.json +23 -0
- package/dist/schemas/onchain_operations_service.schema.json +23 -0
- package/dist/schemas/onchain_operations_treasury.schema.json +23 -0
- package/dist/schemas/onchain_table_data.output.json +939 -69
- package/dist/schemas/onchain_table_data.schema.json +2 -2
- package/dist/schemas/project_operation.output.json +18 -0
- package/dist/schemas/project_operation.schema.json +42 -0
- package/dist/schemas/query_toolkit.schema.json +360 -368
- package/dist/schemas/schema_query.schema.json +6 -3
- package/dist/schemas/trust_score.output.json +327 -0
- package/dist/schemas/trust_score.schema.json +46 -0
- package/package.json +2 -2
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { CUSTOMER_INTELLIGENCE_VERSION } from "./types.js";
|
|
2
|
+
export function assembleServiceBasics(serviceId, raw, wipVerified = false) {
|
|
3
|
+
const activeSales = (raw.sales ?? []).filter((s) => !s.suspension);
|
|
4
|
+
const hasWip = activeSales.some((s) => s.wip_hash && s.wip_hash.length > 0);
|
|
5
|
+
return {
|
|
6
|
+
service_id: serviceId,
|
|
7
|
+
name: raw.name ?? serviceId,
|
|
8
|
+
bPublished: raw.bPublished ?? false,
|
|
9
|
+
bPaused: raw.bPaused ?? false,
|
|
10
|
+
price: raw.price ?? "0",
|
|
11
|
+
price_raw: raw.priceRaw ?? 0n,
|
|
12
|
+
token_type: raw.token_type ?? "0x2::wow::WOW",
|
|
13
|
+
sales_count: activeSales.length,
|
|
14
|
+
machine_id: raw.machine,
|
|
15
|
+
buy_guard_id: raw.buy_guard,
|
|
16
|
+
customer_required_count: raw.customer_required?.length ?? 0,
|
|
17
|
+
arbitrations_count: raw.arbitrations?.length ?? 0,
|
|
18
|
+
compensation_fund_balance: raw.compensation_fund?.balance ?? 0n,
|
|
19
|
+
compensation_lock_duration: raw.compensation_lock_duration ?? 0,
|
|
20
|
+
um_id: raw.um,
|
|
21
|
+
has_wip: hasWip,
|
|
22
|
+
wip_verified: wipVerified,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function assembleWorkflowAnalysis(nodes, isPublished, isPaused) {
|
|
26
|
+
const riskSignals = [];
|
|
27
|
+
const terminalNodes = [];
|
|
28
|
+
const deadEndNodes = [];
|
|
29
|
+
let userOperable = 0;
|
|
30
|
+
let providerOnly = 0;
|
|
31
|
+
let guardGated = 0;
|
|
32
|
+
let hasRefundPath = false;
|
|
33
|
+
let hasArbitrationPath = false;
|
|
34
|
+
let hasMilestone = false;
|
|
35
|
+
const totalForwards = nodes.reduce((sum, n) => sum + (n.forwards?.length ?? 0), 0);
|
|
36
|
+
for (const node of nodes) {
|
|
37
|
+
const outForwards = node.forwards ?? [];
|
|
38
|
+
if (outForwards.length === 0) {
|
|
39
|
+
terminalNodes.push(node.name);
|
|
40
|
+
}
|
|
41
|
+
for (const fwd of outForwards) {
|
|
42
|
+
const op = fwd.namedOperator;
|
|
43
|
+
const guard = fwd.guard;
|
|
44
|
+
if (op === "") {
|
|
45
|
+
if (guard) {
|
|
46
|
+
guardGated++;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
userOperable++;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else if (op === null || op === undefined) {
|
|
53
|
+
providerOnly++;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
providerOnly++;
|
|
57
|
+
}
|
|
58
|
+
const fwdName = (fwd.name ?? "").toLowerCase();
|
|
59
|
+
const target = (fwd.to ?? "").toLowerCase();
|
|
60
|
+
if (fwdName.includes("refund") || target.includes("refund")) {
|
|
61
|
+
hasRefundPath = true;
|
|
62
|
+
}
|
|
63
|
+
if (fwdName.includes("arb") || target.includes("arb")) {
|
|
64
|
+
hasArbitrationPath = true;
|
|
65
|
+
}
|
|
66
|
+
if (fwdName.includes("milestone") || target.includes("milestone")) {
|
|
67
|
+
hasMilestone = true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
for (const node of nodes) {
|
|
72
|
+
const outForwards = node.forwards ?? [];
|
|
73
|
+
if (outForwards.length > 0 && !terminalNodes.includes(node.name)) {
|
|
74
|
+
const allProviderOnly = outForwards.every((f) => f.namedOperator !== "" && f.namedOperator !== null);
|
|
75
|
+
if (allProviderOnly && userOperable === 0) {
|
|
76
|
+
deadEndNodes.push(node.name);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (!hasRefundPath)
|
|
81
|
+
riskSignals.push("no_refund_path");
|
|
82
|
+
if (!hasArbitrationPath)
|
|
83
|
+
riskSignals.push("no_arbitration_path");
|
|
84
|
+
if (userOperable === 0)
|
|
85
|
+
riskSignals.push("no_user_operable_path");
|
|
86
|
+
if (deadEndNodes.length > 0)
|
|
87
|
+
riskSignals.push("potential_dead_ends");
|
|
88
|
+
return {
|
|
89
|
+
machine_published: isPublished,
|
|
90
|
+
machine_paused: isPaused,
|
|
91
|
+
total_nodes: nodes.length,
|
|
92
|
+
total_forwards: totalForwards,
|
|
93
|
+
user_operable_forwards: userOperable,
|
|
94
|
+
provider_only_forwards: providerOnly,
|
|
95
|
+
guard_gated_forwards: guardGated,
|
|
96
|
+
has_refund_path: hasRefundPath,
|
|
97
|
+
has_arbitration_path: hasArbitrationPath,
|
|
98
|
+
has_milestone_nodes: hasMilestone,
|
|
99
|
+
dead_end_nodes: deadEndNodes,
|
|
100
|
+
terminal_nodes: terminalNodes,
|
|
101
|
+
risk_signals: riskSignals,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export function assembleFundSafety(raw, orderAmount) {
|
|
105
|
+
const allocators = raw.order_allocators?.[0]?.allocators ?? [];
|
|
106
|
+
const compBalance = raw.compensation_fund?.balance ?? 0n;
|
|
107
|
+
const lockDuration = raw.compensation_lock_duration ?? 0;
|
|
108
|
+
const refundAllocator = allocators.find((a) => {
|
|
109
|
+
const amt = a.amount;
|
|
110
|
+
return amt?.type === "FixedValue" && amt.value === orderAmount;
|
|
111
|
+
});
|
|
112
|
+
const hasRefundAllocator = allocators.some((a) => a.surplus_to === "order" || a.surplus_to === "Order");
|
|
113
|
+
let priceAnomaly = "none";
|
|
114
|
+
if (orderAmount > 0n) {
|
|
115
|
+
if (compBalance > 0n && orderAmount > compBalance * 3n) {
|
|
116
|
+
priceAnomaly = "low";
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const lockSafe = lockDuration === 0 || lockDuration > 7;
|
|
120
|
+
return {
|
|
121
|
+
has_order_allocator: allocators.length > 0,
|
|
122
|
+
has_refund_allocator: !!refundAllocator || hasRefundAllocator,
|
|
123
|
+
allocator_count: allocators.length,
|
|
124
|
+
refund_allocator_exists: hasRefundAllocator,
|
|
125
|
+
surplus_to_provider: allocators.some((a) => a.surplus_to !== "order" && a.surplus_to !== "Order"),
|
|
126
|
+
user_path_has_allocator: allocators.length > 0,
|
|
127
|
+
compensation_covers_order: compBalance >= orderAmount,
|
|
128
|
+
compensation_ratio: orderAmount > 0n
|
|
129
|
+
? Math.min(1, Number((compBalance * 100n) / orderAmount) / 100)
|
|
130
|
+
: 0,
|
|
131
|
+
lock_duration_safe: lockSafe,
|
|
132
|
+
price_anomaly: priceAnomaly,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
export function assembleTrustSignals(service, reviews, trustScore, arbitrationOwner, serviceOwner) {
|
|
136
|
+
const likes = reviews.filter((r) => r.rating === "like").length;
|
|
137
|
+
const dislikes = reviews.filter((r) => r.rating === "dislike").length;
|
|
138
|
+
const verified = reviews.filter((r) => r.verified || r.has_evidence).length;
|
|
139
|
+
const total = reviews.length;
|
|
140
|
+
const likeRate = total > 0 ? likes / total : 0;
|
|
141
|
+
const arbitrationIndependent = arbitrationOwner !== undefined && serviceOwner !== undefined
|
|
142
|
+
? arbitrationOwner !== serviceOwner
|
|
143
|
+
: true;
|
|
144
|
+
return {
|
|
145
|
+
arbitration_independent: arbitrationIndependent,
|
|
146
|
+
arbitration_count: service.arbitrations?.length ?? 0,
|
|
147
|
+
arbitration_paused: false,
|
|
148
|
+
review_likes: likes,
|
|
149
|
+
review_dislikes: dislikes,
|
|
150
|
+
review_verified_count: verified,
|
|
151
|
+
review_total: total,
|
|
152
|
+
like_rate: likeRate,
|
|
153
|
+
trust_score: trustScore.score,
|
|
154
|
+
trust_level: trustScore.level,
|
|
155
|
+
has_contact: !!service.um,
|
|
156
|
+
has_messenger: !!service.um,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
export function assembleMerchantBehavior(events, orderHistory) {
|
|
160
|
+
if (orderHistory && orderHistory.length > 0) {
|
|
161
|
+
const total = orderHistory.length;
|
|
162
|
+
const completed = orderHistory.filter((o) => o.status === "completed").length;
|
|
163
|
+
const disputed = orderHistory.filter((o) => o.has_dispute).length;
|
|
164
|
+
const repeated = orderHistory.filter((o) => o.is_repeat).length;
|
|
165
|
+
const completedRate = total > 0 ? completed / total : 0;
|
|
166
|
+
const disputeRate = total > 0 ? disputed / total : 0;
|
|
167
|
+
const repeatRate = total > 0 ? repeated / total : 0;
|
|
168
|
+
const half = Math.floor(total / 2);
|
|
169
|
+
let trend = "stable";
|
|
170
|
+
if (total >= 4 && half > 0) {
|
|
171
|
+
const firstHalfDisputes = orderHistory.slice(0, half).filter((o) => o.has_dispute).length;
|
|
172
|
+
const secondHalfDisputes = orderHistory.slice(half).filter((o) => o.has_dispute).length;
|
|
173
|
+
const firstRate = firstHalfDisputes / half;
|
|
174
|
+
const secondRate = secondHalfDisputes / (total - half);
|
|
175
|
+
if (secondRate < firstRate * 0.85)
|
|
176
|
+
trend = "improving";
|
|
177
|
+
else if (secondRate > firstRate * 1.15)
|
|
178
|
+
trend = "declining";
|
|
179
|
+
}
|
|
180
|
+
const redFlags = [];
|
|
181
|
+
if (disputeRate > 0.1)
|
|
182
|
+
redFlags.push("dispute_rate_high");
|
|
183
|
+
if (trend === "declining")
|
|
184
|
+
redFlags.push("declining_trend");
|
|
185
|
+
return {
|
|
186
|
+
total_orders: total,
|
|
187
|
+
completed_rate: completedRate,
|
|
188
|
+
dispute_rate: disputeRate,
|
|
189
|
+
refund_rate: 0,
|
|
190
|
+
arb_loss_rate: 0,
|
|
191
|
+
repeat_buyer_rate: repeatRate,
|
|
192
|
+
recent_trend: trend,
|
|
193
|
+
red_flags: redFlags,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
const orderEvents = events.filter((e) => e.type.includes("Order") || e.type.includes("order"));
|
|
197
|
+
const disputeEvents = events.filter((e) => e.type.includes("Dispute") || e.type.includes("Arb"));
|
|
198
|
+
const total = orderEvents.length;
|
|
199
|
+
const disputes = disputeEvents.length;
|
|
200
|
+
const disputeRate = total > 0 ? disputes / total : 0;
|
|
201
|
+
const redFlags = [];
|
|
202
|
+
if (disputeRate > 0.1)
|
|
203
|
+
redFlags.push("dispute_rate_high");
|
|
204
|
+
return {
|
|
205
|
+
total_orders: total,
|
|
206
|
+
completed_rate: total > 0 ? Math.max(0, 1 - disputeRate) : 0,
|
|
207
|
+
dispute_rate: disputeRate,
|
|
208
|
+
refund_rate: 0,
|
|
209
|
+
arb_loss_rate: 0,
|
|
210
|
+
repeat_buyer_rate: 0,
|
|
211
|
+
recent_trend: "stable",
|
|
212
|
+
red_flags: redFlags,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
export function assembleMarketContext(similarServices, currentPrice) {
|
|
216
|
+
if (similarServices.length === 0) {
|
|
217
|
+
return {
|
|
218
|
+
similar_services_count: 0,
|
|
219
|
+
avg_price: 0n,
|
|
220
|
+
min_price: 0n,
|
|
221
|
+
max_price: 0n,
|
|
222
|
+
price_percentile: 0,
|
|
223
|
+
supply_demand_ratio: 0,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
const prices = similarServices.map((s) => s.price).sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
227
|
+
const sum = prices.reduce((acc, p) => acc + p, 0n);
|
|
228
|
+
const avg = sum / BigInt(prices.length);
|
|
229
|
+
const min = prices[0];
|
|
230
|
+
const max = prices[prices.length - 1];
|
|
231
|
+
let below = 0;
|
|
232
|
+
for (const p of prices) {
|
|
233
|
+
if (p < currentPrice)
|
|
234
|
+
below++;
|
|
235
|
+
}
|
|
236
|
+
const percentile = prices.length > 0 ? below / prices.length : 0;
|
|
237
|
+
return {
|
|
238
|
+
similar_services_count: similarServices.length,
|
|
239
|
+
avg_price: avg,
|
|
240
|
+
min_price: min,
|
|
241
|
+
max_price: max,
|
|
242
|
+
price_percentile: percentile,
|
|
243
|
+
supply_demand_ratio: similarServices.length,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
export function assembleInfoPuzzle(serviceId, raw, depth = "evaluate") {
|
|
247
|
+
const gaps = [];
|
|
248
|
+
const serviceBasics = assembleServiceBasics(serviceId, raw.service, raw.wip_verified ?? false);
|
|
249
|
+
let workflowAnalysis;
|
|
250
|
+
let fundSafety;
|
|
251
|
+
let trustSignals;
|
|
252
|
+
if (depth === "evaluate" || depth === "preorder" || depth === "monitor") {
|
|
253
|
+
if (raw.machine_nodes) {
|
|
254
|
+
workflowAnalysis = assembleWorkflowAnalysis(raw.machine_nodes, raw.machine_published ?? false, raw.machine_paused ?? false);
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
gaps.push("machine_workflow");
|
|
258
|
+
}
|
|
259
|
+
const orderAmount = raw.order_amount ?? serviceBasics.price_raw;
|
|
260
|
+
fundSafety = assembleFundSafety(raw.service, orderAmount);
|
|
261
|
+
if (raw.reviews && raw.trust_score) {
|
|
262
|
+
trustSignals = assembleTrustSignals(raw.service, raw.reviews, raw.trust_score, raw.arbitration_owner, raw.service_owner);
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
gaps.push("reviews_or_trust_score");
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
let merchantBehavior;
|
|
269
|
+
if (depth === "preorder" || depth === "monitor") {
|
|
270
|
+
if (raw.events || raw.order_history) {
|
|
271
|
+
merchantBehavior = assembleMerchantBehavior(raw.events ?? [], raw.order_history);
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
gaps.push("merchant_behavior");
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
let marketContext;
|
|
278
|
+
if (depth === "evaluate" || depth === "preorder") {
|
|
279
|
+
if (raw.similar_services) {
|
|
280
|
+
marketContext = assembleMarketContext(raw.similar_services, serviceBasics.price_raw);
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
gaps.push("market_context");
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
const expectedDimensions = depth === "browse" ? 1
|
|
287
|
+
: depth === "evaluate" ? 4
|
|
288
|
+
: depth === "preorder" ? 6
|
|
289
|
+
: 4;
|
|
290
|
+
const actualDimensions = [
|
|
291
|
+
serviceBasics,
|
|
292
|
+
workflowAnalysis,
|
|
293
|
+
fundSafety,
|
|
294
|
+
trustSignals,
|
|
295
|
+
merchantBehavior,
|
|
296
|
+
marketContext,
|
|
297
|
+
].filter((d) => d !== undefined && d !== null).length;
|
|
298
|
+
const completeness = Math.min(1, actualDimensions / expectedDimensions);
|
|
299
|
+
return {
|
|
300
|
+
service_id: serviceId,
|
|
301
|
+
service_basics: serviceBasics,
|
|
302
|
+
workflow_analysis: workflowAnalysis,
|
|
303
|
+
fund_safety: fundSafety,
|
|
304
|
+
trust_signals: trustSignals,
|
|
305
|
+
merchant_behavior: merchantBehavior,
|
|
306
|
+
market_context: marketContext,
|
|
307
|
+
completeness,
|
|
308
|
+
gaps,
|
|
309
|
+
assembled_at: Date.now(),
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
export { CUSTOMER_INTELLIGENCE_VERSION };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { RiskLevel } from "./types.js";
|
|
2
|
+
import { CUSTOMER_INTELLIGENCE_VERSION } from "./types.js";
|
|
3
|
+
export type AlertSeverity = "info" | "warning" | "critical";
|
|
4
|
+
export type AlertCategory = "progress_stall" | "compensation_drop" | "compensation_insufficient" | "messenger_timeout" | "user_action_required" | "review_window" | "arb_window" | "refund_received" | "anomaly";
|
|
5
|
+
export interface MonitorAlert {
|
|
6
|
+
id: string;
|
|
7
|
+
category: AlertCategory;
|
|
8
|
+
severity: AlertSeverity;
|
|
9
|
+
title: string;
|
|
10
|
+
message: string;
|
|
11
|
+
action?: string;
|
|
12
|
+
timestamp: number;
|
|
13
|
+
order_id?: string;
|
|
14
|
+
service_id?: string;
|
|
15
|
+
node?: string;
|
|
16
|
+
metric?: {
|
|
17
|
+
label: string;
|
|
18
|
+
value: number;
|
|
19
|
+
threshold?: number;
|
|
20
|
+
unit?: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export interface OrderSnapshot {
|
|
24
|
+
order_id: string;
|
|
25
|
+
service_id: string;
|
|
26
|
+
current_node?: string;
|
|
27
|
+
created_at: number;
|
|
28
|
+
last_progress_at?: number;
|
|
29
|
+
now: number;
|
|
30
|
+
expected_progress_hours?: number;
|
|
31
|
+
order_amount?: bigint;
|
|
32
|
+
compensation_balance?: bigint;
|
|
33
|
+
has_arbitration?: boolean;
|
|
34
|
+
has_messenger?: boolean;
|
|
35
|
+
last_merchant_reply_at?: number;
|
|
36
|
+
last_user_message_at?: number;
|
|
37
|
+
pending_user_action?: boolean;
|
|
38
|
+
completed?: boolean;
|
|
39
|
+
refunded?: boolean;
|
|
40
|
+
review_window_days?: number;
|
|
41
|
+
arb_window_days?: number;
|
|
42
|
+
risk_score?: number;
|
|
43
|
+
risk_level?: RiskLevel;
|
|
44
|
+
}
|
|
45
|
+
export interface OrderHistorySnapshot {
|
|
46
|
+
order_id: string;
|
|
47
|
+
previous_node?: string;
|
|
48
|
+
previous_compensation_balance?: bigint;
|
|
49
|
+
snapshot_at: number;
|
|
50
|
+
}
|
|
51
|
+
export interface OrderMonitorContext {
|
|
52
|
+
current: OrderSnapshot;
|
|
53
|
+
previous?: OrderHistorySnapshot;
|
|
54
|
+
thresholds?: MonitorThresholds;
|
|
55
|
+
}
|
|
56
|
+
export interface MonitorThresholds {
|
|
57
|
+
progress_stall_hours?: number;
|
|
58
|
+
compensation_drop_ratio?: number;
|
|
59
|
+
compensation_coverage_min?: number;
|
|
60
|
+
messenger_timeout_hours?: number;
|
|
61
|
+
review_window_closing_days?: number;
|
|
62
|
+
arb_window_closing_days?: number;
|
|
63
|
+
}
|
|
64
|
+
export declare function monitorOrder(ctx: OrderMonitorContext): MonitorAlert[];
|
|
65
|
+
export declare function sortAlerts(alerts: MonitorAlert[]): MonitorAlert[];
|
|
66
|
+
export declare function getCriticalAlerts(alerts: MonitorAlert[]): MonitorAlert[];
|
|
67
|
+
export declare function getActionableAlerts(alerts: MonitorAlert[]): MonitorAlert[];
|
|
68
|
+
export declare function summarizeAlerts(alerts: MonitorAlert[]): string;
|
|
69
|
+
export declare function isBlockingAlert(alert: MonitorAlert): boolean;
|
|
70
|
+
export declare function alertsToReminders(alerts: MonitorAlert[]): Array<{
|
|
71
|
+
id: string;
|
|
72
|
+
priority: "required" | "recommended" | "info" | "reminder";
|
|
73
|
+
message: string;
|
|
74
|
+
}>;
|
|
75
|
+
export { CUSTOMER_INTELLIGENCE_VERSION };
|