@pinepaper.studio/mcp-server 1.3.0 → 1.3.2
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/taxonomy/classifier.d.ts +74 -0
- package/dist/taxonomy/classifier.d.ts.map +1 -0
- package/dist/taxonomy/classifier.js +448 -0
- package/dist/taxonomy/classifier.js.map +1 -0
- package/dist/taxonomy/error-recovery.d.ts +55 -0
- package/dist/taxonomy/error-recovery.d.ts.map +1 -0
- package/dist/taxonomy/error-recovery.js +205 -0
- package/dist/taxonomy/error-recovery.js.map +1 -0
- package/dist/taxonomy/index.d.ts +24 -0
- package/dist/taxonomy/index.d.ts.map +1 -0
- package/dist/taxonomy/index.js +25 -0
- package/dist/taxonomy/index.js.map +1 -0
- package/dist/taxonomy/matcher.d.ts +104 -0
- package/dist/taxonomy/matcher.d.ts.map +1 -0
- package/dist/taxonomy/matcher.js +473 -0
- package/dist/taxonomy/matcher.js.map +1 -0
- package/dist/taxonomy/registry.d.ts +56 -0
- package/dist/taxonomy/registry.d.ts.map +1 -0
- package/dist/taxonomy/registry.js +950 -0
- package/dist/taxonomy/registry.js.map +1 -0
- package/dist/taxonomy/types.d.ts +207 -0
- package/dist/taxonomy/types.d.ts.map +1 -0
- package/dist/taxonomy/types.js +29 -0
- package/dist/taxonomy/types.js.map +1 -0
- package/dist/tools/definitions.d.ts.map +1 -1
- package/dist/tools/definitions.js +266 -0
- package/dist/tools/definitions.js.map +1 -1
- package/dist/tools/handlers.d.ts.map +1 -1
- package/dist/tools/handlers.js +19 -1
- package/dist/tools/handlers.js.map +1 -1
- package/dist/tools/p5-compat/index.d.ts +8 -0
- package/dist/tools/p5-compat/index.d.ts.map +1 -0
- package/dist/tools/p5-compat/index.js +8 -0
- package/dist/tools/p5-compat/index.js.map +1 -0
- package/dist/tools/p5-compat/p5-helpers.d.ts +25 -0
- package/dist/tools/p5-compat/p5-helpers.d.ts.map +1 -0
- package/dist/tools/p5-compat/p5-helpers.js +399 -0
- package/dist/tools/p5-compat/p5-helpers.js.map +1 -0
- package/dist/types/code-generator.d.ts +9 -1
- package/dist/types/code-generator.d.ts.map +1 -1
- package/dist/types/code-generator.js +176 -1
- package/dist/types/code-generator.js.map +1 -1
- package/dist/types/schemas.d.ts +227 -0
- package/dist/types/schemas.d.ts.map +1 -1
- package/dist/types/schemas.js +57 -0
- package/dist/types/schemas.js.map +1 -1
- package/manifest.json +9 -1
- package/package.json +1 -1
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rich Error Recovery with Taxonomy Suggestions
|
|
3
|
+
*
|
|
4
|
+
* Provides intelligent error messages with suggestions based on
|
|
5
|
+
* the semantic taxonomy. Helps users and AI understand how to
|
|
6
|
+
* fix mistakes and find the right tools.
|
|
7
|
+
*/
|
|
8
|
+
import { getTaxonomyMatcher } from './matcher.js';
|
|
9
|
+
/**
|
|
10
|
+
* Build rich error recovery context for common errors
|
|
11
|
+
*/
|
|
12
|
+
export function buildErrorRecovery(errorType, context) {
|
|
13
|
+
const { failedId, availableItems = [], userInput, toolName, locale } = context;
|
|
14
|
+
switch (errorType) {
|
|
15
|
+
case 'ITEM_NOT_FOUND': {
|
|
16
|
+
const similar = findSimilarItemId(failedId || '', availableItems);
|
|
17
|
+
return {
|
|
18
|
+
error: `Item "${failedId}" not found`,
|
|
19
|
+
code: 'ITEM_NOT_FOUND',
|
|
20
|
+
hint: similar
|
|
21
|
+
? `Did you mean "${similar}"?`
|
|
22
|
+
: 'Use pinepaper_get_items to list all available items',
|
|
23
|
+
suggestions: ['pinepaper_get_items'],
|
|
24
|
+
availableItems: availableItems.slice(0, 5),
|
|
25
|
+
didYouMean: similar,
|
|
26
|
+
example: `pinepaper_modify_item({ itemId: "${similar || 'item_1'}", properties: {...} })`,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
case 'INVALID_RELATION': {
|
|
30
|
+
return {
|
|
31
|
+
error: 'Invalid relation type or missing target',
|
|
32
|
+
code: 'INVALID_RELATION',
|
|
33
|
+
hint: 'Relations require both sourceId and targetId to exist',
|
|
34
|
+
suggestions: ['pinepaper_get_items', 'pinepaper_query_relations'],
|
|
35
|
+
availableItems: availableItems.slice(0, 5),
|
|
36
|
+
example: `pinepaper_add_relation({ sourceId: "item_1", targetId: "item_2", relationType: "orbits" })`,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
case 'GENERATOR_NOT_FOUND': {
|
|
40
|
+
const generators = [
|
|
41
|
+
'drawSunburst',
|
|
42
|
+
'drawWaves',
|
|
43
|
+
'drawGrid',
|
|
44
|
+
'drawCircuit',
|
|
45
|
+
'drawSunsetScene',
|
|
46
|
+
'drawStackedCircles',
|
|
47
|
+
'drawPattern',
|
|
48
|
+
];
|
|
49
|
+
return {
|
|
50
|
+
error: 'Generator not found',
|
|
51
|
+
code: 'GENERATOR_NOT_FOUND',
|
|
52
|
+
hint: 'Available generators: ' + generators.join(', '),
|
|
53
|
+
suggestions: ['pinepaper_list_generators'],
|
|
54
|
+
example: `pinepaper_execute_generator({ generatorName: "drawSunburst" })`,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
case 'TOOL_MISMATCH': {
|
|
58
|
+
// Use taxonomy to suggest better tool
|
|
59
|
+
const taxonomyMatcher = getTaxonomyMatcher();
|
|
60
|
+
let similarConcepts = [];
|
|
61
|
+
if (userInput) {
|
|
62
|
+
// This is synchronous lookup from already-built index
|
|
63
|
+
taxonomyMatcher.findMatches(userInput, locale).then((matches) => {
|
|
64
|
+
similarConcepts = matches.slice(0, 3);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
error: `Tool "${toolName}" may not be the best choice for this request`,
|
|
69
|
+
code: 'TOOL_MISMATCH',
|
|
70
|
+
hint: similarConcepts.length > 0
|
|
71
|
+
? `Consider using "${similarConcepts[0]?.node.tool.tool}" instead`
|
|
72
|
+
: 'Use pinepaper_recommend_approach for tool suggestions',
|
|
73
|
+
suggestions: similarConcepts.map((m) => m.node.tool.tool),
|
|
74
|
+
similarConcepts,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
case 'VALIDATION_ERROR': {
|
|
78
|
+
return {
|
|
79
|
+
error: 'Invalid parameters provided',
|
|
80
|
+
code: 'VALIDATION_ERROR',
|
|
81
|
+
hint: 'Check the tool documentation for required and optional parameters',
|
|
82
|
+
suggestions: ['Check tool inputSchema for required fields'],
|
|
83
|
+
example: getToolExample(toolName || ''),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
default:
|
|
87
|
+
return {
|
|
88
|
+
error: errorType,
|
|
89
|
+
code: 'UNKNOWN_ERROR',
|
|
90
|
+
hint: 'Check the MCP server logs for more details',
|
|
91
|
+
suggestions: ['pinepaper_get_items', 'pinepaper_browser_status'],
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Find a similar item ID using Levenshtein distance
|
|
97
|
+
*/
|
|
98
|
+
function findSimilarItemId(failedId, availableItems) {
|
|
99
|
+
if (!failedId || availableItems.length === 0)
|
|
100
|
+
return undefined;
|
|
101
|
+
let bestMatch;
|
|
102
|
+
let bestDistance = Infinity;
|
|
103
|
+
for (const item of availableItems) {
|
|
104
|
+
const distance = levenshteinDistance(failedId.toLowerCase(), item.id.toLowerCase());
|
|
105
|
+
if (distance < bestDistance && distance <= 3) {
|
|
106
|
+
// Allow up to 3 edits
|
|
107
|
+
bestDistance = distance;
|
|
108
|
+
bestMatch = item.id;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return bestMatch;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Calculate Levenshtein distance between two strings
|
|
115
|
+
*/
|
|
116
|
+
function levenshteinDistance(str1, str2) {
|
|
117
|
+
const m = str1.length;
|
|
118
|
+
const n = str2.length;
|
|
119
|
+
if (m === 0)
|
|
120
|
+
return n;
|
|
121
|
+
if (n === 0)
|
|
122
|
+
return m;
|
|
123
|
+
const dp = Array(m + 1)
|
|
124
|
+
.fill(null)
|
|
125
|
+
.map(() => Array(n + 1).fill(0));
|
|
126
|
+
for (let i = 0; i <= m; i++)
|
|
127
|
+
dp[i][0] = i;
|
|
128
|
+
for (let j = 0; j <= n; j++)
|
|
129
|
+
dp[0][j] = j;
|
|
130
|
+
for (let i = 1; i <= m; i++) {
|
|
131
|
+
for (let j = 1; j <= n; j++) {
|
|
132
|
+
if (str1[i - 1] === str2[j - 1]) {
|
|
133
|
+
dp[i][j] = dp[i - 1][j - 1];
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
dp[i][j] = Math.min(dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + 1);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return dp[m][n];
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Get an example usage for a tool
|
|
144
|
+
*/
|
|
145
|
+
function getToolExample(toolName) {
|
|
146
|
+
const examples = {
|
|
147
|
+
pinepaper_create_item: `pinepaper_create_item({ itemType: "circle", position: {x: 400, y: 300}, properties: {radius: 50, color: "#3b82f6"} })`,
|
|
148
|
+
pinepaper_modify_item: `pinepaper_modify_item({ itemId: "item_1", properties: {color: "#ef4444"} })`,
|
|
149
|
+
pinepaper_delete_item: `pinepaper_delete_item({ itemId: "item_1" })`,
|
|
150
|
+
pinepaper_add_relation: `pinepaper_add_relation({ sourceId: "item_1", targetId: "item_2", relationType: "orbits", params: {radius: 100, speed: 0.5} })`,
|
|
151
|
+
pinepaper_animate: `pinepaper_animate({ itemId: "item_1", animationType: "pulse", speed: 0.5 })`,
|
|
152
|
+
pinepaper_execute_generator: `pinepaper_execute_generator({ generatorName: "drawSunburst" })`,
|
|
153
|
+
pinepaper_create_scene: `pinepaper_create_scene({ items: [{name: "sun", itemType: "circle", properties: {radius: 50, color: "#fbbf24"}}], animations: [{target: "sun", type: "pulse"}] })`,
|
|
154
|
+
};
|
|
155
|
+
return examples[toolName] || `${toolName}({ /* see tool definition */ })`;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Format error context for MCP response
|
|
159
|
+
*/
|
|
160
|
+
export function formatRichError(context) {
|
|
161
|
+
const parts = [];
|
|
162
|
+
parts.push(`Error: ${context.error}`);
|
|
163
|
+
if (context.hint) {
|
|
164
|
+
parts.push(`Hint: ${context.hint}`);
|
|
165
|
+
}
|
|
166
|
+
if (context.didYouMean) {
|
|
167
|
+
parts.push(`Did you mean: "${context.didYouMean}"`);
|
|
168
|
+
}
|
|
169
|
+
if (context.availableItems && context.availableItems.length > 0) {
|
|
170
|
+
const itemList = context.availableItems.map((i) => `${i.id} (${i.type})`).join(', ');
|
|
171
|
+
parts.push(`Available items: ${itemList}`);
|
|
172
|
+
}
|
|
173
|
+
if (context.suggestions && context.suggestions.length > 0) {
|
|
174
|
+
parts.push(`Suggestions: ${context.suggestions.join(', ')}`);
|
|
175
|
+
}
|
|
176
|
+
if (context.example) {
|
|
177
|
+
parts.push(`Example: ${context.example}`);
|
|
178
|
+
}
|
|
179
|
+
return parts.join('\n');
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Build taxonomy-aware error for tool validation
|
|
183
|
+
*/
|
|
184
|
+
export async function validateToolWithTaxonomy(toolName, userInput, locale) {
|
|
185
|
+
const matcher = getTaxonomyMatcher();
|
|
186
|
+
await matcher.initialize();
|
|
187
|
+
const matches = await matcher.findMatches(userInput, locale);
|
|
188
|
+
if (matches.length === 0) {
|
|
189
|
+
return null; // Can't validate without matches
|
|
190
|
+
}
|
|
191
|
+
const topMatch = matches[0];
|
|
192
|
+
// Check if the selected tool matches the taxonomy recommendation
|
|
193
|
+
if (topMatch.node.tool.tool !== toolName && topMatch.similarity > 0.8) {
|
|
194
|
+
return {
|
|
195
|
+
error: `Tool "${toolName}" may not be optimal for this request`,
|
|
196
|
+
code: 'TOOL_MISMATCH',
|
|
197
|
+
hint: `The taxonomy suggests "${topMatch.node.tool.tool}" based on "${topMatch.matchedTerm}"`,
|
|
198
|
+
suggestions: [topMatch.node.tool.tool],
|
|
199
|
+
similarConcepts: matches.slice(0, 3),
|
|
200
|
+
example: getToolExample(topMatch.node.tool.tool),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=error-recovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-recovery.js","sourceRoot":"","sources":["../../src/taxonomy/error-recovery.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAyBlD;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAChC,SAAiB,EACjB,OAMC;IAED,MAAM,EAAE,QAAQ,EAAE,cAAc,GAAG,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAE/E,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,gBAAgB,CAAC,CAAC,CAAC;YACtB,MAAM,OAAO,GAAG,iBAAiB,CAAC,QAAQ,IAAI,EAAE,EAAE,cAAc,CAAC,CAAC;YAClE,OAAO;gBACL,KAAK,EAAE,SAAS,QAAQ,aAAa;gBACrC,IAAI,EAAE,gBAAgB;gBACtB,IAAI,EAAE,OAAO;oBACX,CAAC,CAAC,iBAAiB,OAAO,IAAI;oBAC9B,CAAC,CAAC,qDAAqD;gBACzD,WAAW,EAAE,CAAC,qBAAqB,CAAC;gBACpC,cAAc,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;gBAC1C,UAAU,EAAE,OAAO;gBACnB,OAAO,EAAE,oCAAoC,OAAO,IAAI,QAAQ,yBAAyB;aAC1F,CAAC;QACJ,CAAC;QAED,KAAK,kBAAkB,CAAC,CAAC,CAAC;YACxB,OAAO;gBACL,KAAK,EAAE,yCAAyC;gBAChD,IAA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YACL,KAAK,EAAE,SAAS,QAAQ,uCAAuC;YAC/D,IAAI,EAAE,eAAe;YACrB,IAAI,EAAE,0BAA0B,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,eAAe,QAAQ,CAAC,WAAW,GAAG;YAC7F,WAAW,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YACtC,eAAe,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;YACpC,OAAO,EAAE,cAAc,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;SACjD,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semantic Taxonomy System
|
|
3
|
+
*
|
|
4
|
+
* Provides multilingual semantic tool selection for the PinePaper MCP server.
|
|
5
|
+
* This module exports all taxonomy-related functionality.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import { getIntentClassifier, getTaxonomyMatcher } from './taxonomy/index.js';
|
|
9
|
+
*
|
|
10
|
+
* const classifier = getIntentClassifier();
|
|
11
|
+
* await classifier.initialize();
|
|
12
|
+
*
|
|
13
|
+
* // Classify user intent in any language
|
|
14
|
+
* const analysis = await classifier.classify("faire tourner la lune autour de la terre");
|
|
15
|
+
* console.log(analysis.recommendedTool); // { name: 'pinepaper_add_relation', params: {...} }
|
|
16
|
+
*/
|
|
17
|
+
export type { TaxonomyNode, ModifierNode, TaxonomyCategory, MultilingualTerms, ToolMapping, ParameterExtractor, SchemaOrgReference, ClassificationResult, TaxonomyMatch, ExtractedEntity, IntentAnalysis, TaxonomyConfig, TaxonomyError, TaxonomyErrorCode, } from './types.js';
|
|
18
|
+
export { DEFAULT_TAXONOMY_CONFIG } from './types.js';
|
|
19
|
+
export { ANIMATION_TAXONOMY, MOTION_TAXONOMY, TRANSFORMATION_TAXONOMY, ITEM_TAXONOMY, BACKGROUND_TAXONOMY, MODIFIER_NODES, getTaxonomyNode, getNodesByCategory, getModifier, } from './registry.js';
|
|
20
|
+
export { TaxonomyMatcher, getTaxonomyMatcher, resetTaxonomyMatcher, } from './matcher.js';
|
|
21
|
+
export { IntentClassifier, getIntentClassifier, resetIntentClassifier, } from './classifier.js';
|
|
22
|
+
export type { ErrorRecoveryContext } from './error-recovery.js';
|
|
23
|
+
export { buildErrorRecovery, formatRichError, validateToolWithTaxonomy, } from './error-recovery.js';
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/taxonomy/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,aAAa,EACb,eAAe,EACf,cAAc,EACd,cAAc,EACd,aAAa,EACb,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAGrD,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,uBAAuB,EACvB,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,eAAe,EACf,kBAAkB,EAClB,WAAW,GACZ,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AAGzB,YAAY,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,wBAAwB,GACzB,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semantic Taxonomy System
|
|
3
|
+
*
|
|
4
|
+
* Provides multilingual semantic tool selection for the PinePaper MCP server.
|
|
5
|
+
* This module exports all taxonomy-related functionality.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import { getIntentClassifier, getTaxonomyMatcher } from './taxonomy/index.js';
|
|
9
|
+
*
|
|
10
|
+
* const classifier = getIntentClassifier();
|
|
11
|
+
* await classifier.initialize();
|
|
12
|
+
*
|
|
13
|
+
* // Classify user intent in any language
|
|
14
|
+
* const analysis = await classifier.classify("faire tourner la lune autour de la terre");
|
|
15
|
+
* console.log(analysis.recommendedTool); // { name: 'pinepaper_add_relation', params: {...} }
|
|
16
|
+
*/
|
|
17
|
+
export { DEFAULT_TAXONOMY_CONFIG } from './types.js';
|
|
18
|
+
// Registry exports
|
|
19
|
+
export { ANIMATION_TAXONOMY, MOTION_TAXONOMY, TRANSFORMATION_TAXONOMY, ITEM_TAXONOMY, BACKGROUND_TAXONOMY, MODIFIER_NODES, getTaxonomyNode, getNodesByCategory, getModifier, } from './registry.js';
|
|
20
|
+
// Matcher exports
|
|
21
|
+
export { TaxonomyMatcher, getTaxonomyMatcher, resetTaxonomyMatcher, } from './matcher.js';
|
|
22
|
+
// Classifier exports
|
|
23
|
+
export { IntentClassifier, getIntentClassifier, resetIntentClassifier, } from './classifier.js';
|
|
24
|
+
export { buildErrorRecovery, formatRichError, validateToolWithTaxonomy, } from './error-recovery.js';
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/taxonomy/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAoBH,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAErD,mBAAmB;AACnB,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,uBAAuB,EACvB,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,eAAe,EACf,kBAAkB,EAClB,WAAW,GACZ,MAAM,eAAe,CAAC;AAEvB,kBAAkB;AAClB,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,cAAc,CAAC;AAEtB,qBAAqB;AACrB,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,wBAAwB,GACzB,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semantic Taxonomy Matcher
|
|
3
|
+
*
|
|
4
|
+
* Provides fast keyword-based matching with fallback to pattern matching.
|
|
5
|
+
* Uses a hybrid approach: keyword index for exact matches, pattern matching
|
|
6
|
+
* for fuzzy matches, and can be extended with embeddings for semantic search.
|
|
7
|
+
*/
|
|
8
|
+
import type { SupportedLocale } from '../i18n/types.js';
|
|
9
|
+
import type { TaxonomyNode, ModifierNode, TaxonomyMatch, TaxonomyConfig } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Modifier match result
|
|
12
|
+
*/
|
|
13
|
+
interface ModifierMatch {
|
|
14
|
+
modifier: ModifierNode;
|
|
15
|
+
matched: boolean;
|
|
16
|
+
extractedValue?: string | number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Semantic Taxonomy Matcher
|
|
20
|
+
*
|
|
21
|
+
* Provides fast, multilingual matching of user input to taxonomy concepts.
|
|
22
|
+
*/
|
|
23
|
+
export declare class TaxonomyMatcher {
|
|
24
|
+
private keywordIndex;
|
|
25
|
+
private phraseIndex;
|
|
26
|
+
private config;
|
|
27
|
+
private initialized;
|
|
28
|
+
constructor(config?: Partial<TaxonomyConfig>);
|
|
29
|
+
/**
|
|
30
|
+
* Initialize the matcher by building keyword indexes
|
|
31
|
+
*/
|
|
32
|
+
initialize(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Build the keyword index for fast lookups
|
|
35
|
+
*/
|
|
36
|
+
private buildKeywordIndex;
|
|
37
|
+
/**
|
|
38
|
+
* Build the phrase index for multi-word matches
|
|
39
|
+
*/
|
|
40
|
+
private buildPhraseIndex;
|
|
41
|
+
/**
|
|
42
|
+
* Find the best matching taxonomy nodes for user input
|
|
43
|
+
*/
|
|
44
|
+
findMatches(input: string, preferredLocale?: SupportedLocale): Promise<TaxonomyMatch[]>;
|
|
45
|
+
/**
|
|
46
|
+
* Find exact phrase matches
|
|
47
|
+
*/
|
|
48
|
+
private findPhraseMatches;
|
|
49
|
+
/**
|
|
50
|
+
* Find keyword matches
|
|
51
|
+
*/
|
|
52
|
+
private findKeywordMatches;
|
|
53
|
+
/**
|
|
54
|
+
* Find pattern-based matches (fuzzy matching)
|
|
55
|
+
*/
|
|
56
|
+
private findPatternMatches;
|
|
57
|
+
/**
|
|
58
|
+
* Calculate string similarity using a combination of techniques
|
|
59
|
+
*/
|
|
60
|
+
private calculateStringSimilarity;
|
|
61
|
+
/**
|
|
62
|
+
* Calculate Levenshtein distance between two strings
|
|
63
|
+
*/
|
|
64
|
+
private levenshteinDistance;
|
|
65
|
+
/**
|
|
66
|
+
* Detect modifiers in user input
|
|
67
|
+
*/
|
|
68
|
+
detectModifiers(input: string, locale?: SupportedLocale): ModifierMatch[];
|
|
69
|
+
/**
|
|
70
|
+
* Extract parameter values from input using tool's extractors
|
|
71
|
+
*/
|
|
72
|
+
extractParameters(input: string, node: TaxonomyNode, locale?: SupportedLocale): Record<string, unknown>;
|
|
73
|
+
/**
|
|
74
|
+
* Detect the language of the input
|
|
75
|
+
* Simple heuristic based on character analysis
|
|
76
|
+
*/
|
|
77
|
+
detectLocale(input: string): SupportedLocale;
|
|
78
|
+
/**
|
|
79
|
+
* Get the best single match
|
|
80
|
+
*/
|
|
81
|
+
findBestMatch(input: string, locale?: SupportedLocale): Promise<TaxonomyMatch | null>;
|
|
82
|
+
/**
|
|
83
|
+
* Check if matcher is initialized
|
|
84
|
+
*/
|
|
85
|
+
isInitialized(): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Get configuration
|
|
88
|
+
*/
|
|
89
|
+
getConfig(): TaxonomyConfig;
|
|
90
|
+
/**
|
|
91
|
+
* Update configuration
|
|
92
|
+
*/
|
|
93
|
+
setConfig(config: Partial<TaxonomyConfig>): void;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Get or create the singleton TaxonomyMatcher instance
|
|
97
|
+
*/
|
|
98
|
+
export declare function getTaxonomyMatcher(config?: Partial<TaxonomyConfig>): TaxonomyMatcher;
|
|
99
|
+
/**
|
|
100
|
+
* Reset the singleton instance (for testing)
|
|
101
|
+
*/
|
|
102
|
+
export declare function resetTaxonomyMatcher(): void;
|
|
103
|
+
export {};
|
|
104
|
+
//# sourceMappingURL=matcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matcher.d.ts","sourceRoot":"","sources":["../../src/taxonomy/matcher.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,cAAc,EAEf,MAAM,YAAY,CAAC;AAcpB;;GAEG;AACH,UAAU,aAAa;IACrB,QAAQ,EAAE,YAAY,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAClC;AAED;;;;GAIG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,YAAY,CAA+C;IACnE,OAAO,CAAC,WAAW,CAA+C;IAClE,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,WAAW,CAAS;gBAEhB,MAAM,GAAE,OAAO,CAAC,cAAc,CAAM;IAWhD;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAajC;;OAEG;IACH,OAAO,CAAC,iBAA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