@wowok/agent-mcp 2.3.13 → 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 (194) 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/harness/checkpoint.d.ts +8 -0
  36. package/dist/harness/checkpoint.js +129 -0
  37. package/dist/harness/index.d.ts +33 -0
  38. package/dist/harness/index.js +75 -0
  39. package/dist/harness/plan.d.ts +18 -0
  40. package/dist/harness/plan.js +252 -0
  41. package/dist/harness/recover.d.ts +17 -0
  42. package/dist/harness/recover.js +139 -0
  43. package/dist/harness/types.d.ts +137 -0
  44. package/dist/harness/types.js +1 -0
  45. package/dist/harness/verify.d.ts +42 -0
  46. package/dist/harness/verify.js +237 -0
  47. package/dist/index.js +667 -201
  48. package/dist/knowledge/acquisition-flywheel.d.ts +50 -0
  49. package/dist/knowledge/acquisition-flywheel.js +183 -0
  50. package/dist/knowledge/arbitration-trust.d.ts +24 -0
  51. package/dist/knowledge/arbitration-trust.js +117 -0
  52. package/dist/knowledge/audit-rules.d.ts +28 -0
  53. package/dist/knowledge/audit-rules.js +141 -0
  54. package/dist/knowledge/demand-matching.d.ts +29 -0
  55. package/dist/knowledge/demand-matching.js +132 -0
  56. package/dist/knowledge/dynamic-pricing.d.ts +31 -0
  57. package/dist/knowledge/dynamic-pricing.js +87 -0
  58. package/dist/knowledge/flywheel-loop.d.ts +87 -0
  59. package/dist/knowledge/flywheel-loop.js +378 -0
  60. package/dist/knowledge/glossary.d.ts +18 -0
  61. package/dist/knowledge/glossary.js +209 -0
  62. package/dist/knowledge/index.d.ts +64 -0
  63. package/dist/knowledge/index.js +66 -0
  64. package/dist/knowledge/industry-evolution.d.ts +82 -0
  65. package/dist/knowledge/industry-evolution.js +323 -0
  66. package/dist/knowledge/industry-generalizer.d.ts +17 -0
  67. package/dist/knowledge/industry-generalizer.js +381 -0
  68. package/dist/knowledge/industry-registry.d.ts +49 -0
  69. package/dist/knowledge/industry-registry.js +167 -0
  70. package/dist/knowledge/intent-metrics.d.ts +42 -0
  71. package/dist/knowledge/intent-metrics.js +566 -0
  72. package/dist/knowledge/process-model.d.ts +24 -0
  73. package/dist/knowledge/process-model.js +160 -0
  74. package/dist/knowledge/reputation-rules.d.ts +42 -0
  75. package/dist/knowledge/reputation-rules.js +99 -0
  76. package/dist/knowledge/reward-templates.d.ts +25 -0
  77. package/dist/knowledge/reward-templates.js +125 -0
  78. package/dist/knowledge/safety-rules.d.ts +36 -0
  79. package/dist/knowledge/safety-rules.js +171 -0
  80. package/dist/knowledge/tool-constraints.d.ts +30 -0
  81. package/dist/knowledge/tool-constraints.js +185 -0
  82. package/dist/knowledge/trust-metrics.d.ts +37 -0
  83. package/dist/knowledge/trust-metrics.js +138 -0
  84. package/dist/loop-engineering/aggregate.d.ts +50 -0
  85. package/dist/loop-engineering/aggregate.js +132 -0
  86. package/dist/loop-engineering/diagnose.d.ts +22 -0
  87. package/dist/loop-engineering/diagnose.js +273 -0
  88. package/dist/loop-engineering/improve.d.ts +26 -0
  89. package/dist/loop-engineering/improve.js +229 -0
  90. package/dist/loop-engineering/index.d.ts +4 -0
  91. package/dist/loop-engineering/index.js +4 -0
  92. package/dist/loop-engineering/pipeline.d.ts +17 -0
  93. package/dist/loop-engineering/pipeline.js +56 -0
  94. package/dist/mode-market/index.d.ts +3 -0
  95. package/dist/mode-market/index.js +3 -0
  96. package/dist/mode-market/registry.d.ts +53 -0
  97. package/dist/mode-market/registry.js +124 -0
  98. package/dist/mode-market/review.d.ts +27 -0
  99. package/dist/mode-market/review.js +214 -0
  100. package/dist/mode-market/submission.d.ts +25 -0
  101. package/dist/mode-market/submission.js +85 -0
  102. package/dist/project/graph.d.ts +71 -0
  103. package/dist/project/graph.js +314 -0
  104. package/dist/project/index.d.ts +62 -0
  105. package/dist/project/index.js +167 -0
  106. package/dist/project/namespace.d.ts +62 -0
  107. package/dist/project/namespace.js +181 -0
  108. package/dist/project/query.d.ts +40 -0
  109. package/dist/project/query.js +110 -0
  110. package/dist/safety/confirm-gate.d.ts +15 -0
  111. package/dist/safety/confirm-gate.js +44 -0
  112. package/dist/safety/index.d.ts +3 -0
  113. package/dist/safety/index.js +3 -0
  114. package/dist/safety/preview.d.ts +2 -0
  115. package/dist/safety/preview.js +36 -0
  116. package/dist/schema/call/allocation.d.ts +55 -40
  117. package/dist/schema/call/arbitration.d.ts +201 -186
  118. package/dist/schema/call/base.d.ts +2104 -24
  119. package/dist/schema/call/base.js +168 -22
  120. package/dist/schema/call/bridge-handler.js +36 -18
  121. package/dist/schema/call/bridge.d.ts +777 -120
  122. package/dist/schema/call/bridge.js +13 -2
  123. package/dist/schema/call/contact.d.ts +15 -0
  124. package/dist/schema/call/demand.d.ts +69 -54
  125. package/dist/schema/call/guard.d.ts +125 -80
  126. package/dist/schema/call/handler.d.ts +5 -1
  127. package/dist/schema/call/handler.js +108 -3
  128. package/dist/schema/call/index.d.ts +1 -0
  129. package/dist/schema/call/index.js +1 -0
  130. package/dist/schema/call/machine.d.ts +830 -800
  131. package/dist/schema/call/order.d.ts +27 -12
  132. package/dist/schema/call/payment.d.ts +15 -0
  133. package/dist/schema/call/permission.d.ts +15 -0
  134. package/dist/schema/call/personal.d.ts +15 -0
  135. package/dist/schema/call/progress.d.ts +21 -6
  136. package/dist/schema/call/proof.d.ts +42 -12
  137. package/dist/schema/call/proof.js +3 -3
  138. package/dist/schema/call/repository.d.ts +91 -76
  139. package/dist/schema/call/reward.d.ts +51 -36
  140. package/dist/schema/call/semantic.d.ts +24 -0
  141. package/dist/schema/call/semantic.js +981 -0
  142. package/dist/schema/call/service.d.ts +444 -429
  143. package/dist/schema/call/treasury.d.ts +219 -204
  144. package/dist/schema/common/index.js +3 -3
  145. package/dist/schema/local/index.d.ts +341 -74
  146. package/dist/schema/local/index.js +44 -7
  147. package/dist/schema/messenger/index.d.ts +1034 -92
  148. package/dist/schema/messenger/index.js +18 -0
  149. package/dist/schema/operations.d.ts +2634 -1817
  150. package/dist/schema/operations.js +16 -5
  151. package/dist/schema/query/index.d.ts +2293 -2289
  152. package/dist/schema/query/index.js +34 -28
  153. package/dist/schemas/account_operation.output.json +28 -16
  154. package/dist/schemas/account_operation.schema.json +2 -2
  155. package/dist/schemas/bridge_operation.output.json +520 -0
  156. package/dist/schemas/bridge_operation.schema.json +15 -0
  157. package/dist/schemas/guard2file.schema.json +15 -0
  158. package/dist/schemas/index.json +1 -1
  159. package/dist/schemas/local_info_operation.output.json +26 -0
  160. package/dist/schemas/local_info_operation.schema.json +1 -1
  161. package/dist/schemas/local_mark_operation.output.json +27 -1
  162. package/dist/schemas/local_mark_operation.schema.json +4 -4
  163. package/dist/schemas/machineNode2file.schema.json +15 -0
  164. package/dist/schemas/messenger_operation.output.json +549 -0
  165. package/dist/schemas/messenger_operation.schema.json +21 -0
  166. package/dist/schemas/onchain_events.output.json +3 -0
  167. package/dist/schemas/onchain_operations.output.json +814 -37
  168. package/dist/schemas/onchain_operations.schema.json +117 -40
  169. package/dist/schemas/onchain_operations_allocation.schema.json +26 -9
  170. package/dist/schemas/onchain_operations_arbitration.schema.json +26 -9
  171. package/dist/schemas/onchain_operations_contact.schema.json +26 -9
  172. package/dist/schemas/onchain_operations_demand.schema.json +26 -9
  173. package/dist/schemas/onchain_operations_gen_passport.schema.json +51 -17
  174. package/dist/schemas/onchain_operations_guard.schema.json +26 -9
  175. package/dist/schemas/onchain_operations_machine.schema.json +92 -32
  176. package/dist/schemas/onchain_operations_order.schema.json +26 -9
  177. package/dist/schemas/onchain_operations_payment.schema.json +26 -9
  178. package/dist/schemas/onchain_operations_permission.schema.json +26 -9
  179. package/dist/schemas/onchain_operations_personal.schema.json +26 -9
  180. package/dist/schemas/onchain_operations_progress.schema.json +26 -9
  181. package/dist/schemas/onchain_operations_repository.schema.json +26 -9
  182. package/dist/schemas/onchain_operations_reward.schema.json +26 -9
  183. package/dist/schemas/onchain_operations_service.schema.json +26 -9
  184. package/dist/schemas/onchain_operations_treasury.schema.json +26 -9
  185. package/dist/schemas/onchain_table_data.output.json +224 -69
  186. package/dist/schemas/onchain_table_data.schema.json +2 -2
  187. package/dist/schemas/query_toolkit.schema.json +5 -1
  188. package/dist/telemetry/index.d.ts +19 -0
  189. package/dist/telemetry/index.js +112 -0
  190. package/dist/telemetry/redact.d.ts +2 -0
  191. package/dist/telemetry/redact.js +23 -0
  192. package/dist/telemetry/storage.d.ts +8 -0
  193. package/dist/telemetry/storage.js +80 -0
  194. package/package.json +6 -3
@@ -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 };