@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
package/dist/index.js ADDED
@@ -0,0 +1,186 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Vision MCP Server
4
+ *
5
+ * @description MCP Server providing vision capabilities via GLM-4.6V and SiliconFlow
6
+ * This server implements the Model Context Protocol for LLM integration
7
+ *
8
+ * IMPORTANT: This server uses STDIO for MCP communication. Do not use console.log for debugging.
9
+ * Use console.error (stderr) for all logging as required by MCP protocol.
10
+ */
11
+ import { config } from 'dotenv';
12
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
13
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
14
+ import { z } from 'zod';
15
+ // 加载环境变量(如果有 .env 文件)
16
+ config();
17
+ import { logger } from './utils/logger.js';
18
+ import { getVisionTool, VisionToolInputSchema } from './tools/vision-tool.js';
19
+ import { toVisionMCPError, toMCPErrorResponse } from './utils/errors.js';
20
+ /**
21
+ * 创建并配置 MCP Server
22
+ */
23
+ function createMCPServer() {
24
+ const server = new McpServer({
25
+ name: 'vision-mcp',
26
+ version: '1.0.0'
27
+ });
28
+ // 初始化视觉工具
29
+ let visionTool;
30
+ try {
31
+ visionTool = getVisionTool();
32
+ logger.info('Vision MCP Server initialized successfully');
33
+ }
34
+ catch (error) {
35
+ logger.error('Failed to initialize vision tool', error);
36
+ throw error;
37
+ }
38
+ // 注册视觉分析工具
39
+ server.tool('analyze_image', 'Analyze an image using a vision model (GLM-4.6V or SiliconFlow). Supports URL, base64 data URL, or local file path.', {
40
+ image: z.string().describe('Image URL, base64 data URL, or local file path'),
41
+ prompt: z.string().describe('Analysis prompt describing what to analyze'),
42
+ output_format: z.enum(['text', 'json']).optional().default('text').describe('Output format preference (text or json)'),
43
+ template: z.string().optional().describe('System prompt template (ui-analysis, object-detection, ocr, etc.)')
44
+ }, async ({ image, prompt, output_format, template }) => {
45
+ try {
46
+ logger.logRequest('Vision tool called', {
47
+ imageLength: image.length,
48
+ promptLength: prompt.length,
49
+ outputFormat: output_format
50
+ });
51
+ // 验证输入
52
+ const validationResult = VisionToolInputSchema.safeParse({
53
+ image,
54
+ prompt,
55
+ output_format,
56
+ template
57
+ });
58
+ if (!validationResult.success) {
59
+ return {
60
+ content: [
61
+ {
62
+ type: 'text',
63
+ text: JSON.stringify({
64
+ error: 'Invalid input',
65
+ details: validationResult.error.errors
66
+ }, null, 2)
67
+ }
68
+ ],
69
+ isError: true
70
+ };
71
+ }
72
+ // 执行分析
73
+ const result = await visionTool.analyze(validationResult.data);
74
+ logger.logRequest('Tool execution completed', {
75
+ outputLength: result.content.length,
76
+ processingTime: result.metadata.processingTimeMs,
77
+ modelType: result.metadata.modelType
78
+ });
79
+ // 返回结果
80
+ return {
81
+ content: [
82
+ {
83
+ type: 'text',
84
+ text: result.content
85
+ }
86
+ ]
87
+ };
88
+ }
89
+ catch (error) {
90
+ logger.error('Tool execution failed', error);
91
+ return toMCPErrorResponse(toVisionMCPError(error));
92
+ }
93
+ });
94
+ // 注册获取可用模板工具
95
+ server.tool('list_templates', 'List available system prompt templates for different vision analysis tasks', {}, async () => {
96
+ try {
97
+ logger.logRequest('List templates tool called', {});
98
+ // 导入模板信息
99
+ const { getAvailableTemplates } = await import('./prompts/system.js');
100
+ const templates = getAvailableTemplates();
101
+ return {
102
+ content: [
103
+ {
104
+ type: 'text',
105
+ text: JSON.stringify(templates, null, 2)
106
+ }
107
+ ]
108
+ };
109
+ }
110
+ catch (error) {
111
+ logger.error('Failed to list templates', error);
112
+ return toMCPErrorResponse(toVisionMCPError(error));
113
+ }
114
+ });
115
+ // 注册获取配置信息工具
116
+ server.tool('get_config', 'Get current model configuration (model type, name, etc.)', {}, async () => {
117
+ try {
118
+ const { modelConfig } = visionTool.getToolInfo();
119
+ const { maskApiKey } = await import('./config/model-config.js');
120
+ return {
121
+ content: [
122
+ {
123
+ type: 'text',
124
+ text: JSON.stringify({
125
+ type: modelConfig.type,
126
+ name: modelConfig.name,
127
+ baseUrl: modelConfig.baseUrl,
128
+ apiKey: maskApiKey(modelConfig.apiKey),
129
+ timeout: modelConfig.timeout,
130
+ maxRetries: modelConfig.maxRetries
131
+ }, null, 2)
132
+ }
133
+ ]
134
+ };
135
+ }
136
+ catch (error) {
137
+ logger.error('Failed to get config', error);
138
+ return toMCPErrorResponse(toVisionMCPError(error));
139
+ }
140
+ });
141
+ return server;
142
+ }
143
+ /**
144
+ * 主函数
145
+ */
146
+ async function main() {
147
+ try {
148
+ logger.info('Starting Vision MCP Server...');
149
+ // 创建服务器
150
+ const server = createMCPServer();
151
+ // 创建传输层
152
+ const transport = new StdioServerTransport();
153
+ // 连接服务器
154
+ await server.connect(transport);
155
+ logger.error('Vision MCP Server is running on stdio');
156
+ // 处理进程信号
157
+ process.on('SIGINT', async () => {
158
+ logger.error('Received SIGINT, shutting down...');
159
+ process.exit(0);
160
+ });
161
+ process.on('SIGTERM', async () => {
162
+ logger.error('Received SIGTERM, shutting down...');
163
+ process.exit(0);
164
+ });
165
+ // 未捕获异常处理
166
+ process.on('uncaughtException', (error) => {
167
+ logger.error('Uncaught exception', error);
168
+ process.exit(1);
169
+ });
170
+ process.on('unhandledRejection', (reason, promise) => {
171
+ logger.error(`Unhandled rejection at: ${promise}, reason: ${reason}`);
172
+ process.exit(1);
173
+ });
174
+ }
175
+ catch (error) {
176
+ logger.error('Fatal error starting server', error);
177
+ process.exit(1);
178
+ }
179
+ }
180
+ // 运行主函数(无条件执行,修复 Windows 路径问题)
181
+ main().catch((error) => {
182
+ logger.error('Fatal error in main', error);
183
+ process.exit(1);
184
+ });
185
+ export { createMCPServer };
186
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;GAQG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,sBAAsB;AACtB,MAAM,EAAE,CAAC;AAET,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEzE;;GAEG;AACH,SAAS,eAAe;IACtB,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;QAC3B,IAAI,EAAE,YAAY;QAClB,OAAO,EAAE,OAAO;KACjB,CAAC,CAAC;IAEH,UAAU;IACV,IAAI,UAA4C,CAAC;IAEjD,IAAI,CAAC;QACH,UAAU,GAAG,aAAa,EAAE,CAAC;QAC7B,MAAM,CAAC,IAAI,CAAC,4CAA4C,CAAC,CAAC;IAC5D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAC;QACxD,MAAM,KAAK,CAAC;IACd,CAAC;IAED,WAAW;IACX,MAAM,CAAC,IAAI,CACT,eAAe,EACf,qHAAqH,EACrH;QACE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,gDAAgD,CAAC;QAC5E,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,4CAA4C,CAAC;QACzE,aAAa,EAAE,CAAC,CAAC,IAA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C;QAClB,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,KAAK,IAAI,EAAE;YAC/B,MAAM,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;YACnD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;QAEH,UAAU;QACV,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,KAAK,EAAE,EAAE;YACxC,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;YAC1C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE;YACnD,MAAM,CAAC,KAAK,CAAC,2BAA2B,OAAO,aAAa,MAAM,EAAE,CAAC,CAAC;YACtE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;QACnD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,+BAA+B;AAC/B,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;IAC3C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * System Prompt Templates
3
+ *
4
+ * @description 内置的系统提示词模板,覆盖常见视觉任务场景
5
+ */
6
+ export interface SystemPromptTemplate {
7
+ id: string;
8
+ name: string;
9
+ template: string;
10
+ description: string;
11
+ useCases: string[];
12
+ }
13
+ /**
14
+ * 基础系统提示词
15
+ * 提供通用指导原则和规范
16
+ */
17
+ export declare const BASE_SYSTEM_PROMPT = "You are a vision analysis assistant with access to image data.\n\nYour task is to analyze images accurately and provide helpful responses based on what you see.\n\nGuidelines:\n1. Be precise and detailed in your observations\n2. When coordinates or measurements are requested, provide them in the format specified\n3. If an image is unclear or ambiguous, acknowledge the limitations\n4. Convert any complex structured data to the requested format\n5. Be helpful and follow the specific instructions provided by the user\n\nRemember: You are providing visual information to another AI system, so clarity and structure are important.";
18
+ /**
19
+ * 通用描述模板
20
+ */
21
+ export declare const GENERAL_DESCRIPTION_TEMPLATE: SystemPromptTemplate;
22
+ /**
23
+ * UI 分析模板
24
+ * 用于分析 UI 原型图、截图等
25
+ */
26
+ export declare const UI_ANALYSIS_TEMPLATE: SystemPromptTemplate;
27
+ /**
28
+ * 对象定位和检测模板
29
+ */
30
+ export declare const OBJECT_DETECTION_TEMPLATE: SystemPromptTemplate;
31
+ /**
32
+ * OCR 和文本提取模板
33
+ */
34
+ export declare const OCR_TEMPLATE: SystemPromptTemplate;
35
+ /**
36
+ * 结构化信息提取模板
37
+ */
38
+ export declare const STRUCTURED_EXTRACTION_TEMPLATE: SystemPromptTemplate;
39
+ /**
40
+ * 获取系统提示词模板
41
+ *
42
+ * @param templateId 模板 ID
43
+ * @param customInstructions 额外的自定义指令(可选)
44
+ * @returns 完整的系统提示词
45
+ */
46
+ export declare function getSystemPrompt(templateId: string, customInstructions?: string): string;
47
+ /**
48
+ * 所有可用的系统提示词模板
49
+ */
50
+ export declare const SYSTEM_PROMPT_TEMPLATES: Record<string, SystemPromptTemplate>;
51
+ /**
52
+ * 获取模板列表
53
+ */
54
+ export declare function getAvailableTemplates(): Array<{
55
+ id: string;
56
+ name: string;
57
+ description: string;
58
+ useCases: string[];
59
+ }>;
60
+ /**
61
+ * 自动选择合适的模板
62
+ *
63
+ * @param prompt 用户提示词
64
+ * @returns 推荐的模板 ID
65
+ */
66
+ export declare function autoSelectTemplate(prompt: string): string;
67
+ /**
68
+ * 构建完整的提示词
69
+ *
70
+ * @param templateId 模板 ID
71
+ * @param userPrompt 用户提示词
72
+ * @returns 构建完成的提示词
73
+ */
74
+ export declare function buildPrompt(templateId: string | undefined, userPrompt: string): string;
75
+ //# sourceMappingURL=system.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system.d.ts","sourceRoot":"","sources":["../../src/prompts/system.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;;GAGG;AACH,eAAO,MAAM,kBAAkB,4nBAW8E,CAAC;AAE9G;;GAEG;AACH,eAAO,MAAM,4BAA4B,EAAE,oBAe1C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,oBA4ClC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,oBA2BvC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,oBA8B1B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,8BAA8B,EAAE,oBA8B5C,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,kBAAkB,CAAC,EAAE,MAAM,GAAG,MAAM,CAevF;AAED;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAMxE,CAAC;AAEF;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,KAAK,CAAC;IAC7C,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC,CAOD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CA0BzD;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAUtF"}
@@ -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,qBAAqB;IACzB,IAAI,EAAE,qBAAqB;IAC3B,WAAW,EAAE,6CAA6C;IAC1D,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册表,集中管理所有支持的模型提供商
5
+ * 添加新提供商只需在这里注册,无需修改其他文件
6
+ */
7
+ import { ModelConfig } from '../config/model-config.js';
8
+ import { VisionModelAdapter } from '../adapters/base-adapter.js';
9
+ import { ThinkingExtractor } from '../utils/thinking-extractors.js';
10
+ /**
11
+ * 提供商定义接口
12
+ */
13
+ export interface ProviderDefinition {
14
+ /** 提供商类型标识 */
15
+ type: string;
16
+ /** 显示名称 */
17
+ displayName: string;
18
+ /** 默认配置 */
19
+ defaults: {
20
+ baseUrl: string;
21
+ modelName: string;
22
+ timeout: number;
23
+ maxRetries: number;
24
+ };
25
+ /** API Key 验证函数 */
26
+ validateApiKey?: (apiKey: string) => boolean | string;
27
+ /** 适配器工厂函数 */
28
+ createAdapter: (config: ModelConfig) => VisionModelAdapter;
29
+ /** Thinking 提取器 */
30
+ thinkingExtractor: ThinkingExtractor;
31
+ /** 是否启用 thinking */
32
+ enableThinking?: boolean;
33
+ }
34
+ /**
35
+ * 提供商注册表
36
+ */
37
+ declare class ProviderRegistry {
38
+ private providers;
39
+ /**
40
+ * 注册提供商
41
+ */
42
+ register(provider: ProviderDefinition): void;
43
+ /**
44
+ * 获取提供商
45
+ */
46
+ get(type: string): ProviderDefinition | undefined;
47
+ /**
48
+ * 检查是否支持该类型
49
+ */
50
+ has(type: string): boolean;
51
+ /**
52
+ * 获取所有支持的类型
53
+ */
54
+ getSupportedTypes(): string[];
55
+ }
56
+ export declare const registry: ProviderRegistry;
57
+ export {};
58
+ //# sourceMappingURL=provider-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-registry.d.ts","sourceRoot":"","sources":["../../src/providers/provider-registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAoE,MAAM,iCAAiC,CAAC;AAOtI;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,cAAc;IACd,IAAI,EAAE,MAAM,CAAC;IACb,WAAW;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW;IACX,QAAQ,EAAE;QACR,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,mBAAmB;IACnB,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,GAAG,MAAM,CAAC;IACtD,cAAc;IACd,aAAa,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,kBAAkB,CAAC;IAC3D,mBAAmB;IACnB,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,oBAAoB;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;GAEG;AACH,cAAM,gBAAgB;IACpB,OAAO,CAAC,SAAS,CAAyC;IAE1D;;OAEG;IACI,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI;IAInD;;OAEG;IACI,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS;IAIxD;;OAEG;IACI,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIjC;;OAEG;IACI,iBAAiB,IAAI,MAAM,EAAE;CAGrC;AAGD,eAAO,MAAM,QAAQ,kBAAyB,CAAC"}