@wowok/agent-mcp 2.5.3 → 2.5.5
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/README.md +33 -26
- package/dist/customer/index.d.ts +2 -2
- package/dist/customer/index.js +1 -1
- package/dist/customer/info-puzzle.d.ts +39 -2
- package/dist/customer/info-puzzle.js +370 -29
- package/dist/customer/risk-assessment.js +51 -14
- package/dist/customer/types.d.ts +85 -0
- package/dist/knowledge/machine-ledger.js +32 -29
- package/dist/knowledge/machine-risk.js +23 -0
- package/dist/knowledge/machine-templates.js +118 -86
- package/dist/knowledge/reward-confirm.d.ts +3 -0
- package/dist/knowledge/reward-confirm.js +30 -0
- package/dist/knowledge/reward-puzzle.d.ts +1 -0
- package/dist/knowledge/reward-puzzle.js +12 -0
- package/dist/knowledge/reward-risk.d.ts +4 -1
- package/dist/knowledge/reward-risk.js +85 -3
- package/dist/knowledge/reward-templates.d.ts +1 -1
- package/dist/knowledge/reward-templates.js +77 -5
- package/dist/knowledge/tools-reference.js +5 -4
- package/dist/knowledge/trust-metrics.d.ts +4 -0
- package/dist/knowledge/trust-metrics.js +67 -7
- package/dist/project/evaluation.d.ts +53 -0
- package/dist/project/evaluation.js +853 -0
- package/dist/project/graph-builder.d.ts +43 -0
- package/dist/project/graph-builder.js +572 -0
- package/dist/project/handlers.d.ts +152 -0
- package/dist/project/handlers.js +458 -0
- package/dist/project/index.d.ts +1 -0
- package/dist/project/index.js +24 -1
- package/dist/project/query.d.ts +1 -0
- package/dist/project/query.js +2 -0
- package/dist/project/semantic-assembler.d.ts +93 -0
- package/dist/project/semantic-assembler.js +345 -0
- package/dist/schema/call/arbitration.d.ts +54 -54
- package/dist/schema/call/base.js +1 -1
- package/dist/schema/call/demand.d.ts +48 -48
- package/dist/schema/operations.d.ts +76 -76
- package/dist/schema/project/index.d.ts +1558 -3885
- package/dist/schema/project/index.js +357 -961
- package/dist/schema/trust/index.d.ts +24 -24
- package/dist/schemas/bridge_operation.schema.json +1 -1
- package/dist/schemas/guard2file.schema.json +1 -1
- package/dist/schemas/index.json +2 -2
- package/dist/schemas/machineNode2file.schema.json +1 -1
- package/dist/schemas/onchain_operations.schema.json +5 -5
- package/dist/schemas/onchain_operations_allocation.schema.json +1 -1
- package/dist/schemas/onchain_operations_arbitration.schema.json +1 -1
- package/dist/schemas/onchain_operations_contact.schema.json +1 -1
- package/dist/schemas/onchain_operations_demand.schema.json +1 -1
- package/dist/schemas/onchain_operations_gen_passport.schema.json +2 -2
- package/dist/schemas/onchain_operations_gen_proof.schema.json +2 -2
- package/dist/schemas/onchain_operations_guard.schema.json +1 -1
- package/dist/schemas/onchain_operations_machine.schema.json +1 -1
- package/dist/schemas/onchain_operations_order.schema.json +1 -1
- package/dist/schemas/onchain_operations_payment.schema.json +1 -1
- package/dist/schemas/onchain_operations_permission.schema.json +1 -1
- package/dist/schemas/onchain_operations_personal.schema.json +1 -1
- package/dist/schemas/onchain_operations_progress.schema.json +1 -1
- package/dist/schemas/onchain_operations_proof.schema.json +1 -1
- package/dist/schemas/onchain_operations_repository.schema.json +1 -1
- package/dist/schemas/onchain_operations_reward.schema.json +1 -1
- package/dist/schemas/onchain_operations_service.schema.json +1 -1
- package/dist/schemas/onchain_operations_treasury.schema.json +1 -1
- package/dist/schemas/project_operation.output.json +975 -2471
- package/dist/schemas/project_operation.schema.json +207 -534
- package/dist/tools/handlers/onchain.js +97 -19
- package/dist/tools/handlers/project.js +34 -1046
- package/dist/tools/index.js +84 -55
- package/package.json +2 -2
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import { type Project, type ProjectObject, type EvaluationType } from "@wowok/wowok";
|
|
3
|
+
import type { ProjectOperationInputSchema } from "../schema/project/index.js";
|
|
4
|
+
type ProjectInput = z.infer<typeof ProjectOperationInputSchema>;
|
|
5
|
+
export declare function handleListProjects(v: ProjectInput): Promise<{
|
|
6
|
+
action: "list_projects";
|
|
7
|
+
items: {
|
|
8
|
+
objectCount: number;
|
|
9
|
+
objectTypes: string[];
|
|
10
|
+
id: string;
|
|
11
|
+
prefix: string;
|
|
12
|
+
name: string;
|
|
13
|
+
description: string | null;
|
|
14
|
+
industry: string | null;
|
|
15
|
+
perspective: import("@wowok/wowok").ProjectPerspective;
|
|
16
|
+
status: import("@wowok/wowok").ProjectStatus;
|
|
17
|
+
labels: string[] | null;
|
|
18
|
+
currentVersion: string | null;
|
|
19
|
+
serviceAddress: string | null;
|
|
20
|
+
defaultAccount: string | null;
|
|
21
|
+
network: string;
|
|
22
|
+
createdAt: number;
|
|
23
|
+
updatedAt: number;
|
|
24
|
+
metadata: Record<string, unknown> | null;
|
|
25
|
+
}[];
|
|
26
|
+
total: number;
|
|
27
|
+
}>;
|
|
28
|
+
export declare function handleCreateProject(v: ProjectInput): Promise<{
|
|
29
|
+
action: "create_project";
|
|
30
|
+
project: Project;
|
|
31
|
+
}>;
|
|
32
|
+
export declare function handleCreateProjectFromOnchain(v: ProjectInput): Promise<{
|
|
33
|
+
action: "create_project_from_onchain";
|
|
34
|
+
project: Project;
|
|
35
|
+
objects: ProjectObject[];
|
|
36
|
+
graphEdgeCount: number;
|
|
37
|
+
}>;
|
|
38
|
+
export declare function handleUpdateProject(v: ProjectInput): Promise<{
|
|
39
|
+
action: "update_project";
|
|
40
|
+
project: Project;
|
|
41
|
+
}>;
|
|
42
|
+
export declare function handleGetProjectDetail(v: ProjectInput): Promise<{
|
|
43
|
+
action: "get_project_detail";
|
|
44
|
+
project: Project;
|
|
45
|
+
objects: ProjectObject[];
|
|
46
|
+
graphEdgeCount: number;
|
|
47
|
+
evaluations: {
|
|
48
|
+
id: string;
|
|
49
|
+
evalType: EvaluationType;
|
|
50
|
+
score: number | null;
|
|
51
|
+
summary: string | null;
|
|
52
|
+
evaluatedAt: number;
|
|
53
|
+
}[];
|
|
54
|
+
versions: {
|
|
55
|
+
version: string;
|
|
56
|
+
description: string | null;
|
|
57
|
+
createdAt: number;
|
|
58
|
+
}[];
|
|
59
|
+
}>;
|
|
60
|
+
export declare function handleAddObject(v: ProjectInput): Promise<{
|
|
61
|
+
action: "add_object";
|
|
62
|
+
object: ProjectObject;
|
|
63
|
+
}>;
|
|
64
|
+
export declare function handleRemoveObject(v: ProjectInput): Promise<{
|
|
65
|
+
action: "remove_object";
|
|
66
|
+
removed: true;
|
|
67
|
+
}>;
|
|
68
|
+
export declare function handleUpdateObject(v: ProjectInput): Promise<{
|
|
69
|
+
action: "update_object";
|
|
70
|
+
object: ProjectObject;
|
|
71
|
+
}>;
|
|
72
|
+
export declare function handleCreateVersion(v: ProjectInput): Promise<{
|
|
73
|
+
action: "create_version";
|
|
74
|
+
version: {
|
|
75
|
+
version: string;
|
|
76
|
+
description: string | null;
|
|
77
|
+
createdAt: number;
|
|
78
|
+
};
|
|
79
|
+
}>;
|
|
80
|
+
export declare function handleBuildGraph(v: ProjectInput): Promise<{
|
|
81
|
+
action: "build_graph";
|
|
82
|
+
nodeCount: number;
|
|
83
|
+
edgeCount: number;
|
|
84
|
+
edgesBySource: Record<string, number>;
|
|
85
|
+
reputationCount: number;
|
|
86
|
+
builtAt: number;
|
|
87
|
+
}>;
|
|
88
|
+
export declare function handleGetGraph(v: ProjectInput): Promise<{
|
|
89
|
+
action: "get_graph";
|
|
90
|
+
edges: {
|
|
91
|
+
sourceObject: string;
|
|
92
|
+
targetObject: string;
|
|
93
|
+
edgeSource: import("@wowok/wowok").EdgeSource;
|
|
94
|
+
relationshipType: import("@wowok/wowok").RelationshipType;
|
|
95
|
+
fieldName: string | null;
|
|
96
|
+
depth: number;
|
|
97
|
+
verified: boolean;
|
|
98
|
+
weight: number;
|
|
99
|
+
direction: string | null;
|
|
100
|
+
}[];
|
|
101
|
+
}>;
|
|
102
|
+
export declare function handleEvaluateProject(v: ProjectInput): Promise<{
|
|
103
|
+
action: "evaluate_project";
|
|
104
|
+
evaluationType: EvaluationType;
|
|
105
|
+
score: number;
|
|
106
|
+
summary: string;
|
|
107
|
+
criterionScores: import("./evaluation.js").CriterionScore[];
|
|
108
|
+
findings: import("./evaluation.js").EvaluationFinding[];
|
|
109
|
+
strengths: string[];
|
|
110
|
+
needsLlm: boolean;
|
|
111
|
+
llmPrompt: string | undefined;
|
|
112
|
+
evaluationId: string;
|
|
113
|
+
}>;
|
|
114
|
+
export declare function handleSaveEvaluation(v: ProjectInput): Promise<{
|
|
115
|
+
action: "save_evaluation";
|
|
116
|
+
evaluation: {
|
|
117
|
+
id: string;
|
|
118
|
+
evalType: EvaluationType;
|
|
119
|
+
score: number | null;
|
|
120
|
+
summary: string | null;
|
|
121
|
+
evaluatedAt: number;
|
|
122
|
+
};
|
|
123
|
+
}>;
|
|
124
|
+
export declare function handleCompareProjects(v: ProjectInput): Promise<{
|
|
125
|
+
action: "compare_projects";
|
|
126
|
+
evaluationType: EvaluationType;
|
|
127
|
+
ranking: import("./evaluation.js").ProjectComparisonEntry[];
|
|
128
|
+
bestProjectId: string | null;
|
|
129
|
+
}>;
|
|
130
|
+
export declare function handleRefreshObjects(v: ProjectInput): Promise<{
|
|
131
|
+
action: "refresh_objects";
|
|
132
|
+
refreshedCount: number;
|
|
133
|
+
failedCount: number;
|
|
134
|
+
refreshedAt: number;
|
|
135
|
+
}>;
|
|
136
|
+
export declare function handleDeleteProject(v: ProjectInput): Promise<{
|
|
137
|
+
action: "delete_project";
|
|
138
|
+
deleted: true;
|
|
139
|
+
}>;
|
|
140
|
+
export declare function handleGetObjectDiff(v: ProjectInput): Promise<{
|
|
141
|
+
action: "get_object_diff";
|
|
142
|
+
address: string;
|
|
143
|
+
fromTime: number;
|
|
144
|
+
toTime: number;
|
|
145
|
+
changedFields: {
|
|
146
|
+
fieldPath: string;
|
|
147
|
+
oldValue: unknown;
|
|
148
|
+
newValue: unknown;
|
|
149
|
+
changeType: "modified" | "removed" | "added";
|
|
150
|
+
}[];
|
|
151
|
+
}>;
|
|
152
|
+
export {};
|
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
import { LocalProject, LocalMark, query_objects, } from "@wowok/wowok";
|
|
2
|
+
import { GraphBuilder } from "./graph-builder.js";
|
|
3
|
+
import { SemanticAssembler } from "./semantic-assembler.js";
|
|
4
|
+
import { runEvaluation, compareProjects, } from "./evaluation.js";
|
|
5
|
+
const localProject = LocalProject.Instance();
|
|
6
|
+
function requireField(value, name) {
|
|
7
|
+
if (value === undefined || value === null) {
|
|
8
|
+
throw new Error(`'${name}' is required for this action`);
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
async function resolveProjectId(v) {
|
|
13
|
+
if (v.project_id)
|
|
14
|
+
return v.project_id;
|
|
15
|
+
if (v.project) {
|
|
16
|
+
const p = await localProject.getProjectByPrefix(v.project);
|
|
17
|
+
if (!p)
|
|
18
|
+
throw new Error(`Project not found by prefix: ${v.project}`);
|
|
19
|
+
return p.id;
|
|
20
|
+
}
|
|
21
|
+
throw new Error("Either 'project_id' or 'project' (prefix) is required for this action");
|
|
22
|
+
}
|
|
23
|
+
async function resolveObjectAddress(v) {
|
|
24
|
+
if (v.object_address)
|
|
25
|
+
return v.object_address;
|
|
26
|
+
if (v.object_name_add) {
|
|
27
|
+
const mark = await LocalMark.Instance().get(v.object_name_add);
|
|
28
|
+
if (mark?.address)
|
|
29
|
+
return mark.address;
|
|
30
|
+
throw new Error(`LocalMark name not found: ${v.object_name_add}`);
|
|
31
|
+
}
|
|
32
|
+
throw new Error("Either 'object_address' or 'object_name_add' is required for add_object");
|
|
33
|
+
}
|
|
34
|
+
export async function handleListProjects(v) {
|
|
35
|
+
const filter = {};
|
|
36
|
+
if (v.filter_status)
|
|
37
|
+
filter.status = v.filter_status;
|
|
38
|
+
if (v.filter_perspective)
|
|
39
|
+
filter.perspective = v.filter_perspective;
|
|
40
|
+
if (v.filter_network)
|
|
41
|
+
filter.network = v.filter_network;
|
|
42
|
+
const projects = await localProject.listProjects(Object.keys(filter).length > 0 ? filter : undefined);
|
|
43
|
+
const items = await Promise.all(projects.map(async (p) => {
|
|
44
|
+
const objs = await localProject.listObjects(p.id);
|
|
45
|
+
const types = new Set();
|
|
46
|
+
for (const o of objs) {
|
|
47
|
+
if (o.objectType)
|
|
48
|
+
types.add(o.objectType);
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
...p,
|
|
52
|
+
objectCount: objs.length,
|
|
53
|
+
objectTypes: Array.from(types),
|
|
54
|
+
};
|
|
55
|
+
}));
|
|
56
|
+
return {
|
|
57
|
+
action: "list_projects",
|
|
58
|
+
items,
|
|
59
|
+
total: items.length,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export async function handleCreateProject(v) {
|
|
63
|
+
const prefix = requireField(v.project, "project (prefix)");
|
|
64
|
+
const name = requireField(v.project_name, "project_name");
|
|
65
|
+
const existing = await localProject.getProjectByPrefix(prefix);
|
|
66
|
+
if (existing) {
|
|
67
|
+
throw new Error(`Project prefix '${prefix}' already exists (project: '${existing.name}', id: '${existing.id}'). ` +
|
|
68
|
+
`Use a different prefix or update the existing project.`);
|
|
69
|
+
}
|
|
70
|
+
const create = {
|
|
71
|
+
prefix,
|
|
72
|
+
name,
|
|
73
|
+
description: v.project_description,
|
|
74
|
+
industry: v.project_industry,
|
|
75
|
+
perspective: v.project_perspective ?? "producer",
|
|
76
|
+
labels: v.project_labels,
|
|
77
|
+
serviceAddress: v.service_address,
|
|
78
|
+
network: v.project_network ?? "testnet",
|
|
79
|
+
};
|
|
80
|
+
const project = await localProject.createProject(create);
|
|
81
|
+
return { action: "create_project", project };
|
|
82
|
+
}
|
|
83
|
+
export async function handleCreateProjectFromOnchain(v) {
|
|
84
|
+
const serviceAddress = requireField(v.service_address, "service_address");
|
|
85
|
+
const network = (v.project_network ?? "testnet");
|
|
86
|
+
let prefix = v.project ?? `svc_${serviceAddress.slice(2, 8)}`;
|
|
87
|
+
const name = v.project_name ?? `Consumer Project ${serviceAddress.slice(2, 8)}`;
|
|
88
|
+
const existing = await localProject.getProjectByPrefix(prefix);
|
|
89
|
+
if (existing) {
|
|
90
|
+
if (v.project) {
|
|
91
|
+
throw new Error(`Project prefix '${prefix}' already exists (project: '${existing.name}', id: '${existing.id}'). ` +
|
|
92
|
+
`Use a different prefix.`);
|
|
93
|
+
}
|
|
94
|
+
let suffix = 2;
|
|
95
|
+
while (await localProject.getProjectByPrefix(`${prefix}_${suffix}`)) {
|
|
96
|
+
suffix++;
|
|
97
|
+
}
|
|
98
|
+
prefix = `${prefix}_${suffix}`;
|
|
99
|
+
}
|
|
100
|
+
const project = await localProject.createProject({
|
|
101
|
+
prefix,
|
|
102
|
+
name,
|
|
103
|
+
description: v.project_description ?? `Auto-discovered from Service ${serviceAddress}`,
|
|
104
|
+
industry: v.project_industry,
|
|
105
|
+
perspective: "consumer",
|
|
106
|
+
labels: v.project_labels,
|
|
107
|
+
serviceAddress,
|
|
108
|
+
network: network,
|
|
109
|
+
});
|
|
110
|
+
const builder = new GraphBuilder({
|
|
111
|
+
maxDepth: v.max_depth ?? 3,
|
|
112
|
+
enableRegistrar: v.enable_registrar ?? true,
|
|
113
|
+
enablePotential: v.enable_potential ?? false,
|
|
114
|
+
projectId: project.id,
|
|
115
|
+
network: network,
|
|
116
|
+
});
|
|
117
|
+
const graphResult = await builder.buildRelationshipGraph(serviceAddress);
|
|
118
|
+
const objects = [];
|
|
119
|
+
for (const node of graphResult.graph.nodes) {
|
|
120
|
+
const isCore = node.address === serviceAddress;
|
|
121
|
+
const obj = await localProject.addObject(project.id, {
|
|
122
|
+
objectAddress: node.address,
|
|
123
|
+
objectType: node.objectType ?? undefined,
|
|
124
|
+
objectName: node.objectName ?? undefined,
|
|
125
|
+
role: (isCore ? "core" : "dependency"),
|
|
126
|
+
});
|
|
127
|
+
objects.push(obj);
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
action: "create_project_from_onchain",
|
|
131
|
+
project,
|
|
132
|
+
objects,
|
|
133
|
+
graphEdgeCount: graphResult.graph.edges.length,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
export async function handleUpdateProject(v) {
|
|
137
|
+
const id = await resolveProjectId(v);
|
|
138
|
+
const update = {
|
|
139
|
+
name: v.project_name,
|
|
140
|
+
description: v.project_description,
|
|
141
|
+
industry: v.project_industry,
|
|
142
|
+
perspective: v.project_perspective,
|
|
143
|
+
status: v.project_status,
|
|
144
|
+
labels: v.project_labels,
|
|
145
|
+
serviceAddress: v.service_address,
|
|
146
|
+
};
|
|
147
|
+
const project = await localProject.updateProject(id, update);
|
|
148
|
+
return { action: "update_project", project };
|
|
149
|
+
}
|
|
150
|
+
export async function handleGetProjectDetail(v) {
|
|
151
|
+
const id = await resolveProjectId(v);
|
|
152
|
+
const project = await localProject.getProject(id);
|
|
153
|
+
if (!project)
|
|
154
|
+
throw new Error(`Project not found: ${id}`);
|
|
155
|
+
const objects = await localProject.listObjects(id);
|
|
156
|
+
const edges = await localProject.getGraph(id);
|
|
157
|
+
const evaluations = await localProject.listEvaluations(id);
|
|
158
|
+
const versions = await localProject.listVersions(id);
|
|
159
|
+
return {
|
|
160
|
+
action: "get_project_detail",
|
|
161
|
+
project,
|
|
162
|
+
objects,
|
|
163
|
+
graphEdgeCount: edges.length,
|
|
164
|
+
evaluations: evaluations.map(e => ({
|
|
165
|
+
id: e.id,
|
|
166
|
+
evalType: e.evalType,
|
|
167
|
+
score: e.score,
|
|
168
|
+
summary: e.summary,
|
|
169
|
+
evaluatedAt: e.evaluatedAt,
|
|
170
|
+
})),
|
|
171
|
+
versions: versions.map(v => ({
|
|
172
|
+
version: v.version,
|
|
173
|
+
description: v.description,
|
|
174
|
+
createdAt: v.createdAt,
|
|
175
|
+
})),
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
export async function handleAddObject(v) {
|
|
179
|
+
const projectId = await resolveProjectId(v);
|
|
180
|
+
const objectAddress = await resolveObjectAddress(v);
|
|
181
|
+
const obj = await localProject.addObject(projectId, {
|
|
182
|
+
objectAddress,
|
|
183
|
+
objectType: v.object_type_add,
|
|
184
|
+
objectName: v.object_name_add,
|
|
185
|
+
role: v.object_role ?? "reference",
|
|
186
|
+
tags: v.object_tags_add,
|
|
187
|
+
});
|
|
188
|
+
return { action: "add_object", object: obj };
|
|
189
|
+
}
|
|
190
|
+
export async function handleRemoveObject(v) {
|
|
191
|
+
const objectId = requireField(v.object_id_remove, "object_id_remove");
|
|
192
|
+
await localProject.removeObject(objectId);
|
|
193
|
+
return { action: "remove_object", removed: true };
|
|
194
|
+
}
|
|
195
|
+
export async function handleUpdateObject(v) {
|
|
196
|
+
const objectId = requireField(v.object_id_update, "object_id_update");
|
|
197
|
+
const updates = {};
|
|
198
|
+
if (v.object_name_update !== undefined)
|
|
199
|
+
updates.objectName = v.object_name_update;
|
|
200
|
+
if (v.object_type_update !== undefined)
|
|
201
|
+
updates.objectType = v.object_type_update;
|
|
202
|
+
if (v.object_role_update !== undefined)
|
|
203
|
+
updates.role = v.object_role_update;
|
|
204
|
+
if (v.object_tags_update !== undefined)
|
|
205
|
+
updates.tags = v.object_tags_update;
|
|
206
|
+
const obj = await localProject.updateObject(objectId, updates);
|
|
207
|
+
return { action: "update_object", object: obj };
|
|
208
|
+
}
|
|
209
|
+
export async function handleCreateVersion(v) {
|
|
210
|
+
const projectId = await resolveProjectId(v);
|
|
211
|
+
const version = requireField(v.version, "version");
|
|
212
|
+
const project = await localProject.getProject(projectId);
|
|
213
|
+
if (!project)
|
|
214
|
+
throw new Error(`Project not found: ${projectId}`);
|
|
215
|
+
const created = await localProject.createVersion(projectId, version, v.version_description);
|
|
216
|
+
return {
|
|
217
|
+
action: "create_version",
|
|
218
|
+
version: {
|
|
219
|
+
version: created.version,
|
|
220
|
+
description: created.description,
|
|
221
|
+
createdAt: created.createdAt,
|
|
222
|
+
},
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
export async function handleBuildGraph(v) {
|
|
226
|
+
const projectId = await resolveProjectId(v);
|
|
227
|
+
const project = await localProject.getProject(projectId);
|
|
228
|
+
if (!project)
|
|
229
|
+
throw new Error(`Project not found: ${projectId}`);
|
|
230
|
+
let rootAddress = project.serviceAddress;
|
|
231
|
+
if (!rootAddress) {
|
|
232
|
+
const objects = await localProject.listObjects(projectId);
|
|
233
|
+
if (objects.length === 0) {
|
|
234
|
+
throw new Error("Cannot build graph: project has no objects and no service_address");
|
|
235
|
+
}
|
|
236
|
+
rootAddress = objects[0].objectAddress;
|
|
237
|
+
}
|
|
238
|
+
const builder = new GraphBuilder({
|
|
239
|
+
maxDepth: v.max_depth ?? 3,
|
|
240
|
+
enableRegistrar: v.enable_registrar ?? true,
|
|
241
|
+
enablePotential: v.enable_potential ?? false,
|
|
242
|
+
projectId,
|
|
243
|
+
network: project.network,
|
|
244
|
+
});
|
|
245
|
+
const result = await builder.buildRelationshipGraph(rootAddress);
|
|
246
|
+
const edgesBySource = {};
|
|
247
|
+
for (const edge of result.graph.edges) {
|
|
248
|
+
const src = edge.edgeSource ?? "unknown";
|
|
249
|
+
edgesBySource[src] = (edgesBySource[src] ?? 0) + 1;
|
|
250
|
+
}
|
|
251
|
+
return {
|
|
252
|
+
action: "build_graph",
|
|
253
|
+
nodeCount: result.graph.nodes.length,
|
|
254
|
+
edgeCount: result.graph.edges.length,
|
|
255
|
+
edgesBySource,
|
|
256
|
+
reputationCount: result.reputation.size,
|
|
257
|
+
builtAt: result.graph.builtAt,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
export async function handleGetGraph(v) {
|
|
261
|
+
const projectId = await resolveProjectId(v);
|
|
262
|
+
const edges = await localProject.getGraph(projectId);
|
|
263
|
+
return {
|
|
264
|
+
action: "get_graph",
|
|
265
|
+
edges: edges.map(e => ({
|
|
266
|
+
sourceObject: e.sourceObject,
|
|
267
|
+
targetObject: e.targetObject,
|
|
268
|
+
edgeSource: e.edgeSource,
|
|
269
|
+
relationshipType: e.relationshipType,
|
|
270
|
+
fieldName: e.fieldName,
|
|
271
|
+
depth: e.depth,
|
|
272
|
+
verified: e.verified,
|
|
273
|
+
weight: e.weight,
|
|
274
|
+
direction: e.direction,
|
|
275
|
+
})),
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
export async function handleEvaluateProject(v) {
|
|
279
|
+
const projectId = await resolveProjectId(v);
|
|
280
|
+
const evalType = requireField(v.evaluation_type, "evaluation_type");
|
|
281
|
+
const project = await localProject.getProject(projectId);
|
|
282
|
+
if (!project)
|
|
283
|
+
throw new Error(`Project not found: ${projectId}`);
|
|
284
|
+
if (v.refresh_before_eval) {
|
|
285
|
+
await refreshProjectObjects(projectId, project.network);
|
|
286
|
+
}
|
|
287
|
+
const objects = await localProject.listObjects(projectId);
|
|
288
|
+
const edges = await localProject.getGraph(projectId);
|
|
289
|
+
const addresses = objects.map(o => o.objectAddress);
|
|
290
|
+
const cacheEntries = await localProject.getCachedObjects(addresses);
|
|
291
|
+
const objectCache = new Map();
|
|
292
|
+
for (const [addr, entry] of cacheEntries)
|
|
293
|
+
objectCache.set(addr, entry);
|
|
294
|
+
let llmPrompt;
|
|
295
|
+
if (evalType === "worth_buying" || evalType === "value") {
|
|
296
|
+
const assembler = new SemanticAssembler();
|
|
297
|
+
const reputation = new Map();
|
|
298
|
+
for (const edge of edges) {
|
|
299
|
+
if (edge.edgeSource === "registrar" && edge.relationshipType === "affiliation") {
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
const context = await assembler.assemble(project, objects, edges, reputation);
|
|
303
|
+
const promptResult = assembler.buildEvaluationPrompt(evalType, context);
|
|
304
|
+
llmPrompt = promptResult.prompt;
|
|
305
|
+
}
|
|
306
|
+
const evalInput = {
|
|
307
|
+
project,
|
|
308
|
+
objects,
|
|
309
|
+
edges: edges,
|
|
310
|
+
objectCache: objectCache,
|
|
311
|
+
reputation: undefined,
|
|
312
|
+
};
|
|
313
|
+
const result = runEvaluation(evalInput, evalType, llmPrompt);
|
|
314
|
+
let evaluationId = "";
|
|
315
|
+
if (!result.needsLlm) {
|
|
316
|
+
const evalInput2 = {
|
|
317
|
+
projectId,
|
|
318
|
+
evalType,
|
|
319
|
+
score: result.score,
|
|
320
|
+
summary: result.summary,
|
|
321
|
+
details: {
|
|
322
|
+
criterionScores: result.criterionScores,
|
|
323
|
+
findings: result.findings,
|
|
324
|
+
strengths: result.strengths,
|
|
325
|
+
},
|
|
326
|
+
};
|
|
327
|
+
const saved = await localProject.saveEvaluation(evalInput2);
|
|
328
|
+
evaluationId = saved.id;
|
|
329
|
+
}
|
|
330
|
+
return {
|
|
331
|
+
action: "evaluate_project",
|
|
332
|
+
evaluationType: result.evaluationType,
|
|
333
|
+
score: result.score,
|
|
334
|
+
summary: result.summary,
|
|
335
|
+
criterionScores: result.criterionScores,
|
|
336
|
+
findings: result.findings,
|
|
337
|
+
strengths: result.strengths,
|
|
338
|
+
needsLlm: result.needsLlm,
|
|
339
|
+
llmPrompt: result.llmPrompt,
|
|
340
|
+
evaluationId,
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
export async function handleSaveEvaluation(v) {
|
|
344
|
+
const projectId = await resolveProjectId(v);
|
|
345
|
+
const evalType = requireField(v.evaluation_type, "evaluation_type");
|
|
346
|
+
const score = requireField(v.eval_score, "eval_score");
|
|
347
|
+
const summary = v.eval_summary ?? "";
|
|
348
|
+
const details = v.eval_details ?? {};
|
|
349
|
+
const saved = await localProject.saveEvaluation({
|
|
350
|
+
projectId,
|
|
351
|
+
evalType,
|
|
352
|
+
score,
|
|
353
|
+
summary,
|
|
354
|
+
details,
|
|
355
|
+
});
|
|
356
|
+
return {
|
|
357
|
+
action: "save_evaluation",
|
|
358
|
+
evaluation: {
|
|
359
|
+
id: saved.id,
|
|
360
|
+
evalType: saved.evalType,
|
|
361
|
+
score: saved.score,
|
|
362
|
+
summary: saved.summary,
|
|
363
|
+
evaluatedAt: saved.evaluatedAt,
|
|
364
|
+
},
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
export async function handleCompareProjects(v) {
|
|
368
|
+
const projectIds = requireField(v.compare_project_ids, "compare_project_ids");
|
|
369
|
+
const evalType = (v.evaluation_type ?? "worth_buying");
|
|
370
|
+
const entries = [];
|
|
371
|
+
for (const pid of projectIds) {
|
|
372
|
+
const project = await localProject.getProject(pid);
|
|
373
|
+
if (!project)
|
|
374
|
+
continue;
|
|
375
|
+
const evals = await localProject.listEvaluations(pid, { evalType });
|
|
376
|
+
const latest = evals[0];
|
|
377
|
+
entries.push({
|
|
378
|
+
projectId: pid,
|
|
379
|
+
projectName: project.name,
|
|
380
|
+
score: latest?.score ?? null,
|
|
381
|
+
summary: latest?.summary ?? null,
|
|
382
|
+
evaluatedAt: latest?.evaluatedAt ?? null,
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
const comparison = compareProjects(entries, evalType);
|
|
386
|
+
return {
|
|
387
|
+
action: "compare_projects",
|
|
388
|
+
evaluationType: comparison.evaluationType,
|
|
389
|
+
ranking: comparison.ranking,
|
|
390
|
+
bestProjectId: comparison.bestProjectId,
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
async function refreshProjectObjects(projectId, network) {
|
|
394
|
+
const objects = await localProject.listObjects(projectId);
|
|
395
|
+
const addresses = objects.map(o => o.objectAddress);
|
|
396
|
+
if (addresses.length === 0)
|
|
397
|
+
return { refreshedCount: 0, failedCount: 0 };
|
|
398
|
+
let refreshedCount = 0;
|
|
399
|
+
let failedCount = 0;
|
|
400
|
+
const BATCH_SIZE = 50;
|
|
401
|
+
for (let i = 0; i < addresses.length; i += BATCH_SIZE) {
|
|
402
|
+
const batch = addresses.slice(i, i + BATCH_SIZE);
|
|
403
|
+
try {
|
|
404
|
+
const response = await query_objects({
|
|
405
|
+
objects: batch,
|
|
406
|
+
no_cache: true,
|
|
407
|
+
network,
|
|
408
|
+
});
|
|
409
|
+
for (const obj of response?.objects ?? []) {
|
|
410
|
+
if (obj?.object) {
|
|
411
|
+
await localProject.cacheObject(obj.object, obj.type ?? null, JSON.stringify(obj), network);
|
|
412
|
+
refreshedCount++;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
catch {
|
|
417
|
+
failedCount += batch.length;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
return { refreshedCount, failedCount };
|
|
421
|
+
}
|
|
422
|
+
export async function handleRefreshObjects(v) {
|
|
423
|
+
const projectId = await resolveProjectId(v);
|
|
424
|
+
const project = await localProject.getProject(projectId);
|
|
425
|
+
if (!project)
|
|
426
|
+
throw new Error(`Project not found: ${projectId}`);
|
|
427
|
+
const network = project.network;
|
|
428
|
+
const { refreshedCount, failedCount } = await refreshProjectObjects(projectId, network);
|
|
429
|
+
return {
|
|
430
|
+
action: "refresh_objects",
|
|
431
|
+
refreshedCount,
|
|
432
|
+
failedCount,
|
|
433
|
+
refreshedAt: Date.now(),
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
export async function handleDeleteProject(v) {
|
|
437
|
+
const id = await resolveProjectId(v);
|
|
438
|
+
await localProject.deleteProject(id);
|
|
439
|
+
return { action: "delete_project", deleted: true };
|
|
440
|
+
}
|
|
441
|
+
export async function handleGetObjectDiff(v) {
|
|
442
|
+
const address = requireField(v.diff_address, "diff_address");
|
|
443
|
+
const fromTime = requireField(v.diff_from_time, "diff_from_time");
|
|
444
|
+
const toTime = requireField(v.diff_to_time, "diff_to_time");
|
|
445
|
+
const diff = await localProject.getObjectDiff(address, fromTime, toTime);
|
|
446
|
+
return {
|
|
447
|
+
action: "get_object_diff",
|
|
448
|
+
address: diff.address,
|
|
449
|
+
fromTime: diff.fromTime,
|
|
450
|
+
toTime: diff.toTime,
|
|
451
|
+
changedFields: diff.changedFields.map(f => ({
|
|
452
|
+
fieldPath: f.fieldPath,
|
|
453
|
+
oldValue: f.oldValue,
|
|
454
|
+
newValue: f.newValue,
|
|
455
|
+
changeType: f.changeType,
|
|
456
|
+
})),
|
|
457
|
+
};
|
|
458
|
+
}
|
package/dist/project/index.d.ts
CHANGED
package/dist/project/index.js
CHANGED
|
@@ -217,7 +217,30 @@ function extractAddressFromResult(result) {
|
|
|
217
217
|
return undefined;
|
|
218
218
|
}
|
|
219
219
|
export async function queryProjects() {
|
|
220
|
-
|
|
220
|
+
const tagProjects = await listProjects();
|
|
221
|
+
try {
|
|
222
|
+
const { LocalProject } = await import("@wowok/wowok");
|
|
223
|
+
const sqliteProjects = await LocalProject.Instance().listProjects();
|
|
224
|
+
const sqliteInfos = sqliteProjects.map(p => ({
|
|
225
|
+
prefix: p.prefix,
|
|
226
|
+
objectCount: 0,
|
|
227
|
+
types: [],
|
|
228
|
+
versions: p.currentVersion ? [p.currentVersion] : [],
|
|
229
|
+
objects: [],
|
|
230
|
+
...p,
|
|
231
|
+
}));
|
|
232
|
+
const merged = new Map();
|
|
233
|
+
for (const p of tagProjects)
|
|
234
|
+
merged.set(p.prefix, p);
|
|
235
|
+
for (const p of sqliteInfos) {
|
|
236
|
+
if (!merged.has(p.prefix))
|
|
237
|
+
merged.set(p.prefix, p);
|
|
238
|
+
}
|
|
239
|
+
return Array.from(merged.values());
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
return tagProjects;
|
|
243
|
+
}
|
|
221
244
|
}
|
|
222
245
|
export async function queryProjectObjects(prefix) {
|
|
223
246
|
return listProjectObjects(prefix);
|
package/dist/project/query.d.ts
CHANGED
package/dist/project/query.js
CHANGED
|
@@ -42,6 +42,7 @@ export async function listProjects() {
|
|
|
42
42
|
address: m.address,
|
|
43
43
|
type,
|
|
44
44
|
version: v,
|
|
45
|
+
tags: m.tags,
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
48
|
}
|
|
@@ -68,6 +69,7 @@ export async function listProjectObjects(prefix) {
|
|
|
68
69
|
address: m.address,
|
|
69
70
|
type: typeTag?.slice(TAG_PREFIX.type.length),
|
|
70
71
|
version: matched.version,
|
|
72
|
+
tags: m.tags,
|
|
71
73
|
});
|
|
72
74
|
}
|
|
73
75
|
return results;
|