@yuaone/core 0.9.13 → 0.9.15

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.
@@ -0,0 +1,241 @@
1
+ /**
2
+ * @module vision-intent-detector
3
+ * @description Detects when LLM or user text signals intent to look at an image,
4
+ * then extracts the target file path. Supports 9+ languages.
5
+ */
6
+ const LANG_PATTERNS = [
7
+ {
8
+ lang: "ko",
9
+ phrases: [
10
+ "이미지 확인",
11
+ "스크린샷 확인",
12
+ "사진 봐",
13
+ "그림 확인",
14
+ "이미지 봐",
15
+ "화면 봐",
16
+ "파일 읽어",
17
+ "이미지 읽어",
18
+ "스크린샷 읽어",
19
+ "이미지를 확인",
20
+ "사진을 봐",
21
+ "그림을 확인",
22
+ "이미지를 봐",
23
+ "화면을 봐",
24
+ ],
25
+ },
26
+ {
27
+ lang: "en",
28
+ phrases: [
29
+ "let me see",
30
+ "let me look at",
31
+ "check the image",
32
+ "look at",
33
+ "view the screenshot",
34
+ "analyze the image",
35
+ "read the image",
36
+ "show me",
37
+ "what's in",
38
+ "examine",
39
+ "inspect the image",
40
+ "open the image",
41
+ "view the image",
42
+ "check the screenshot",
43
+ "analyze the screenshot",
44
+ ],
45
+ },
46
+ {
47
+ lang: "ja",
48
+ phrases: [
49
+ "画像を確認",
50
+ "スクリーンショットを見",
51
+ "イメージを確認",
52
+ "画像を見て",
53
+ "画像を読む",
54
+ "画像を調べる",
55
+ ],
56
+ },
57
+ {
58
+ lang: "zh",
59
+ phrases: [
60
+ "查看图片",
61
+ "看一下图",
62
+ "检查截图",
63
+ "分析图像",
64
+ "查看截图",
65
+ "看看图片",
66
+ "读取图片",
67
+ ],
68
+ },
69
+ {
70
+ lang: "es",
71
+ phrases: [
72
+ "ver la imagen",
73
+ "analizar imagen",
74
+ "revisar captura",
75
+ "mirar la imagen",
76
+ "examinar la imagen",
77
+ "ver captura de pantalla",
78
+ ],
79
+ },
80
+ {
81
+ lang: "fr",
82
+ phrases: [
83
+ "voir l'image",
84
+ "regarder l'image",
85
+ "analyser l'image",
86
+ "vérifier l'image",
87
+ "examiner l'image",
88
+ "regarder la capture",
89
+ ],
90
+ },
91
+ {
92
+ lang: "de",
93
+ phrases: [
94
+ "bild ansehen",
95
+ "screenshot prüfen",
96
+ "bild analysieren",
97
+ "bild überprüfen",
98
+ "screenshot ansehen",
99
+ "bild lesen",
100
+ ],
101
+ },
102
+ {
103
+ lang: "ru",
104
+ phrases: [
105
+ "посмотрите на изображение",
106
+ "проверь скриншот",
107
+ "посмотри на изображение",
108
+ "проверить скриншот",
109
+ "посмотри на картинку",
110
+ "проверь изображение",
111
+ ],
112
+ },
113
+ {
114
+ lang: "ar",
115
+ phrases: [
116
+ "انظر إلى الصورة",
117
+ "تحقق من الصورة",
118
+ "راجع الصورة",
119
+ "حلل الصورة",
120
+ "فحص لقطة الشاشة",
121
+ ],
122
+ },
123
+ ];
124
+ // ─── File path extraction regex ─────────────────────────────────────────────
125
+ /** Matches quoted image paths: "foo.png", 'bar.jpg', `baz.webp` */
126
+ const QUOTED_IMAGE_PATH_RE = /['"`]([^'"`\s]+\.(?:png|jpg|jpeg|gif|webp|svg|bmp))['"`]/gi;
127
+ /** Matches bare image paths (relative or absolute, no spaces) */
128
+ const BARE_IMAGE_PATH_RE = /(?:^|[\s(,])(\/?(?:[\w.\-]+\/)*[\w.\-]+\.(?:png|jpg|jpeg|gif|webp|svg|bmp))(?:$|[\s),])/gi;
129
+ // ─── Language detection helpers ──────────────────────────────────────────────
130
+ function detectScript(text) {
131
+ if (/[\uAC00-\uD7A3]/.test(text))
132
+ return "ko";
133
+ if (/[\u3040-\u309F\u30A0-\u30FF]/.test(text))
134
+ return "ja";
135
+ if (/[\u4E00-\u9FFF]/.test(text))
136
+ return "zh";
137
+ if (/[\u0600-\u06FF]/.test(text))
138
+ return "ar";
139
+ if (/[\u0400-\u04FF]/.test(text))
140
+ return "ru";
141
+ return null;
142
+ }
143
+ // ─── Core class ─────────────────────────────────────────────────────────────
144
+ /**
145
+ * Detects vision intent in LLM / user text and extracts image file paths.
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * const detector = new VisionIntentDetector();
150
+ * const intent = detector.detect('let me look at "screenshot.png" to diagnose the error');
151
+ * // → { detectedLanguage: "en", filePath: "screenshot.png", intentPhrase: "let me look at", confidence: 0.95 }
152
+ * ```
153
+ */
154
+ export class VisionIntentDetector {
155
+ /**
156
+ * Attempt to detect a vision intent in `text`.
157
+ *
158
+ * Returns `null` when no intent signal is found, or when an intent is found
159
+ * but no image file path can be extracted from the surrounding context.
160
+ */
161
+ detect(text) {
162
+ if (!text || text.trim().length === 0)
163
+ return null;
164
+ const lower = text.toLowerCase();
165
+ // Try each language's patterns
166
+ for (const { lang, phrases } of LANG_PATTERNS) {
167
+ for (const phrase of phrases) {
168
+ const phraseToCheck = lang === "de" ? phrase.toLowerCase() : phrase;
169
+ if (lower.includes(phraseToCheck)) {
170
+ // Phrase matched — now find an image path in the text
171
+ const filePath = extractImagePath(text);
172
+ if (filePath) {
173
+ // Higher confidence when the phrase is more specific
174
+ const confidence = computeConfidence(phrase, filePath);
175
+ return {
176
+ detectedLanguage: lang,
177
+ filePath,
178
+ intentPhrase: phrase,
179
+ confidence,
180
+ };
181
+ }
182
+ }
183
+ }
184
+ }
185
+ // Fallback: detect by Unicode script only (phrase not in list but script is clear)
186
+ const scriptLang = detectScript(text);
187
+ if (scriptLang) {
188
+ const filePath = extractImagePath(text);
189
+ if (filePath) {
190
+ return {
191
+ detectedLanguage: scriptLang,
192
+ filePath,
193
+ intentPhrase: "",
194
+ confidence: 0.4, // low confidence — no phrase match
195
+ };
196
+ }
197
+ }
198
+ return null;
199
+ }
200
+ }
201
+ // ─── Helpers ─────────────────────────────────────────────────────────────────
202
+ /**
203
+ * Extract the first image file path from text.
204
+ * Prefers quoted paths (more explicit) over bare paths.
205
+ */
206
+ function extractImagePath(text) {
207
+ // Reset lastIndex (global regex reuse safety)
208
+ QUOTED_IMAGE_PATH_RE.lastIndex = 0;
209
+ BARE_IMAGE_PATH_RE.lastIndex = 0;
210
+ const quotedMatch = QUOTED_IMAGE_PATH_RE.exec(text);
211
+ if (quotedMatch?.[1])
212
+ return quotedMatch[1];
213
+ const bareMatch = BARE_IMAGE_PATH_RE.exec(text);
214
+ if (bareMatch?.[1])
215
+ return bareMatch[1].trim();
216
+ return null;
217
+ }
218
+ /**
219
+ * Compute confidence score based on phrase specificity and path quality.
220
+ *
221
+ * - Long, specific phrases (e.g. "analyze the image") → 0.90–0.95
222
+ * - Short generic phrases (e.g. "show me") → 0.70–0.80
223
+ * - Quoted path found → +0.05 bonus (capped at 1.0)
224
+ */
225
+ function computeConfidence(phrase, filePath) {
226
+ let base = 0.75;
227
+ // Longer phrase → more specific intent
228
+ if (phrase.length >= 15)
229
+ base = 0.95;
230
+ else if (phrase.length >= 10)
231
+ base = 0.90;
232
+ else if (phrase.length >= 6)
233
+ base = 0.80;
234
+ // Quoted path → more explicit reference
235
+ if (/['"`]/.test(filePath)) {
236
+ // path itself was extracted from quotes
237
+ base = Math.min(1.0, base + 0.05);
238
+ }
239
+ return Math.round(base * 100) / 100;
240
+ }
241
+ //# sourceMappingURL=vision-intent-detector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vision-intent-detector.js","sourceRoot":"","sources":["../src/vision-intent-detector.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAoBH,MAAM,aAAa,GAAkB;IACnC;QACE,IAAI,EAAE,IAAI;QACV,OAAO,EAAE;YACP,QAAQ;YACR,SAAS;YACT,MAAM;YACN,OAAO;YACP,OAAO;YACP,MAAM;YACN,OAAO;YACP,QAAQ;YACR,SAAS;YACT,SAAS;YACT,OAAO;YACP,QAAQ;YACR,QAAQ;YACR,OAAO;SACR;KACF;IACD;QACE,IAAI,EAAE,IAAI;QACV,OAAO,EAAE;YACP,YAAY;YACZ,gBAAgB;YAChB,iBAAiB;YACjB,SAAS;YACT,qBAAqB;YACrB,mBAAmB;YACnB,gBAAgB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AAI,GAAG,IAAI,CAAC;SACrC,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC;QAAE,IAAI,GAAG,IAAI,CAAC;IAEzC,wCAAwC;IACxC,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC3B,wCAAwC;QACxC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,GAAG,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;AACtC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuaone/core",
3
- "version": "0.9.13",
3
+ "version": "0.9.15",
4
4
  "description": "YUAN Agent Core Runtime",
5
5
  "license": "AGPL-3.0",
6
6
  "type": "module",