intention-coding 0.2.4 → 0.3.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.
- package/dist/cli/analyze-image.d.ts +2 -0
- package/dist/config.d.ts +9 -0
- package/dist/index.js +6385 -4774
- package/dist/services/api-test/add-tasks-to-plan.d.ts +8 -8
- package/dist/services/api-test/api-test.d.ts +4 -4
- package/dist/services/api-test/index.d.ts +14 -14
- package/dist/services/api-test/test-plan.d.ts +10 -10
- package/dist/services/api-test/update-task.d.ts +8 -8
- package/dist/services/change-summarizer/prompt/change-analysis.d.ts +1 -0
- package/dist/services/claude-code/index.d.ts +12 -12
- package/dist/services/code-generator/database-manager.d.ts +4 -4
- package/dist/services/code-generator/enhanced-tools.d.ts +12 -12
- 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/image-converter/converter.d.ts +84 -0
- package/dist/services/image-converter/index.d.ts +132 -0
- package/dist/services/index.d.ts +0 -0
- package/dist/services/project-template/index.d.ts +7 -7
- package/dist/services/project-template/prompt/project-rules.d.ts +1 -0
- package/dist/services/requirement-analyzer/chunk-reader.d.ts +37 -0
- package/dist/services/requirement-analyzer/index.d.ts +30 -90
- package/dist/services/requirement-analyzer/prompt/api-template.d.ts +1 -0
- package/dist/services/requirement-analyzer/prompt/app-template.d.ts +1 -0
- package/dist/services/requirement-analyzer/prompt/enhanced-feature-extraction.d.ts +1 -0
- package/dist/services/requirement-analyzer/prompt/fallback-document.d.ts +1 -0
- package/dist/services/requirement-analyzer/prompt/feature-dependency-analysis.d.ts +1 -0
- package/dist/services/requirement-analyzer/prompt/feature-extraction.d.ts +2 -0
- package/dist/services/requirement-analyzer/prompt/pc-page-template.d.ts +1 -0
- package/dist/services/requirement-analyzer/prompt/requirement-analysis.d.ts +2 -0
- package/dist/services/requirement-analyzer/prompt/sdk-template.d.ts +1 -0
- package/dist/utils/openai.d.ts +31 -0
- package/dist/utils/pack.d.ts +1 -1
- package/package.json +4 -2
- package/dist/prompt/change-analysis.md +0 -53
- package/dist/prompt/initialize-project-standard.xml +0 -66
- package/dist/prompt/instructions.md +0 -235
- package/dist/prompt/velocity-template-generation.xml +0 -112
- package/dist/services/openai-service.d.ts +0 -29
- package/dist/services/requirement-analyzer/auto-trigger.d.ts +0 -1
- package/dist/services/velocity-template/index.d.ts +0 -334
|
@@ -82,7 +82,7 @@ export declare const UpdateTaskParams: z.ZodObject<{
|
|
|
82
82
|
test_requirements: z.ZodOptional<z.ZodString>;
|
|
83
83
|
custom_context: z.ZodOptional<z.ZodString>;
|
|
84
84
|
}, "strip", z.ZodTypeAny, {
|
|
85
|
-
status?: "pending" | "completed" | "
|
|
85
|
+
status?: "pending" | "completed" | "in_progress" | "failed" | "cancelled" | undefined;
|
|
86
86
|
description?: string | undefined;
|
|
87
87
|
priority?: "medium" | "low" | "high" | "critical" | undefined;
|
|
88
88
|
title?: string | undefined;
|
|
@@ -94,7 +94,7 @@ export declare const UpdateTaskParams: z.ZodObject<{
|
|
|
94
94
|
estimated_hours?: number | undefined;
|
|
95
95
|
actual_hours?: number | undefined;
|
|
96
96
|
}, {
|
|
97
|
-
status?: "pending" | "completed" | "
|
|
97
|
+
status?: "pending" | "completed" | "in_progress" | "failed" | "cancelled" | undefined;
|
|
98
98
|
description?: string | undefined;
|
|
99
99
|
priority?: "medium" | "low" | "high" | "critical" | undefined;
|
|
100
100
|
title?: string | undefined;
|
|
@@ -109,7 +109,7 @@ export declare const UpdateTaskParams: z.ZodObject<{
|
|
|
109
109
|
}, "strip", z.ZodTypeAny, {
|
|
110
110
|
task_id: string;
|
|
111
111
|
updates: {
|
|
112
|
-
status?: "pending" | "completed" | "
|
|
112
|
+
status?: "pending" | "completed" | "in_progress" | "failed" | "cancelled" | undefined;
|
|
113
113
|
description?: string | undefined;
|
|
114
114
|
priority?: "medium" | "low" | "high" | "critical" | undefined;
|
|
115
115
|
title?: string | undefined;
|
|
@@ -124,7 +124,7 @@ export declare const UpdateTaskParams: z.ZodObject<{
|
|
|
124
124
|
}, {
|
|
125
125
|
task_id: string;
|
|
126
126
|
updates: {
|
|
127
|
-
status?: "pending" | "completed" | "
|
|
127
|
+
status?: "pending" | "completed" | "in_progress" | "failed" | "cancelled" | undefined;
|
|
128
128
|
description?: string | undefined;
|
|
129
129
|
priority?: "medium" | "low" | "high" | "critical" | undefined;
|
|
130
130
|
title?: string | undefined;
|
|
@@ -147,12 +147,12 @@ export declare const QueueQueryParams: z.ZodObject<{
|
|
|
147
147
|
}, "strip", z.ZodTypeAny, {
|
|
148
148
|
limit: number;
|
|
149
149
|
offset: number;
|
|
150
|
-
status?: "pending" | "completed" | "
|
|
150
|
+
status?: "pending" | "completed" | "in_progress" | "failed" | "cancelled" | undefined;
|
|
151
151
|
project_name?: string | undefined;
|
|
152
152
|
priority?: "medium" | "low" | "high" | "critical" | undefined;
|
|
153
153
|
assignee?: string | undefined;
|
|
154
154
|
}, {
|
|
155
|
-
status?: "pending" | "completed" | "
|
|
155
|
+
status?: "pending" | "completed" | "in_progress" | "failed" | "cancelled" | undefined;
|
|
156
156
|
project_name?: string | undefined;
|
|
157
157
|
priority?: "medium" | "low" | "high" | "critical" | undefined;
|
|
158
158
|
assignee?: string | undefined;
|
|
@@ -268,7 +268,7 @@ export declare const updateTaskTool: {
|
|
|
268
268
|
test_requirements: z.ZodOptional<z.ZodString>;
|
|
269
269
|
custom_context: z.ZodOptional<z.ZodString>;
|
|
270
270
|
}, "strip", z.ZodTypeAny, {
|
|
271
|
-
status?: "pending" | "completed" | "
|
|
271
|
+
status?: "pending" | "completed" | "in_progress" | "failed" | "cancelled" | undefined;
|
|
272
272
|
description?: string | undefined;
|
|
273
273
|
priority?: "medium" | "low" | "high" | "critical" | undefined;
|
|
274
274
|
title?: string | undefined;
|
|
@@ -280,7 +280,7 @@ export declare const updateTaskTool: {
|
|
|
280
280
|
estimated_hours?: number | undefined;
|
|
281
281
|
actual_hours?: number | undefined;
|
|
282
282
|
}, {
|
|
283
|
-
status?: "pending" | "completed" | "
|
|
283
|
+
status?: "pending" | "completed" | "in_progress" | "failed" | "cancelled" | undefined;
|
|
284
284
|
description?: string | undefined;
|
|
285
285
|
priority?: "medium" | "low" | "high" | "critical" | undefined;
|
|
286
286
|
title?: string | undefined;
|
|
@@ -295,7 +295,7 @@ export declare const updateTaskTool: {
|
|
|
295
295
|
}, "strip", z.ZodTypeAny, {
|
|
296
296
|
task_id: string;
|
|
297
297
|
updates: {
|
|
298
|
-
status?: "pending" | "completed" | "
|
|
298
|
+
status?: "pending" | "completed" | "in_progress" | "failed" | "cancelled" | undefined;
|
|
299
299
|
description?: string | undefined;
|
|
300
300
|
priority?: "medium" | "low" | "high" | "critical" | undefined;
|
|
301
301
|
title?: string | undefined;
|
|
@@ -310,7 +310,7 @@ export declare const updateTaskTool: {
|
|
|
310
310
|
}, {
|
|
311
311
|
task_id: string;
|
|
312
312
|
updates: {
|
|
313
|
-
status?: "pending" | "completed" | "
|
|
313
|
+
status?: "pending" | "completed" | "in_progress" | "failed" | "cancelled" | undefined;
|
|
314
314
|
description?: string | undefined;
|
|
315
315
|
priority?: "medium" | "low" | "high" | "critical" | undefined;
|
|
316
316
|
title?: string | undefined;
|
|
@@ -344,12 +344,12 @@ export declare const queryTasksTool: {
|
|
|
344
344
|
}, "strip", z.ZodTypeAny, {
|
|
345
345
|
limit: number;
|
|
346
346
|
offset: number;
|
|
347
|
-
status?: "pending" | "completed" | "
|
|
347
|
+
status?: "pending" | "completed" | "in_progress" | "failed" | "cancelled" | undefined;
|
|
348
348
|
project_name?: string | undefined;
|
|
349
349
|
priority?: "medium" | "low" | "high" | "critical" | undefined;
|
|
350
350
|
assignee?: string | undefined;
|
|
351
351
|
}, {
|
|
352
|
-
status?: "pending" | "completed" | "
|
|
352
|
+
status?: "pending" | "completed" | "in_progress" | "failed" | "cancelled" | undefined;
|
|
353
353
|
project_name?: string | undefined;
|
|
354
354
|
priority?: "medium" | "low" | "high" | "critical" | undefined;
|
|
355
355
|
assignee?: string | 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
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export interface ConvertImageOptions {
|
|
2
|
+
input_path: string;
|
|
3
|
+
output_format: string;
|
|
4
|
+
quality?: number;
|
|
5
|
+
width?: number;
|
|
6
|
+
height?: number;
|
|
7
|
+
maintain_aspect_ratio?: boolean;
|
|
8
|
+
output_path?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface BatchConvertOptions {
|
|
11
|
+
input_paths: string[];
|
|
12
|
+
output_format: string;
|
|
13
|
+
quality?: number;
|
|
14
|
+
width?: number;
|
|
15
|
+
height?: number;
|
|
16
|
+
maintain_aspect_ratio?: boolean;
|
|
17
|
+
output_directory?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ConvertResult {
|
|
20
|
+
output_path: string;
|
|
21
|
+
file_size: number;
|
|
22
|
+
dimensions: {
|
|
23
|
+
width: number;
|
|
24
|
+
height: number;
|
|
25
|
+
};
|
|
26
|
+
format: string;
|
|
27
|
+
}
|
|
28
|
+
export interface BatchConvertResult {
|
|
29
|
+
success: boolean;
|
|
30
|
+
output_path?: string;
|
|
31
|
+
error?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface ImageInfo {
|
|
34
|
+
format: string;
|
|
35
|
+
width: number;
|
|
36
|
+
height: number;
|
|
37
|
+
channels: number;
|
|
38
|
+
size: number;
|
|
39
|
+
space?: string;
|
|
40
|
+
}
|
|
41
|
+
export declare class ImageConverter {
|
|
42
|
+
private supportedInputFormats;
|
|
43
|
+
private supportedOutputFormats;
|
|
44
|
+
constructor();
|
|
45
|
+
/**
|
|
46
|
+
* 转换单个图片
|
|
47
|
+
*/
|
|
48
|
+
convertImage(options: ConvertImageOptions): Promise<ConvertResult>;
|
|
49
|
+
/**
|
|
50
|
+
* 批量转换图片
|
|
51
|
+
*/
|
|
52
|
+
batchConvertImages(options: BatchConvertOptions): Promise<BatchConvertResult[]>;
|
|
53
|
+
/**
|
|
54
|
+
* 获取图片信息
|
|
55
|
+
*/
|
|
56
|
+
getImageInfo(imagePath: string): Promise<ImageInfo>;
|
|
57
|
+
/**
|
|
58
|
+
* 获取支持的格式列表
|
|
59
|
+
*/
|
|
60
|
+
getSupportedFormats(): {
|
|
61
|
+
input: string[];
|
|
62
|
+
output: string[];
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* 转换为SVG格式
|
|
66
|
+
*/
|
|
67
|
+
private convertToSvg;
|
|
68
|
+
/**
|
|
69
|
+
* 转换为ICO格式(简化版本)
|
|
70
|
+
*/
|
|
71
|
+
private convertToIco;
|
|
72
|
+
/**
|
|
73
|
+
* 获取文件格式
|
|
74
|
+
*/
|
|
75
|
+
private getFileFormat;
|
|
76
|
+
/**
|
|
77
|
+
* 生成输出文件路径
|
|
78
|
+
*/
|
|
79
|
+
private generateOutputPath;
|
|
80
|
+
/**
|
|
81
|
+
* 生成输出文件名
|
|
82
|
+
*/
|
|
83
|
+
private generateOutputFilename;
|
|
84
|
+
}
|