intention-coding 0.2.3 → 0.2.5
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/cli/analyze-image.d.ts +2 -0
- package/dist/config.d.ts +5 -0
- package/dist/index.js +650 -809
- package/dist/prompt/{change-analysis.md → change-analysis.ts} +2 -2
- package/dist/services/change-summarizer/prompt/change-analysis.d.ts +1 -0
- package/dist/services/claude-code/index.d.ts +6 -6
- package/dist/services/image-analysis/config.d.ts +14 -0
- package/dist/services/image-analysis/factory.d.ts +33 -0
- package/dist/services/image-analysis/image-analysis.d.ts +36 -0
- package/dist/services/image-analysis/image-encoder.d.ts +20 -0
- package/dist/services/image-analysis/image-validator.d.ts +30 -0
- package/dist/services/image-analysis/index.d.ts +29 -0
- package/dist/services/image-analysis/tools.d.ts +55 -0
- package/dist/services/image-analysis/types.d.ts +154 -0
- package/dist/services/index.d.ts +5 -0
- package/dist/{services → utils}/openai-service.d.ts +30 -0
- package/package.json +7 -6
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const changeAnalysisPrompt = "\u8BF7\u5206\u6790\u672C\u6B21\u4EE3\u7801\u53D8\u66F4\uFF0C\u5E76\u4E0E\u9700\u6C42\u8FDB\u884C\u5BF9\u6BD4\uFF0C\u786E\u4FDD\u5B9E\u73B0\u7684\u5B8C\u6574\u6027\u3002\n\n\u8BF7\u6309\u4EE5\u4E0B\u6B65\u9AA4\u8FDB\u884C\u5206\u6790\uFF1A\n\n## 1. \u4EE3\u7801\u53D8\u66F4\u603B\u7ED3\n\u5206\u6790git diff\u5185\u5BB9\uFF0C\u603B\u7ED3\uFF1A\n- \u65B0\u589E\u6587\u4EF6\u53CA\u5176\u529F\u80FD\n- \u4FEE\u6539\u6587\u4EF6\u53CA\u53D8\u66F4\u5185\u5BB9\n- \u5220\u9664\u6587\u4EF6\u53CA\u539F\u56E0\n- \u4E3B\u8981\u529F\u80FD\u6A21\u5757\u53D8\u66F4\n\n## 2. \u63A5\u53E3\u4E0E\u9700\u6C42\u5BF9\u5E94\u5173\u7CFB\u8868\n\u6839\u636E\u4EE3\u7801\u53D8\u66F4\uFF0C\u751F\u6210\u63A5\u53E3\u4E0E\u9700\u6C42\u5BF9\u5E94\u5173\u7CFB\u8868\uFF1A\n\n| \u9700\u6C42\u529F\u80FD | \u5B9E\u73B0\u63A5\u53E3 | \u8BF7\u6C42\u65B9\u5F0F | URL | \u53D8\u66F4\u72B6\u6001 |\n|---------|---------|---------|-----|----------|\n| [\u9700\u6C42\u529F\u80FD\u63CF\u8FF0] | [Controller.method] | [GET/POST/PUT/DELETE] | [/api/path] | [\u65B0\u589E/\u4FEE\u6539/\u5220\u9664] |\n\n## 3. \u6838\u5FC3\u903B\u8F91\u65B9\u6CD5\u8868\n\u5206\u6790\u6838\u5FC3\u4E1A\u52A1\u903B\u8F91\u65B9\u6CD5\uFF1A\n\n| \u65B9\u6CD5\u540D\u79F0 | \u6240\u5C5E\u7C7B | \u529F\u80FD\u8BF4\u660E | \u53D8\u66F4\u72B6\u6001 |\n|---------|-------|---------|----------|\n| [methodName] | [ClassName] | [\u529F\u80FD\u63CF\u8FF0] | [\u65B0\u589E/\u4FEE\u6539/\u5220\u9664] |\n\n## 4. \u524D\u7AEF\u9875\u9762\u4E0E\u63A5\u53E3\u5BF9\u5E94\u5173\u7CFB\u8868\n\u5206\u6790\u524D\u7AEF\u9875\u9762\u53D8\u66F4\uFF1A\n\n| \u9875\u9762\u540D\u79F0 | \u8C03\u7528\u63A5\u53E3 | \u7EC4\u4EF6\u540D\u79F0 | \u8DEF\u7531\u8DEF\u5F84 | \u53D8\u66F4\u72B6\u6001 |\n|---------|---------|---------|---------|----------|\n| [\u9875\u9762\u540D\u79F0] | [Controller.method] | [ComponentName] | [/path] | [\u65B0\u589E/\u4FEE\u6539/\u5220\u9664] |\n\n## 5. \u524D\u7AEF\u6838\u5FC3\u7EC4\u4EF6\u8868\n\u5206\u6790\u524D\u7AEF\u7EC4\u4EF6\u53D8\u66F4\uFF1A\n\n| \u7EC4\u4EF6\u540D\u79F0 | \u6240\u5C5E\u9875\u9762 | \u529F\u80FD\u8BF4\u660E | \u53D8\u66F4\u72B6\u6001 |\n|---------|---------|---------|----------|\n| [ComponentName] | [PageName] | [\u529F\u80FD\u63CF\u8FF0] | [\u65B0\u589E/\u4FEE\u6539/\u5220\u9664] |\n\n## 6. \u9700\u6C42\u5B8C\u6574\u6027\u68C0\u67E5\n\u5BF9\u6BD4\u539F\u59CB\u9700\u6C42\uFF0C\u68C0\u67E5\uFF1A\n- \u2705 \u5DF2\u5B8C\u6210\u7684\u529F\u80FD\n- \u26A0\uFE0F \u90E8\u5206\u5B8C\u6210\u7684\u529F\u80FD\n- \u274C \u672A\u5B9E\u73B0\u7684\u529F\u80FD\n- \uD83D\uDD04 \u9700\u8981\u8FDB\u4E00\u6B65\u5B8C\u5584\u7684\u529F\u80FD\n\n## 7. \u5EFA\u8BAE\u4E0E\u603B\u7ED3\n- \u5B9E\u73B0\u8D28\u91CF\u8BC4\u4F30\n- \u6F5C\u5728\u95EE\u9898\u8BC6\u522B\n- \u540E\u7EED\u5F00\u53D1\u5EFA\u8BAE\n- \u6D4B\u8BD5\u5EFA\u8BAE\n\n\u8BF7\u786E\u4FDD\u6240\u6709\u8868\u683C\u4E0A\u4E0B\u5BF9\u9F50\uFF0C\u5185\u5BB9\u8BE6\u5B9E\u51C6\u786E\u3002";
|
|
@@ -109,25 +109,25 @@ export declare const claudeCodeSessions: {
|
|
|
109
109
|
start: z.ZodOptional<z.ZodString>;
|
|
110
110
|
end: z.ZodOptional<z.ZodString>;
|
|
111
111
|
}, "strip", z.ZodTypeAny, {
|
|
112
|
-
start?: string | undefined;
|
|
113
112
|
end?: string | undefined;
|
|
114
|
-
}, {
|
|
115
113
|
start?: string | undefined;
|
|
114
|
+
}, {
|
|
116
115
|
end?: string | undefined;
|
|
116
|
+
start?: string | undefined;
|
|
117
117
|
}>>;
|
|
118
118
|
sizeLimit: z.ZodOptional<z.ZodNumber>;
|
|
119
119
|
}, "strip", z.ZodTypeAny, {
|
|
120
120
|
project?: string | undefined;
|
|
121
121
|
dateRange?: {
|
|
122
|
-
start?: string | undefined;
|
|
123
122
|
end?: string | undefined;
|
|
123
|
+
start?: string | undefined;
|
|
124
124
|
} | undefined;
|
|
125
125
|
sizeLimit?: number | undefined;
|
|
126
126
|
}, {
|
|
127
127
|
project?: string | undefined;
|
|
128
128
|
dateRange?: {
|
|
129
|
-
start?: string | undefined;
|
|
130
129
|
end?: string | undefined;
|
|
130
|
+
start?: string | undefined;
|
|
131
131
|
} | undefined;
|
|
132
132
|
sizeLimit?: number | undefined;
|
|
133
133
|
}>>;
|
|
@@ -148,8 +148,8 @@ export declare const claudeCodeSessions: {
|
|
|
148
148
|
filter?: {
|
|
149
149
|
project?: string | undefined;
|
|
150
150
|
dateRange?: {
|
|
151
|
-
start?: string | undefined;
|
|
152
151
|
end?: string | undefined;
|
|
152
|
+
start?: string | undefined;
|
|
153
153
|
} | undefined;
|
|
154
154
|
sizeLimit?: number | undefined;
|
|
155
155
|
} | undefined;
|
|
@@ -165,8 +165,8 @@ export declare const claudeCodeSessions: {
|
|
|
165
165
|
filter?: {
|
|
166
166
|
project?: string | undefined;
|
|
167
167
|
dateRange?: {
|
|
168
|
-
start?: string | undefined;
|
|
169
168
|
end?: string | undefined;
|
|
169
|
+
start?: string | undefined;
|
|
170
170
|
} | undefined;
|
|
171
171
|
sizeLimit?: number | undefined;
|
|
172
172
|
} | undefined;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface ImageAnalysisConfig {
|
|
2
|
+
prompt?: string;
|
|
3
|
+
temperature?: number;
|
|
4
|
+
imagePath?: string;
|
|
5
|
+
maxTokens?: number;
|
|
6
|
+
systemPrompt?: string;
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
apiKey?: string;
|
|
9
|
+
supportedFormats?: string[];
|
|
10
|
+
maxFileSize?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare const MODEL_NAME = "moonshot-v1-128k-vision-preview";
|
|
13
|
+
export declare const DEFAULT_CONFIG: ImageAnalysisConfig;
|
|
14
|
+
export declare function createConfig(baseConfig?: Partial<ImageAnalysisConfig>): ImageAnalysisConfig;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ImageAnalysisService } from './image-analysis';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new instance of the ImageAnalysisService
|
|
4
|
+
*
|
|
5
|
+
* Note: Configuration is now handled by the unified OpenAI service
|
|
6
|
+
*
|
|
7
|
+
* @param config - Legacy parameter (ignored, kept for backward compatibility)
|
|
8
|
+
* @returns A new ImageAnalysisService instance
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const service = createImageAnalysisService();
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function createImageAnalysisService(config?: any): ImageAnalysisService;
|
|
16
|
+
/**
|
|
17
|
+
* Default singleton instance of the ImageAnalysisService
|
|
18
|
+
*
|
|
19
|
+
* This instance uses the default configuration or environment variables.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { imageAnalysisService } from 'src/services/image-analysis';
|
|
24
|
+
*
|
|
25
|
+
* const result = await imageAnalysisService.analyzeImage({
|
|
26
|
+
* imagePath: '/path/to/image.jpg',
|
|
27
|
+
* prompt: 'Describe this image',
|
|
28
|
+
* maxTokens: 4000,
|
|
29
|
+
* temperature: 0.7
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare const imageAnalysisService: ImageAnalysisService;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ImageAnalysisParams, ImageAnalysisResult } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Service for analyzing images using the unified OpenAI service
|
|
4
|
+
*/
|
|
5
|
+
export declare class ImageAnalysisService {
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new instance of the ImageAnalysisService
|
|
8
|
+
*/
|
|
9
|
+
constructor();
|
|
10
|
+
/**
|
|
11
|
+
* Analyzes an image using the moonshot-vision model
|
|
12
|
+
*
|
|
13
|
+
* @param params - Parameters for the image analysis
|
|
14
|
+
* @param params.imagePath - Absolute path to the local image file
|
|
15
|
+
* @param params.prompt - The prompt describing what to analyze in the image
|
|
16
|
+
* @param params.maxTokens - Maximum tokens to generate (default: 4000)
|
|
17
|
+
* @param params.temperature - Temperature for generation (default: 0.7)
|
|
18
|
+
* @param params.systemPrompt - Optional system prompt to set behavior
|
|
19
|
+
* @returns Analysis result with content, usage statistics, and metadata
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const result = await imageAnalysisService.analyzeImage({
|
|
24
|
+
* imagePath: '/path/to/image.jpg',
|
|
25
|
+
* prompt: 'Describe this image in detail',
|
|
26
|
+
* maxTokens: 4000,
|
|
27
|
+
* temperature: 0.7
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* console.log(result.content);
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @throws {ImageAnalysisError} If the image cannot be analyzed
|
|
34
|
+
*/
|
|
35
|
+
analyzeImage(params: ImageAnalysisParams): Promise<ImageAnalysisResult>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility class for encoding images to base64
|
|
3
|
+
*/
|
|
4
|
+
export declare class ImageEncoder {
|
|
5
|
+
/**
|
|
6
|
+
* Encodes an image file to base64 with data URI scheme
|
|
7
|
+
*
|
|
8
|
+
* @param imagePath - Absolute path to the image file
|
|
9
|
+
* @returns Base64 encoded image with data URI scheme
|
|
10
|
+
* @throws ImageAnalysisError if the file cannot be encoded
|
|
11
|
+
*/
|
|
12
|
+
static encodeImageToBase64(imagePath: string): Promise<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Streams a file to base64 string for memory efficiency
|
|
15
|
+
*
|
|
16
|
+
* @param filePath - Path to the file
|
|
17
|
+
* @returns Base64 encoded string
|
|
18
|
+
*/
|
|
19
|
+
private static streamToBase64;
|
|
20
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ImageFileInfo } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Utility class for validating image files
|
|
4
|
+
*/
|
|
5
|
+
export declare class ImageValidator {
|
|
6
|
+
static readonly SUPPORTED_FORMATS: string[];
|
|
7
|
+
static readonly MAX_FILE_SIZE: number;
|
|
8
|
+
/**
|
|
9
|
+
* Validates an image file
|
|
10
|
+
*
|
|
11
|
+
* @param imagePath - Absolute path to the image file
|
|
12
|
+
* @returns Information about the image file
|
|
13
|
+
* @throws ImageAnalysisError if the file is invalid
|
|
14
|
+
*/
|
|
15
|
+
static validateImage(imagePath: string): Promise<ImageFileInfo>;
|
|
16
|
+
/**
|
|
17
|
+
* Checks if the image format is supported
|
|
18
|
+
*
|
|
19
|
+
* @param format - Image format (extension)
|
|
20
|
+
* @returns True if the format is supported
|
|
21
|
+
*/
|
|
22
|
+
static isFormatSupported(format: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Gets the MIME type for an image format
|
|
25
|
+
*
|
|
26
|
+
* @param format - Image format (extension)
|
|
27
|
+
* @returns MIME type string
|
|
28
|
+
*/
|
|
29
|
+
static getMimeType(format: string): string;
|
|
30
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ImageAnalysisService } from "./image-analysis";
|
|
2
|
+
import { ImageValidator } from "./image-validator";
|
|
3
|
+
import { ImageEncoder } from "./image-encoder";
|
|
4
|
+
import { ImageAnalysisParams, ImageAnalysisResult, ImageFileInfo, ErrorCodes, ImageAnalysisError } from "./types";
|
|
5
|
+
import { createImageAnalysisService, imageAnalysisService } from "./factory";
|
|
6
|
+
/**
|
|
7
|
+
* @module ImageAnalysis
|
|
8
|
+
*
|
|
9
|
+
* A service for analyzing images using the Moonshot Vision API.
|
|
10
|
+
* This service allows you to analyze local images with custom prompts
|
|
11
|
+
* using the moonshot-vision model.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { imageAnalysisService } from 'src/services/image-analysis';
|
|
16
|
+
*
|
|
17
|
+
* const result = await imageAnalysisService.analyzeImage({
|
|
18
|
+
* imagePath: '/path/to/image.jpg',
|
|
19
|
+
* prompt: 'Describe this image',
|
|
20
|
+
* maxTokens: 4000,
|
|
21
|
+
* temperature: 0.7
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* console.log(result.content);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export { ImageAnalysisService, ImageValidator, ImageEncoder, createImageAnalysisService, imageAnalysisService, };
|
|
28
|
+
export { analyzeImageTool, imageAnalysisTools } from "./tools";
|
|
29
|
+
export type { ImageAnalysisParams, ImageAnalysisResult, ImageFileInfo, ErrorCodes, ImageAnalysisError, };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Tool for analyzing images using the moonshot-vision model
|
|
4
|
+
*/
|
|
5
|
+
export declare const analyzeImageTool: {
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
parameters: z.ZodObject<{
|
|
9
|
+
imagePath: z.ZodString;
|
|
10
|
+
prompt: z.ZodString;
|
|
11
|
+
maxTokens: z.ZodOptional<z.ZodNumber>;
|
|
12
|
+
temperature: z.ZodOptional<z.ZodNumber>;
|
|
13
|
+
systemPrompt: z.ZodOptional<z.ZodString>;
|
|
14
|
+
}, "strip", z.ZodTypeAny, {
|
|
15
|
+
prompt: string;
|
|
16
|
+
imagePath: string;
|
|
17
|
+
temperature?: number | undefined;
|
|
18
|
+
maxTokens?: number | undefined;
|
|
19
|
+
systemPrompt?: string | undefined;
|
|
20
|
+
}, {
|
|
21
|
+
prompt: string;
|
|
22
|
+
imagePath: string;
|
|
23
|
+
temperature?: number | undefined;
|
|
24
|
+
maxTokens?: number | undefined;
|
|
25
|
+
systemPrompt?: string | undefined;
|
|
26
|
+
}>;
|
|
27
|
+
execute: (args: any) => Promise<string>;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Export all image analysis tools
|
|
31
|
+
*/
|
|
32
|
+
export declare const imageAnalysisTools: {
|
|
33
|
+
name: string;
|
|
34
|
+
description: string;
|
|
35
|
+
parameters: z.ZodObject<{
|
|
36
|
+
imagePath: z.ZodString;
|
|
37
|
+
prompt: z.ZodString;
|
|
38
|
+
maxTokens: z.ZodOptional<z.ZodNumber>;
|
|
39
|
+
temperature: z.ZodOptional<z.ZodNumber>;
|
|
40
|
+
systemPrompt: z.ZodOptional<z.ZodString>;
|
|
41
|
+
}, "strip", z.ZodTypeAny, {
|
|
42
|
+
prompt: string;
|
|
43
|
+
imagePath: string;
|
|
44
|
+
temperature?: number | undefined;
|
|
45
|
+
maxTokens?: number | undefined;
|
|
46
|
+
systemPrompt?: string | undefined;
|
|
47
|
+
}, {
|
|
48
|
+
prompt: string;
|
|
49
|
+
imagePath: string;
|
|
50
|
+
temperature?: number | undefined;
|
|
51
|
+
maxTokens?: number | undefined;
|
|
52
|
+
systemPrompt?: string | undefined;
|
|
53
|
+
}>;
|
|
54
|
+
execute: (args: any) => Promise<string>;
|
|
55
|
+
}[];
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Parameters for image analysis requests
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* const params: ImageAnalysisParams = {
|
|
8
|
+
* imagePath: '/path/to/image.jpg',
|
|
9
|
+
* prompt: 'Describe this image in detail',
|
|
10
|
+
* maxTokens: 2000,
|
|
11
|
+
* temperature: 0.5,
|
|
12
|
+
* systemPrompt: 'You are a helpful assistant'
|
|
13
|
+
* };
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare const ImageAnalysisParams: z.ZodObject<{
|
|
17
|
+
imagePath: z.ZodEffects<z.ZodString, string, string>;
|
|
18
|
+
prompt: z.ZodString;
|
|
19
|
+
maxTokens: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
20
|
+
temperature: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
21
|
+
systemPrompt: z.ZodOptional<z.ZodString>;
|
|
22
|
+
}, "strip", z.ZodTypeAny, {
|
|
23
|
+
prompt: string;
|
|
24
|
+
temperature: number;
|
|
25
|
+
imagePath: string;
|
|
26
|
+
maxTokens: number;
|
|
27
|
+
systemPrompt?: string | undefined;
|
|
28
|
+
}, {
|
|
29
|
+
prompt: string;
|
|
30
|
+
imagePath: string;
|
|
31
|
+
temperature?: number | undefined;
|
|
32
|
+
maxTokens?: number | undefined;
|
|
33
|
+
systemPrompt?: string | undefined;
|
|
34
|
+
}>;
|
|
35
|
+
export type ImageAnalysisParams = z.infer<typeof ImageAnalysisParams>;
|
|
36
|
+
/**
|
|
37
|
+
* Result of image analysis
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const result: ImageAnalysisResult = {
|
|
42
|
+
* content: 'This is an image of a cat sitting on a windowsill...',
|
|
43
|
+
* usage: {
|
|
44
|
+
* promptTokens: 100,
|
|
45
|
+
* completionTokens: 50,
|
|
46
|
+
* totalTokens: 150
|
|
47
|
+
* },
|
|
48
|
+
* metadata: {
|
|
49
|
+
* imagePath: '/path/to/image.jpg',
|
|
50
|
+
* imageSize: 1024000,
|
|
51
|
+
* imageFormat: 'jpg',
|
|
52
|
+
* processingTime: 1500
|
|
53
|
+
* }
|
|
54
|
+
* };
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export interface ImageAnalysisResult {
|
|
58
|
+
content: string;
|
|
59
|
+
usage?: {
|
|
60
|
+
promptTokens: number;
|
|
61
|
+
completionTokens: number;
|
|
62
|
+
totalTokens: number;
|
|
63
|
+
};
|
|
64
|
+
metadata: {
|
|
65
|
+
imagePath: string;
|
|
66
|
+
imageSize: number;
|
|
67
|
+
imageFormat: string;
|
|
68
|
+
processingTime: number;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Information about an image file
|
|
73
|
+
*/
|
|
74
|
+
export interface ImageFileInfo {
|
|
75
|
+
exists: boolean;
|
|
76
|
+
size: number;
|
|
77
|
+
format: string;
|
|
78
|
+
isSupported: boolean;
|
|
79
|
+
mimeType: string;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Vision API request structure
|
|
83
|
+
* Note: The model is hardcoded to 'moonshot-v1-8k-vision-preview' and cannot be configured.
|
|
84
|
+
*/
|
|
85
|
+
export interface VisionRequest {
|
|
86
|
+
model: string;
|
|
87
|
+
messages: Array<{
|
|
88
|
+
role: 'user' | 'system';
|
|
89
|
+
content: Array<{
|
|
90
|
+
type: 'text' | 'image_url';
|
|
91
|
+
text?: string;
|
|
92
|
+
image_url?: {
|
|
93
|
+
url: string;
|
|
94
|
+
};
|
|
95
|
+
}>;
|
|
96
|
+
}>;
|
|
97
|
+
max_tokens?: number;
|
|
98
|
+
temperature?: number;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Vision API response structure
|
|
102
|
+
*/
|
|
103
|
+
export interface VisionResponse {
|
|
104
|
+
choices: Array<{
|
|
105
|
+
message: {
|
|
106
|
+
content: string;
|
|
107
|
+
role: string;
|
|
108
|
+
};
|
|
109
|
+
finish_reason: string;
|
|
110
|
+
}>;
|
|
111
|
+
usage: {
|
|
112
|
+
prompt_tokens: number;
|
|
113
|
+
completion_tokens: number;
|
|
114
|
+
total_tokens: number;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Error codes for image analysis
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* try {
|
|
123
|
+
* await imageAnalysisService.analyzeImage(params);
|
|
124
|
+
* } catch (error) {
|
|
125
|
+
* if (error instanceof ImageAnalysisError) {
|
|
126
|
+
* switch (error.code) {
|
|
127
|
+
* case ErrorCodes.FILE_NOT_FOUND:
|
|
128
|
+
* console.error('Image file not found');
|
|
129
|
+
* break;
|
|
130
|
+
* case ErrorCodes.API_ERROR:
|
|
131
|
+
* console.error('API error:', error.message);
|
|
132
|
+
* break;
|
|
133
|
+
* // Handle other error codes
|
|
134
|
+
* }
|
|
135
|
+
* }
|
|
136
|
+
* }
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export declare enum ErrorCodes {
|
|
140
|
+
FILE_NOT_FOUND = "FILE_NOT_FOUND",
|
|
141
|
+
UNSUPPORTED_FORMAT = "UNSUPPORTED_FORMAT",
|
|
142
|
+
FILE_TOO_LARGE = "FILE_TOO_LARGE",
|
|
143
|
+
PERMISSION_DENIED = "PERMISSION_DENIED",
|
|
144
|
+
API_ERROR = "API_ERROR",
|
|
145
|
+
VALIDATION_ERROR = "VALIDATION_ERROR"
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Custom error class for image analysis errors
|
|
149
|
+
*/
|
|
150
|
+
export declare class ImageAnalysisError extends Error {
|
|
151
|
+
code: ErrorCodes;
|
|
152
|
+
details?: any | undefined;
|
|
153
|
+
constructor(message: string, code: ErrorCodes, details?: any | undefined);
|
|
154
|
+
}
|
|
@@ -18,12 +18,42 @@ export declare const OpenAIParams: z.ZodObject<{
|
|
|
18
18
|
temperature?: number | undefined;
|
|
19
19
|
system_prompt?: string | undefined;
|
|
20
20
|
}>;
|
|
21
|
+
export declare const VisionParams: z.ZodObject<{
|
|
22
|
+
prompt: z.ZodString;
|
|
23
|
+
image_base64: z.ZodString;
|
|
24
|
+
model: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
25
|
+
max_tokens: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
26
|
+
temperature: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
27
|
+
system_prompt: z.ZodOptional<z.ZodString>;
|
|
28
|
+
}, "strip", z.ZodTypeAny, {
|
|
29
|
+
prompt: string;
|
|
30
|
+
model: string;
|
|
31
|
+
max_tokens: number;
|
|
32
|
+
temperature: number;
|
|
33
|
+
image_base64: string;
|
|
34
|
+
system_prompt?: string | undefined;
|
|
35
|
+
}, {
|
|
36
|
+
prompt: string;
|
|
37
|
+
image_base64: string;
|
|
38
|
+
model?: string | undefined;
|
|
39
|
+
max_tokens?: number | undefined;
|
|
40
|
+
temperature?: number | undefined;
|
|
41
|
+
system_prompt?: string | undefined;
|
|
42
|
+
}>;
|
|
21
43
|
export type OpenAIParams = z.infer<typeof OpenAIParams>;
|
|
44
|
+
export type VisionParams = z.infer<typeof VisionParams>;
|
|
22
45
|
export declare class OpenAIService {
|
|
23
46
|
private apiKey;
|
|
24
47
|
private baseUrl;
|
|
25
48
|
constructor(apiKey?: string, baseUrl?: string);
|
|
26
49
|
generateText(params: OpenAIParams): Promise<string>;
|
|
27
50
|
generateStream(params: OpenAIParams): Promise<AsyncIterable<string>>;
|
|
51
|
+
/**
|
|
52
|
+
* Analyze an image using vision capabilities
|
|
53
|
+
*
|
|
54
|
+
* @param params - Vision analysis parameters
|
|
55
|
+
* @returns Analysis result content
|
|
56
|
+
*/
|
|
57
|
+
analyzeImage(params: VisionParams): Promise<string>;
|
|
28
58
|
}
|
|
29
59
|
export declare const openAIService: OpenAIService;
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "intention-coding",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "软件工程化的需求分析,功能设计,代码编写,测试运行和发布部署",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
|
-
"import": "./dist/index.js"
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"require": "./dist/index.cjs"
|
|
10
11
|
}
|
|
11
12
|
},
|
|
12
13
|
"bin": "./dist/index.js",
|
|
13
|
-
"main": "./dist/index.
|
|
14
|
+
"main": "./dist/index.cjs",
|
|
14
15
|
"module": "./dist/index.js",
|
|
15
16
|
"types": "./dist/index.d.ts",
|
|
16
17
|
"files": [
|
|
@@ -25,10 +26,11 @@
|
|
|
25
26
|
"prepublish": "npm run build"
|
|
26
27
|
},
|
|
27
28
|
"engines": {
|
|
28
|
-
"node": ">=20.
|
|
29
|
+
"node": ">=16.20.2"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@rslib/core": "^0.10.0",
|
|
33
|
+
"@types/pdf-parse": "^1.1.5",
|
|
32
34
|
"@types/better-sqlite3": "^7.6.13",
|
|
33
35
|
"@types/node": "^18.0.0",
|
|
34
36
|
"@types/uuid": "^10.0.0",
|
|
@@ -39,10 +41,9 @@
|
|
|
39
41
|
"zod": "3.25.64"
|
|
40
42
|
},
|
|
41
43
|
"dependencies": {
|
|
42
|
-
"@types/pdf-parse": "^1.1.5",
|
|
43
44
|
"aico-pack": "2.1.0",
|
|
44
45
|
"axios": "^1.10.0",
|
|
45
|
-
"fastmcp": "^3.
|
|
46
|
+
"fastmcp": "^3.9.0",
|
|
46
47
|
"html-to-md": "^0.8.8",
|
|
47
48
|
"lru-cache": "^11.1.0",
|
|
48
49
|
"mammoth": "^1.9.1",
|