@pinepaper.studio/mcp-server 1.3.1 → 1.3.3
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 +409 -0
- package/dist/tools/definitions.js.map +1 -1
- package/dist/tools/handlers.d.ts.map +1 -1
- package/dist/tools/handlers.js +10 -1
- package/dist/tools/handlers.js.map +1 -1
- package/dist/types/code-generator.d.ts +5 -1
- package/dist/types/code-generator.d.ts.map +1 -1
- package/dist/types/code-generator.js +168 -1
- package/dist/types/code-generator.js.map +1 -1
- package/dist/types/schemas.d.ts +219 -0
- package/dist/types/schemas.d.ts.map +1 -1
- package/dist/types/schemas.js +51 -0
- package/dist/types/schemas.js.map +1 -1
- package/manifest.json +6 -1
- package/package.json +1 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Intent Classifier
|
|
3
|
+
*
|
|
4
|
+
* High-level classifier that combines taxonomy matching, modifier detection,
|
|
5
|
+
* entity extraction, and parameter inference to understand user intent
|
|
6
|
+
* and recommend the best MCP tool.
|
|
7
|
+
*/
|
|
8
|
+
import type { SupportedLocale } from '../i18n/types.js';
|
|
9
|
+
import type { IntentAnalysis, TaxonomyError, TaxonomyConfig } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Intent Classifier
|
|
12
|
+
*
|
|
13
|
+
* Analyzes user input to determine intent and recommend appropriate MCP tools.
|
|
14
|
+
*/
|
|
15
|
+
export declare class IntentClassifier {
|
|
16
|
+
private matcher;
|
|
17
|
+
private config;
|
|
18
|
+
private initialized;
|
|
19
|
+
constructor(config?: Partial<TaxonomyConfig>);
|
|
20
|
+
/**
|
|
21
|
+
* Initialize the classifier
|
|
22
|
+
*/
|
|
23
|
+
initialize(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Classify user input and recommend tool
|
|
26
|
+
*/
|
|
27
|
+
classify(input: string, providedLocale?: SupportedLocale): Promise<IntentAnalysis>;
|
|
28
|
+
/**
|
|
29
|
+
* Extract entities from user input
|
|
30
|
+
*/
|
|
31
|
+
private extractEntities;
|
|
32
|
+
/**
|
|
33
|
+
* Build tool parameters from classification and entities
|
|
34
|
+
*/
|
|
35
|
+
private buildToolParams;
|
|
36
|
+
/**
|
|
37
|
+
* Convert position keyword to coordinates
|
|
38
|
+
*/
|
|
39
|
+
private positionKeywordToCoordinates;
|
|
40
|
+
/**
|
|
41
|
+
* Check if clarification is needed
|
|
42
|
+
*/
|
|
43
|
+
private needsClarification;
|
|
44
|
+
/**
|
|
45
|
+
* Build clarification prompt
|
|
46
|
+
*/
|
|
47
|
+
private buildClarificationPrompt;
|
|
48
|
+
/**
|
|
49
|
+
* Get suggestions when no match is found
|
|
50
|
+
*/
|
|
51
|
+
private getSuggestions;
|
|
52
|
+
/**
|
|
53
|
+
* Validate a tool selection against the taxonomy
|
|
54
|
+
*/
|
|
55
|
+
validateToolSelection(toolName: string, userInput: string): Promise<TaxonomyError | null>;
|
|
56
|
+
/**
|
|
57
|
+
* Get tool recommendation with rich context
|
|
58
|
+
*/
|
|
59
|
+
getRecommendation(input: string, locale?: SupportedLocale): Promise<{
|
|
60
|
+
tool: string;
|
|
61
|
+
params: Record<string, unknown>;
|
|
62
|
+
confidence: number;
|
|
63
|
+
explanation: string;
|
|
64
|
+
} | null>;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get or create the singleton IntentClassifier instance
|
|
68
|
+
*/
|
|
69
|
+
export declare function getIntentClassifier(config?: Partial<TaxonomyConfig>): IntentClassifier;
|
|
70
|
+
/**
|
|
71
|
+
* Reset the singleton instance (for testing)
|
|
72
|
+
*/
|
|
73
|
+
export declare function resetIntentClassifier(): void;
|
|
74
|
+
//# sourceMappingURL=classifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classifier.d.ts","sourceRoot":"","sources":["../../src/taxonomy/classifier.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EAEV,cAAc,EAId,aAAa,EAEb,cAAc,EACf,MAAM,YAAY,CAAC;AAuFpB;;;;GAIG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,OAAO,CAAkB;IACjC,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,WAAW,CAAS;gBAEhB,MAAM,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC;IAY5C;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAMjC;;OAEG;IACG,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;IA4ExF;;OAEG;IACH,OAAO,CAAC,eAAe;IAwFvB;;OAEG;IACH,OAAO,CAAC,eAAe;IAwDvB;;OAEG;IACH,OAAO,CAAC,4BAA4B;IAqBpC;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAsB1B;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAkBhC;;OAEG;IACH,OAAO,CAAC,cAAc;IAetB;;OAEG;IACG,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IA6B/F;;OAEG;IACG,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC;QACxE,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAChC,UAAU,EAAE,MAAM,CAAC;QACnB,WAAW,EAAE,MAAM,CAAC;KACrB,GAAG,IAAI,CAAC;CAmBV;AAKD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,gBAAgB,CAKtF;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C"}
|
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Intent Classifier
|
|
3
|
+
*
|
|
4
|
+
* High-level classifier that combines taxonomy matching, modifier detection,
|
|
5
|
+
* entity extraction, and parameter inference to understand user intent
|
|
6
|
+
* and recommend the best MCP tool.
|
|
7
|
+
*/
|
|
8
|
+
import { getTaxonomyMatcher } from './matcher.js';
|
|
9
|
+
import { ANIMATION_TAXONOMY } from './registry.js';
|
|
10
|
+
/**
|
|
11
|
+
* Color name to hex mapping for common colors
|
|
12
|
+
*/
|
|
13
|
+
const COLOR_MAP = {
|
|
14
|
+
// Basic colors
|
|
15
|
+
red: '#ff0000',
|
|
16
|
+
green: '#00ff00',
|
|
17
|
+
blue: '#0000ff',
|
|
18
|
+
yellow: '#ffff00',
|
|
19
|
+
orange: '#ffa500',
|
|
20
|
+
purple: '#800080',
|
|
21
|
+
pink: '#ffc0cb',
|
|
22
|
+
white: '#ffffff',
|
|
23
|
+
black: '#000000',
|
|
24
|
+
gray: '#808080',
|
|
25
|
+
grey: '#808080',
|
|
26
|
+
brown: '#a52a2a',
|
|
27
|
+
cyan: '#00ffff',
|
|
28
|
+
magenta: '#ff00ff',
|
|
29
|
+
// Extended colors
|
|
30
|
+
gold: '#ffd700',
|
|
31
|
+
silver: '#c0c0c0',
|
|
32
|
+
navy: '#000080',
|
|
33
|
+
teal: '#008080',
|
|
34
|
+
maroon: '#800000',
|
|
35
|
+
olive: '#808000',
|
|
36
|
+
lime: '#00ff00',
|
|
37
|
+
aqua: '#00ffff',
|
|
38
|
+
coral: '#ff7f50',
|
|
39
|
+
salmon: '#fa8072',
|
|
40
|
+
turquoise: '#40e0d0',
|
|
41
|
+
violet: '#ee82ee',
|
|
42
|
+
indigo: '#4b0082',
|
|
43
|
+
crimson: '#dc143c',
|
|
44
|
+
beige: '#f5f5dc',
|
|
45
|
+
ivory: '#fffff0',
|
|
46
|
+
lavender: '#e6e6fa',
|
|
47
|
+
// Multilingual color names
|
|
48
|
+
rojo: '#ff0000',
|
|
49
|
+
verde: '#00ff00',
|
|
50
|
+
azul: '#0000ff',
|
|
51
|
+
amarillo: '#ffff00',
|
|
52
|
+
naranja: '#ffa500',
|
|
53
|
+
morado: '#800080',
|
|
54
|
+
blanco: '#ffffff',
|
|
55
|
+
negro: '#000000',
|
|
56
|
+
rouge: '#ff0000',
|
|
57
|
+
vert: '#00ff00',
|
|
58
|
+
bleu: '#0000ff',
|
|
59
|
+
jaune: '#ffff00',
|
|
60
|
+
blanc: '#ffffff',
|
|
61
|
+
noir: '#000000',
|
|
62
|
+
rot: '#ff0000',
|
|
63
|
+
grün: '#00ff00',
|
|
64
|
+
blau: '#0000ff',
|
|
65
|
+
gelb: '#ffff00',
|
|
66
|
+
weiss: '#ffffff',
|
|
67
|
+
schwarz: '#000000',
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Patterns for extracting entities from user input
|
|
71
|
+
*/
|
|
72
|
+
const ENTITY_PATTERNS = {
|
|
73
|
+
// Hex color (#fff, #ffffff)
|
|
74
|
+
hexColor: /#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})\b/g,
|
|
75
|
+
// RGB/RGBA
|
|
76
|
+
rgbColor: /rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/gi,
|
|
77
|
+
// Numbers with optional units
|
|
78
|
+
number: /\b(\d+(?:\.\d+)?)\s*(px|%|deg|s|ms|seconds?)?\b/gi,
|
|
79
|
+
// Position keywords
|
|
80
|
+
position: /\b(center|top|bottom|left|right|top-left|top-right|bottom-left|bottom-right|middle)\b/gi,
|
|
81
|
+
// Named items (quoted strings or specific patterns)
|
|
82
|
+
quotedString: /"([^"]+)"|'([^']+)'/g,
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Intent Classifier
|
|
86
|
+
*
|
|
87
|
+
* Analyzes user input to determine intent and recommend appropriate MCP tools.
|
|
88
|
+
*/
|
|
89
|
+
export class IntentClassifier {
|
|
90
|
+
matcher;
|
|
91
|
+
config;
|
|
92
|
+
initialized = false;
|
|
93
|
+
constructor(config) {
|
|
94
|
+
this.config = {
|
|
95
|
+
minConfidence: 0.6,
|
|
96
|
+
useSemanticSearch: false,
|
|
97
|
+
maxSuggestions: 3,
|
|
98
|
+
defaultLocale: 'en',
|
|
99
|
+
debug: false,
|
|
100
|
+
...config,
|
|
101
|
+
};
|
|
102
|
+
this.matcher = getTaxonomyMatcher(config);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Initialize the classifier
|
|
106
|
+
*/
|
|
107
|
+
async initialize() {
|
|
108
|
+
if (this.initialized)
|
|
109
|
+
return;
|
|
110
|
+
await this.matcher.initialize();
|
|
111
|
+
this.initialized = true;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Classify user input and recommend tool
|
|
115
|
+
*/
|
|
116
|
+
async classify(input, providedLocale) {
|
|
117
|
+
if (!this.initialized) {
|
|
118
|
+
await this.initialize();
|
|
119
|
+
}
|
|
120
|
+
// 1. Detect language
|
|
121
|
+
const detectedLocale = providedLocale || this.matcher.detectLocale(input);
|
|
122
|
+
// 2. Find taxonomy matches
|
|
123
|
+
const matches = await this.matcher.findMatches(input, detectedLocale);
|
|
124
|
+
// 3. Detect modifiers
|
|
125
|
+
const modifierMatches = this.matcher.detectModifiers(input, detectedLocale);
|
|
126
|
+
const activeModifiers = modifierMatches.map((m) => m.modifier);
|
|
127
|
+
// 4. Extract entities
|
|
128
|
+
const entities = this.extractEntities(input);
|
|
129
|
+
// 5. Build classification result
|
|
130
|
+
let classification;
|
|
131
|
+
if (matches.length === 0) {
|
|
132
|
+
classification = {
|
|
133
|
+
method: 'unknown',
|
|
134
|
+
confidence: 0,
|
|
135
|
+
suggestions: this.getSuggestions(input),
|
|
136
|
+
detectedLocale,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
const bestMatch = matches[0];
|
|
141
|
+
classification = {
|
|
142
|
+
method: bestMatch.similarity > 0.85 ? 'keyword' : 'pattern',
|
|
143
|
+
confidence: bestMatch.similarity,
|
|
144
|
+
node: bestMatch.node,
|
|
145
|
+
modifiers: activeModifiers,
|
|
146
|
+
extractedParams: this.matcher.extractParameters(input, bestMatch.node, detectedLocale),
|
|
147
|
+
detectedLocale,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
// 6. Build recommended tool call
|
|
151
|
+
let recommendedTool;
|
|
152
|
+
if (classification.node) {
|
|
153
|
+
const params = this.buildToolParams(classification.node, classification, entities, activeModifiers);
|
|
154
|
+
recommendedTool = {
|
|
155
|
+
name: classification.node.tool.tool,
|
|
156
|
+
params,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
// 7. Check if clarification is needed
|
|
160
|
+
const needsClarification = this.needsClarification(classification, matches);
|
|
161
|
+
// 8. Build alternatives
|
|
162
|
+
const alternatives = matches.length > 1
|
|
163
|
+
? matches.slice(1).map((m) => ({
|
|
164
|
+
method: 'pattern',
|
|
165
|
+
confidence: m.similarity,
|
|
166
|
+
node: m.node,
|
|
167
|
+
detectedLocale,
|
|
168
|
+
}))
|
|
169
|
+
: undefined;
|
|
170
|
+
return {
|
|
171
|
+
classification,
|
|
172
|
+
entities,
|
|
173
|
+
recommendedTool,
|
|
174
|
+
alternatives,
|
|
175
|
+
needsClarification,
|
|
176
|
+
clarificationPrompt: needsClarification ? this.buildClarificationPrompt(matches, input) : undefined,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Extract entities from user input
|
|
181
|
+
*/
|
|
182
|
+
extractEntities(input) {
|
|
183
|
+
const entities = [];
|
|
184
|
+
// Extract hex colors
|
|
185
|
+
const hexMatches = input.matchAll(ENTITY_PATTERNS.hexColor);
|
|
186
|
+
for (const match of hexMatches) {
|
|
187
|
+
entities.push({
|
|
188
|
+
type: 'color',
|
|
189
|
+
value: match[0],
|
|
190
|
+
normalized: match[0].toLowerCase(),
|
|
191
|
+
position: { start: match.index, end: match.index + match[0].length },
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
// Extract RGB colors
|
|
195
|
+
const rgbMatches = input.matchAll(ENTITY_PATTERNS.rgbColor);
|
|
196
|
+
for (const match of rgbMatches) {
|
|
197
|
+
const r = parseInt(match[1], 10);
|
|
198
|
+
const g = parseInt(match[2], 10);
|
|
199
|
+
const b = parseInt(match[3], 10);
|
|
200
|
+
const hex = `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}`;
|
|
201
|
+
entities.push({
|
|
202
|
+
type: 'color',
|
|
203
|
+
value: match[0],
|
|
204
|
+
normalized: hex,
|
|
205
|
+
position: { start: match.index, end: match.index + match[0].length },
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
// Extract named colors
|
|
209
|
+
const lowerInput = input.toLowerCase();
|
|
210
|
+
for (const [name, hex] of Object.entries(COLOR_MAP)) {
|
|
211
|
+
const index = lowerInput.indexOf(name);
|
|
212
|
+
if (index !== -1) {
|
|
213
|
+
// Check it's a word boundary
|
|
214
|
+
const before = index > 0 ? lowerInput[index - 1] : ' ';
|
|
215
|
+
const after = lowerInput[index + name.length] || ' ';
|
|
216
|
+
if (/\s|^/.test(before) && /\s|$|[.,!?;:]/.test(after)) {
|
|
217
|
+
entities.push({
|
|
218
|
+
type: 'color',
|
|
219
|
+
value: name,
|
|
220
|
+
normalized: hex,
|
|
221
|
+
position: { start: index, end: index + name.length },
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
// Extract numbers
|
|
227
|
+
const numberMatches = input.matchAll(ENTITY_PATTERNS.number);
|
|
228
|
+
for (const match of numberMatches) {
|
|
229
|
+
const value = parseFloat(match[1]);
|
|
230
|
+
const unit = match[2]?.toLowerCase();
|
|
231
|
+
entities.push({
|
|
232
|
+
type: 'number',
|
|
233
|
+
value: match[0],
|
|
234
|
+
normalized: { value, unit },
|
|
235
|
+
position: { start: match.index, end: match.index + match[0].length },
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
// Extract positions
|
|
239
|
+
const positionMatches = input.matchAll(ENTITY_PATTERNS.position);
|
|
240
|
+
for (const match of positionMatches) {
|
|
241
|
+
entities.push({
|
|
242
|
+
type: 'position',
|
|
243
|
+
value: match[0],
|
|
244
|
+
normalized: match[0].toLowerCase(),
|
|
245
|
+
position: { start: match.index, end: match.index + match[0].length },
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
// Extract quoted strings (names, labels)
|
|
249
|
+
const quotedMatches = input.matchAll(ENTITY_PATTERNS.quotedString);
|
|
250
|
+
for (const match of quotedMatches) {
|
|
251
|
+
const content = match[1] || match[2];
|
|
252
|
+
entities.push({
|
|
253
|
+
type: 'name',
|
|
254
|
+
value: content,
|
|
255
|
+
normalized: content,
|
|
256
|
+
position: { start: match.index, end: match.index + match[0].length },
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
return entities;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Build tool parameters from classification and entities
|
|
263
|
+
*/
|
|
264
|
+
buildToolParams(node, classification, entities, modifiers) {
|
|
265
|
+
const params = {
|
|
266
|
+
...node.tool.defaultParams,
|
|
267
|
+
...classification.extractedParams,
|
|
268
|
+
};
|
|
269
|
+
// Apply modifier modifications
|
|
270
|
+
for (const modifier of modifiers) {
|
|
271
|
+
Object.assign(params, modifier.modifications);
|
|
272
|
+
}
|
|
273
|
+
// Apply entities
|
|
274
|
+
const colorEntity = entities.find((e) => e.type === 'color');
|
|
275
|
+
if (colorEntity && !params.fillColor) {
|
|
276
|
+
params.fillColor = colorEntity.normalized;
|
|
277
|
+
}
|
|
278
|
+
// Apply position if found
|
|
279
|
+
const positionEntity = entities.find((e) => e.type === 'position');
|
|
280
|
+
if (positionEntity && !params.position) {
|
|
281
|
+
params.position = this.positionKeywordToCoordinates(positionEntity.normalized);
|
|
282
|
+
}
|
|
283
|
+
// Apply size/radius from numbers
|
|
284
|
+
const numberEntities = entities.filter((e) => e.type === 'number');
|
|
285
|
+
for (const numEntity of numberEntities) {
|
|
286
|
+
const { value, unit } = numEntity.normalized;
|
|
287
|
+
if (unit === 'px' || unit === undefined) {
|
|
288
|
+
// Could be radius or size
|
|
289
|
+
if (!params.radius && node.id.includes('circle')) {
|
|
290
|
+
params.radius = value;
|
|
291
|
+
}
|
|
292
|
+
else if (!params.size) {
|
|
293
|
+
params.size = value;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
else if (unit === 's' || unit === 'seconds') {
|
|
297
|
+
params.duration = value;
|
|
298
|
+
}
|
|
299
|
+
else if (unit === 'deg') {
|
|
300
|
+
params.angle = value;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
// Apply name/content from quoted strings
|
|
304
|
+
const nameEntity = entities.find((e) => e.type === 'name');
|
|
305
|
+
if (nameEntity && node.id === 'create_text') {
|
|
306
|
+
params.content = nameEntity.normalized;
|
|
307
|
+
}
|
|
308
|
+
return params;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Convert position keyword to coordinates
|
|
312
|
+
*/
|
|
313
|
+
positionKeywordToCoordinates(keyword) {
|
|
314
|
+
// Default canvas size assumptions (can be made configurable)
|
|
315
|
+
const width = 1920;
|
|
316
|
+
const height = 1080;
|
|
317
|
+
const positions = {
|
|
318
|
+
center: { x: width / 2, y: height / 2 },
|
|
319
|
+
middle: { x: width / 2, y: height / 2 },
|
|
320
|
+
top: { x: width / 2, y: 100 },
|
|
321
|
+
bottom: { x: width / 2, y: height - 100 },
|
|
322
|
+
left: { x: 100, y: height / 2 },
|
|
323
|
+
right: { x: width - 100, y: height / 2 },
|
|
324
|
+
'top-left': { x: 100, y: 100 },
|
|
325
|
+
'top-right': { x: width - 100, y: 100 },
|
|
326
|
+
'bottom-left': { x: 100, y: height - 100 },
|
|
327
|
+
'bottom-right': { x: width - 100, y: height - 100 },
|
|
328
|
+
};
|
|
329
|
+
return positions[keyword] || positions.center;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Check if clarification is needed
|
|
333
|
+
*/
|
|
334
|
+
needsClarification(classification, matches) {
|
|
335
|
+
// Unknown classification
|
|
336
|
+
if (classification.method === 'unknown') {
|
|
337
|
+
return true;
|
|
338
|
+
}
|
|
339
|
+
// Low confidence
|
|
340
|
+
if (classification.confidence < this.config.minConfidence) {
|
|
341
|
+
return true;
|
|
342
|
+
}
|
|
343
|
+
// Multiple high-confidence matches (ambiguous)
|
|
344
|
+
if (matches.length >= 2) {
|
|
345
|
+
const secondBest = matches[1];
|
|
346
|
+
if (secondBest.similarity > 0.7 && classification.confidence - secondBest.similarity < 0.1) {
|
|
347
|
+
return true;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Build clarification prompt
|
|
354
|
+
*/
|
|
355
|
+
buildClarificationPrompt(matches, input) {
|
|
356
|
+
if (matches.length === 0) {
|
|
357
|
+
return `I couldn't understand what you want to do with "${input}". Could you rephrase or be more specific?`;
|
|
358
|
+
}
|
|
359
|
+
if (matches.length === 1 && matches[0].similarity < this.config.minConfidence) {
|
|
360
|
+
return `Did you mean "${matches[0].node.id.replace(/_/g, ' ')}"? (Confidence: ${Math.round(matches[0].similarity * 100)}%)`;
|
|
361
|
+
}
|
|
362
|
+
// Multiple ambiguous matches
|
|
363
|
+
const options = matches
|
|
364
|
+
.slice(0, 3)
|
|
365
|
+
.map((m, i) => `${i + 1}. ${m.node.id.replace(/_/g, ' ')} (${Math.round(m.similarity * 100)}%)`)
|
|
366
|
+
.join('\n');
|
|
367
|
+
return `I found multiple possible interpretations:\n${options}\n\nWhich one did you mean?`;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Get suggestions when no match is found
|
|
371
|
+
*/
|
|
372
|
+
getSuggestions(input) {
|
|
373
|
+
// Return common concepts as suggestions
|
|
374
|
+
const commonConcepts = [
|
|
375
|
+
'create_circle',
|
|
376
|
+
'create_rectangle',
|
|
377
|
+
'create_text',
|
|
378
|
+
'rotation',
|
|
379
|
+
'orbital_motion',
|
|
380
|
+
'pulse',
|
|
381
|
+
'fade',
|
|
382
|
+
];
|
|
383
|
+
return commonConcepts.slice(0, this.config.maxSuggestions);
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Validate a tool selection against the taxonomy
|
|
387
|
+
*/
|
|
388
|
+
async validateToolSelection(toolName, userInput) {
|
|
389
|
+
// Find taxonomy node for this tool
|
|
390
|
+
const matchingNode = ANIMATION_TAXONOMY.find((n) => n.tool.tool === toolName);
|
|
391
|
+
if (!matchingNode) {
|
|
392
|
+
// Tool not in taxonomy, can't validate
|
|
393
|
+
return null;
|
|
394
|
+
}
|
|
395
|
+
// Check if user input aligns with this tool's concept
|
|
396
|
+
const matches = await this.matcher.findMatches(userInput);
|
|
397
|
+
const topMatch = matches[0];
|
|
398
|
+
if (!topMatch) {
|
|
399
|
+
return null; // Can't determine mismatch
|
|
400
|
+
}
|
|
401
|
+
if (topMatch.node.tool.tool !== toolName && topMatch.similarity > 0.8) {
|
|
402
|
+
return {
|
|
403
|
+
code: 'TAXONOMY_AMBIGUOUS',
|
|
404
|
+
message: `Tool "${toolName}" may not be the best choice for this request`,
|
|
405
|
+
suggestions: [topMatch.node.tool.tool],
|
|
406
|
+
hint: `Consider using "${topMatch.node.tool.tool}" instead (matched "${topMatch.matchedTerm}" with ${Math.round(topMatch.similarity * 100)}% confidence)`,
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
return null;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Get tool recommendation with rich context
|
|
413
|
+
*/
|
|
414
|
+
async getRecommendation(input, locale) {
|
|
415
|
+
const analysis = await this.classify(input, locale);
|
|
416
|
+
if (!analysis.recommendedTool) {
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
const explanation = analysis.classification.node
|
|
420
|
+
? `Matched "${analysis.classification.node.id}" via ${analysis.classification.method} ` +
|
|
421
|
+
`(${Math.round(analysis.classification.confidence * 100)}% confidence)`
|
|
422
|
+
: 'No specific match found';
|
|
423
|
+
return {
|
|
424
|
+
tool: analysis.recommendedTool.name,
|
|
425
|
+
params: analysis.recommendedTool.params,
|
|
426
|
+
confidence: analysis.classification.confidence,
|
|
427
|
+
explanation,
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
// Singleton instance
|
|
432
|
+
let classifierInstance = null;
|
|
433
|
+
/**
|
|
434
|
+
* Get or create the singleton IntentClassifier instance
|
|
435
|
+
*/
|
|
436
|
+
export function getIntentClassifier(config) {
|
|
437
|
+
if (!classifierInstance) {
|
|
438
|
+
classifierInstance = new IntentClassifier(config);
|
|
439
|
+
}
|
|
440
|
+
return classifierInstance;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Reset the singleton instance (for testing)
|
|
444
|
+
*/
|
|
445
|
+
export function resetIntentClassifier() {
|
|
446
|
+
classifierInstance = null;
|
|
447
|
+
}
|
|
448
|
+
//# sourceMappingURL=classifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classifier.js","sourceRoot":"","sources":["../../src/taxonomy/classifier.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAaH,OAAO,EAAmB,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAmC,MAAM,eAAe,CAAC;AAEpF;;GAEG;AACH,MAAM,SAAS,GAA2B;IACxC,eAAe;IACf,GAAG,EAAE,SAAS;IACd,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,SAAS;IACf,MAAM,EAAE,SAAS;IACjB,MAAM,EAAE,SAAS;IACjB,MAAM,EAAE,SAAS;IACjB,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,SAAS;IAChB,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,SAAS;IAElB,kBAAkB;IAClB,IAAI,EAAE,SAAS;IACf,MAAM,EAAE,SAAS;IACjB,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,SAAS;IACf,MAAM,EAAE,SAAS;IACjB,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,SAAS;IAChB,MAAM,EAAE,SAAS;IACjB,SAAS,EAAE,SAAS;IACpB,MAAM,EAAE,SAAS;IACjB,MAAM,EAAE,SAAS;IACjB,OAAO,EAAE,S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BAAkB,CAAC;AAC5B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB;IACnC,kBAAkB,GAAG,IAAI,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
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 type { SupportedLocale } from '../i18n/types.js';
|
|
9
|
+
import type { TaxonomyErrorCode, TaxonomyMatch } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Error recovery context with rich suggestions
|
|
12
|
+
*/
|
|
13
|
+
export interface ErrorRecoveryContext {
|
|
14
|
+
/** The original error */
|
|
15
|
+
error: string;
|
|
16
|
+
/** Error code for programmatic handling */
|
|
17
|
+
code: TaxonomyErrorCode | string;
|
|
18
|
+
/** Human-readable hint */
|
|
19
|
+
hint?: string;
|
|
20
|
+
/** Suggested alternative tools or actions */
|
|
21
|
+
suggestions?: string[];
|
|
22
|
+
/** Available items that might be relevant */
|
|
23
|
+
availableItems?: Array<{
|
|
24
|
+
id: string;
|
|
25
|
+
type: string;
|
|
26
|
+
}>;
|
|
27
|
+
/** Similar concepts from taxonomy */
|
|
28
|
+
similarConcepts?: TaxonomyMatch[];
|
|
29
|
+
/** Did you mean this item? */
|
|
30
|
+
didYouMean?: string;
|
|
31
|
+
/** Example of correct usage */
|
|
32
|
+
example?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Build rich error recovery context for common errors
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildErrorRecovery(errorType: string, context: {
|
|
38
|
+
failedId?: string;
|
|
39
|
+
availableItems?: Array<{
|
|
40
|
+
id: string;
|
|
41
|
+
type: string;
|
|
42
|
+
}>;
|
|
43
|
+
userInput?: string;
|
|
44
|
+
toolName?: string;
|
|
45
|
+
locale?: SupportedLocale;
|
|
46
|
+
}): ErrorRecoveryContext;
|
|
47
|
+
/**
|
|
48
|
+
* Format error context for MCP response
|
|
49
|
+
*/
|
|
50
|
+
export declare function formatRichError(context: ErrorRecoveryContext): string;
|
|
51
|
+
/**
|
|
52
|
+
* Build taxonomy-aware error for tool validation
|
|
53
|
+
*/
|
|
54
|
+
export declare function validateToolWithTaxonomy(toolName: string, userInput: string, locale?: SupportedLocale): Promise<ErrorRecoveryContext | null>;
|
|
55
|
+
//# sourceMappingURL=error-recovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-recovery.d.ts","sourceRoot":"","sources":["../../src/taxonomy/error-recovery.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EAAiB,iBAAiB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAIlF;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,yBAAyB;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,IAAI,EAAE,iBAAiB,GAAG,MAAM,CAAC;IACjC,0BAA0B;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6CAA6C;IAC7C,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,6CAA6C;IAC7C,cAAc,CAAC,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACrD,qCAAqC;IACrC,eAAe,CAAC,EAAE,aAAa,EAAE,CAAC;IAClC,8BAA8B;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+BAA+B;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,MAAM,EACjB,OAA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