@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,30 @@
|
|
|
1
|
+
export type ConstraintSeverity = "error" | "warning";
|
|
2
|
+
export interface FieldConstraint {
|
|
3
|
+
field: string;
|
|
4
|
+
description: string;
|
|
5
|
+
severity: ConstraintSeverity;
|
|
6
|
+
check: (data: any) => boolean;
|
|
7
|
+
message: (data: any) => string;
|
|
8
|
+
}
|
|
9
|
+
export interface OperationConstraint {
|
|
10
|
+
operation_type: string;
|
|
11
|
+
constraints: FieldConstraint[];
|
|
12
|
+
mutuallyExclusive?: Array<{
|
|
13
|
+
fields: string[];
|
|
14
|
+
reason: string;
|
|
15
|
+
}>;
|
|
16
|
+
requireOneOf?: Array<{
|
|
17
|
+
fields: string[];
|
|
18
|
+
reason: string;
|
|
19
|
+
}>;
|
|
20
|
+
}
|
|
21
|
+
export declare const TOOL_CONSTRAINTS: OperationConstraint[];
|
|
22
|
+
export interface ConstraintViolation {
|
|
23
|
+
field: string;
|
|
24
|
+
severity: ConstraintSeverity;
|
|
25
|
+
message: string;
|
|
26
|
+
}
|
|
27
|
+
export declare function validateOperation(operation_type: string, data: any): ConstraintViolation[];
|
|
28
|
+
export declare function hasBlockingViolations(violations: ConstraintViolation[]): boolean;
|
|
29
|
+
export declare function getWarningViolations(violations: ConstraintViolation[]): ConstraintViolation[];
|
|
30
|
+
export declare const TOOL_CONSTRAINTS_VERSION = 1;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
export const TOOL_CONSTRAINTS = [
|
|
2
|
+
{
|
|
3
|
+
operation_type: "service",
|
|
4
|
+
constraints: [
|
|
5
|
+
{
|
|
6
|
+
field: "namedNew.name",
|
|
7
|
+
description: "Service should have a name for easy reference",
|
|
8
|
+
severity: "warning",
|
|
9
|
+
check: (d) => !!d?.namedNew?.name || typeof d?.object === "string",
|
|
10
|
+
message: () => "Service without a name is hard to reference later. Consider setting namedNew.name.",
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
field: "price",
|
|
14
|
+
description: "Service price should be set before publish",
|
|
15
|
+
severity: "warning",
|
|
16
|
+
check: (d) => d?.price !== undefined || !d?.publish,
|
|
17
|
+
message: () => "Publishing a service without a price — customers won't know the cost.",
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
requireOneOf: [
|
|
21
|
+
{ fields: ["object", "namedNew"], reason: "Must specify either an existing object (string) or create new (namedNew)" },
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
operation_type: "machine",
|
|
26
|
+
constraints: [
|
|
27
|
+
{
|
|
28
|
+
field: "node.nodes",
|
|
29
|
+
description: "Machine must have at least one node",
|
|
30
|
+
severity: "error",
|
|
31
|
+
check: (d) => Array.isArray(d?.node?.nodes) && d.node.nodes.length > 0,
|
|
32
|
+
message: () => "Machine has no nodes. A workflow template requires at least one node.",
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
operation_type: "payment",
|
|
38
|
+
constraints: [
|
|
39
|
+
{
|
|
40
|
+
field: "revenue",
|
|
41
|
+
description: "Payment requires at least one revenue entry",
|
|
42
|
+
severity: "error",
|
|
43
|
+
check: (d) => Array.isArray(d?.revenue) && d.revenue.length > 0,
|
|
44
|
+
message: () => "Payment requires a non-empty 'revenue' array (payment recipients and amounts).",
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
field: "revenue[0].amount",
|
|
48
|
+
description: "Payment revenue amount must be specified",
|
|
49
|
+
severity: "error",
|
|
50
|
+
check: (d) => Array.isArray(d?.revenue) && d.revenue.length > 0 &&
|
|
51
|
+
(!!d.revenue[0]?.amount?.balance || !!d.revenue[0]?.amount?.coin),
|
|
52
|
+
message: () => "Payment revenue[0].amount must specify either 'balance' value or 'coin' object (see CoinParamSchema).",
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
operation_type: "order",
|
|
58
|
+
constraints: [
|
|
59
|
+
{
|
|
60
|
+
field: "service",
|
|
61
|
+
description: "Order must reference a service",
|
|
62
|
+
severity: "error",
|
|
63
|
+
check: (d) => !!d?.service,
|
|
64
|
+
message: () => "Order requires a 'service' field pointing to the service being ordered.",
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
operation_type: "reward",
|
|
70
|
+
constraints: [
|
|
71
|
+
{
|
|
72
|
+
field: "coin_add",
|
|
73
|
+
description: "Reward funding requires coin_add",
|
|
74
|
+
severity: "warning",
|
|
75
|
+
check: (d) => {
|
|
76
|
+
if (d?.claim || d?.guard_add || d?.guard_remove_expired || d?.owner_receive || d?.receive) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
return !!d?.coin_add?.balance || !!d?.coin_add?.coin;
|
|
80
|
+
},
|
|
81
|
+
message: () => "Reward funding requires 'coin_add' with either 'balance' value or 'coin' object (see CoinParamSchema). Other operations (claim, guard_add, etc.) don't need coin_add.",
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
operation_type: "guard",
|
|
87
|
+
constraints: [
|
|
88
|
+
{
|
|
89
|
+
field: "root",
|
|
90
|
+
description: "Guard must specify root (node tree or file)",
|
|
91
|
+
severity: "error",
|
|
92
|
+
check: (d) => !!d?.root,
|
|
93
|
+
message: () => "Guard requires a 'root' field (type='node' for tree or type='file' to load from file).",
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
operation_type: "permission",
|
|
99
|
+
constraints: [
|
|
100
|
+
{
|
|
101
|
+
field: "with_forbidden",
|
|
102
|
+
description: "Permission should have at least one rule",
|
|
103
|
+
severity: "warning",
|
|
104
|
+
check: (d) => Array.isArray(d?.with_forbidden) && d.with_forbidden.length > 0 || Array.isArray(d?.with_allowed) && d.with_allowed.length > 0,
|
|
105
|
+
message: () => "Permission has no rules (with_forbidden/with_allowed). An empty permission allows nothing.",
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
operation_type: "demand",
|
|
111
|
+
constraints: [
|
|
112
|
+
{
|
|
113
|
+
field: "reward",
|
|
114
|
+
description: "Demand should have a reward to attract solutions",
|
|
115
|
+
severity: "warning",
|
|
116
|
+
check: (d) => !!d?.reward,
|
|
117
|
+
message: () => "Demand without a reward pool may not attract solution providers.",
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
operation_type: "progress",
|
|
123
|
+
constraints: [
|
|
124
|
+
{
|
|
125
|
+
field: "parent",
|
|
126
|
+
description: "Progress must reference a parent machine",
|
|
127
|
+
severity: "error",
|
|
128
|
+
check: (d) => !!d?.parent,
|
|
129
|
+
message: () => "Progress requires a 'parent' field pointing to the Machine.",
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
},
|
|
133
|
+
];
|
|
134
|
+
const CONSTRAINT_INDEX = new Map(TOOL_CONSTRAINTS.map((c) => [c.operation_type, c]));
|
|
135
|
+
export function validateOperation(operation_type, data) {
|
|
136
|
+
const constraint = CONSTRAINT_INDEX.get(operation_type);
|
|
137
|
+
if (!constraint)
|
|
138
|
+
return [];
|
|
139
|
+
const violations = [];
|
|
140
|
+
for (const c of constraint.constraints) {
|
|
141
|
+
try {
|
|
142
|
+
if (!c.check(data)) {
|
|
143
|
+
violations.push({
|
|
144
|
+
field: c.field,
|
|
145
|
+
severity: c.severity,
|
|
146
|
+
message: c.message(data),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (constraint.requireOneOf) {
|
|
154
|
+
for (const req of constraint.requireOneOf) {
|
|
155
|
+
const hasAtLeastOne = req.fields.some((f) => data?.[f] !== undefined && data?.[f] !== null);
|
|
156
|
+
if (!hasAtLeastOne) {
|
|
157
|
+
violations.push({
|
|
158
|
+
field: req.fields.join("|"),
|
|
159
|
+
severity: "error",
|
|
160
|
+
message: req.reason,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (constraint.mutuallyExclusive) {
|
|
166
|
+
for (const mex of constraint.mutuallyExclusive) {
|
|
167
|
+
const setFields = mex.fields.filter((f) => data?.[f] !== undefined && data?.[f] !== null);
|
|
168
|
+
if (setFields.length > 1) {
|
|
169
|
+
violations.push({
|
|
170
|
+
field: setFields.join("|"),
|
|
171
|
+
severity: "error",
|
|
172
|
+
message: `Fields are mutually exclusive: ${setFields.join(", ")}. ${mex.reason}`,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return violations;
|
|
178
|
+
}
|
|
179
|
+
export function hasBlockingViolations(violations) {
|
|
180
|
+
return violations.some((v) => v.severity === "error");
|
|
181
|
+
}
|
|
182
|
+
export function getWarningViolations(violations) {
|
|
183
|
+
return violations.filter((v) => v.severity === "warning");
|
|
184
|
+
}
|
|
185
|
+
export const TOOL_CONSTRAINTS_VERSION = 1;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface ServiceTrustMetrics {
|
|
2
|
+
arbitrationScore?: number;
|
|
3
|
+
arbitrationCases?: number;
|
|
4
|
+
reviewStats?: {
|
|
5
|
+
likes: number;
|
|
6
|
+
dislikes: number;
|
|
7
|
+
verifiedReviews: number;
|
|
8
|
+
totalReviews: number;
|
|
9
|
+
};
|
|
10
|
+
orderCount?: number;
|
|
11
|
+
completedRate?: number;
|
|
12
|
+
avgCompletionTime?: number;
|
|
13
|
+
compensationFundBalance?: bigint;
|
|
14
|
+
hasPublishedEvents?: boolean;
|
|
15
|
+
hasMachineBound?: boolean;
|
|
16
|
+
hasBuyGuard?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface TrustDimension {
|
|
19
|
+
name: string;
|
|
20
|
+
score: number;
|
|
21
|
+
maxScore: number;
|
|
22
|
+
description: string;
|
|
23
|
+
humanReadable: string;
|
|
24
|
+
}
|
|
25
|
+
export interface ServiceTrustScore {
|
|
26
|
+
score: number;
|
|
27
|
+
level: "high_risk" | "caution" | "moderate" | "trusted";
|
|
28
|
+
breakdown: TrustDimension[];
|
|
29
|
+
summary: string;
|
|
30
|
+
warnings: string[];
|
|
31
|
+
}
|
|
32
|
+
export declare const TRUST_METRICS_VERSION = 1;
|
|
33
|
+
export declare function computeServiceTrustScore(metrics: ServiceTrustMetrics): ServiceTrustScore;
|
|
34
|
+
export declare function quickTrustCheck(metrics: ServiceTrustMetrics): {
|
|
35
|
+
pass: boolean;
|
|
36
|
+
reason: string;
|
|
37
|
+
};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
export const TRUST_METRICS_VERSION = 1;
|
|
2
|
+
const TRUST_LEVELS = [
|
|
3
|
+
{ min: 75, level: "trusted", label: "高信任" },
|
|
4
|
+
{ min: 50, level: "moderate", label: "中等信任" },
|
|
5
|
+
{ min: 25, level: "caution", label: "需注意" },
|
|
6
|
+
{ min: 0, level: "high_risk", label: "高风险" },
|
|
7
|
+
];
|
|
8
|
+
export function computeServiceTrustScore(metrics) {
|
|
9
|
+
const breakdown = [];
|
|
10
|
+
const warnings = [];
|
|
11
|
+
const arbScore = computeArbitrationDimension(metrics);
|
|
12
|
+
breakdown.push(arbScore);
|
|
13
|
+
if (arbScore.score < arbScore.maxScore * 0.3) {
|
|
14
|
+
warnings.push("仲裁信任分较低,建议检查仲裁记录");
|
|
15
|
+
}
|
|
16
|
+
const reviewScore = computeReviewDimension(metrics);
|
|
17
|
+
breakdown.push(reviewScore);
|
|
18
|
+
if (reviewScore.score < reviewScore.maxScore * 0.3 && metrics.reviewStats) {
|
|
19
|
+
warnings.push(`好评率较低 (${metrics.reviewStats.likes}/${metrics.reviewStats.totalReviews})`);
|
|
20
|
+
}
|
|
21
|
+
const fulfillmentScore = computeFulfillmentDimension(metrics);
|
|
22
|
+
breakdown.push(fulfillmentScore);
|
|
23
|
+
if (metrics.completedRate !== undefined && metrics.completedRate < 0.7) {
|
|
24
|
+
warnings.push(`完成率仅 ${Math.round(metrics.completedRate * 100)}%`);
|
|
25
|
+
}
|
|
26
|
+
const fundScore = computeFundDimension(metrics);
|
|
27
|
+
breakdown.push(fundScore);
|
|
28
|
+
if (metrics.compensationFundBalance === undefined || metrics.compensationFundBalance === 0n) {
|
|
29
|
+
warnings.push("无赔偿金,客户权益保障不足");
|
|
30
|
+
}
|
|
31
|
+
const transparencyScore = computeTransparencyDimension(metrics);
|
|
32
|
+
breakdown.push(transparencyScore);
|
|
33
|
+
const totalScore = breakdown.reduce((sum, d) => sum + d.score, 0);
|
|
34
|
+
const level = TRUST_LEVELS.find((l) => totalScore >= l.min)?.level ?? "high_risk";
|
|
35
|
+
const label = TRUST_LEVELS.find((l) => totalScore >= l.min)?.label ?? "高风险";
|
|
36
|
+
const summary = buildSummary(totalScore, label, metrics, breakdown);
|
|
37
|
+
return { score: totalScore, level, breakdown, summary, warnings };
|
|
38
|
+
}
|
|
39
|
+
function computeArbitrationDimension(metrics) {
|
|
40
|
+
const maxScore = 30;
|
|
41
|
+
if (metrics.arbitrationScore === undefined) {
|
|
42
|
+
return { name: "arbitration", score: maxScore * 0.5, maxScore, description: "仲裁信任分(无数据,默认中等)", humanReadable: "仲裁记录: 无数据" };
|
|
43
|
+
}
|
|
44
|
+
const score = Math.round((metrics.arbitrationScore / 100) * maxScore);
|
|
45
|
+
return {
|
|
46
|
+
name: "arbitration",
|
|
47
|
+
score,
|
|
48
|
+
maxScore,
|
|
49
|
+
description: `仲裁信任分 ${metrics.arbitrationScore}/100`,
|
|
50
|
+
humanReadable: `仲裁信任: ${metrics.arbitrationScore}/100${metrics.arbitrationCases !== undefined ? ` (${metrics.arbitrationCases} 案件)` : ""}`,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function computeReviewDimension(metrics) {
|
|
54
|
+
const maxScore = 25;
|
|
55
|
+
if (!metrics.reviewStats || metrics.reviewStats.totalReviews === 0) {
|
|
56
|
+
return { name: "reviews", score: maxScore * 0.5, maxScore, description: "评价声誉(无评价数据)", humanReadable: "评价: 无数据" };
|
|
57
|
+
}
|
|
58
|
+
const { likes, dislikes, verifiedReviews, totalReviews } = metrics.reviewStats;
|
|
59
|
+
const likeRate = likes / Math.max(1, totalReviews);
|
|
60
|
+
const verifiedBoost = Math.min(5, verifiedReviews);
|
|
61
|
+
const score = Math.round(likeRate * (maxScore - 5) + verifiedBoost);
|
|
62
|
+
return {
|
|
63
|
+
name: "reviews",
|
|
64
|
+
score: Math.min(maxScore, score),
|
|
65
|
+
maxScore,
|
|
66
|
+
description: `好评率 ${Math.round(likeRate * 100)}% (${totalReviews} 条评价, ${verifiedReviews} 条带凭证)`,
|
|
67
|
+
humanReadable: `好评率 ${Math.round(likeRate * 100)}% (${totalReviews} 评价)`,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function computeFulfillmentDimension(metrics) {
|
|
71
|
+
const maxScore = 20;
|
|
72
|
+
if (metrics.orderCount === undefined) {
|
|
73
|
+
return { name: "fulfillment", score: maxScore * 0.5, maxScore, description: "履约记录(无订单数据)", humanReadable: "履约: 无数据" };
|
|
74
|
+
}
|
|
75
|
+
let score = 0;
|
|
76
|
+
const orderScore = Math.min(10, Math.floor(metrics.orderCount / 5));
|
|
77
|
+
score += orderScore;
|
|
78
|
+
if (metrics.completedRate !== undefined) {
|
|
79
|
+
score += Math.round(metrics.completedRate * 10);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
score += 5;
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
name: "fulfillment",
|
|
86
|
+
score: Math.min(maxScore, score),
|
|
87
|
+
maxScore,
|
|
88
|
+
description: `已完成 ${metrics.orderCount} 单, 完成率 ${metrics.completedRate !== undefined ? Math.round(metrics.completedRate * 100) + "%" : "未知"}`,
|
|
89
|
+
humanReadable: `履约: ${metrics.orderCount} 单${metrics.avgCompletionTime !== undefined ? `, 平均 ${metrics.avgCompletionTime}h` : ""}`,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function computeFundDimension(metrics) {
|
|
93
|
+
const maxScore = 15;
|
|
94
|
+
if (metrics.compensationFundBalance === undefined || metrics.compensationFundBalance === 0n) {
|
|
95
|
+
return { name: "fund_safety", score: 0, maxScore, description: "无赔偿金", humanReadable: "赔偿金: 无" };
|
|
96
|
+
}
|
|
97
|
+
const threshold = 1000000000000n;
|
|
98
|
+
const ratio = Number(metrics.compensationFundBalance * 100n / threshold) / 100;
|
|
99
|
+
const score = Math.min(maxScore, Math.round(ratio * maxScore));
|
|
100
|
+
return {
|
|
101
|
+
name: "fund_safety",
|
|
102
|
+
score,
|
|
103
|
+
maxScore,
|
|
104
|
+
description: `赔偿金 ${metrics.compensationFundBalance} 最小单位`,
|
|
105
|
+
humanReadable: `赔偿金: 充足`,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function computeTransparencyDimension(metrics) {
|
|
109
|
+
const maxScore = 10;
|
|
110
|
+
let score = 0;
|
|
111
|
+
if (metrics.hasPublishedEvents)
|
|
112
|
+
score += 4;
|
|
113
|
+
if (metrics.hasMachineBound)
|
|
114
|
+
score += 3;
|
|
115
|
+
if (metrics.hasBuyGuard)
|
|
116
|
+
score += 3;
|
|
117
|
+
return {
|
|
118
|
+
name: "transparency",
|
|
119
|
+
score: Math.min(maxScore, score),
|
|
120
|
+
maxScore,
|
|
121
|
+
description: `链上事件 ${metrics.hasPublishedEvents ? "✓" : "✗"}, Machine ${metrics.hasMachineBound ? "✓" : "✗"}, Guard ${metrics.hasBuyGuard ? "✓" : "✗"}`,
|
|
122
|
+
humanReadable: `透明度: ${["事件", "Machine", "Guard"].filter((_, i) => [metrics.hasPublishedEvents, metrics.hasMachineBound, metrics.hasBuyGuard][i]).join("+") || "无"}`,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function buildSummary(score, label, metrics, breakdown) {
|
|
126
|
+
const parts = [`信任分 ${score}/100 (${label})`];
|
|
127
|
+
for (const d of breakdown) {
|
|
128
|
+
parts.push(`${d.humanReadable}`);
|
|
129
|
+
}
|
|
130
|
+
return parts.join("; ");
|
|
131
|
+
}
|
|
132
|
+
export function quickTrustCheck(metrics) {
|
|
133
|
+
const result = computeServiceTrustScore(metrics);
|
|
134
|
+
if (result.score < 25) {
|
|
135
|
+
return { pass: false, reason: `信任分 ${result.score}/100,高风险: ${result.warnings.join("; ")}` };
|
|
136
|
+
}
|
|
137
|
+
return { pass: true, reason: `信任分 ${result.score}/100 (${result.level})` };
|
|
138
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AggregatedStats } from "./aggregate.js";
|
|
2
|
-
export type DiagnosisType = "rule_gap" | "description_quality" | "skill_need" | "recovery_ineffectiveness" | "latency_anomaly";
|
|
2
|
+
export type DiagnosisType = "rule_gap" | "description_quality" | "skill_need" | "recovery_ineffectiveness" | "latency_anomaly" | "industry_health_anomaly";
|
|
3
3
|
export type DiagnosisSeverity = "P0" | "P1" | "P2" | "P3";
|
|
4
4
|
export interface Diagnosis {
|
|
5
5
|
diagnosis_id: string;
|
|
@@ -9,7 +9,7 @@ export interface Diagnosis {
|
|
|
9
9
|
description: string;
|
|
10
10
|
evidence: Record<string, unknown>;
|
|
11
11
|
target: string;
|
|
12
|
-
proposed_improvement_type: "rule_addition" | "description_rewrite" | "skill_creation" | "recovery_priority_adjustment" | "investigation";
|
|
12
|
+
proposed_improvement_type: "rule_addition" | "description_rewrite" | "skill_creation" | "recovery_priority_adjustment" | "investigation" | "industry_update_application";
|
|
13
13
|
}
|
|
14
14
|
export interface DiagnosisReport {
|
|
15
15
|
report_id: string;
|
|
@@ -18,4 +18,5 @@ export interface DiagnosisReport {
|
|
|
18
18
|
diagnoses: Diagnosis[];
|
|
19
19
|
summary: string;
|
|
20
20
|
}
|
|
21
|
+
export declare function diagnoseIndustryHealth(industries?: string[]): Diagnosis[];
|
|
21
22
|
export declare function diagnose(stats: AggregatedStats): DiagnosisReport;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { listIndustriesWithSignals, getIndustryEvolutionStatus, getPendingSuggestions, getIndustrySignalCount, } from "../knowledge/flywheel-loop.js";
|
|
1
2
|
const THRESHOLDS = {
|
|
2
3
|
UNKNOWN_ERROR_RATE_P0: 0.15,
|
|
3
4
|
UNKNOWN_ERROR_RATE_P1: 0.08,
|
|
@@ -154,6 +155,98 @@ function diagnoseLatencyAnomalies(stats) {
|
|
|
154
155
|
}
|
|
155
156
|
return diagnoses;
|
|
156
157
|
}
|
|
158
|
+
const INDUSTRY_HEALTH_THRESHOLDS = {
|
|
159
|
+
CRITICAL_HEALTH_SCORE: 45,
|
|
160
|
+
STRESSED_HEALTH_SCORE: 65,
|
|
161
|
+
HIGH_PENDING_SUGGESTIONS: 3,
|
|
162
|
+
STALE_SIGNAL_THRESHOLD: 20,
|
|
163
|
+
};
|
|
164
|
+
export function diagnoseIndustryHealth(industries) {
|
|
165
|
+
const targets = industries ?? listIndustriesWithSignals();
|
|
166
|
+
const diagnoses = [];
|
|
167
|
+
for (const industry of targets) {
|
|
168
|
+
const status = getIndustryEvolutionStatus(industry);
|
|
169
|
+
const pendingDetail = getPendingSuggestions(industry);
|
|
170
|
+
const signalCount = getIndustrySignalCount(industry);
|
|
171
|
+
if (status.health) {
|
|
172
|
+
const score = status.health.health_score;
|
|
173
|
+
if (score < INDUSTRY_HEALTH_THRESHOLDS.CRITICAL_HEALTH_SCORE) {
|
|
174
|
+
diagnoses.push({
|
|
175
|
+
diagnosis_id: `DIAG-IND-${Date.now()}-${industry}-critical`,
|
|
176
|
+
type: "industry_health_anomaly",
|
|
177
|
+
severity: "P0",
|
|
178
|
+
title: `Industry '${industry}' health critical (${score}/100, ${status.health.level})`,
|
|
179
|
+
description: `Industry health score is in the danger zone. Weaknesses: ${status.health.weaknesses.join("; ") || "none"}. Recommendations: ${status.health.recommendations.join("; ") || "none"}.`,
|
|
180
|
+
evidence: {
|
|
181
|
+
industry,
|
|
182
|
+
health_score: score,
|
|
183
|
+
health_level: status.health.level,
|
|
184
|
+
weaknesses: status.health.weaknesses,
|
|
185
|
+
recommendations: status.health.recommendations,
|
|
186
|
+
signal_count: signalCount,
|
|
187
|
+
},
|
|
188
|
+
target: `industry:${industry}`,
|
|
189
|
+
proposed_improvement_type: "industry_update_application",
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
else if (score < INDUSTRY_HEALTH_THRESHOLDS.STRESSED_HEALTH_SCORE) {
|
|
193
|
+
diagnoses.push({
|
|
194
|
+
diagnosis_id: `DIAG-IND-${Date.now()}-${industry}-stressed`,
|
|
195
|
+
type: "industry_health_anomaly",
|
|
196
|
+
severity: "P1",
|
|
197
|
+
title: `Industry '${industry}' health stressed (${score}/100, ${status.health.level})`,
|
|
198
|
+
description: `Industry health score is under pressure. Weaknesses: ${status.health.weaknesses.join("; ") || "none"}.`,
|
|
199
|
+
evidence: {
|
|
200
|
+
industry,
|
|
201
|
+
health_score: score,
|
|
202
|
+
health_level: status.health.level,
|
|
203
|
+
weaknesses: status.health.weaknesses,
|
|
204
|
+
signal_count: signalCount,
|
|
205
|
+
},
|
|
206
|
+
target: `industry:${industry}`,
|
|
207
|
+
proposed_improvement_type: "industry_update_application",
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (pendingDetail.length >= INDUSTRY_HEALTH_THRESHOLDS.HIGH_PENDING_SUGGESTIONS) {
|
|
212
|
+
const highPriority = pendingDetail.filter((s) => s.priority === "high");
|
|
213
|
+
diagnoses.push({
|
|
214
|
+
diagnosis_id: `DIAG-IND-${Date.now()}-${industry}-pending`,
|
|
215
|
+
type: "industry_health_anomaly",
|
|
216
|
+
severity: highPriority.length > 0 ? "P1" : "P2",
|
|
217
|
+
title: `Industry '${industry}' has ${pendingDetail.length} pending suggestions (${highPriority.length} high priority)`,
|
|
218
|
+
description: `Industry has ${pendingDetail.length} pending evolution suggestions unprocessed. Review and apply promptly to drive industry evolution.`,
|
|
219
|
+
evidence: {
|
|
220
|
+
industry,
|
|
221
|
+
pending_count: pendingDetail.length,
|
|
222
|
+
high_priority_count: highPriority.length,
|
|
223
|
+
suggestion_types: pendingDetail.map((s) => s.suggestion_type),
|
|
224
|
+
suggestion_summaries: pendingDetail.map((s) => ({ type: s.suggestion_type, field: s.field, priority: s.priority })),
|
|
225
|
+
},
|
|
226
|
+
target: `industry:${industry}:pending_suggestions`,
|
|
227
|
+
proposed_improvement_type: "industry_update_application",
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
if (signalCount >= INDUSTRY_HEALTH_THRESHOLDS.STALE_SIGNAL_THRESHOLD && !status.health) {
|
|
231
|
+
diagnoses.push({
|
|
232
|
+
diagnosis_id: `DIAG-IND-${Date.now()}-${industry}-stale`,
|
|
233
|
+
type: "industry_health_anomaly",
|
|
234
|
+
severity: "P2",
|
|
235
|
+
title: `Industry '${industry}' has ${signalCount} signals but no health report (evolution stale)`,
|
|
236
|
+
description: `Industry has accumulated ${signalCount} signals but health score has not been recalculated. May need to manually trigger updateIndustryCognition or check scheduling configuration.`,
|
|
237
|
+
evidence: {
|
|
238
|
+
industry,
|
|
239
|
+
signal_count: signalCount,
|
|
240
|
+
evolution_ready: status.evolution_ready,
|
|
241
|
+
version: status.version,
|
|
242
|
+
},
|
|
243
|
+
target: `industry:${industry}:cognition`,
|
|
244
|
+
proposed_improvement_type: "industry_update_application",
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return diagnoses;
|
|
249
|
+
}
|
|
157
250
|
export function diagnose(stats) {
|
|
158
251
|
const all = [
|
|
159
252
|
...diagnoseRuleGaps(stats),
|
|
@@ -161,6 +254,7 @@ export function diagnose(stats) {
|
|
|
161
254
|
...diagnoseSkillNeeds(stats),
|
|
162
255
|
...diagnoseRecoveryIneffectiveness(stats),
|
|
163
256
|
...diagnoseLatencyAnomalies(stats),
|
|
257
|
+
...diagnoseIndustryHealth(),
|
|
164
258
|
];
|
|
165
259
|
const severityOrder = { P0: 0, P1: 1, P2: 2, P3: 3 };
|
|
166
260
|
all.sort((a, b) => severityOrder[a.severity] - severityOrder[b.severity]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DiagnosisReport } from "./diagnose.js";
|
|
2
|
-
export type ProposalType = "error_rule_addition" | "intent_rule_addition" | "description_rewrite" | "skill_creation" | "recovery_priority_adjustment" | "investigation";
|
|
2
|
+
export type ProposalType = "error_rule_addition" | "intent_rule_addition" | "description_rewrite" | "skill_creation" | "recovery_priority_adjustment" | "investigation" | "industry_update_application";
|
|
3
3
|
export type AutomationLevel = "full" | "semi" | "manual";
|
|
4
4
|
export interface ImprovementProposal {
|
|
5
5
|
proposal_id: string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getPendingSuggestions } from "../knowledge/flywheel-loop.js";
|
|
1
2
|
function proposeErrorRuleAddition(diagnosis) {
|
|
2
3
|
const evidence = diagnosis.evidence;
|
|
3
4
|
const topMessages = evidence.top_error_messages || [];
|
|
@@ -54,7 +55,7 @@ function proposeDescriptionRewrite(diagnosis) {
|
|
|
54
55
|
current_semantic_hit_rate: evidence.semantic_hit_rate,
|
|
55
56
|
target_semantic_hit_rate: 0.80,
|
|
56
57
|
rewrite_guidelines: [
|
|
57
|
-
"Follow 4-part format:
|
|
58
|
+
"Follow 4-part format: Meaning + Constraint + Relation + Example",
|
|
58
59
|
"Add explicit intent signals to INTENT_RULES",
|
|
59
60
|
"Include concrete examples for common operation types",
|
|
60
61
|
],
|
|
@@ -139,6 +140,53 @@ function proposeInvestigation(diagnosis) {
|
|
|
139
140
|
ab_test_recommended: false,
|
|
140
141
|
};
|
|
141
142
|
}
|
|
143
|
+
function proposeIndustryUpdate(diagnosis) {
|
|
144
|
+
const evidence = diagnosis.evidence;
|
|
145
|
+
const industry = evidence.industry ?? diagnosis.target.split(":")[1] ?? "unknown";
|
|
146
|
+
const pendingSuggestions = industry !== "unknown"
|
|
147
|
+
? getPendingSuggestions(industry)
|
|
148
|
+
: [];
|
|
149
|
+
const changes = pendingSuggestions.map((s) => ({
|
|
150
|
+
suggestion_type: s.suggestion_type,
|
|
151
|
+
field: s.field,
|
|
152
|
+
suggested_value: s.suggested_value,
|
|
153
|
+
evidence: s.evidence,
|
|
154
|
+
confidence: s.confidence,
|
|
155
|
+
priority: s.priority,
|
|
156
|
+
}));
|
|
157
|
+
const isHealthCritical = evidence.health_score !== undefined && evidence.health_score < 45;
|
|
158
|
+
const hasHighPrioritySuggestions = (evidence.high_priority_count ?? 0) > 0;
|
|
159
|
+
return {
|
|
160
|
+
proposal_id: `PROP-IND-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`,
|
|
161
|
+
source_diagnosis_id: diagnosis.diagnosis_id,
|
|
162
|
+
type: "industry_update_application",
|
|
163
|
+
priority: diagnosis.severity,
|
|
164
|
+
automation: isHealthCritical ? "semi" : "manual",
|
|
165
|
+
title: `Apply ${pendingSuggestions.length} evolution suggestions for industry '${industry}'`,
|
|
166
|
+
description: `Industry '${industry}' has health anomaly (health score ${evidence.health_score ?? "N/A"}, level ${evidence.health_level ?? "N/A"}). ` +
|
|
167
|
+
`Has ${pendingSuggestions.length} pending evolution suggestions (${(evidence.high_priority_count ?? 0)} high priority). ` +
|
|
168
|
+
`Review and apply to drive industry cognition evolution. Weaknesses: ${(evidence.weaknesses ?? []).join("; ") || "none"}.`,
|
|
169
|
+
target: `industry:${industry}`,
|
|
170
|
+
proposed_change: {
|
|
171
|
+
action: "apply_industry_updates",
|
|
172
|
+
industry,
|
|
173
|
+
current_health_score: evidence.health_score,
|
|
174
|
+
current_health_level: evidence.health_level,
|
|
175
|
+
weaknesses: evidence.weaknesses ?? [],
|
|
176
|
+
recommendations: evidence.recommendations ?? [],
|
|
177
|
+
pending_suggestion_count: pendingSuggestions.length,
|
|
178
|
+
high_priority_count: evidence.high_priority_count ?? 0,
|
|
179
|
+
suggestions: changes,
|
|
180
|
+
auto_applicable_suggestions: changes.filter((c) => c.confidence >= 0.85 && c.priority === "high"),
|
|
181
|
+
apply_guidance: hasHighPrioritySuggestions
|
|
182
|
+
? "Prioritize reviewing high-priority suggestions; high-confidence (≥0.85) suggestions can be semi-automatically applied"
|
|
183
|
+
: "No high-priority suggestions, review via normal process",
|
|
184
|
+
},
|
|
185
|
+
evidence: diagnosis.evidence,
|
|
186
|
+
review_status: "pending",
|
|
187
|
+
ab_test_recommended: false,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
142
190
|
export function generateImprovements(report) {
|
|
143
191
|
const proposals = [];
|
|
144
192
|
for (const diagnosis of report.diagnoses) {
|
|
@@ -156,6 +204,9 @@ export function generateImprovements(report) {
|
|
|
156
204
|
case "recovery_priority_adjustment":
|
|
157
205
|
proposal = proposeRecoveryAdjustment(diagnosis);
|
|
158
206
|
break;
|
|
207
|
+
case "industry_update_application":
|
|
208
|
+
proposal = proposeIndustryUpdate(diagnosis);
|
|
209
|
+
break;
|
|
159
210
|
default:
|
|
160
211
|
proposal = proposeInvestigation(diagnosis);
|
|
161
212
|
}
|