@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.
- 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/harness/checkpoint.d.ts +8 -0
- package/dist/harness/checkpoint.js +129 -0
- package/dist/harness/index.d.ts +33 -0
- package/dist/harness/index.js +75 -0
- package/dist/harness/plan.d.ts +18 -0
- package/dist/harness/plan.js +252 -0
- package/dist/harness/recover.d.ts +17 -0
- package/dist/harness/recover.js +139 -0
- package/dist/harness/types.d.ts +137 -0
- package/dist/harness/types.js +1 -0
- package/dist/harness/verify.d.ts +42 -0
- package/dist/harness/verify.js +237 -0
- package/dist/index.js +667 -201
- 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/aggregate.d.ts +50 -0
- package/dist/loop-engineering/aggregate.js +132 -0
- package/dist/loop-engineering/diagnose.d.ts +22 -0
- package/dist/loop-engineering/diagnose.js +273 -0
- package/dist/loop-engineering/improve.d.ts +26 -0
- package/dist/loop-engineering/improve.js +229 -0
- package/dist/loop-engineering/index.d.ts +4 -0
- package/dist/loop-engineering/index.js +4 -0
- package/dist/loop-engineering/pipeline.d.ts +17 -0
- package/dist/loop-engineering/pipeline.js +56 -0
- package/dist/mode-market/index.d.ts +3 -0
- package/dist/mode-market/index.js +3 -0
- package/dist/mode-market/registry.d.ts +53 -0
- package/dist/mode-market/registry.js +124 -0
- package/dist/mode-market/review.d.ts +27 -0
- package/dist/mode-market/review.js +214 -0
- package/dist/mode-market/submission.d.ts +25 -0
- package/dist/mode-market/submission.js +85 -0
- 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 +55 -40
- package/dist/schema/call/arbitration.d.ts +201 -186
- package/dist/schema/call/base.d.ts +2104 -24
- package/dist/schema/call/base.js +168 -22
- package/dist/schema/call/bridge-handler.js +36 -18
- package/dist/schema/call/bridge.d.ts +777 -120
- 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 +5 -1
- package/dist/schema/call/handler.js +108 -3
- package/dist/schema/call/index.d.ts +1 -0
- package/dist/schema/call/index.js +1 -0
- package/dist/schema/call/machine.d.ts +830 -800
- package/dist/schema/call/order.d.ts +27 -12
- 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 +21 -6
- 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 +51 -36
- package/dist/schema/call/semantic.d.ts +24 -0
- package/dist/schema/call/semantic.js +981 -0
- package/dist/schema/call/service.d.ts +444 -429
- package/dist/schema/call/treasury.d.ts +219 -204
- package/dist/schema/common/index.js +3 -3
- package/dist/schema/local/index.d.ts +341 -74
- package/dist/schema/local/index.js +44 -7
- package/dist/schema/messenger/index.d.ts +1034 -92
- package/dist/schema/messenger/index.js +18 -0
- package/dist/schema/operations.d.ts +2634 -1817
- package/dist/schema/operations.js +16 -5
- package/dist/schema/query/index.d.ts +2293 -2289
- package/dist/schema/query/index.js +34 -28
- package/dist/schemas/account_operation.output.json +28 -16
- package/dist/schemas/account_operation.schema.json +2 -2
- 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 +26 -0
- package/dist/schemas/local_info_operation.schema.json +1 -1
- package/dist/schemas/local_mark_operation.output.json +27 -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 +549 -0
- package/dist/schemas/messenger_operation.schema.json +21 -0
- package/dist/schemas/onchain_events.output.json +3 -0
- package/dist/schemas/onchain_operations.output.json +814 -37
- package/dist/schemas/onchain_operations.schema.json +117 -40
- package/dist/schemas/onchain_operations_allocation.schema.json +26 -9
- package/dist/schemas/onchain_operations_arbitration.schema.json +26 -9
- package/dist/schemas/onchain_operations_contact.schema.json +26 -9
- package/dist/schemas/onchain_operations_demand.schema.json +26 -9
- package/dist/schemas/onchain_operations_gen_passport.schema.json +51 -17
- package/dist/schemas/onchain_operations_guard.schema.json +26 -9
- package/dist/schemas/onchain_operations_machine.schema.json +92 -32
- package/dist/schemas/onchain_operations_order.schema.json +26 -9
- package/dist/schemas/onchain_operations_payment.schema.json +26 -9
- package/dist/schemas/onchain_operations_permission.schema.json +26 -9
- package/dist/schemas/onchain_operations_personal.schema.json +26 -9
- package/dist/schemas/onchain_operations_progress.schema.json +26 -9
- package/dist/schemas/onchain_operations_repository.schema.json +26 -9
- package/dist/schemas/onchain_operations_reward.schema.json +26 -9
- package/dist/schemas/onchain_operations_service.schema.json +26 -9
- package/dist/schemas/onchain_operations_treasury.schema.json +26 -9
- package/dist/schemas/onchain_table_data.output.json +224 -69
- package/dist/schemas/onchain_table_data.schema.json +2 -2
- package/dist/schemas/query_toolkit.schema.json +5 -1
- package/dist/telemetry/index.d.ts +19 -0
- package/dist/telemetry/index.js +112 -0
- package/dist/telemetry/redact.d.ts +2 -0
- package/dist/telemetry/redact.js +23 -0
- package/dist/telemetry/storage.d.ts +8 -0
- package/dist/telemetry/storage.js +80 -0
- package/package.json +6 -3
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
export class ProjectGraph {
|
|
2
|
+
nodes = new Map();
|
|
3
|
+
edges = [];
|
|
4
|
+
outEdges = new Map();
|
|
5
|
+
inEdges = new Map();
|
|
6
|
+
cycles = [];
|
|
7
|
+
updatedAt = Date.now();
|
|
8
|
+
upsertNode(node) {
|
|
9
|
+
const existing = this.nodes.get(node.id);
|
|
10
|
+
if (existing) {
|
|
11
|
+
this.nodes.set(node.id, {
|
|
12
|
+
...existing,
|
|
13
|
+
...node,
|
|
14
|
+
project: node.project ?? existing.project,
|
|
15
|
+
type: node.type ?? existing.type,
|
|
16
|
+
address: node.address ?? existing.address,
|
|
17
|
+
});
|
|
18
|
+
return this.nodes.get(node.id);
|
|
19
|
+
}
|
|
20
|
+
this.nodes.set(node.id, { ...node });
|
|
21
|
+
return node;
|
|
22
|
+
}
|
|
23
|
+
addEdge(from, to, kind) {
|
|
24
|
+
if (from === to)
|
|
25
|
+
return;
|
|
26
|
+
if (!this.nodes.has(from))
|
|
27
|
+
this.upsertNode({ id: from });
|
|
28
|
+
if (!this.nodes.has(to))
|
|
29
|
+
this.upsertNode({ id: to });
|
|
30
|
+
const dup = this.edges.some((e) => e.from === from && e.to === to && e.kind === kind);
|
|
31
|
+
if (dup)
|
|
32
|
+
return;
|
|
33
|
+
const idx = this.edges.length;
|
|
34
|
+
this.edges.push({ from, to, kind });
|
|
35
|
+
if (!this.outEdges.has(from))
|
|
36
|
+
this.outEdges.set(from, new Set());
|
|
37
|
+
this.outEdges.get(from).add(idx);
|
|
38
|
+
if (!this.inEdges.has(to))
|
|
39
|
+
this.inEdges.set(to, new Set());
|
|
40
|
+
this.inEdges.get(to).add(idx);
|
|
41
|
+
this.updatedAt = Date.now();
|
|
42
|
+
}
|
|
43
|
+
removeNode(id) {
|
|
44
|
+
if (!this.nodes.has(id))
|
|
45
|
+
return;
|
|
46
|
+
this.nodes.delete(id);
|
|
47
|
+
const outSet = this.outEdges.get(id);
|
|
48
|
+
const inSet = this.inEdges.get(id);
|
|
49
|
+
const indicesToRemove = new Set([
|
|
50
|
+
...(outSet ?? []),
|
|
51
|
+
...(inSet ?? []),
|
|
52
|
+
]);
|
|
53
|
+
const newEdges = [];
|
|
54
|
+
const indexMap = new Map();
|
|
55
|
+
for (let i = 0; i < this.edges.length; i++) {
|
|
56
|
+
if (indicesToRemove.has(i))
|
|
57
|
+
continue;
|
|
58
|
+
indexMap.set(i, newEdges.length);
|
|
59
|
+
newEdges.push(this.edges[i]);
|
|
60
|
+
}
|
|
61
|
+
this.edges = newEdges;
|
|
62
|
+
this.outEdges.clear();
|
|
63
|
+
this.inEdges.clear();
|
|
64
|
+
for (let i = 0; i < this.edges.length; i++) {
|
|
65
|
+
const e = this.edges[i];
|
|
66
|
+
if (!this.outEdges.has(e.from))
|
|
67
|
+
this.outEdges.set(e.from, new Set());
|
|
68
|
+
this.outEdges.get(e.from).add(i);
|
|
69
|
+
if (!this.inEdges.has(e.to))
|
|
70
|
+
this.inEdges.set(e.to, new Set());
|
|
71
|
+
this.inEdges.get(e.to).add(i);
|
|
72
|
+
}
|
|
73
|
+
this.updatedAt = Date.now();
|
|
74
|
+
}
|
|
75
|
+
getNode(id) {
|
|
76
|
+
return this.nodes.get(id);
|
|
77
|
+
}
|
|
78
|
+
listNodes(projectPrefix) {
|
|
79
|
+
const all = Array.from(this.nodes.values());
|
|
80
|
+
if (!projectPrefix)
|
|
81
|
+
return all;
|
|
82
|
+
return all.filter((n) => n.project === projectPrefix);
|
|
83
|
+
}
|
|
84
|
+
getDependencies(id) {
|
|
85
|
+
const idxs = this.outEdges.get(id);
|
|
86
|
+
if (!idxs)
|
|
87
|
+
return [];
|
|
88
|
+
return Array.from(idxs).map((i) => this.edges[i]);
|
|
89
|
+
}
|
|
90
|
+
getReferencedBy(id) {
|
|
91
|
+
const idxs = this.inEdges.get(id);
|
|
92
|
+
if (!idxs)
|
|
93
|
+
return [];
|
|
94
|
+
return Array.from(idxs).map((i) => this.edges[i]);
|
|
95
|
+
}
|
|
96
|
+
detectCycles() {
|
|
97
|
+
const WHITE = 0, GRAY = 1, BLACK = 2;
|
|
98
|
+
const color = new Map();
|
|
99
|
+
for (const id of this.nodes.keys())
|
|
100
|
+
color.set(id, WHITE);
|
|
101
|
+
const cycles = [];
|
|
102
|
+
const stack = [];
|
|
103
|
+
const dfs = (u) => {
|
|
104
|
+
color.set(u, GRAY);
|
|
105
|
+
stack.push(u);
|
|
106
|
+
const outIdxs = this.outEdges.get(u);
|
|
107
|
+
if (outIdxs) {
|
|
108
|
+
for (const i of outIdxs) {
|
|
109
|
+
const v = this.edges[i].to;
|
|
110
|
+
if (color.get(v) === GRAY) {
|
|
111
|
+
const start = stack.indexOf(v);
|
|
112
|
+
if (start >= 0) {
|
|
113
|
+
cycles.push(stack.slice(start).concat(v));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else if (color.get(v) === WHITE) {
|
|
117
|
+
dfs(v);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
stack.pop();
|
|
122
|
+
color.set(u, BLACK);
|
|
123
|
+
};
|
|
124
|
+
for (const id of this.nodes.keys()) {
|
|
125
|
+
if (color.get(id) === WHITE)
|
|
126
|
+
dfs(id);
|
|
127
|
+
}
|
|
128
|
+
this.cycles = cycles;
|
|
129
|
+
return cycles;
|
|
130
|
+
}
|
|
131
|
+
findDanglingDependencies() {
|
|
132
|
+
const result = [];
|
|
133
|
+
for (const [id, node] of this.nodes) {
|
|
134
|
+
const deps = this.getDependencies(id);
|
|
135
|
+
const missing = deps
|
|
136
|
+
.map((e) => this.nodes.get(e.to))
|
|
137
|
+
.filter((n) => !!n)
|
|
138
|
+
.filter((n) => !n.address && !n.project)
|
|
139
|
+
.map((n) => n.id);
|
|
140
|
+
if (missing.length > 0) {
|
|
141
|
+
result.push({ from: id, missing: Array.from(new Set(missing)) });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
snapshot() {
|
|
147
|
+
return {
|
|
148
|
+
nodes: Object.fromEntries(this.nodes),
|
|
149
|
+
edges: this.edges,
|
|
150
|
+
cycles: this.cycles,
|
|
151
|
+
version: 1,
|
|
152
|
+
updatedAt: this.updatedAt,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
restore(snap) {
|
|
156
|
+
this.nodes.clear();
|
|
157
|
+
this.edges = [];
|
|
158
|
+
this.outEdges.clear();
|
|
159
|
+
this.inEdges.clear();
|
|
160
|
+
for (const [id, node] of Object.entries(snap.nodes)) {
|
|
161
|
+
this.nodes.set(id, { ...node });
|
|
162
|
+
}
|
|
163
|
+
for (const e of snap.edges) {
|
|
164
|
+
this.addEdge(e.from, e.to, e.kind);
|
|
165
|
+
}
|
|
166
|
+
this.cycles = snap.cycles ?? [];
|
|
167
|
+
this.updatedAt = snap.updatedAt ?? Date.now();
|
|
168
|
+
}
|
|
169
|
+
clear() {
|
|
170
|
+
this.nodes.clear();
|
|
171
|
+
this.edges = [];
|
|
172
|
+
this.outEdges.clear();
|
|
173
|
+
this.inEdges.clear();
|
|
174
|
+
this.cycles = [];
|
|
175
|
+
this.updatedAt = Date.now();
|
|
176
|
+
}
|
|
177
|
+
get nodeCount() { return this.nodes.size; }
|
|
178
|
+
get edgeCount() { return this.edges.length; }
|
|
179
|
+
getEdges() {
|
|
180
|
+
return this.edges;
|
|
181
|
+
}
|
|
182
|
+
attachDecisionContext(nodeId, ctx) {
|
|
183
|
+
if (!nodeId)
|
|
184
|
+
return undefined;
|
|
185
|
+
const node = this.nodes.get(nodeId) ?? this.upsertNode({ id: nodeId });
|
|
186
|
+
const fullCtx = {
|
|
187
|
+
id: ctx.id ?? `${nodeId}_${Date.now()}`,
|
|
188
|
+
decided_at: ctx.decided_at ?? Date.now(),
|
|
189
|
+
decider: ctx.decider,
|
|
190
|
+
industry: ctx.industry,
|
|
191
|
+
intent: ctx.intent,
|
|
192
|
+
alternatives: ctx.alternatives,
|
|
193
|
+
rationale: ctx.rationale,
|
|
194
|
+
outcome: ctx.outcome,
|
|
195
|
+
};
|
|
196
|
+
if (!node.decision_contexts)
|
|
197
|
+
node.decision_contexts = [];
|
|
198
|
+
node.decision_contexts.push(fullCtx);
|
|
199
|
+
this.updatedAt = Date.now();
|
|
200
|
+
return fullCtx;
|
|
201
|
+
}
|
|
202
|
+
getDecisionContexts(nodeId) {
|
|
203
|
+
return this.nodes.get(nodeId)?.decision_contexts ?? [];
|
|
204
|
+
}
|
|
205
|
+
queryDecisionContextsByIndustry(industry) {
|
|
206
|
+
const results = [];
|
|
207
|
+
for (const [id, node] of this.nodes) {
|
|
208
|
+
if (!node.decision_contexts)
|
|
209
|
+
continue;
|
|
210
|
+
for (const ctx of node.decision_contexts) {
|
|
211
|
+
if (ctx.industry === industry) {
|
|
212
|
+
results.push({ node_id: id, ctx });
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
results.sort((a, b) => b.ctx.decided_at - a.ctx.decided_at);
|
|
217
|
+
return results;
|
|
218
|
+
}
|
|
219
|
+
backfillDecisionOutcome(decisionId, outcome) {
|
|
220
|
+
for (const node of this.nodes.values()) {
|
|
221
|
+
if (!node.decision_contexts)
|
|
222
|
+
continue;
|
|
223
|
+
const ctx = node.decision_contexts.find((c) => c.id === decisionId);
|
|
224
|
+
if (ctx) {
|
|
225
|
+
ctx.outcome = outcome;
|
|
226
|
+
this.updatedAt = Date.now();
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
export function extractReferences(operation_type, data) {
|
|
234
|
+
const refs = [];
|
|
235
|
+
if (!data || typeof data !== "object")
|
|
236
|
+
return refs;
|
|
237
|
+
const pushRef = (field, val, kind) => {
|
|
238
|
+
if (!val)
|
|
239
|
+
return;
|
|
240
|
+
if (typeof val === "string") {
|
|
241
|
+
if (val.trim())
|
|
242
|
+
refs.push({ field, target: val.trim(), kind });
|
|
243
|
+
}
|
|
244
|
+
else if (Array.isArray(val)) {
|
|
245
|
+
for (const v of val)
|
|
246
|
+
pushRef(field, v, kind);
|
|
247
|
+
}
|
|
248
|
+
else if (typeof val === "object") {
|
|
249
|
+
const name = val.name_or_address ?? val.name ?? val.address;
|
|
250
|
+
if (typeof name === "string" && name.trim()) {
|
|
251
|
+
refs.push({ field, target: name.trim(), kind });
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
if (operation_type === "service") {
|
|
256
|
+
pushRef("machine", data.machine, "machine");
|
|
257
|
+
pushRef("order_allocators", data.order_allocators, "order_allocators");
|
|
258
|
+
pushRef("arbitrations", data.arbitrations, "arbitrations");
|
|
259
|
+
pushRef("compensation_fund", data.compensation_fund, "compensation_fund");
|
|
260
|
+
pushRef("rewards", data.rewards, "rewards");
|
|
261
|
+
pushRef("buy_guard", data.buy_guard, "buy_guard");
|
|
262
|
+
pushRef("permission", data.permission, "permission");
|
|
263
|
+
}
|
|
264
|
+
if (operation_type === "order") {
|
|
265
|
+
pushRef("service", data.service, "service");
|
|
266
|
+
pushRef("progress", data.progress, "progress");
|
|
267
|
+
pushRef("arbitration", data.arbitration, "arbitration");
|
|
268
|
+
}
|
|
269
|
+
if (operation_type === "machine" && Array.isArray(data.node?.nodes)) {
|
|
270
|
+
for (const n of data.node.nodes) {
|
|
271
|
+
if (!n || typeof n !== "object")
|
|
272
|
+
continue;
|
|
273
|
+
const nodeName = n.name;
|
|
274
|
+
if (typeof nodeName !== "string")
|
|
275
|
+
continue;
|
|
276
|
+
if (Array.isArray(n.pairs)) {
|
|
277
|
+
for (const p of n.pairs) {
|
|
278
|
+
if (p && typeof p === "object") {
|
|
279
|
+
if (typeof p.prev === "string") {
|
|
280
|
+
refs.push({ field: `node.${nodeName}.prev`, target: p.prev, kind: "prev" });
|
|
281
|
+
}
|
|
282
|
+
if (typeof p.next === "string") {
|
|
283
|
+
refs.push({ field: `node.${nodeName}.next`, target: p.next, kind: "next" });
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (Array.isArray(n.forward)) {
|
|
289
|
+
for (const f of n.forward) {
|
|
290
|
+
if (f && typeof f === "object" && typeof f.next === "string") {
|
|
291
|
+
refs.push({ field: `node.${nodeName}.forward`, target: f.next, kind: "forward" });
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (operation_type === "progress" && data.parent) {
|
|
298
|
+
pushRef("parent", data.parent, "parent");
|
|
299
|
+
}
|
|
300
|
+
if (data.permission)
|
|
301
|
+
pushRef("permission", data.permission, "permission");
|
|
302
|
+
if (data.guard)
|
|
303
|
+
pushRef("guard", data.guard, "guard");
|
|
304
|
+
if (data.buy_guard)
|
|
305
|
+
pushRef("buy_guard", data.buy_guard, "buy_guard");
|
|
306
|
+
return refs;
|
|
307
|
+
}
|
|
308
|
+
export function nodeIdOf(name, address) {
|
|
309
|
+
if (name && typeof name === "string" && name.trim())
|
|
310
|
+
return name.trim();
|
|
311
|
+
if (address && typeof address === "string" && address.trim())
|
|
312
|
+
return address.trim();
|
|
313
|
+
return undefined;
|
|
314
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type ProjectObjectType, type ProjectRole, type IndustryMode } from "./namespace.js";
|
|
2
|
+
import { ProjectGraph } from "./graph.js";
|
|
3
|
+
import { type ProjectInfo, type DependencyTrace, type ReverseTrace } from "./query.js";
|
|
4
|
+
export * from "./namespace.js";
|
|
5
|
+
export * from "./graph.js";
|
|
6
|
+
export * from "./query.js";
|
|
7
|
+
export declare function isProjectServiceEnabled(): boolean;
|
|
8
|
+
export declare function getGraph(): ProjectGraph;
|
|
9
|
+
export declare function setGraph(g: ProjectGraph): void;
|
|
10
|
+
export interface NormalizeCallInput {
|
|
11
|
+
operation_type: string;
|
|
12
|
+
data: any;
|
|
13
|
+
projectPrefix?: string;
|
|
14
|
+
role?: ProjectRole;
|
|
15
|
+
industry?: IndustryMode;
|
|
16
|
+
version?: string;
|
|
17
|
+
shareable?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface NormalizeCallResult {
|
|
20
|
+
data: any;
|
|
21
|
+
warnings: string[];
|
|
22
|
+
project?: {
|
|
23
|
+
prefix: string;
|
|
24
|
+
type?: ProjectObjectType;
|
|
25
|
+
version?: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export declare function normalize(input: NormalizeCallInput): NormalizeCallResult;
|
|
29
|
+
export declare function observe(operation_type: string, data: any, result?: any): void;
|
|
30
|
+
export declare function queryProjects(): Promise<ProjectInfo[]>;
|
|
31
|
+
export declare function queryProjectObjects(prefix: string): Promise<{
|
|
32
|
+
name?: string;
|
|
33
|
+
address?: string;
|
|
34
|
+
type?: string;
|
|
35
|
+
}[]>;
|
|
36
|
+
export declare function queryShareableObjects(): Promise<{
|
|
37
|
+
name?: string;
|
|
38
|
+
address?: string;
|
|
39
|
+
type?: string;
|
|
40
|
+
project?: string;
|
|
41
|
+
}[]>;
|
|
42
|
+
export declare function queryDependencies(objectId: string): DependencyTrace;
|
|
43
|
+
export declare function queryReferencedBy(objectId: string): ReverseTrace;
|
|
44
|
+
export declare function queryPrePublishCheck(serviceId: string): string[];
|
|
45
|
+
export declare function queryCrossProjectReferences(): {
|
|
46
|
+
edge: import("./graph.js").GraphEdge;
|
|
47
|
+
fromProject?: string;
|
|
48
|
+
toProject?: string;
|
|
49
|
+
}[];
|
|
50
|
+
export declare function queryGraphStats(): {
|
|
51
|
+
nodeCount: number;
|
|
52
|
+
edgeCount: number;
|
|
53
|
+
cycles: string[][];
|
|
54
|
+
dangling: {
|
|
55
|
+
from: string;
|
|
56
|
+
missing: string[];
|
|
57
|
+
}[];
|
|
58
|
+
};
|
|
59
|
+
export declare function saveGraph(): string;
|
|
60
|
+
export declare function loadGraph(): boolean;
|
|
61
|
+
export declare function hasPersistedGraph(): boolean;
|
|
62
|
+
export declare const PROJECT_SERVICE_VERSION = 1;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { normalizeForProject, extractProjectPrefix, TAG_PREFIX, } from "./namespace.js";
|
|
2
|
+
import { ProjectGraph, extractReferences, nodeIdOf, } from "./graph.js";
|
|
3
|
+
import { listProjects, listProjectObjects, listShareableObjects, traceDependencies, traceReferencedBy, prePublishCheck, findCrossProjectReferences, } from "./query.js";
|
|
4
|
+
import { isEnabled as isRuntimeEnabled } from "../config/index.js";
|
|
5
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync } from "fs";
|
|
6
|
+
import { dirname, join } from "path";
|
|
7
|
+
import { homedir } from "os";
|
|
8
|
+
export * from "./namespace.js";
|
|
9
|
+
export * from "./graph.js";
|
|
10
|
+
export * from "./query.js";
|
|
11
|
+
export function isProjectServiceEnabled() {
|
|
12
|
+
return isRuntimeEnabled("project_service");
|
|
13
|
+
}
|
|
14
|
+
let GRAPH_INSTANCE = null;
|
|
15
|
+
let GRAPH_HYDRATED = false;
|
|
16
|
+
function isAutoHydrateEnabled() {
|
|
17
|
+
const v = process.env.WOWOK_PROJECT_SERVICE_HYDRATE;
|
|
18
|
+
return v === "1" || v === "true";
|
|
19
|
+
}
|
|
20
|
+
export function getGraph() {
|
|
21
|
+
if (!GRAPH_INSTANCE) {
|
|
22
|
+
GRAPH_INSTANCE = new ProjectGraph();
|
|
23
|
+
if (isAutoHydrateEnabled() && !GRAPH_HYDRATED) {
|
|
24
|
+
GRAPH_HYDRATED = true;
|
|
25
|
+
try {
|
|
26
|
+
loadGraph();
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return GRAPH_INSTANCE;
|
|
33
|
+
}
|
|
34
|
+
export function setGraph(g) {
|
|
35
|
+
GRAPH_INSTANCE = g;
|
|
36
|
+
}
|
|
37
|
+
export function normalize(input) {
|
|
38
|
+
if (!isProjectServiceEnabled()) {
|
|
39
|
+
return { data: input.data, warnings: [] };
|
|
40
|
+
}
|
|
41
|
+
return normalizeForProject({
|
|
42
|
+
operation_type: input.operation_type,
|
|
43
|
+
data: input.data,
|
|
44
|
+
projectPrefix: input.projectPrefix,
|
|
45
|
+
role: input.role,
|
|
46
|
+
industry: input.industry,
|
|
47
|
+
version: input.version,
|
|
48
|
+
shareable: input.shareable,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
export function observe(operation_type, data, result) {
|
|
52
|
+
if (!isProjectServiceEnabled())
|
|
53
|
+
return;
|
|
54
|
+
try {
|
|
55
|
+
const graph = getGraph();
|
|
56
|
+
const namedNew = data?.namedNew ?? data?.object;
|
|
57
|
+
const name = namedNew?.name;
|
|
58
|
+
const address = extractAddressFromResult(result);
|
|
59
|
+
const nodeId = nodeIdOf(name, address);
|
|
60
|
+
if (!nodeId)
|
|
61
|
+
return;
|
|
62
|
+
const tags = namedNew?.tags;
|
|
63
|
+
const project = extractProjectPrefix(tags);
|
|
64
|
+
const typeTag = tags?.find((t) => t.startsWith(TAG_PREFIX.type));
|
|
65
|
+
const type = typeTag?.slice(TAG_PREFIX.type.length);
|
|
66
|
+
const node = { id: nodeId, project, type, address };
|
|
67
|
+
graph.upsertNode(node);
|
|
68
|
+
const refs = extractReferences(operation_type, data);
|
|
69
|
+
for (const r of refs) {
|
|
70
|
+
graph.addEdge(nodeId, r.target, r.kind);
|
|
71
|
+
}
|
|
72
|
+
if (isRuntimeEnabled("graph_persist")) {
|
|
73
|
+
try {
|
|
74
|
+
saveGraph();
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function extractAddressFromResult(result) {
|
|
84
|
+
if (!result || typeof result !== "object")
|
|
85
|
+
return undefined;
|
|
86
|
+
const candidate = result?.object_id ??
|
|
87
|
+
result?.objectId ??
|
|
88
|
+
result?.effects?.created?.[0]?.reference?.objectId ??
|
|
89
|
+
result?.objectRef?.objectId ??
|
|
90
|
+
result?.data?.objectId;
|
|
91
|
+
if (typeof candidate === "string" && candidate.startsWith("0x"))
|
|
92
|
+
return candidate;
|
|
93
|
+
const inner = result.result ?? result.data;
|
|
94
|
+
if (inner && typeof inner === "object") {
|
|
95
|
+
const c2 = inner.object_id ??
|
|
96
|
+
inner.objectId ??
|
|
97
|
+
inner.effects?.created?.[0]?.reference?.objectId ??
|
|
98
|
+
inner.objectRef?.objectId;
|
|
99
|
+
if (typeof c2 === "string" && c2.startsWith("0x"))
|
|
100
|
+
return c2;
|
|
101
|
+
}
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
export async function queryProjects() {
|
|
105
|
+
return listProjects();
|
|
106
|
+
}
|
|
107
|
+
export async function queryProjectObjects(prefix) {
|
|
108
|
+
return listProjectObjects(prefix);
|
|
109
|
+
}
|
|
110
|
+
export async function queryShareableObjects() {
|
|
111
|
+
return listShareableObjects();
|
|
112
|
+
}
|
|
113
|
+
export function queryDependencies(objectId) {
|
|
114
|
+
return traceDependencies(getGraph(), objectId);
|
|
115
|
+
}
|
|
116
|
+
export function queryReferencedBy(objectId) {
|
|
117
|
+
return traceReferencedBy(getGraph(), objectId);
|
|
118
|
+
}
|
|
119
|
+
export function queryPrePublishCheck(serviceId) {
|
|
120
|
+
return prePublishCheck(getGraph(), serviceId);
|
|
121
|
+
}
|
|
122
|
+
export function queryCrossProjectReferences() {
|
|
123
|
+
return findCrossProjectReferences(getGraph());
|
|
124
|
+
}
|
|
125
|
+
export function queryGraphStats() {
|
|
126
|
+
const g = getGraph();
|
|
127
|
+
return {
|
|
128
|
+
nodeCount: g.nodeCount,
|
|
129
|
+
edgeCount: g.edgeCount,
|
|
130
|
+
cycles: g.detectCycles(),
|
|
131
|
+
dangling: g.findDanglingDependencies(),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function graphFilePath() {
|
|
135
|
+
const dir = process.env.WOWOK_CONFIG_DIR
|
|
136
|
+
? process.env.WOWOK_CONFIG_DIR
|
|
137
|
+
: join(homedir(), ".wowok");
|
|
138
|
+
return join(dir, "project-graph.json");
|
|
139
|
+
}
|
|
140
|
+
export function saveGraph() {
|
|
141
|
+
const path = graphFilePath();
|
|
142
|
+
const dir = dirname(path);
|
|
143
|
+
if (!existsSync(dir))
|
|
144
|
+
mkdirSync(dir, { recursive: true });
|
|
145
|
+
const snap = getGraph().snapshot();
|
|
146
|
+
writeFileSync(path, JSON.stringify(snap, null, 2), "utf-8");
|
|
147
|
+
return path;
|
|
148
|
+
}
|
|
149
|
+
export function loadGraph() {
|
|
150
|
+
const path = graphFilePath();
|
|
151
|
+
if (!existsSync(path))
|
|
152
|
+
return false;
|
|
153
|
+
try {
|
|
154
|
+
const raw = readFileSync(path, "utf-8");
|
|
155
|
+
const snap = JSON.parse(raw);
|
|
156
|
+
if (snap && snap.nodes && snap.edges) {
|
|
157
|
+
getGraph().restore(snap);
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
catch { }
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
export function hasPersistedGraph() {
|
|
165
|
+
return existsSync(graphFilePath());
|
|
166
|
+
}
|
|
167
|
+
export const PROJECT_SERVICE_VERSION = 1;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export type ProjectObjectType = "service" | "machine" | "guard" | "permission" | "reward" | "arb" | "progress" | "treasury" | "demand" | "repository" | "contact" | "order" | "allocation" | "personal" | "payment" | "proof";
|
|
2
|
+
export type ProjectRole = "workflow" | "trust" | "revenue" | "acceptance" | "identity" | "communication" | "marketing" | "governance";
|
|
3
|
+
export type IndustryMode = "freelance" | "rental" | "education" | "travel" | "subscription" | "general";
|
|
4
|
+
export declare const TAG_PREFIX: {
|
|
5
|
+
readonly project: "project:";
|
|
6
|
+
readonly type: "type:";
|
|
7
|
+
readonly role: "role:";
|
|
8
|
+
readonly industry: "industry:";
|
|
9
|
+
readonly version: "version:";
|
|
10
|
+
readonly shareable: "shareable:";
|
|
11
|
+
readonly archived: "archived:";
|
|
12
|
+
};
|
|
13
|
+
export declare const NAMESPACE_CONSTRAINTS: {
|
|
14
|
+
readonly projectPrefixMin: 3;
|
|
15
|
+
readonly projectPrefixMax: 16;
|
|
16
|
+
readonly purposeMin: 1;
|
|
17
|
+
readonly purposeMax: 32;
|
|
18
|
+
readonly versionPattern: RegExp;
|
|
19
|
+
};
|
|
20
|
+
export interface NameValidation {
|
|
21
|
+
valid: boolean;
|
|
22
|
+
reason?: string;
|
|
23
|
+
parsed?: {
|
|
24
|
+
projectPrefix: string;
|
|
25
|
+
type: ProjectObjectType;
|
|
26
|
+
purpose: string;
|
|
27
|
+
version?: string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export declare function validateProjectName(name: string): NameValidation;
|
|
31
|
+
export declare function objectTypeFromOperation(operation_type: string): ProjectObjectType | undefined;
|
|
32
|
+
export interface TagInjectionOptions {
|
|
33
|
+
projectPrefix?: string;
|
|
34
|
+
type?: ProjectObjectType;
|
|
35
|
+
role?: ProjectRole;
|
|
36
|
+
industry?: IndustryMode;
|
|
37
|
+
version?: string;
|
|
38
|
+
shareable?: boolean;
|
|
39
|
+
existingTags?: string[];
|
|
40
|
+
}
|
|
41
|
+
export declare function buildProjectTags(opts: TagInjectionOptions): string[];
|
|
42
|
+
export declare function extractProjectPrefix(tags: string[] | undefined): string | undefined;
|
|
43
|
+
export interface NormalizeResult {
|
|
44
|
+
data: any;
|
|
45
|
+
warnings: string[];
|
|
46
|
+
project?: {
|
|
47
|
+
prefix: string;
|
|
48
|
+
type?: ProjectObjectType;
|
|
49
|
+
version?: string;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export interface NormalizeInput {
|
|
53
|
+
operation_type: string;
|
|
54
|
+
data: any;
|
|
55
|
+
projectPrefix?: string;
|
|
56
|
+
role?: ProjectRole;
|
|
57
|
+
industry?: IndustryMode;
|
|
58
|
+
version?: string;
|
|
59
|
+
shareable?: boolean;
|
|
60
|
+
}
|
|
61
|
+
export declare function normalizeForProject(input: NormalizeInput): NormalizeResult;
|
|
62
|
+
export declare const NAMESPACE_VERSION = 1;
|