@wowok/agent-mcp 2.6.3 → 2.6.4
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/customer/customer-advice.d.ts +31 -0
- package/dist/customer/customer-advice.js +129 -0
- package/dist/customer/index.d.ts +2 -0
- package/dist/customer/index.js +2 -0
- package/dist/customer/info-puzzle.d.ts +8 -1
- package/dist/customer/info-puzzle.js +30 -5
- package/dist/customer/order-monitor.d.ts +2 -0
- package/dist/customer/order-monitor.js +3 -2
- package/dist/customer/post-purchase.d.ts +2 -0
- package/dist/customer/post-purchase.js +6 -5
- package/dist/customer/preorder-compare.d.ts +24 -0
- package/dist/customer/preorder-compare.js +34 -0
- package/dist/customer/reminder-system.d.ts +2 -0
- package/dist/customer/reminder-system.js +2 -1
- package/dist/customer/risk-assessment.js +4 -3
- package/dist/customer/types.d.ts +5 -0
- package/dist/examples/arbitration-dispute-create.json +41 -0
- package/dist/examples/arbitration-vote-weighted.json +35 -0
- package/dist/examples/arbitration-voting-guard-add.json +38 -0
- package/dist/examples/demand-present-service.json +33 -0
- package/dist/examples/gen-passport-verify-guard.json +48 -0
- package/dist/examples/guard-template-balance-check.json +36 -15
- package/dist/examples/guard-template-time-lock.json +33 -12
- package/dist/examples/insurance-guard-claim-timelock.json +75 -0
- package/dist/examples/insurance-guard-withdraw-allocation.json +96 -0
- package/dist/examples/insurance-machine-create-publish.json +75 -0
- package/dist/examples/insurance-service-allocators-publish.json +56 -0
- package/dist/examples/machine-multisig-threshold.json +86 -0
- package/dist/examples/machine-template-7node-rental.json +99 -94
- package/dist/examples/payment-scenario-bound.json +45 -0
- package/dist/examples/rental-ziroom-machine-create.json +126 -114
- package/dist/examples/rental-ziroom-permission-create.json +10 -3
- package/dist/examples/rental-ziroom-service-create.json +27 -18
- package/dist/examples/retail-adv-guard-customer-win-create.json +80 -0
- package/dist/examples/retail-adv-guard-messenger-proof-create.json +65 -0
- package/dist/examples/retail-adv-guard-reward-timeout-create.json +92 -0
- package/dist/examples/retail-adv-reward-guard-add.json +51 -0
- package/dist/examples/retail-myshop-allocation-activate.json +55 -0
- package/dist/examples/retail-myshop-arbitration-create.json +40 -0
- package/dist/examples/retail-myshop-contact-create.json +43 -0
- package/dist/examples/retail-myshop-order-create.json +56 -0
- package/dist/examples/retail-myshop-progress-operate.json +38 -0
- package/dist/examples/retail-myshop-reward-create.json +35 -0
- package/dist/examples/service-discount-issue.json +46 -0
- package/dist/examples/threebody-guard-create.json +56 -0
- package/dist/examples/threebody-machine-create.json +72 -0
- package/dist/examples/threebody-permission-create.json +38 -0
- package/dist/examples/threebody-service-allocators.json +49 -0
- package/dist/examples/travel-guard-time-lock.json +69 -0
- package/dist/examples/travel-guard-weather-oracle.json +70 -0
- package/dist/examples/travel-machine-create.json +136 -0
- package/dist/examples/travel-repository-create.json +47 -0
- package/dist/examples/travel-service-create.json +102 -0
- package/dist/examples/travel-treasury-create.json +34 -0
- package/dist/examples/treasury-deposit.json +37 -0
- package/dist/examples/treasury-withdraw.json +38 -0
- package/dist/extensions/business-modules.d.ts +49 -0
- package/dist/extensions/business-modules.js +287 -0
- package/dist/extensions/capability-manifest.js +192 -5
- package/dist/extensions/constraint-registry.js +3 -1
- package/dist/extensions/modes.js +10 -4
- package/dist/extensions/registry.d.ts +14 -9
- package/dist/extensions/registry.js +69 -14
- package/dist/extensions/types.d.ts +1 -0
- package/dist/knowledge/fund-layer.d.ts +67 -1
- package/dist/knowledge/fund-layer.js +561 -12
- package/dist/knowledge/guard-templates.d.ts +10 -0
- package/dist/knowledge/guard-templates.js +50 -0
- package/dist/knowledge/index.d.ts +2 -2
- package/dist/knowledge/index.js +2 -2
- package/dist/knowledge/machine-risk.js +4 -1
- package/dist/knowledge/progress-context.js +1 -1
- package/dist/knowledge/progress-ledger.js +3 -3
- package/dist/knowledge/progress-templates.js +1 -1
- package/dist/knowledge/progress-translation.js +1 -1
- package/dist/knowledge/safety-rules.d.ts +83 -1
- package/dist/knowledge/safety-rules.js +166 -2
- package/dist/knowledge/scenario-modes.d.ts +1 -1
- package/dist/knowledge/scenario-modes.js +13 -11
- package/dist/knowledge/template-registry.d.ts +48 -0
- package/dist/knowledge/template-registry.js +341 -0
- package/dist/knowledge/tool-constraints.js +6 -6
- package/dist/knowledge/tools-reference.js +11 -8
- package/dist/participation/merchant-interest.d.ts +32 -0
- package/dist/participation/merchant-interest.js +100 -0
- package/dist/participation/radar-core.d.ts +104 -0
- package/dist/participation/radar-core.js +269 -0
- package/dist/project/context-assembly.js +8 -0
- package/dist/project/edit-planner.js +27 -56
- package/dist/project/evaluation.d.ts +36 -0
- package/dist/project/evaluation.js +422 -56
- package/dist/project/game-theory.d.ts +43 -0
- package/dist/project/game-theory.js +177 -0
- package/dist/project/graph-builder.js +1 -0
- package/dist/project/handlers.d.ts +38 -0
- package/dist/project/handlers.js +65 -35
- package/dist/project/intent-analyzer.d.ts +71 -0
- package/dist/project/intent-analyzer.js +149 -0
- package/dist/project/machine-nodes.d.ts +2 -0
- package/dist/project/machine-nodes.js +36 -0
- package/dist/project/merchant-guide.d.ts +165 -0
- package/dist/project/merchant-guide.js +264 -0
- package/dist/project/mode-actions.d.ts +199 -0
- package/dist/project/mode-actions.js +309 -0
- package/dist/project/participation-radar.d.ts +18 -0
- package/dist/project/participation-radar.js +428 -0
- package/dist/project/pipeline-actions.d.ts +101 -0
- package/dist/project/pipeline-actions.js +109 -0
- package/dist/project/semantic-graph.d.ts +95 -0
- package/dist/project/semantic-graph.js +245 -0
- package/dist/schema/call/allocation.d.ts +11 -11
- package/dist/schema/call/allocation.js +11 -1
- package/dist/schema/call/arbitration.d.ts +21 -21
- package/dist/schema/call/arbitration.js +17 -9
- package/dist/schema/call/base.d.ts +2 -2
- package/dist/schema/call/base.js +1 -1
- package/dist/schema/call/bridge.d.ts +127 -127
- package/dist/schema/call/bridge.js +12 -12
- package/dist/schema/call/contact.d.ts +3 -3
- package/dist/schema/call/demand.d.ts +3 -3
- package/dist/schema/call/guard.d.ts +11 -11
- package/dist/schema/call/guard.js +1 -1
- package/dist/schema/call/machine.d.ts +216 -21
- package/dist/schema/call/machine.js +1 -1
- package/dist/schema/call/order.d.ts +7 -7
- package/dist/schema/call/payment.d.ts +3 -3
- package/dist/schema/call/permission.d.ts +3 -3
- package/dist/schema/call/personal.d.ts +337 -3
- package/dist/schema/call/personal.js +10 -0
- package/dist/schema/call/progress.d.ts +177 -9
- package/dist/schema/call/progress.js +7 -3
- package/dist/schema/call/proof.d.ts +6 -6
- package/dist/schema/call/repository.d.ts +3 -3
- package/dist/schema/call/reward.d.ts +57 -57
- package/dist/schema/call/semantic.js +41 -1
- package/dist/schema/call/service.d.ts +114 -114
- package/dist/schema/call/service.js +11 -2
- package/dist/schema/call/treasury.d.ts +57 -57
- package/dist/schema/messenger/index.js +4 -1
- package/dist/schema/operations.d.ts +713 -291
- package/dist/schema/operations.js +33 -0
- package/dist/schema/project/index.d.ts +4635 -100
- package/dist/schema/project/index.js +868 -1
- package/dist/schema/query/index.d.ts +363 -19
- package/dist/schema/query/index.js +25 -3
- package/dist/schema/schema-query/index.d.ts +13 -7
- package/dist/schema/schema-query/index.js +29 -5
- package/dist/schema/trust/index.d.ts +1012 -6
- package/dist/schema/trust/index.js +212 -11
- package/dist/schema/utils/skills-recommendation.js +1 -0
- package/dist/schema-query/index.d.ts +4 -1
- package/dist/schema-query/index.js +255 -1
- package/dist/schemas/bridge_operation.schema.json +14 -7
- package/dist/schemas/guard2file.schema.json +2 -0
- package/dist/schemas/index.json +1 -1
- package/dist/schemas/machineNode2file.schema.json +2 -0
- package/dist/schemas/messenger_operation.schema.json +1 -1
- package/dist/schemas/onchain_operations.schema.json +143 -15
- package/dist/schemas/onchain_operations_allocation.schema.json +2 -1
- package/dist/schemas/onchain_operations_arbitration.schema.json +7 -5
- package/dist/schemas/onchain_operations_contact.schema.json +1 -0
- package/dist/schemas/onchain_operations_demand.schema.json +1 -0
- package/dist/schemas/onchain_operations_gen_passport.schema.json +2 -0
- package/dist/schemas/onchain_operations_gen_proof.schema.json +2 -0
- package/dist/schemas/onchain_operations_guard.schema.json +578 -0
- package/dist/schemas/onchain_operations_machine.schema.json +1 -0
- package/dist/schemas/onchain_operations_order.schema.json +4 -3
- package/dist/schemas/onchain_operations_payment.schema.json +1 -0
- package/dist/schemas/onchain_operations_permission.schema.json +1 -0
- package/dist/schemas/onchain_operations_personal.schema.json +37 -0
- package/dist/schemas/onchain_operations_progress.schema.json +90 -3
- package/dist/schemas/onchain_operations_proof.schema.json +1 -0
- package/dist/schemas/onchain_operations_repository.schema.json +1 -0
- package/dist/schemas/onchain_operations_reward.schema.json +1 -0
- package/dist/schemas/onchain_operations_service.schema.json +4 -3
- package/dist/schemas/onchain_operations_treasury.schema.json +1 -0
- package/dist/schemas/project_operation.output.json +2243 -1
- package/dist/schemas/project_operation.schema.json +683 -1
- package/dist/schemas/query_toolkit.output.json +1 -1
- package/dist/schemas/query_toolkit.schema.json +37 -0
- package/dist/schemas/schema_query.output.json +1 -1
- package/dist/schemas/schema_query.schema.json +30 -5
- package/dist/schemas/trust_score.output.json +392 -1
- package/dist/schemas/trust_score.schema.json +275 -1
- package/dist/tools/handlers/onchain.js +73 -8
- package/dist/tools/handlers/project.js +46 -0
- package/dist/tools/handlers/query.js +117 -2
- package/dist/tools/handlers/schema-query.js +41 -0
- package/dist/tools/handlers/trust.js +192 -6
- package/dist/tools/index.js +52 -9
- package/dist/tools/wrap.js +194 -15
- package/package.json +2 -2
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { getIndustryModeRegistry, getMetricRegistry, getConstraintRegistry, } from "../extensions/index.js";
|
|
2
|
+
import { inferTraitsFromDescription, findSimilarIndustries, } from "../knowledge/industry-generalizer.js";
|
|
3
|
+
import { searchExamples } from "../schema-query/index.js";
|
|
4
|
+
const LOCAL_MODE_OWNER = "local";
|
|
5
|
+
const RM1_11_NODE_REGEX = /(^|_)(disputed?|refund(?:ed)?|arbitration|arb)(_|$)/i;
|
|
6
|
+
function validateMachineShape(machineShape, fieldName) {
|
|
7
|
+
const violations = [];
|
|
8
|
+
if (!Array.isArray(machineShape))
|
|
9
|
+
return violations;
|
|
10
|
+
const seen = new Set();
|
|
11
|
+
for (const node of machineShape) {
|
|
12
|
+
const name = node?.name;
|
|
13
|
+
if (typeof name !== "string" || !name) {
|
|
14
|
+
violations.push(`${fieldName}: every node must have a non-empty string 'name'`);
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (seen.has(name)) {
|
|
18
|
+
violations.push(`${fieldName}: duplicate node name '${name}' (R-M1-10)`);
|
|
19
|
+
}
|
|
20
|
+
seen.add(name);
|
|
21
|
+
if (RM1_11_NODE_REGEX.test(name)) {
|
|
22
|
+
violations.push(`${fieldName}: node '${name}' violates R-M1-11 — dispute/refund flows must NOT be ` +
|
|
23
|
+
`modeled as Machine nodes. Disputes flow through Service.arbitrations → Arbitration.dispute() ` +
|
|
24
|
+
`independently of the Machine. Use business-state nodes (e.g. 'cancelled', 'return_approved') ` +
|
|
25
|
+
`and route fund refunds via Allocator triggered by those states.`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return violations;
|
|
29
|
+
}
|
|
30
|
+
export function handleRecommendIndustry(v) {
|
|
31
|
+
const intent = (v.intent ?? v.project_description ?? v.project_name ?? "").trim();
|
|
32
|
+
if (!intent) {
|
|
33
|
+
throw new Error("recommend_industry requires 'intent' (business description text). " +
|
|
34
|
+
"Example: intent='I rent cameras to photographers with deposit and damage inspection'.");
|
|
35
|
+
}
|
|
36
|
+
const inference = inferTraitsFromDescription(intent);
|
|
37
|
+
const matches = findSimilarIndustries(inference.traits, 3);
|
|
38
|
+
const recommendations = matches.map((m) => {
|
|
39
|
+
const examples = searchExamples(m.industry).slice(0, 3).map((e) => ({
|
|
40
|
+
file: e.file,
|
|
41
|
+
title: e.title,
|
|
42
|
+
operation_type: e.operation_type,
|
|
43
|
+
verified: e.verified,
|
|
44
|
+
}));
|
|
45
|
+
return {
|
|
46
|
+
industry: m.industry,
|
|
47
|
+
similarity: m.similarity,
|
|
48
|
+
matched_traits: m.matched_traits,
|
|
49
|
+
reference_examples: examples,
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
const top = recommendations[0];
|
|
53
|
+
return {
|
|
54
|
+
action: "recommend_industry",
|
|
55
|
+
intent,
|
|
56
|
+
inferred_traits: inference.traits,
|
|
57
|
+
inference_confidence: inference.confidence,
|
|
58
|
+
matched_keywords: inference.matched_keywords,
|
|
59
|
+
recommendations,
|
|
60
|
+
hint: top
|
|
61
|
+
? `Top match: '${top.industry}' (similarity ${(top.similarity * 100).toFixed(0)}%). ` +
|
|
62
|
+
`Create the project with project_operation action='create_project' project_industry='${top.industry}' ` +
|
|
63
|
+
`to get a ready-made blueprint (~10 draft objects + graph edges), or choose another industry from ` +
|
|
64
|
+
`'recommendations', or use project_industry='custom' with skip_templates=true to build from scratch. ` +
|
|
65
|
+
`Review reference examples via schema_query action='search_examples' query='<industry>'.`
|
|
66
|
+
: "No similar industry found. Use project_industry='custom' with skip_templates=true to build from scratch.",
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export async function handleListModes() {
|
|
70
|
+
const registry = getIndustryModeRegistry();
|
|
71
|
+
const builtin = registry.listModes()
|
|
72
|
+
.filter((m) => m.source === "builtin")
|
|
73
|
+
.map((m) => ({
|
|
74
|
+
name: m.name,
|
|
75
|
+
display_name: m.display_name,
|
|
76
|
+
version: m.version,
|
|
77
|
+
key_risk: m.key_risk,
|
|
78
|
+
machine_nodes: m.machine_shape.map((n) => n.name),
|
|
79
|
+
similar_industries: m.similar_industries ?? [],
|
|
80
|
+
}));
|
|
81
|
+
const userModes = (await registry.listUserModes(LOCAL_MODE_OWNER)).map((m) => ({
|
|
82
|
+
name: m.name,
|
|
83
|
+
display_name: m.display_name,
|
|
84
|
+
version: m.version,
|
|
85
|
+
derived_from: m.derived_from ?? null,
|
|
86
|
+
key_risk: m.key_risk,
|
|
87
|
+
machine_nodes: m.machine_shape.map((n) => n.name),
|
|
88
|
+
evolution_history: (m.evolution_history ?? []).map((h) => ({
|
|
89
|
+
version: h.version,
|
|
90
|
+
changed_at: h.changed_at,
|
|
91
|
+
changes: h.changes,
|
|
92
|
+
})),
|
|
93
|
+
}));
|
|
94
|
+
return {
|
|
95
|
+
action: "list_modes",
|
|
96
|
+
builtin_modes: builtin,
|
|
97
|
+
user_modes: userModes,
|
|
98
|
+
owner: LOCAL_MODE_OWNER,
|
|
99
|
+
hint: "Use a builtin mode name as project_industry in create_project. " +
|
|
100
|
+
"Use derive_user_mode to customize a builtin mode, or register_user_mode for a fully custom mode. " +
|
|
101
|
+
"User modes are referenced as '<name>' in derive/evolve/unregister actions.",
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export async function handleDeriveUserMode(v) {
|
|
105
|
+
const source = requireField(v.mode_source, "mode_source");
|
|
106
|
+
const newName = requireField(v.mode_name, "mode_name");
|
|
107
|
+
const changes = v.mode_changes ?? {};
|
|
108
|
+
const violations = validateMachineShape(changes.machine_shape, "mode_changes.machine_shape");
|
|
109
|
+
if (violations.length > 0) {
|
|
110
|
+
throw new Error(`derive_user_mode blocked:\n${violations.join("\n")}`);
|
|
111
|
+
}
|
|
112
|
+
const registry = getIndustryModeRegistry();
|
|
113
|
+
const derived = await registry.deriveMode(source, changes, LOCAL_MODE_OWNER, newName, v.mode_display_name);
|
|
114
|
+
if (!derived) {
|
|
115
|
+
throw new Error(`derive_user_mode failed: source mode '${source}' not found, or name '${newName}' conflicts ` +
|
|
116
|
+
`with a builtin/existing user mode. Call list_modes to see available names.`);
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
action: "derive_user_mode",
|
|
120
|
+
mode: summarizeUserMode(derived),
|
|
121
|
+
hint: `Mode '${newName}' derived from '${source}'. Use it as project_industry in create_project ` +
|
|
122
|
+
`(applyTemplate resolves user modes via 'local:${newName}'). Iterate with evolve_user_mode.`,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export async function handleEvolveUserMode(v) {
|
|
126
|
+
const name = requireField(v.mode_name, "mode_name");
|
|
127
|
+
const description = requireField(v.mode_change_description, "mode_change_description");
|
|
128
|
+
const changes = v.mode_changes ?? {};
|
|
129
|
+
const violations = validateMachineShape(changes.machine_shape, "mode_changes.machine_shape");
|
|
130
|
+
if (violations.length > 0) {
|
|
131
|
+
throw new Error(`evolve_user_mode blocked:\n${violations.join("\n")}`);
|
|
132
|
+
}
|
|
133
|
+
const registry = getIndustryModeRegistry();
|
|
134
|
+
const evolved = await registry.evolveMode(name, changes, LOCAL_MODE_OWNER, description, v.mode_bump_version ?? true);
|
|
135
|
+
if (!evolved) {
|
|
136
|
+
throw new Error(`evolve_user_mode failed: user mode '${name}' not found for owner '${LOCAL_MODE_OWNER}'. ` +
|
|
137
|
+
`Call list_modes to see your modes.`);
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
action: "evolve_user_mode",
|
|
141
|
+
mode: summarizeUserMode(evolved),
|
|
142
|
+
hint: `Mode '${name}' evolved to ${evolved.version}. Evolution history recorded.`,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
export async function handleRegisterUserMode(v) {
|
|
146
|
+
const name = requireField(v.mode_name, "mode_name");
|
|
147
|
+
const payload = v.mode_changes ?? {};
|
|
148
|
+
const missing = [];
|
|
149
|
+
if (!Array.isArray(payload.machine_shape) || payload.machine_shape.length === 0) {
|
|
150
|
+
missing.push("machine_shape (non-empty array of {name, role})");
|
|
151
|
+
}
|
|
152
|
+
if (typeof payload.key_risk !== "string" || !payload.key_risk) {
|
|
153
|
+
missing.push("key_risk (string describing the industry's key risk)");
|
|
154
|
+
}
|
|
155
|
+
if (missing.length > 0) {
|
|
156
|
+
throw new Error(`register_user_mode requires these fields in mode_changes: ${missing.join(", ")}. ` +
|
|
157
|
+
`Tip: derive_user_mode from a builtin mode is usually easier than registering from scratch.`);
|
|
158
|
+
}
|
|
159
|
+
const violations = validateMachineShape(payload.machine_shape, "mode_changes.machine_shape");
|
|
160
|
+
if (violations.length > 0) {
|
|
161
|
+
throw new Error(`register_user_mode blocked:\n${violations.join("\n")}`);
|
|
162
|
+
}
|
|
163
|
+
const registry = getIndustryModeRegistry();
|
|
164
|
+
const general = registry.getMode("general");
|
|
165
|
+
if (!general)
|
|
166
|
+
throw new Error("Builtin mode 'general' not registered — cannot build custom mode defaults");
|
|
167
|
+
const mode = {
|
|
168
|
+
...general,
|
|
169
|
+
...payload,
|
|
170
|
+
name,
|
|
171
|
+
display_name: v.mode_display_name ?? name,
|
|
172
|
+
version: "v1",
|
|
173
|
+
source: "custom",
|
|
174
|
+
owner: LOCAL_MODE_OWNER,
|
|
175
|
+
derived_from: undefined,
|
|
176
|
+
evolution_history: [],
|
|
177
|
+
};
|
|
178
|
+
const ok = await registry.registerUserMode(mode, LOCAL_MODE_OWNER);
|
|
179
|
+
if (!ok) {
|
|
180
|
+
throw new Error(`register_user_mode failed: name '${name}' conflicts with a builtin/existing user mode, ` +
|
|
181
|
+
`or payload is invalid. Call list_modes to see available names.`);
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
action: "register_user_mode",
|
|
185
|
+
mode: summarizeUserMode(mode),
|
|
186
|
+
hint: `Custom mode '${name}' registered. Use it as project_industry in create_project.`,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
export async function handleUnregisterUserMode(v) {
|
|
190
|
+
const name = requireField(v.mode_name, "mode_name");
|
|
191
|
+
const registry = getIndustryModeRegistry();
|
|
192
|
+
const ok = await registry.unregisterUserMode(name, LOCAL_MODE_OWNER);
|
|
193
|
+
if (!ok) {
|
|
194
|
+
throw new Error(`unregister_user_mode failed: user mode '${name}' not found for owner '${LOCAL_MODE_OWNER}'.`);
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
action: "unregister_user_mode",
|
|
198
|
+
removed: true,
|
|
199
|
+
mode_name: name,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
export function handleRegisterCustomMetric(v) {
|
|
203
|
+
const id = requireField(v.metric_id, "metric_id");
|
|
204
|
+
const displayName = requireField(v.metric_display_name, "metric_display_name");
|
|
205
|
+
const description = requireField(v.metric_description, "metric_description");
|
|
206
|
+
const type = requireField(v.metric_type, "metric_type");
|
|
207
|
+
const scale = requireField(v.metric_scale, "metric_scale");
|
|
208
|
+
const ok = getMetricRegistry().registerCustomMetric(id, displayName, description, type, scale, LOCAL_MODE_OWNER, v.metric_weight);
|
|
209
|
+
if (!ok) {
|
|
210
|
+
throw new Error(`register_custom_metric failed: metric_id '${id}' already exists or fields are invalid.`);
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
action: "register_custom_metric",
|
|
214
|
+
metric: {
|
|
215
|
+
metric_id: id,
|
|
216
|
+
display_name: displayName,
|
|
217
|
+
description,
|
|
218
|
+
type,
|
|
219
|
+
scale,
|
|
220
|
+
weight: v.metric_weight ?? 1.0,
|
|
221
|
+
scope: "custom",
|
|
222
|
+
owner: LOCAL_MODE_OWNER,
|
|
223
|
+
},
|
|
224
|
+
hint: `Custom metric '${id}' registered globally — all modes can reference it via custom_metrics.`,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
export function handleRegisterCustomConstraint(v) {
|
|
228
|
+
const id = requireField(v.constraint_id, "constraint_id");
|
|
229
|
+
const displayName = requireField(v.constraint_display_name, "constraint_display_name");
|
|
230
|
+
const description = requireField(v.constraint_description, "constraint_description");
|
|
231
|
+
const rule = v.constraint_rule;
|
|
232
|
+
if (!rule || typeof rule !== "object" || !("type" in rule)) {
|
|
233
|
+
throw new Error("constraint_rule is required and must be one of: " +
|
|
234
|
+
"{type:'capability_required', capability_id} | {type:'capability_forbidden', capability_id} | " +
|
|
235
|
+
"{type:'numeric_limit', field, max?, min?} | {type:'condition_required', condition, ai_evaluated:true}");
|
|
236
|
+
}
|
|
237
|
+
const ok = getConstraintRegistry().registerCustomConstraint(id, displayName, description, rule, LOCAL_MODE_OWNER, v.constraint_severity ?? "soft", v.constraint_on_violation ?? "warn");
|
|
238
|
+
if (!ok) {
|
|
239
|
+
throw new Error(`register_custom_constraint failed: constraint_id '${id}' already exists or rule is invalid.`);
|
|
240
|
+
}
|
|
241
|
+
return {
|
|
242
|
+
action: "register_custom_constraint",
|
|
243
|
+
constraint: {
|
|
244
|
+
constraint_id: id,
|
|
245
|
+
display_name: displayName,
|
|
246
|
+
description,
|
|
247
|
+
rule,
|
|
248
|
+
severity: v.constraint_severity ?? "soft",
|
|
249
|
+
on_violation: v.constraint_on_violation ?? "warn",
|
|
250
|
+
scope: "custom",
|
|
251
|
+
owner: LOCAL_MODE_OWNER,
|
|
252
|
+
},
|
|
253
|
+
hint: `Custom constraint '${id}' registered. 'hard' constraints block applyTemplate on violation; 'soft' only warn.`,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
export function handleListMetricsConstraints(v) {
|
|
257
|
+
const metrics = getMetricRegistry().listMetrics({
|
|
258
|
+
type: v.metric_type_filter,
|
|
259
|
+
scope: v.scope_filter,
|
|
260
|
+
}).map((m) => ({
|
|
261
|
+
metric_id: m.metric_id,
|
|
262
|
+
display_name: m.display_name,
|
|
263
|
+
description: m.description,
|
|
264
|
+
type: m.type,
|
|
265
|
+
scale: m.scale,
|
|
266
|
+
weight: m.weight,
|
|
267
|
+
scope: m.scope,
|
|
268
|
+
}));
|
|
269
|
+
const constraints = getConstraintRegistry().listConstraints({
|
|
270
|
+
scope: v.scope_filter,
|
|
271
|
+
}).map((c) => ({
|
|
272
|
+
constraint_id: c.constraint_id,
|
|
273
|
+
display_name: c.display_name,
|
|
274
|
+
description: c.description,
|
|
275
|
+
rule: c.rule,
|
|
276
|
+
severity: c.severity,
|
|
277
|
+
on_violation: c.on_violation,
|
|
278
|
+
scope: c.scope,
|
|
279
|
+
}));
|
|
280
|
+
return {
|
|
281
|
+
action: "list_metrics_constraints",
|
|
282
|
+
metrics,
|
|
283
|
+
constraints,
|
|
284
|
+
hint: "Register custom entries via register_custom_metric / register_custom_constraint. " +
|
|
285
|
+
"Filter with metric_type_filter ('risk'|'benefit') or scope_filter ('builtin'|'custom').",
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
function requireField(value, fieldName) {
|
|
289
|
+
if (value === undefined || value === null || (typeof value === "string" && !value.trim())) {
|
|
290
|
+
throw new Error(`'${fieldName}' is required for this action`);
|
|
291
|
+
}
|
|
292
|
+
return value;
|
|
293
|
+
}
|
|
294
|
+
function summarizeUserMode(m) {
|
|
295
|
+
return {
|
|
296
|
+
name: m.name,
|
|
297
|
+
display_name: m.display_name,
|
|
298
|
+
version: m.version,
|
|
299
|
+
derived_from: m.derived_from ?? null,
|
|
300
|
+
owner: m.owner,
|
|
301
|
+
key_risk: m.key_risk,
|
|
302
|
+
machine_nodes: m.machine_shape.map((n) => n.name),
|
|
303
|
+
evolution_history: (m.evolution_history ?? []).map((h) => ({
|
|
304
|
+
version: h.version,
|
|
305
|
+
changed_at: h.changed_at,
|
|
306
|
+
changes: h.changes,
|
|
307
|
+
})),
|
|
308
|
+
};
|
|
309
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import { type OrderRadarResult } from "../participation/radar-core.js";
|
|
3
|
+
import type { ProjectOperationInputSchema } from "../schema/project/index.js";
|
|
4
|
+
type ProjectInput = z.infer<typeof ProjectOperationInputSchema>;
|
|
5
|
+
export declare function handleParticipationRadar(v: ProjectInput): Promise<{
|
|
6
|
+
action: "participation_radar";
|
|
7
|
+
account: string;
|
|
8
|
+
orders_analyzed: number;
|
|
9
|
+
actionable: OrderRadarResult[];
|
|
10
|
+
waiting: OrderRadarResult[];
|
|
11
|
+
all_pending_claims: (import("../participation/radar-core.js").PendingClaim & {
|
|
12
|
+
progress: string;
|
|
13
|
+
})[];
|
|
14
|
+
unread_messages_total: number;
|
|
15
|
+
data_gaps: string[];
|
|
16
|
+
summary: string;
|
|
17
|
+
}>;
|
|
18
|
+
export {};
|