@lutery/vision-mcp 1.0.0

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.
Files changed (122) hide show
  1. package/README.md +428 -0
  2. package/dist/adapters/base-adapter.d.ts +69 -0
  3. package/dist/adapters/base-adapter.d.ts.map +1 -0
  4. package/dist/adapters/base-adapter.js +143 -0
  5. package/dist/adapters/base-adapter.js.map +1 -0
  6. package/dist/adapters/claude-adapter.d.ts +38 -0
  7. package/dist/adapters/claude-adapter.d.ts.map +1 -0
  8. package/dist/adapters/claude-adapter.js +251 -0
  9. package/dist/adapters/claude-adapter.js.map +1 -0
  10. package/dist/adapters/glm-adapter.d.ts +15 -0
  11. package/dist/adapters/glm-adapter.d.ts.map +1 -0
  12. package/dist/adapters/glm-adapter.js +131 -0
  13. package/dist/adapters/glm-adapter.js.map +1 -0
  14. package/dist/adapters/modelscope-adapter.d.ts +20 -0
  15. package/dist/adapters/modelscope-adapter.d.ts.map +1 -0
  16. package/dist/adapters/modelscope-adapter.js +142 -0
  17. package/dist/adapters/modelscope-adapter.js.map +1 -0
  18. package/dist/adapters/openai-adapter.d.ts +20 -0
  19. package/dist/adapters/openai-adapter.d.ts.map +1 -0
  20. package/dist/adapters/openai-adapter.js +194 -0
  21. package/dist/adapters/openai-adapter.js.map +1 -0
  22. package/dist/adapters/siliconflow-adapter.d.ts +21 -0
  23. package/dist/adapters/siliconflow-adapter.d.ts.map +1 -0
  24. package/dist/adapters/siliconflow-adapter.js +145 -0
  25. package/dist/adapters/siliconflow-adapter.js.map +1 -0
  26. package/dist/config/model-config.d.ts +39 -0
  27. package/dist/config/model-config.d.ts.map +1 -0
  28. package/dist/config/model-config.js +115 -0
  29. package/dist/config/model-config.js.map +1 -0
  30. package/dist/index.d.ts +17 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +186 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/prompts/system.d.ts +75 -0
  35. package/dist/prompts/system.d.ts.map +1 -0
  36. package/dist/prompts/system.js +272 -0
  37. package/dist/prompts/system.js.map +1 -0
  38. package/dist/providers/provider-registry.d.ts +58 -0
  39. package/dist/providers/provider-registry.d.ts.map +1 -0
  40. package/dist/providers/provider-registry.js +173 -0
  41. package/dist/providers/provider-registry.js.map +1 -0
  42. package/dist/src/adapters/base-adapter.d.ts +59 -0
  43. package/dist/src/adapters/base-adapter.d.ts.map +1 -0
  44. package/dist/src/adapters/base-adapter.js +83 -0
  45. package/dist/src/adapters/base-adapter.js.map +1 -0
  46. package/dist/src/adapters/glm-adapter.d.ts +15 -0
  47. package/dist/src/adapters/glm-adapter.d.ts.map +1 -0
  48. package/dist/src/adapters/glm-adapter.js +116 -0
  49. package/dist/src/adapters/glm-adapter.js.map +1 -0
  50. package/dist/src/adapters/siliconflow-adapter.d.ts +21 -0
  51. package/dist/src/adapters/siliconflow-adapter.d.ts.map +1 -0
  52. package/dist/src/adapters/siliconflow-adapter.js +130 -0
  53. package/dist/src/adapters/siliconflow-adapter.js.map +1 -0
  54. package/dist/src/config/model-config.d.ts +40 -0
  55. package/dist/src/config/model-config.d.ts.map +1 -0
  56. package/dist/src/config/model-config.js +126 -0
  57. package/dist/src/config/model-config.js.map +1 -0
  58. package/dist/src/index.d.ts +17 -0
  59. package/dist/src/index.d.ts.map +1 -0
  60. package/dist/src/index.js +188 -0
  61. package/dist/src/index.js.map +1 -0
  62. package/dist/src/prompts/system.d.ts +75 -0
  63. package/dist/src/prompts/system.d.ts.map +1 -0
  64. package/dist/src/prompts/system.js +272 -0
  65. package/dist/src/prompts/system.js.map +1 -0
  66. package/dist/src/tools/vision-tool.d.ts +91 -0
  67. package/dist/src/tools/vision-tool.d.ts.map +1 -0
  68. package/dist/src/tools/vision-tool.js +171 -0
  69. package/dist/src/tools/vision-tool.js.map +1 -0
  70. package/dist/src/utils/errors.d.ts +65 -0
  71. package/dist/src/utils/errors.d.ts.map +1 -0
  72. package/dist/src/utils/errors.js +146 -0
  73. package/dist/src/utils/errors.js.map +1 -0
  74. package/dist/src/utils/image-input.d.ts +45 -0
  75. package/dist/src/utils/image-input.d.ts.map +1 -0
  76. package/dist/src/utils/image-input.js +226 -0
  77. package/dist/src/utils/image-input.js.map +1 -0
  78. package/dist/src/utils/logger.d.ts +63 -0
  79. package/dist/src/utils/logger.d.ts.map +1 -0
  80. package/dist/src/utils/logger.js +157 -0
  81. package/dist/src/utils/logger.js.map +1 -0
  82. package/dist/test/integration.test.d.ts +10 -0
  83. package/dist/test/integration.test.d.ts.map +1 -0
  84. package/dist/test/integration.test.js +270 -0
  85. package/dist/test/integration.test.js.map +1 -0
  86. package/dist/test/test-utils.d.ts +45 -0
  87. package/dist/test/test-utils.d.ts.map +1 -0
  88. package/dist/test/test-utils.js +107 -0
  89. package/dist/test/test-utils.js.map +1 -0
  90. package/dist/test/vision-tool.test.d.ts +9 -0
  91. package/dist/test/vision-tool.test.d.ts.map +1 -0
  92. package/dist/test/vision-tool.test.js +167 -0
  93. package/dist/test/vision-tool.test.js.map +1 -0
  94. package/dist/tools/vision-tool.d.ts +91 -0
  95. package/dist/tools/vision-tool.d.ts.map +1 -0
  96. package/dist/tools/vision-tool.js +167 -0
  97. package/dist/tools/vision-tool.js.map +1 -0
  98. package/dist/utils/data-url-parser.d.ts +27 -0
  99. package/dist/utils/data-url-parser.d.ts.map +1 -0
  100. package/dist/utils/data-url-parser.js +53 -0
  101. package/dist/utils/data-url-parser.js.map +1 -0
  102. package/dist/utils/errors.d.ts +65 -0
  103. package/dist/utils/errors.d.ts.map +1 -0
  104. package/dist/utils/errors.js +146 -0
  105. package/dist/utils/errors.js.map +1 -0
  106. package/dist/utils/image-input.d.ts +45 -0
  107. package/dist/utils/image-input.d.ts.map +1 -0
  108. package/dist/utils/image-input.js +238 -0
  109. package/dist/utils/image-input.js.map +1 -0
  110. package/dist/utils/logger.d.ts +63 -0
  111. package/dist/utils/logger.d.ts.map +1 -0
  112. package/dist/utils/logger.js +157 -0
  113. package/dist/utils/logger.js.map +1 -0
  114. package/dist/utils/thinking-extractors.d.ts +34 -0
  115. package/dist/utils/thinking-extractors.d.ts.map +1 -0
  116. package/dist/utils/thinking-extractors.js +83 -0
  117. package/dist/utils/thinking-extractors.js.map +1 -0
  118. package/dist/utils/thinking-filter.d.ts +32 -0
  119. package/dist/utils/thinking-filter.d.ts.map +1 -0
  120. package/dist/utils/thinking-filter.js +147 -0
  121. package/dist/utils/thinking-filter.js.map +1 -0
  122. package/package.json +41 -0
@@ -0,0 +1,272 @@
1
+ /**
2
+ * System Prompt Templates
3
+ *
4
+ * @description 内置的系统提示词模板,覆盖常见视觉任务场景
5
+ */
6
+ /**
7
+ * 基础系统提示词
8
+ * 提供通用指导原则和规范
9
+ */
10
+ export const BASE_SYSTEM_PROMPT = `You are a vision analysis assistant with access to image data.
11
+
12
+ Your task is to analyze images accurately and provide helpful responses based on what you see.
13
+
14
+ Guidelines:
15
+ 1. Be precise and detailed in your observations
16
+ 2. When coordinates or measurements are requested, provide them in the format specified
17
+ 3. If an image is unclear or ambiguous, acknowledge the limitations
18
+ 4. Convert any complex structured data to the requested format
19
+ 5. Be helpful and follow the specific instructions provided by the user
20
+
21
+ Remember: You are providing visual information to another AI system, so clarity and structure are important.`;
22
+ /**
23
+ * 通用描述模板
24
+ */
25
+ export const GENERAL_DESCRIPTION_TEMPLATE = {
26
+ id: 'general-description',
27
+ name: 'General Description',
28
+ description: 'Provide a detailed description of the image',
29
+ useCases: ['image description', 'scene analysis', 'object identification'],
30
+ template: `${BASE_SYSTEM_PROMPT}
31
+
32
+ Analyze this image and provide a comprehensive description. Include:
33
+ - Main objects and their characteristics
34
+ - Setting or environment
35
+ - Colors, lighting, and composition
36
+ - Any text or symbols visible
37
+ - Overall mood or atmosphere
38
+
39
+ Focus on observable details and be specific.`
40
+ };
41
+ /**
42
+ * UI 分析模板
43
+ * 用于分析 UI 原型图、截图等
44
+ */
45
+ export const UI_ANALYSIS_TEMPLATE = {
46
+ id: 'ui-analysis',
47
+ name: 'UI Analysis',
48
+ description: 'Analyze UI prototypes and screenshots',
49
+ useCases: ['UI design analysis', 'interface review', 'component identification'],
50
+ template: `${BASE_SYSTEM_PROMPT}
51
+
52
+ You are analyzing a UI design or interface screenshot. Your goal is to extract structured information about the UI elements and layout.
53
+
54
+ Please provide:
55
+ 1. **Overall Layout**
56
+ - Screen/window dimensions (if apparent)
57
+ - Layout type (grid, flex, absolute positioning, etc.)
58
+ - Main sections and their relative positions
59
+
60
+ 2. **UI Components**
61
+ - Identify all interactive elements (buttons, inputs, links, etc.)
62
+ - For each component, provide:
63
+ * Type (button, input, card, navigation, etc.)
64
+ * Text content or labels
65
+ * Approximate position and size (relative coordinates or percentages)
66
+ * Visual style (colors, borders, shadows, etc.)
67
+
68
+ 3. **Visual Hierarchy**
69
+ - Primary actions and elements
70
+ - Secondary or supporting elements
71
+ - Navigation structure
72
+
73
+ 4. **Design Patterns**
74
+ - Common patterns used (cards, lists, modals, etc.)
75
+ - Responsive design considerations
76
+ - Accessibility features (if visible)
77
+
78
+ 5. **Content Analysis**
79
+ - Text content and typography
80
+ - Images and media elements
81
+ - Icons and symbols
82
+
83
+ If you need to provide coordinates or positions, use:
84
+ - Either percentage-based coordinates (x, y, width, height as percentages)
85
+ - Or pixel coordinates if the image dimensions are clear
86
+ Format: {x: 10, y: 20, width: 30, height: 15} (in respective units)
87
+
88
+ Be precise about relationships between elements and their spatial arrangement.`
89
+ };
90
+ /**
91
+ * 对象定位和检测模板
92
+ */
93
+ export const OBJECT_DETECTION_TEMPLATE = {
94
+ id: 'object-detection',
95
+ name: 'Object Detection and Localization',
96
+ description: 'Detect and locate objects in the image with coordinates',
97
+ useCases: ['object detection', 'element positioning', 'bounding box localization'],
98
+ template: `${BASE_SYSTEM_PROMPT}
99
+
100
+ Your task is to identify and locate specific objects or elements in the image. For each detected object, provide:
101
+
102
+ 1. **Object Information**
103
+ - Object class/type
104
+ - Description and characteristics
105
+ - Confidence level (if applicable)
106
+
107
+ 2. **Position and Size**
108
+ - Bounding box coordinates in this format: {x: 10, y: 20, width: 30, height: 15}
109
+ - Coordinate system: origin (0,0) at top-left, units are percentage of image dimensions
110
+ - Alternative: If percentages aren't appropriate, describe relative position (e.g., "center", "top-right")
111
+
112
+ 3. **Additional Details**
113
+ - Color, size, or other distinguishing features
114
+ - Relationship to other objects
115
+ - Any text or labels associated with the object
116
+
117
+ If multiple objects of the same type exist, list them all with their unique positions.
118
+
119
+ Please format the response as structured data that can be easily parsed.`
120
+ };
121
+ /**
122
+ * OCR 和文本提取模板
123
+ */
124
+ export const OCR_TEMPLATE = {
125
+ id: 'ocr',
126
+ name: 'OCR and Text Extraction',
127
+ description: 'Extract text from images with positioning',
128
+ useCases: ['text extraction', 'OCR', 'document scanning'],
129
+ template: `${BASE_SYSTEM_PROMPT}
130
+
131
+ Extract all visible text from the image with the following details:
132
+
133
+ 1. **Text Content**
134
+ - All readable text in the image
135
+ - Maintain the original structure and grouping
136
+ - Preserve formatting if relevant (headings, paragraphs, lists)
137
+
138
+ 2. **Text Positioning**
139
+ - For each text element, provide approximate coordinates
140
+ - Format: {text: "content", x: 10, y: 20, width: 30, height: 15}
141
+ - Coordinates are optional but helpful for reference
142
+
143
+ 3. **Additional Information**
144
+ - Font characteristics (if apparent: size, weight, style)
145
+ - Text color and background
146
+ - Language detection if multiple languages present
147
+
148
+ 4. **Structured Output**
149
+ - Organize extracted text logically
150
+ - Group related text elements
151
+ - Indicate hierarchy if present (titles, body text, captions)
152
+
153
+ Present the extracted information in a clear, structured format that preserves the original layout information.`
154
+ };
155
+ /**
156
+ * 结构化信息提取模板
157
+ */
158
+ export const STRUCTURED_EXTRACTION_TEMPLATE = {
159
+ id: 'structured-extraction',
160
+ name: 'Structured Information Extraction',
161
+ description: 'Extract structured data according to a specific schema',
162
+ useCases: ['data extraction', 'form processing', 'structured analysis'],
163
+ template: `${BASE_SYSTEM_PROMPT}
164
+
165
+ Extract structured information from the image following the user's specified schema or format. Focus on:
166
+
167
+ 1. **Identifying Key Information**
168
+ - Extract all relevant data points
169
+ - Capture relationships between data elements
170
+ - Include contextual information
171
+
172
+ 2. **Data Validation**
173
+ - Verify data types and formats
174
+ - Note any missing or ambiguous information
175
+ - Flag potential errors or inconsistencies
176
+
177
+ 3. **Output Structure**
178
+ - Follow the requested JSON schema or format exactly
179
+ - Include all required fields
180
+ - Use appropriate data types (string, number, array, object)
181
+
182
+ 4. **Quality Assurance**
183
+ - Double-check extracted values for accuracy
184
+ - Provide confidence levels if uncertain
185
+ - Note any assumptions made
186
+
187
+ If specific fields or format are requested in the user prompt, prioritize those requirements.`
188
+ };
189
+ /**
190
+ * 获取系统提示词模板
191
+ *
192
+ * @param templateId 模板 ID
193
+ * @param customInstructions 额外的自定义指令(可选)
194
+ * @returns 完整的系统提示词
195
+ */
196
+ export function getSystemPrompt(templateId, customInstructions) {
197
+ const template = SYSTEM_PROMPT_TEMPLATES[templateId];
198
+ if (!template) {
199
+ throw new Error(`Unknown template ID: ${templateId}`);
200
+ }
201
+ let prompt = template.template;
202
+ // 如果有自定义指令,追加到提示词中
203
+ if (customInstructions) {
204
+ prompt += `\n\n=== Additional Instructions ===\n${customInstructions}`;
205
+ }
206
+ return prompt;
207
+ }
208
+ /**
209
+ * 所有可用的系统提示词模板
210
+ */
211
+ export const SYSTEM_PROMPT_TEMPLATES = {
212
+ 'general-description': GENERAL_DESCRIPTION_TEMPLATE,
213
+ 'ui-analysis': UI_ANALYSIS_TEMPLATE,
214
+ 'object-detection': OBJECT_DETECTION_TEMPLATE,
215
+ 'ocr': OCR_TEMPLATE,
216
+ 'structured-extraction': STRUCTURED_EXTRACTION_TEMPLATE
217
+ };
218
+ /**
219
+ * 获取模板列表
220
+ */
221
+ export function getAvailableTemplates() {
222
+ return Object.values(SYSTEM_PROMPT_TEMPLATES).map(t => ({
223
+ id: t.id,
224
+ name: t.name,
225
+ description: t.description,
226
+ useCases: t.useCases
227
+ }));
228
+ }
229
+ /**
230
+ * 自动选择合适的模板
231
+ *
232
+ * @param prompt 用户提示词
233
+ * @returns 推荐的模板 ID
234
+ */
235
+ export function autoSelectTemplate(prompt) {
236
+ const lowerPrompt = prompt.toLowerCase();
237
+ // 关键词匹配
238
+ if (lowerPrompt.includes('ui') || lowerPrompt.includes('interface') || lowerPrompt.includes('prototype')) {
239
+ return 'ui-analysis';
240
+ }
241
+ if (lowerPrompt.includes('detect') || lowerPrompt.includes('locate') || lowerPrompt.includes('position')) {
242
+ return 'object-detection';
243
+ }
244
+ if (lowerPrompt.includes('ocr') || lowerPrompt.includes('text') || lowerPrompt.includes('extract text')) {
245
+ return 'ocr';
246
+ }
247
+ if (lowerPrompt.includes('json') || lowerPrompt.includes('structured') || lowerPrompt.includes('schema')) {
248
+ return 'structured-extraction';
249
+ }
250
+ if (lowerPrompt.includes('describe') || lowerPrompt.includes('what') || lowerPrompt.includes('explain')) {
251
+ return 'general-description';
252
+ }
253
+ // 默认使用通用描述模板
254
+ return 'general-description';
255
+ }
256
+ /**
257
+ * 构建完整的提示词
258
+ *
259
+ * @param templateId 模板 ID
260
+ * @param userPrompt 用户提示词
261
+ * @returns 构建完成的提示词
262
+ */
263
+ export function buildPrompt(templateId, userPrompt) {
264
+ // 如果没有指定模板,自动选择
265
+ const selectedTemplateId = templateId || autoSelectTemplate(userPrompt);
266
+ // 构建完整提示词
267
+ const systemPrompt = getSystemPrompt(selectedTemplateId);
268
+ // 组合系统提示词和用户提示词
269
+ // Note: 实际使用时可能在消息数组中分别传递
270
+ return `${systemPrompt}\n\n=== User Request ===\n${userPrompt}`;
271
+ }
272
+ //# sourceMappingURL=system.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system.js","sourceRoot":"","sources":["../../../src/prompts/system.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;;;;;;;;;;;6GAW2E,CAAC;AAE9G;;GAEG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAyB;IAChE,EAAE,EAAE,qBAAq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@@ -0,0 +1,91 @@
1
+ /**
2
+ * Vision Tool
3
+ *
4
+ * @description MCP 视觉分析工具,提供统一的图片分析接口
5
+ */
6
+ import { z } from 'zod';
7
+ import { ModelConfig } from '../config/model-config.js';
8
+ /**
9
+ * 工具参数 Schema
10
+ */
11
+ export declare const VisionToolInputSchema: z.ZodObject<{
12
+ /**
13
+ * 图片输入:支持 URL、base64(data URL) 或本地路径
14
+ * @example "https://example.com/image.jpg"
15
+ * @example "data:image/jpeg;base64,/9j/4AAQ..."
16
+ * @example "/path/to/local/image.png"
17
+ */
18
+ image: z.ZodString;
19
+ /**
20
+ * 分析提示词:描述要执行的分析任务
21
+ * @example "Describe this UI design and extract all components"
22
+ * @example "Detect objects and provide their coordinates"
23
+ * @example "Extract text using OCR"
24
+ */
25
+ prompt: z.ZodString;
26
+ /**
27
+ * 输出格式:可选,指定为 "text" 或 "json"
28
+ * @default "text"
29
+ */
30
+ output_format: z.ZodDefault<z.ZodOptional<z.ZodEnum<["text", "json"]>>>;
31
+ /**
32
+ * 系统提示词模板:可选,指定使用的模板
33
+ * @default auto-detected based on prompt
34
+ * @example "ui-analysis"
35
+ * @example "object-detection"
36
+ */
37
+ template: z.ZodOptional<z.ZodString>;
38
+ }, "strict", z.ZodTypeAny, {
39
+ image: string;
40
+ prompt: string;
41
+ output_format: "text" | "json";
42
+ template?: string | undefined;
43
+ }, {
44
+ image: string;
45
+ prompt: string;
46
+ output_format?: "text" | "json" | undefined;
47
+ template?: string | undefined;
48
+ }>;
49
+ export type VisionToolInput = z.infer<typeof VisionToolInputSchema>;
50
+ /**
51
+ * 工具响应格式
52
+ */
53
+ export interface VisionToolResponse {
54
+ content: string;
55
+ format: 'text' | 'json';
56
+ metadata: {
57
+ modelType: string;
58
+ modelName: string;
59
+ imageFormat: string;
60
+ processingTimeMs: number;
61
+ imageSize: number;
62
+ };
63
+ }
64
+ /**
65
+ * 视觉工具类
66
+ */
67
+ export declare class VisionTool {
68
+ private modelConfig;
69
+ private adapter;
70
+ constructor(config?: ModelConfig);
71
+ /**
72
+ * 创建模型适配器
73
+ */
74
+ private createAdapter;
75
+ /**
76
+ * 执行视觉分析
77
+ */
78
+ analyze(input: VisionToolInput): Promise<VisionToolResponse>;
79
+ /**
80
+ * 构建元数据
81
+ */
82
+ private buildMetadata;
83
+ /**
84
+ * 获取工具信息
85
+ */
86
+ getToolInfo(): {
87
+ modelConfig: ModelConfig;
88
+ };
89
+ }
90
+ export declare function getVisionTool(config?: ModelConfig): VisionTool;
91
+ //# sourceMappingURL=vision-tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vision-tool.d.ts","sourceRoot":"","sources":["../../../src/tools/vision-tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAwC,MAAM,2BAA2B,CAAC;AAS9F;;GAEG;AACH,eAAO,MAAM,qBAAqB;IAChC;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;OAGG;;IAGH;;;;;OAKG;;;;;;;;;;;;EAEM,CAAC;AAEZ,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,QAAQ,EAAE;QACR,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;QACpB,gBAAgB,EAAE,MAAM,CAAC;QACzB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,OAAO,CAAqB;gBAExB,MAAM,CAAC,EAAE,WAAW;IAgBhC;;OAEG;IACH,OAAO,CAAC,aAAa;IAarB;;OAEG;IACU,OAAO,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA2EzE;;OAEG;IACH,OAAO,CAAC,aAAa;IAUrB;;OAEG;IACI,WAAW,IAAI;QACpB,WAAW,EAAE,WAAW,CAAC;KAC1B;CAKF;AAOD,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,UAAU,CAK9D"}
@@ -0,0 +1,171 @@
1
+ /**
2
+ * Vision Tool
3
+ *
4
+ * @description MCP 视觉分析工具,提供统一的图片分析接口
5
+ */
6
+ import { z } from 'zod';
7
+ import { loadModelConfig, validateModelConfig } from '../config/model-config.js';
8
+ import { GLM4VisionAdapter } from '../adapters/glm-adapter.js';
9
+ import { SiliconFlowAdapter } from '../adapters/siliconflow-adapter.js';
10
+ import { normalizeImageInput } from '../utils/image-input.js';
11
+ import { ModelConfigError } from '../utils/errors.js';
12
+ import { logger } from '../utils/logger.js';
13
+ import { buildPrompt } from '../prompts/system.js';
14
+ /**
15
+ * 工具参数 Schema
16
+ */
17
+ export const VisionToolInputSchema = z.object({
18
+ /**
19
+ * 图片输入:支持 URL、base64(data URL) 或本地路径
20
+ * @example "https://example.com/image.jpg"
21
+ * @example "data:image/jpeg;base64,/9j/4AAQ..."
22
+ * @example "/path/to/local/image.png"
23
+ */
24
+ image: z.string().describe('Image URL, base64 data URL, or local file path'),
25
+ /**
26
+ * 分析提示词:描述要执行的分析任务
27
+ * @example "Describe this UI design and extract all components"
28
+ * @example "Detect objects and provide their coordinates"
29
+ * @example "Extract text using OCR"
30
+ */
31
+ prompt: z.string().describe('Analysis prompt describing the task'),
32
+ /**
33
+ * 输出格式:可选,指定为 "text" 或 "json"
34
+ * @default "text"
35
+ */
36
+ output_format: z.enum(['text', 'json']).optional().default('text').describe('Output format preference'),
37
+ /**
38
+ * 系统提示词模板:可选,指定使用的模板
39
+ * @default auto-detected based on prompt
40
+ * @example "ui-analysis"
41
+ * @example "object-detection"
42
+ */
43
+ template: z.string().optional().describe('System prompt template to use')
44
+ }).strict();
45
+ /**
46
+ * 视觉工具类
47
+ */
48
+ export class VisionTool {
49
+ modelConfig;
50
+ adapter;
51
+ constructor(config) {
52
+ // 加载配置
53
+ this.modelConfig = config || loadModelConfig();
54
+ // 验证配置
55
+ validateModelConfig(this.modelConfig);
56
+ // 创建适配器
57
+ this.adapter = this.createAdapter(this.modelConfig);
58
+ logger.info('Vision tool initialized', {
59
+ modelType: this.modelConfig.type,
60
+ modelName: this.modelConfig.name
61
+ });
62
+ }
63
+ /**
64
+ * 创建模型适配器
65
+ */
66
+ createAdapter(config) {
67
+ switch (config.type) {
68
+ case 'glm-4.6v':
69
+ return new GLM4VisionAdapter(config);
70
+ case 'siliconflow':
71
+ return new SiliconFlowAdapter(config);
72
+ default:
73
+ throw new ModelConfigError(`Unsupported model type: ${config.type}`);
74
+ }
75
+ }
76
+ /**
77
+ * 执行视觉分析
78
+ */
79
+ async analyze(input) {
80
+ const startTime = Date.now();
81
+ const requestId = Math.random().toString(36).substring(7);
82
+ logger.logRequest('Vision analysis started', {
83
+ requestId,
84
+ modelType: this.modelConfig.type,
85
+ imageInputLength: input.image.length,
86
+ hasTemplate: !!input.template
87
+ });
88
+ try {
89
+ // 1. 规范化图片输入
90
+ logger.debug('Normalizing image input', { requestId });
91
+ const normalizedImage = await normalizeImageInput(input.image);
92
+ logger.debug('Image normalized successfully', {
93
+ requestId,
94
+ type: normalizedImage.type,
95
+ mimeType: normalizedImage.mimeType,
96
+ dataLength: normalizedImage.dataUrl.length
97
+ });
98
+ // 2. 构建完整提示词
99
+ logger.debug('Building prompt', { requestId });
100
+ const fullPrompt = buildPrompt(input.template, input.prompt);
101
+ logger.debug('Prompt built', {
102
+ requestId,
103
+ promptLength: fullPrompt.length,
104
+ templateUsed: input.template || 'auto-detected'
105
+ });
106
+ // 3. 调用视觉模型
107
+ logger.logRequest('Calling vision model', {
108
+ requestId,
109
+ modelType: this.modelConfig.type,
110
+ modelName: this.modelConfig.name
111
+ });
112
+ const modelResponse = await this.adapter.analyzeWithResponse(normalizedImage.dataUrl, fullPrompt);
113
+ // 4. 构建响应
114
+ const response = {
115
+ content: modelResponse.content,
116
+ format: input.output_format,
117
+ metadata: {
118
+ modelType: this.modelConfig.type,
119
+ modelName: this.modelConfig.name,
120
+ imageFormat: normalizedImage.mimeType,
121
+ processingTimeMs: Date.now() - startTime,
122
+ imageSize: normalizedImage.dataUrl.length
123
+ }
124
+ };
125
+ logger.logRequest('Vision analysis completed', {
126
+ requestId,
127
+ processingTimeMs: response.metadata.processingTimeMs,
128
+ outputLength: response.content.length
129
+ });
130
+ return response;
131
+ }
132
+ catch (error) {
133
+ logger.error('Vision analysis failed', error, {
134
+ requestId,
135
+ processingTimeMs: Date.now() - startTime
136
+ });
137
+ throw error;
138
+ }
139
+ }
140
+ /**
141
+ * 构建元数据
142
+ */
143
+ buildMetadata(normalizedImage, startTime) {
144
+ return {
145
+ modelType: this.modelConfig.type,
146
+ modelName: this.modelConfig.name,
147
+ imageFormat: normalizedImage.mimeType,
148
+ processingTimeMs: Date.now() - startTime,
149
+ imageSize: normalizedImage.dataUrl.length
150
+ };
151
+ }
152
+ /**
153
+ * 获取工具信息
154
+ */
155
+ getToolInfo() {
156
+ return {
157
+ modelConfig: this.modelConfig
158
+ };
159
+ }
160
+ }
161
+ /**
162
+ * 创建工具实例(单例模式)
163
+ */
164
+ let toolInstance;
165
+ export function getVisionTool(config) {
166
+ if (!toolInstance) {
167
+ toolInstance = new VisionTool(config);
168
+ }
169
+ return toolInstance;
170
+ }
171
+ //# sourceMappingURL=vision-tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vision-tool.js","sourceRoot":"","sources":["../../../src/tools/vision-tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAe,eAAe,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAC9F,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gBACpD,YAAY,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM;aACtC,CAAC,CAAC;YAEH,OAAO,QAAQ,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,wBAAwB,EAAE,KAAc,EAAE;gBACrD,SAAS;gBACT,gBAAgB,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;aACzC,CAAC,CAAC;YAEH,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED;;OAEG;IACK,aAAa,CAAC,eAAqC,EAAE,SAAiB;QAC5E,OAAO;YACL,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI;YAChC,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI;YAChC,WAAW,EAAE,eAAe,CAAC,QAAQ;YACrC,gBAAgB,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;YACxC,SAAS,EAAE,eAAe,CAAC,OAAO,CAAC,MAAM;SAC1C,CAAC;IACJ,CAAC;IAED;;OAEG;IACI,WAAW;QAGhB,OAAO;YACL,WAAW,EAAE,IAAI,CAAC,WAAW;SAC9B,CAAC;IACJ,CAAC;CACF;AAED;;GAEG;AACH,IAAI,YAAoC,CAAC;AAEzC,MAAM,UAAU,aAAa,CAAC,MAAoB;IAChD,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Vision MCP Error Types
3
+ *
4
+ * @description 统一错误处理系统,提供清晰的错误分类和信息
5
+ */
6
+ export declare enum VisionMCPErrorCode {
7
+ INVALID_INPUT = "INVALID_INPUT",
8
+ MODEL_CONFIG_ERROR = "MODEL_CONFIG_ERROR",
9
+ IMAGE_LOAD_ERROR = "IMAGE_LOAD_ERROR",
10
+ MODEL_API_ERROR = "MODEL_API_ERROR",
11
+ TIMEOUT_ERROR = "TIMEOUT_ERROR",
12
+ UNKNOWN_ERROR = "UNKNOWN_ERROR"
13
+ }
14
+ export interface VisionMCPErrorOptions {
15
+ message: string;
16
+ code: VisionMCPErrorCode;
17
+ details?: Record<string, any>;
18
+ cause?: unknown;
19
+ }
20
+ export declare class VisionMCPError extends Error {
21
+ readonly code: VisionMCPErrorCode;
22
+ readonly details?: Record<string, any>;
23
+ readonly timestamp: Date;
24
+ constructor({ message, code, details, cause }: VisionMCPErrorOptions);
25
+ toJSON(): {
26
+ error: {
27
+ message: string;
28
+ code: VisionMCPErrorCode;
29
+ details: {
30
+ [x: string]: any;
31
+ };
32
+ timestamp: string;
33
+ };
34
+ };
35
+ }
36
+ export declare class InvalidInputError extends VisionMCPError {
37
+ constructor(message: string, details?: Record<string, any>, cause?: unknown);
38
+ }
39
+ export declare class ModelConfigError extends VisionMCPError {
40
+ constructor(message: string, details?: Record<string, any>, cause?: unknown);
41
+ }
42
+ export declare class ImageLoadError extends VisionMCPError {
43
+ constructor(message: string, details?: Record<string, any>, cause?: unknown);
44
+ }
45
+ export declare class ModelAPIError extends VisionMCPError {
46
+ constructor(message: string, details?: Record<string, any>, cause?: unknown);
47
+ }
48
+ export declare class TimeoutError extends VisionMCPError {
49
+ constructor(message: string, details?: Record<string, any>, cause?: unknown);
50
+ }
51
+ /**
52
+ * 将未知错误转换为 VisionMCPError
53
+ */
54
+ export declare function toVisionMCPError(error: unknown, context?: string): VisionMCPError;
55
+ /**
56
+ * 将错误映射为 MCP 工具响应格式
57
+ */
58
+ export declare function toMCPErrorResponse(error: VisionMCPError): {
59
+ content: {
60
+ type: "text";
61
+ text: string;
62
+ }[];
63
+ isError: boolean;
64
+ };
65
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,oBAAY,kBA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