@wowok/agent-mcp 2.2.11 → 2.2.13
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/docs/index.d.ts +3 -0
- package/dist/docs/index.js +2 -0
- package/dist/docs/loader.d.ts +12 -0
- package/dist/docs/loader.js +177 -0
- package/dist/docs/search.d.ts +17 -0
- package/dist/docs/search.js +325 -0
- package/dist/docs/types.d.ts +55 -0
- package/dist/docs/types.js +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +146 -39
- package/docs/README.md +249 -0
- package/docs/WIP.md +388 -0
- package/docs/WTS.md +536 -0
- package/docs/docs/account.md +914 -0
- package/docs/docs/allocation.md +635 -0
- package/docs/docs/arbitration.md +1804 -0
- package/docs/docs/arbitration_state_machine.md +270 -0
- package/docs/docs/contact.md +709 -0
- package/docs/docs/demand.md +948 -0
- package/docs/docs/guard.md +1465 -0
- package/docs/docs/localinfo.md +432 -0
- package/docs/docs/localmark.md +583 -0
- package/docs/docs/machine.md +2490 -0
- package/docs/docs/messenger.md +2098 -0
- package/docs/docs/onchain_events.md +267 -0
- package/docs/docs/order.md +1001 -0
- package/docs/docs/payment.md +512 -0
- package/docs/docs/permission.md +1438 -0
- package/docs/docs/personal.md +742 -0
- package/docs/docs/progress.md +1748 -0
- package/docs/docs/query.md +467 -0
- package/docs/docs/repository.md +1043 -0
- package/docs/docs/reward.md +833 -0
- package/docs/docs/service.md +2130 -0
- package/docs/docs/stage-01-introduction.md +243 -0
- package/docs/docs/stage-02-trust.md +302 -0
- package/docs/docs/stage-03-collaboration.md +337 -0
- package/docs/docs/stage-04-transaction.md +277 -0
- package/docs/docs/stage-05-business.md +151 -0
- package/docs/docs/stage-06-personal.md +203 -0
- package/docs/docs/stage-07-query.md +572 -0
- package/docs/docs/stage-08-examples.md +184 -0
- package/docs/docs/treasury.md +1149 -0
- package/docs/docs/wowok_buildin_info.md +740 -0
- package/docs/examples/Insurance/Insurance.md +594 -0
- package/docs/examples/Insurance/Insurance_TestResults.md +481 -0
- package/docs/examples/Insurance/insurance_complete_guard_v1.json +50 -0
- package/docs/examples/MyShop/MyShop.md +1353 -0
- package/docs/examples/MyShop/MyShop_TestResults.md +1003 -0
- package/docs/examples/MyShop_Advanced/MyShop_Advanced.md +1898 -0
- package/docs/examples/MyShop_Advanced/MyShop_Advanced_MerchantSystem_TestResults.md +1297 -0
- package/docs/examples/MyShop_Advanced/MyShop_Advanced_OrderFlow_TestResults.md +743 -0
- package/docs/examples/MyShop_Advanced/machine_nodes.json +222 -0
- package/docs/examples/ThreeBody_Signature/ThreeBody_Signature.md +776 -0
- package/docs/examples/ThreeBody_Signature/ThreeBody_Signature_TestResults.md +599 -0
- package/docs/examples/Travel/Travel.md +1157 -0
- package/docs/examples/Travel/Travel_TestResults.md +743 -0
- package/docs/examples/Travel/calc-weather-timestamps.js +8 -0
- package/docs/examples/Travel/travel_machine_v2_export.json +104 -0
- package/docs/examples/Travel/weather_check_guard_v1.json +51 -0
- package/docs/skills/WOWOK.md +650 -0
- package/docs/skills/onchain_operations/_common.md +406 -0
- package/docs/skills/onchain_operations/_index.md +196 -0
- package/docs/skills/onchain_operations/allocation.md +28 -0
- package/docs/skills/onchain_operations/arbitration.md +106 -0
- package/docs/skills/onchain_operations/contact.md +40 -0
- package/docs/skills/onchain_operations/demand.md +53 -0
- package/docs/skills/onchain_operations/gen_passport.md +23 -0
- package/docs/skills/onchain_operations/guard.md +56 -0
- package/docs/skills/onchain_operations/machine.md +89 -0
- package/docs/skills/onchain_operations/order.md +56 -0
- package/docs/skills/onchain_operations/payment.md +24 -0
- package/docs/skills/onchain_operations/permission.md +68 -0
- package/docs/skills/onchain_operations/personal.md +58 -0
- package/docs/skills/onchain_operations/progress.md +38 -0
- package/docs/skills/onchain_operations/repository.md +70 -0
- package/docs/skills/onchain_operations/reward.md +38 -0
- package/docs/skills/onchain_operations/service.md +78 -0
- package/docs/skills/onchain_operations/treasury.md +68 -0
- package/docs/skills/schema-account_operation.md +402 -0
- package/docs/skills/schema-guard2file.md +153 -0
- package/docs/skills/schema-local_info_operation.md +160 -0
- package/docs/skills/schema-local_mark_operation.md +148 -0
- package/docs/skills/schema-machineNode2file.md +155 -0
- package/docs/skills/schema-messenger_operation.md +547 -0
- package/docs/skills/schema-onchain_events.md +201 -0
- package/docs/skills/schema-onchain_table_data.md +334 -0
- package/docs/skills/schema-query_toolkit.md +395 -0
- package/docs/skills/schema-wip_file.md +240 -0
- package/docs/skills/schema-wowok_buildin_info.md +296 -0
- package/docs/wip-examples/three_body.html +57 -0
- package/docs/wip-examples/three_body.wip +30 -0
- package/package.json +3 -2
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type { Document, DocumentCategory, DocumentIndex, SearchResult, SchemaInfo, ExampleInfo, LearnRequest, LearnResponse, LearnAction, } from "./types.js";
|
|
2
|
+
export { loadAllDocuments, isDocumentationAvailable, getDocStats, } from "./loader.js";
|
|
3
|
+
export { processLearnRequest, searchDocuments, getOperationSchema, getToolSchema, getExampleInfo, getGuide, listOperations, listExamples, } from "./search.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Document, DocumentIndex } from "./types.js";
|
|
2
|
+
export declare function loadAllDocuments(): {
|
|
3
|
+
documents: Document[];
|
|
4
|
+
index: DocumentIndex;
|
|
5
|
+
};
|
|
6
|
+
export declare function isDocumentationAvailable(): boolean;
|
|
7
|
+
export declare function getDocStats(): {
|
|
8
|
+
total: number;
|
|
9
|
+
skills: number;
|
|
10
|
+
examples: number;
|
|
11
|
+
available: boolean;
|
|
12
|
+
};
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
5
|
+
const __dirname = path.dirname(__filename);
|
|
6
|
+
const DOCS_PATHS = {
|
|
7
|
+
skills: path.join(__dirname, "../../docs/skills"),
|
|
8
|
+
examples: path.join(__dirname, "../../docs/examples"),
|
|
9
|
+
};
|
|
10
|
+
function getDocsPath(type) {
|
|
11
|
+
return DOCS_PATHS[type];
|
|
12
|
+
}
|
|
13
|
+
function extractTitle(content, filename) {
|
|
14
|
+
const h1Match = content.match(/^#\s+(.+)$/m);
|
|
15
|
+
if (h1Match) {
|
|
16
|
+
return h1Match[1].trim();
|
|
17
|
+
}
|
|
18
|
+
return filename.replace(/\.md$/, "").replace(/[_-]/g, " ");
|
|
19
|
+
}
|
|
20
|
+
function determineCategory(filePath, content) {
|
|
21
|
+
const normalizedPath = filePath.toLowerCase();
|
|
22
|
+
if (normalizedPath.includes("examples")) {
|
|
23
|
+
return "example";
|
|
24
|
+
}
|
|
25
|
+
if (normalizedPath.includes("onchain_operations")) {
|
|
26
|
+
return "operation-schema";
|
|
27
|
+
}
|
|
28
|
+
if (normalizedPath.match(/schema-.*\.md$/)) {
|
|
29
|
+
return "tool-schema";
|
|
30
|
+
}
|
|
31
|
+
if (normalizedPath.includes("_common.md") || normalizedPath.includes("_index.md")) {
|
|
32
|
+
return "common";
|
|
33
|
+
}
|
|
34
|
+
if (normalizedPath.includes("wowok.md")) {
|
|
35
|
+
return "skill-overview";
|
|
36
|
+
}
|
|
37
|
+
return "common";
|
|
38
|
+
}
|
|
39
|
+
function extractTags(content) {
|
|
40
|
+
const tags = [];
|
|
41
|
+
const keywordsMatch = content.match(/keywords?:\s*([^\n]+)/i);
|
|
42
|
+
if (keywordsMatch) {
|
|
43
|
+
const keywords = keywordsMatch[1]
|
|
44
|
+
.split(/[,;]/)
|
|
45
|
+
.map((k) => k.trim().toLowerCase())
|
|
46
|
+
.filter((k) => k.length > 0);
|
|
47
|
+
tags.push(...keywords);
|
|
48
|
+
}
|
|
49
|
+
const operationTypes = [
|
|
50
|
+
"service", "machine", "progress", "repository", "arbitration",
|
|
51
|
+
"contact", "treasury", "reward", "allocation", "permission",
|
|
52
|
+
"guard", "personal", "payment", "demand", "order", "gen_passport"
|
|
53
|
+
];
|
|
54
|
+
for (const op of operationTypes) {
|
|
55
|
+
const regex = new RegExp(`\\b${op}\\b`, "i");
|
|
56
|
+
if (regex.test(content)) {
|
|
57
|
+
tags.push(op);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return [...new Set(tags)];
|
|
61
|
+
}
|
|
62
|
+
function loadDocument(filePath, basePath) {
|
|
63
|
+
try {
|
|
64
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
65
|
+
const relativePath = path.relative(basePath, filePath);
|
|
66
|
+
const filename = path.basename(filePath);
|
|
67
|
+
const stats = fs.statSync(filePath);
|
|
68
|
+
return {
|
|
69
|
+
id: relativePath.replace(/\\/g, "/"),
|
|
70
|
+
path: filePath,
|
|
71
|
+
title: extractTitle(content, filename),
|
|
72
|
+
content,
|
|
73
|
+
category: determineCategory(filePath, content),
|
|
74
|
+
tags: extractTags(content),
|
|
75
|
+
lastModified: stats.mtimeMs,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
console.error(`Failed to load document: ${filePath}`, error);
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function findMarkdownFiles(dir) {
|
|
84
|
+
const files = [];
|
|
85
|
+
try {
|
|
86
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
87
|
+
for (const entry of entries) {
|
|
88
|
+
const fullPath = path.join(dir, entry.name);
|
|
89
|
+
if (entry.isDirectory()) {
|
|
90
|
+
files.push(...findMarkdownFiles(fullPath));
|
|
91
|
+
}
|
|
92
|
+
else if (entry.name.endsWith(".md")) {
|
|
93
|
+
files.push(fullPath);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
console.warn(`Cannot read directory: ${dir}`);
|
|
99
|
+
}
|
|
100
|
+
return files;
|
|
101
|
+
}
|
|
102
|
+
function loadSkillsDocs() {
|
|
103
|
+
const skillsPath = getDocsPath("skills");
|
|
104
|
+
const files = findMarkdownFiles(skillsPath);
|
|
105
|
+
return files
|
|
106
|
+
.map((file) => loadDocument(file, skillsPath))
|
|
107
|
+
.filter((doc) => doc !== null);
|
|
108
|
+
}
|
|
109
|
+
function loadExamplesDocs() {
|
|
110
|
+
const examplesPath = getDocsPath("examples");
|
|
111
|
+
const files = findMarkdownFiles(examplesPath);
|
|
112
|
+
return files
|
|
113
|
+
.map((file) => loadDocument(file, examplesPath))
|
|
114
|
+
.filter((doc) => doc !== null);
|
|
115
|
+
}
|
|
116
|
+
function buildIndex(documents) {
|
|
117
|
+
const index = {
|
|
118
|
+
operations: new Map(),
|
|
119
|
+
tools: new Map(),
|
|
120
|
+
examples: new Map(),
|
|
121
|
+
guides: new Map(),
|
|
122
|
+
all: documents,
|
|
123
|
+
};
|
|
124
|
+
for (const doc of documents) {
|
|
125
|
+
if (doc.category === "operation-schema") {
|
|
126
|
+
const operationMatch = doc.id.match(/onchain_operations\/(.+)\.md$/);
|
|
127
|
+
if (operationMatch && !operationMatch[1].startsWith("_")) {
|
|
128
|
+
index.operations.set(operationMatch[1], doc);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (doc.category === "tool-schema") {
|
|
132
|
+
const toolMatch = doc.id.match(/schema-(.+)\.md$/);
|
|
133
|
+
if (toolMatch) {
|
|
134
|
+
index.tools.set(toolMatch[1], doc);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (doc.category === "example") {
|
|
138
|
+
const exampleMatch = doc.id.match(/^([^/]+)\//);
|
|
139
|
+
if (exampleMatch) {
|
|
140
|
+
const exampleName = exampleMatch[1];
|
|
141
|
+
if (!index.examples.has(exampleName)) {
|
|
142
|
+
index.examples.set(exampleName, []);
|
|
143
|
+
}
|
|
144
|
+
index.examples.get(exampleName).push(doc);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (doc.category === "common" || doc.category === "skill-overview") {
|
|
148
|
+
const guideKey = doc.id.replace(/\.md$/, "");
|
|
149
|
+
index.guides.set(guideKey, doc);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return index;
|
|
153
|
+
}
|
|
154
|
+
export function loadAllDocuments() {
|
|
155
|
+
const skillsDocs = loadSkillsDocs();
|
|
156
|
+
const examplesDocs = loadExamplesDocs();
|
|
157
|
+
const allDocs = [...skillsDocs, ...examplesDocs];
|
|
158
|
+
const index = buildIndex(allDocs);
|
|
159
|
+
return { documents: allDocs, index };
|
|
160
|
+
}
|
|
161
|
+
export function isDocumentationAvailable() {
|
|
162
|
+
const skillsPath = getDocsPath("skills");
|
|
163
|
+
const examplesPath = getDocsPath("examples");
|
|
164
|
+
return fs.existsSync(skillsPath) && fs.existsSync(examplesPath);
|
|
165
|
+
}
|
|
166
|
+
export function getDocStats() {
|
|
167
|
+
const skillsPath = getDocsPath("skills");
|
|
168
|
+
const examplesPath = getDocsPath("examples");
|
|
169
|
+
const skillsFiles = fs.existsSync(skillsPath) ? findMarkdownFiles(skillsPath).length : 0;
|
|
170
|
+
const examplesFiles = fs.existsSync(examplesPath) ? findMarkdownFiles(examplesPath).length : 0;
|
|
171
|
+
return {
|
|
172
|
+
total: skillsFiles + examplesFiles,
|
|
173
|
+
skills: skillsFiles,
|
|
174
|
+
examples: examplesFiles,
|
|
175
|
+
available: fs.existsSync(skillsPath) && fs.existsSync(examplesPath),
|
|
176
|
+
};
|
|
177
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Document, DocumentIndex, SearchResult, SchemaInfo, ExampleInfo, LearnRequest, LearnResponse } from "./types.js";
|
|
2
|
+
export declare function searchDocuments(index: DocumentIndex, query: string, limit?: number): SearchResult[];
|
|
3
|
+
export declare function getOperationSchema(index: DocumentIndex, operationType: string): SchemaInfo | null;
|
|
4
|
+
export declare function getToolSchema(index: DocumentIndex, toolName: string): SchemaInfo | null;
|
|
5
|
+
export declare function getExampleInfo(index: DocumentIndex, exampleName: string): ExampleInfo | null;
|
|
6
|
+
export declare function getGuide(index: DocumentIndex, topic: string): Document | null;
|
|
7
|
+
export declare function listOperations(index: DocumentIndex): Array<{
|
|
8
|
+
name: string;
|
|
9
|
+
title: string;
|
|
10
|
+
description: string;
|
|
11
|
+
}>;
|
|
12
|
+
export declare function listExamples(index: DocumentIndex): Array<{
|
|
13
|
+
name: string;
|
|
14
|
+
title: string;
|
|
15
|
+
docCount: number;
|
|
16
|
+
}>;
|
|
17
|
+
export declare function processLearnRequest(index: DocumentIndex, request: LearnRequest): LearnResponse;
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
function calculateScore(document, query) {
|
|
2
|
+
const lowerQuery = query.toLowerCase();
|
|
3
|
+
const lowerTitle = document.title.toLowerCase();
|
|
4
|
+
const lowerContent = document.content.toLowerCase();
|
|
5
|
+
const lowerTags = document.tags.map((t) => t.toLowerCase());
|
|
6
|
+
let score = 0;
|
|
7
|
+
if (lowerTitle === lowerQuery) {
|
|
8
|
+
score += 100;
|
|
9
|
+
}
|
|
10
|
+
else if (lowerTitle.includes(lowerQuery)) {
|
|
11
|
+
score += 50;
|
|
12
|
+
}
|
|
13
|
+
if (lowerTags.some((tag) => tag === lowerQuery)) {
|
|
14
|
+
score += 40;
|
|
15
|
+
}
|
|
16
|
+
if (lowerTags.some((tag) => tag.includes(lowerQuery))) {
|
|
17
|
+
score += 20;
|
|
18
|
+
}
|
|
19
|
+
const contentMatches = (lowerContent.match(new RegExp(lowerQuery, "g")) || []).length;
|
|
20
|
+
score += Math.min(contentMatches * 5, 30);
|
|
21
|
+
if (document.category === "operation-schema" && lowerQuery.match(/^(service|guard|machine|order)$/)) {
|
|
22
|
+
score += 10;
|
|
23
|
+
}
|
|
24
|
+
return score;
|
|
25
|
+
}
|
|
26
|
+
function extractSnippets(content, query, maxSnippets = 3) {
|
|
27
|
+
const lowerContent = content.toLowerCase();
|
|
28
|
+
const lowerQuery = query.toLowerCase();
|
|
29
|
+
const snippets = [];
|
|
30
|
+
const sentences = content.split(/[.!?\n]+/);
|
|
31
|
+
for (const sentence of sentences) {
|
|
32
|
+
if (sentence.toLowerCase().includes(lowerQuery) && sentence.trim().length > 20) {
|
|
33
|
+
snippets.push(sentence.trim());
|
|
34
|
+
if (snippets.length >= maxSnippets)
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return snippets;
|
|
39
|
+
}
|
|
40
|
+
export function searchDocuments(index, query, limit = 5) {
|
|
41
|
+
const results = [];
|
|
42
|
+
for (const doc of index.all) {
|
|
43
|
+
const score = calculateScore(doc, query);
|
|
44
|
+
if (score > 0) {
|
|
45
|
+
results.push({
|
|
46
|
+
document: doc,
|
|
47
|
+
score,
|
|
48
|
+
matches: extractSnippets(doc.content, query),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
results.sort((a, b) => b.score - a.score);
|
|
53
|
+
return results.slice(0, limit);
|
|
54
|
+
}
|
|
55
|
+
export function getOperationSchema(index, operationType) {
|
|
56
|
+
const doc = index.operations.get(operationType.toLowerCase());
|
|
57
|
+
if (!doc)
|
|
58
|
+
return null;
|
|
59
|
+
const descMatch = doc.content.match(/>\s*([^\n]+)/);
|
|
60
|
+
const description = descMatch ? descMatch[1].trim() : "";
|
|
61
|
+
const schemaMatch = doc.content.match(/##\s*Data Schema\s*([\s\S]*?)(?=##|$)/);
|
|
62
|
+
const dataSchema = schemaMatch ? schemaMatch[1].trim() : undefined;
|
|
63
|
+
const relatedOps = [];
|
|
64
|
+
for (const [opName] of index.operations) {
|
|
65
|
+
if (opName !== operationType && doc.content.toLowerCase().includes(opName.toLowerCase())) {
|
|
66
|
+
relatedOps.push(opName);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
operationType,
|
|
71
|
+
title: doc.title,
|
|
72
|
+
description,
|
|
73
|
+
dataSchema,
|
|
74
|
+
relatedOperations: relatedOps.slice(0, 5),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export function getToolSchema(index, toolName) {
|
|
78
|
+
const doc = index.tools.get(toolName.toLowerCase());
|
|
79
|
+
if (!doc)
|
|
80
|
+
return null;
|
|
81
|
+
const descMatch = doc.content.match(/>\s*([^\n]+)/);
|
|
82
|
+
const description = descMatch ? descMatch[1].trim() : "";
|
|
83
|
+
return {
|
|
84
|
+
toolName,
|
|
85
|
+
title: doc.title,
|
|
86
|
+
description,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export function getExampleInfo(index, exampleName) {
|
|
90
|
+
const docs = index.examples.get(exampleName);
|
|
91
|
+
if (!docs || docs.length === 0)
|
|
92
|
+
return null;
|
|
93
|
+
const mainDoc = docs.find((d) => d.id.toLowerCase().includes(".md") && !d.id.toLowerCase().includes("test")) || docs[0];
|
|
94
|
+
const descMatch = mainDoc.content.match(/##\s*Overview\s*([\s\S]*?)(?=##|$)/);
|
|
95
|
+
const description = descMatch
|
|
96
|
+
? descMatch[1].trim().slice(0, 200) + "..."
|
|
97
|
+
: mainDoc.content.slice(0, 200) + "...";
|
|
98
|
+
const testResults = docs.find((d) => d.id.toLowerCase().includes("testresult"));
|
|
99
|
+
return {
|
|
100
|
+
name: exampleName,
|
|
101
|
+
title: mainDoc.title,
|
|
102
|
+
description,
|
|
103
|
+
documents: docs,
|
|
104
|
+
testResults,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
export function getGuide(index, topic) {
|
|
108
|
+
let doc = index.guides.get(topic.toLowerCase());
|
|
109
|
+
if (doc)
|
|
110
|
+
return doc;
|
|
111
|
+
const prefixes = ["", "_", "onchain_operations/", "schema-"];
|
|
112
|
+
for (const prefix of prefixes) {
|
|
113
|
+
doc = index.guides.get(`${prefix}${topic.toLowerCase()}`);
|
|
114
|
+
if (doc)
|
|
115
|
+
return doc;
|
|
116
|
+
}
|
|
117
|
+
for (const [key, value] of index.guides) {
|
|
118
|
+
if (key.includes(topic.toLowerCase())) {
|
|
119
|
+
return value;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
export function listOperations(index) {
|
|
125
|
+
const operations = [];
|
|
126
|
+
for (const [name, doc] of index.operations) {
|
|
127
|
+
const descMatch = doc.content.match(/>\s*([^\n]+)/);
|
|
128
|
+
const description = descMatch ? descMatch[1].trim() : "";
|
|
129
|
+
operations.push({
|
|
130
|
+
name,
|
|
131
|
+
title: doc.title,
|
|
132
|
+
description,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return operations.sort((a, b) => a.name.localeCompare(b.name));
|
|
136
|
+
}
|
|
137
|
+
export function listExamples(index) {
|
|
138
|
+
const examples = [];
|
|
139
|
+
for (const [name, docs] of index.examples) {
|
|
140
|
+
const mainDoc = docs.find((d) => !d.id.toLowerCase().includes("test")) || docs[0];
|
|
141
|
+
examples.push({
|
|
142
|
+
name,
|
|
143
|
+
title: mainDoc.title,
|
|
144
|
+
docCount: docs.length,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
return examples.sort((a, b) => a.name.localeCompare(b.name));
|
|
148
|
+
}
|
|
149
|
+
export function processLearnRequest(index, request) {
|
|
150
|
+
switch (request.action) {
|
|
151
|
+
case "search": {
|
|
152
|
+
if (!request.query) {
|
|
153
|
+
return {
|
|
154
|
+
success: false,
|
|
155
|
+
action: "search",
|
|
156
|
+
data: null,
|
|
157
|
+
message: "Search query is required",
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
const results = searchDocuments(index, request.query);
|
|
161
|
+
if (results.length === 0) {
|
|
162
|
+
return {
|
|
163
|
+
success: true,
|
|
164
|
+
action: "search",
|
|
165
|
+
data: [],
|
|
166
|
+
message: `No documents found for "${request.query}"`,
|
|
167
|
+
suggestions: ["Try a different keyword", "Use 'list_operations' to see available operations", "Use 'list_examples' to see available examples"],
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
success: true,
|
|
172
|
+
action: "search",
|
|
173
|
+
data: results.map((r) => ({
|
|
174
|
+
title: r.document.title,
|
|
175
|
+
category: r.document.category,
|
|
176
|
+
path: r.document.id,
|
|
177
|
+
score: r.score,
|
|
178
|
+
snippets: r.matches,
|
|
179
|
+
})),
|
|
180
|
+
message: `Found ${results.length} document(s) for "${request.query}"`,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
case "get_schema": {
|
|
184
|
+
const opType = request.operationType || request.topic;
|
|
185
|
+
const toolName = request.toolName;
|
|
186
|
+
if (opType) {
|
|
187
|
+
const schema = getOperationSchema(index, opType);
|
|
188
|
+
if (!schema) {
|
|
189
|
+
return {
|
|
190
|
+
success: false,
|
|
191
|
+
action: "get_schema",
|
|
192
|
+
data: null,
|
|
193
|
+
message: `Operation schema not found: ${opType}`,
|
|
194
|
+
suggestions: Array.from(index.operations.keys()).slice(0, 5),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
success: true,
|
|
199
|
+
action: "get_schema",
|
|
200
|
+
data: schema,
|
|
201
|
+
message: `Schema for operation: ${opType}`,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
if (toolName) {
|
|
205
|
+
const schema = getToolSchema(index, toolName);
|
|
206
|
+
if (!schema) {
|
|
207
|
+
return {
|
|
208
|
+
success: false,
|
|
209
|
+
action: "get_schema",
|
|
210
|
+
data: null,
|
|
211
|
+
message: `Tool schema not found: ${toolName}`,
|
|
212
|
+
suggestions: Array.from(index.tools.keys()).slice(0, 5),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
success: true,
|
|
217
|
+
action: "get_schema",
|
|
218
|
+
data: schema,
|
|
219
|
+
message: `Schema for tool: ${toolName}`,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
success: false,
|
|
224
|
+
action: "get_schema",
|
|
225
|
+
data: null,
|
|
226
|
+
message: "operationType or toolName is required",
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
case "learn_example": {
|
|
230
|
+
const exampleName = request.example || request.topic;
|
|
231
|
+
if (!exampleName) {
|
|
232
|
+
return {
|
|
233
|
+
success: false,
|
|
234
|
+
action: "learn_example",
|
|
235
|
+
data: null,
|
|
236
|
+
message: "Example name is required",
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
const info = getExampleInfo(index, exampleName);
|
|
240
|
+
if (!info) {
|
|
241
|
+
const available = listExamples(index);
|
|
242
|
+
return {
|
|
243
|
+
success: false,
|
|
244
|
+
action: "learn_example",
|
|
245
|
+
data: null,
|
|
246
|
+
message: `Example not found: ${exampleName}`,
|
|
247
|
+
suggestions: available.map((e) => e.name),
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
return {
|
|
251
|
+
success: true,
|
|
252
|
+
action: "learn_example",
|
|
253
|
+
data: {
|
|
254
|
+
name: info.name,
|
|
255
|
+
title: info.title,
|
|
256
|
+
description: info.description,
|
|
257
|
+
documents: info.documents.map((d) => ({
|
|
258
|
+
title: d.title,
|
|
259
|
+
path: d.id,
|
|
260
|
+
category: d.category,
|
|
261
|
+
})),
|
|
262
|
+
hasTestResults: !!info.testResults,
|
|
263
|
+
},
|
|
264
|
+
message: `Example: ${info.title}`,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
case "guide": {
|
|
268
|
+
const topic = request.topic || request.query;
|
|
269
|
+
if (!topic) {
|
|
270
|
+
return {
|
|
271
|
+
success: false,
|
|
272
|
+
action: "guide",
|
|
273
|
+
data: null,
|
|
274
|
+
message: "Topic is required",
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
const doc = getGuide(index, topic);
|
|
278
|
+
if (!doc) {
|
|
279
|
+
return {
|
|
280
|
+
success: false,
|
|
281
|
+
action: "guide",
|
|
282
|
+
data: null,
|
|
283
|
+
message: `Guide not found: ${topic}`,
|
|
284
|
+
suggestions: ["Try 'WOWOK' for overview", "Try '_index' for operations index", "Use 'search' to find relevant content"],
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
return {
|
|
288
|
+
success: true,
|
|
289
|
+
action: "guide",
|
|
290
|
+
data: {
|
|
291
|
+
title: doc.title,
|
|
292
|
+
category: doc.category,
|
|
293
|
+
content: doc.content,
|
|
294
|
+
tags: doc.tags,
|
|
295
|
+
},
|
|
296
|
+
message: `Guide: ${doc.title}`,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
case "list_operations": {
|
|
300
|
+
const operations = listOperations(index);
|
|
301
|
+
return {
|
|
302
|
+
success: true,
|
|
303
|
+
action: "list_operations",
|
|
304
|
+
data: operations,
|
|
305
|
+
message: `Available operations: ${operations.length}`,
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
case "list_examples": {
|
|
309
|
+
const examples = listExamples(index);
|
|
310
|
+
return {
|
|
311
|
+
success: true,
|
|
312
|
+
action: "list_examples",
|
|
313
|
+
data: examples,
|
|
314
|
+
message: `Available examples: ${examples.length}`,
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
default:
|
|
318
|
+
return {
|
|
319
|
+
success: false,
|
|
320
|
+
action: request.action,
|
|
321
|
+
data: null,
|
|
322
|
+
message: `Unknown action: ${request.action}`,
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export interface Document {
|
|
2
|
+
id: string;
|
|
3
|
+
path: string;
|
|
4
|
+
title: string;
|
|
5
|
+
content: string;
|
|
6
|
+
category: DocumentCategory;
|
|
7
|
+
tags: string[];
|
|
8
|
+
lastModified: number;
|
|
9
|
+
}
|
|
10
|
+
export type DocumentCategory = "skill-overview" | "operation-schema" | "tool-schema" | "example" | "common";
|
|
11
|
+
export interface DocumentIndex {
|
|
12
|
+
operations: Map<string, Document>;
|
|
13
|
+
tools: Map<string, Document>;
|
|
14
|
+
examples: Map<string, Document[]>;
|
|
15
|
+
guides: Map<string, Document>;
|
|
16
|
+
all: Document[];
|
|
17
|
+
}
|
|
18
|
+
export interface SearchResult {
|
|
19
|
+
document: Document;
|
|
20
|
+
score: number;
|
|
21
|
+
matches: string[];
|
|
22
|
+
}
|
|
23
|
+
export interface SchemaInfo {
|
|
24
|
+
operationType?: string;
|
|
25
|
+
toolName?: string;
|
|
26
|
+
title: string;
|
|
27
|
+
description: string;
|
|
28
|
+
dataSchema?: string;
|
|
29
|
+
examples?: string[];
|
|
30
|
+
relatedOperations?: string[];
|
|
31
|
+
}
|
|
32
|
+
export interface ExampleInfo {
|
|
33
|
+
name: string;
|
|
34
|
+
title: string;
|
|
35
|
+
description: string;
|
|
36
|
+
documents: Document[];
|
|
37
|
+
testResults?: Document;
|
|
38
|
+
}
|
|
39
|
+
export type LearnAction = "search" | "get_schema" | "learn_example" | "guide" | "list_operations" | "list_examples";
|
|
40
|
+
export interface LearnRequest {
|
|
41
|
+
action: LearnAction;
|
|
42
|
+
topic?: string;
|
|
43
|
+
query?: string;
|
|
44
|
+
example?: string;
|
|
45
|
+
operationType?: string;
|
|
46
|
+
toolName?: string;
|
|
47
|
+
}
|
|
48
|
+
export interface LearnResponse {
|
|
49
|
+
[key: string]: unknown;
|
|
50
|
+
success: boolean;
|
|
51
|
+
action: LearnAction;
|
|
52
|
+
data: unknown;
|
|
53
|
+
message: string;
|
|
54
|
+
suggestions?: string[];
|
|
55
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -15642,6 +15642,15 @@ declare const WatchQueryOperationsSchema: z.ZodEffects<z.ZodUnion<[z.ZodDiscrimi
|
|
|
15642
15642
|
cursor?: string | null | undefined;
|
|
15643
15643
|
limit?: number | null | undefined;
|
|
15644
15644
|
} | undefined;
|
|
15645
|
+
}>, z.ZodObject<{
|
|
15646
|
+
query_type: z.ZodLiteral<"local_names">;
|
|
15647
|
+
addresses: z.ZodArray<z.ZodString, "many">;
|
|
15648
|
+
}, "strip", z.ZodTypeAny, {
|
|
15649
|
+
query_type: "local_names";
|
|
15650
|
+
addresses: string[];
|
|
15651
|
+
}, {
|
|
15652
|
+
query_type: "local_names";
|
|
15653
|
+
addresses: string[];
|
|
15645
15654
|
}>]>, z.ZodDiscriminatedUnion<"query_type", [z.ZodObject<{
|
|
15646
15655
|
query_type: z.ZodLiteral<"onchain_personal_profile">;
|
|
15647
15656
|
account: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
@@ -15775,6 +15784,9 @@ declare const WatchQueryOperationsSchema: z.ZodEffects<z.ZodUnion<[z.ZodDiscrimi
|
|
|
15775
15784
|
cursor?: string | null | undefined;
|
|
15776
15785
|
limit?: number | null | undefined;
|
|
15777
15786
|
} | undefined;
|
|
15787
|
+
} | {
|
|
15788
|
+
query_type: "local_names";
|
|
15789
|
+
addresses: string[];
|
|
15778
15790
|
} | {
|
|
15779
15791
|
query_type: "onchain_personal_profile";
|
|
15780
15792
|
no_cache?: boolean | undefined;
|