@bedolla/enrivision 0.1.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/LICENSE +619 -0
- package/README.md +214 -0
- package/dist/client/EnriProxyClient.d.ts +323 -0
- package/dist/client/EnriProxyClient.d.ts.map +1 -0
- package/dist/client/EnriProxyClient.js +348 -0
- package/dist/client/EnriProxyClient.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +90 -0
- package/dist/index.js.map +1 -0
- package/dist/package-info.d.ts +8 -0
- package/dist/package-info.d.ts.map +1 -0
- package/dist/package-info.js +28 -0
- package/dist/package-info.js.map +1 -0
- package/dist/server/EnriVisionServer.d.ts +63 -0
- package/dist/server/EnriVisionServer.d.ts.map +1 -0
- package/dist/server/EnriVisionServer.js +246 -0
- package/dist/server/EnriVisionServer.js.map +1 -0
- package/dist/shared/tar.d.ts +108 -0
- package/dist/shared/tar.d.ts.map +1 -0
- package/dist/shared/tar.js +346 -0
- package/dist/shared/tar.js.map +1 -0
- package/dist/shared/validation.d.ts +61 -0
- package/dist/shared/validation.d.ts.map +1 -0
- package/dist/shared/validation.js +107 -0
- package/dist/shared/validation.js.map +1 -0
- package/dist/tools/AnalyzeMediaTool.d.ts +302 -0
- package/dist/tools/AnalyzeMediaTool.d.ts.map +1 -0
- package/dist/tools/AnalyzeMediaTool.js +509 -0
- package/dist/tools/AnalyzeMediaTool.js.map +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ANALYZE MEDIA TOOL
|
|
3
|
+
*
|
|
4
|
+
* Implements the `analyze_media` MCP tool:
|
|
5
|
+
* - Validates local file path
|
|
6
|
+
* - Streams the file to EnriProxy via resumable uploads
|
|
7
|
+
* - Triggers server-side analysis and returns text-only results
|
|
8
|
+
*
|
|
9
|
+
* @module tools/AnalyzeMediaTool
|
|
10
|
+
*/
|
|
11
|
+
import { type EnriProxyClient } from "../client/EnriProxyClient.js";
|
|
12
|
+
/**
|
|
13
|
+
* Tool parameters for `analyze_media`.
|
|
14
|
+
*/
|
|
15
|
+
export interface AnalyzeMediaToolParams {
|
|
16
|
+
/**
|
|
17
|
+
* Absolute local filesystem path on the MCP host.
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* Use `paths` to analyze multiple images in a single call.
|
|
21
|
+
*/
|
|
22
|
+
readonly path?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Absolute local filesystem paths on the MCP host.
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* When provided, EnriVision uploads the files as a single media-set archive
|
|
28
|
+
* (resumable, up to 4GB) and triggers server-side batching + reduce.
|
|
29
|
+
*
|
|
30
|
+
* This is intended for many UI screenshots / photo sets.
|
|
31
|
+
*/
|
|
32
|
+
readonly paths?: ReadonlyArray<string>;
|
|
33
|
+
/**
|
|
34
|
+
* Optional analysis hint (ui, diagram, chart, error, code, meeting, tutorial, photo).
|
|
35
|
+
*/
|
|
36
|
+
readonly context?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Optional explicit user question.
|
|
39
|
+
*/
|
|
40
|
+
readonly question?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Preferred response language code (e.g., "es", "en").
|
|
43
|
+
*/
|
|
44
|
+
readonly language?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Optional max frames override for videos (1-20).
|
|
47
|
+
*/
|
|
48
|
+
readonly maxFrames?: number;
|
|
49
|
+
/**
|
|
50
|
+
* Optional override for transcription on videos.
|
|
51
|
+
*/
|
|
52
|
+
readonly transcribe?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Optional transcription language hint for Whisper.
|
|
55
|
+
*/
|
|
56
|
+
readonly transcriptionLanguage?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Optional analysis mode selector (auto|single|multipass).
|
|
59
|
+
*/
|
|
60
|
+
readonly analysisMode?: "auto" | "single" | "multipass";
|
|
61
|
+
/**
|
|
62
|
+
* Optional video multipass tuning.
|
|
63
|
+
*/
|
|
64
|
+
readonly video?: {
|
|
65
|
+
/**
|
|
66
|
+
* Optional clip start offset in seconds for targeted video analysis.
|
|
67
|
+
*
|
|
68
|
+
* @remarks
|
|
69
|
+
* Use this when the question references a specific timestamp to avoid
|
|
70
|
+
* scanning the full timeline.
|
|
71
|
+
*/
|
|
72
|
+
readonly clipStartSeconds?: number;
|
|
73
|
+
/**
|
|
74
|
+
* Optional clip duration in seconds for targeted video analysis.
|
|
75
|
+
*
|
|
76
|
+
* @remarks
|
|
77
|
+
* Use together with {@link clipStartSeconds} to analyze only a time window.
|
|
78
|
+
*/
|
|
79
|
+
readonly clipDurationSeconds?: number;
|
|
80
|
+
/**
|
|
81
|
+
* Segment duration in seconds.
|
|
82
|
+
*/
|
|
83
|
+
readonly segmentSeconds?: number;
|
|
84
|
+
/**
|
|
85
|
+
* Maximum number of segments to analyze.
|
|
86
|
+
*/
|
|
87
|
+
readonly maxSegments?: number;
|
|
88
|
+
/**
|
|
89
|
+
* Maximum frames per segment.
|
|
90
|
+
*/
|
|
91
|
+
readonly maxFramesPerSegment?: number;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Optional document multipass tuning (PDF).
|
|
95
|
+
*/
|
|
96
|
+
readonly document?: {
|
|
97
|
+
/**
|
|
98
|
+
* Maximum pages to analyze in total.
|
|
99
|
+
*/
|
|
100
|
+
readonly maxPagesTotal?: number;
|
|
101
|
+
/**
|
|
102
|
+
* Pages per batch.
|
|
103
|
+
*/
|
|
104
|
+
readonly pagesPerBatch?: number;
|
|
105
|
+
/**
|
|
106
|
+
* Maximum rendered pages per batch.
|
|
107
|
+
*/
|
|
108
|
+
readonly maxImagesPerBatch?: number;
|
|
109
|
+
/**
|
|
110
|
+
* Minimum extracted text length to treat a page as textual.
|
|
111
|
+
*/
|
|
112
|
+
readonly scannedTextThresholdChars?: number;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Optional audio multipass tuning.
|
|
116
|
+
*/
|
|
117
|
+
readonly audio?: {
|
|
118
|
+
/**
|
|
119
|
+
* Whether to include timestamped segments in audio extraction.
|
|
120
|
+
*/
|
|
121
|
+
readonly timestamps?: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Segment duration in seconds for audio multipass.
|
|
124
|
+
*/
|
|
125
|
+
readonly segmentSeconds?: number;
|
|
126
|
+
/**
|
|
127
|
+
* Maximum number of audio segments to analyze.
|
|
128
|
+
*/
|
|
129
|
+
readonly maxSegments?: number;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Optional image-set multipass tuning.
|
|
133
|
+
*
|
|
134
|
+
* @remarks
|
|
135
|
+
* Used only when analyzing multiple images via `paths`.
|
|
136
|
+
*/
|
|
137
|
+
readonly images?: {
|
|
138
|
+
/**
|
|
139
|
+
* Maximum number of images to analyze in total.
|
|
140
|
+
*/
|
|
141
|
+
readonly maxImagesTotal?: number;
|
|
142
|
+
/**
|
|
143
|
+
* Images per batch for multipass map calls.
|
|
144
|
+
*/
|
|
145
|
+
readonly imagesPerBatch?: number;
|
|
146
|
+
/**
|
|
147
|
+
* Maximum dimension for images (width/height).
|
|
148
|
+
*/
|
|
149
|
+
readonly maxDimension?: number;
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Structured result for `analyze_media`.
|
|
154
|
+
*/
|
|
155
|
+
export interface AnalyzeMediaToolResult extends Record<string, unknown> {
|
|
156
|
+
/**
|
|
157
|
+
* Text analysis produced by EnriProxy.
|
|
158
|
+
*/
|
|
159
|
+
readonly analysis: string;
|
|
160
|
+
/**
|
|
161
|
+
* Detected media type.
|
|
162
|
+
*/
|
|
163
|
+
readonly media_type: string;
|
|
164
|
+
/**
|
|
165
|
+
* Extraction metadata returned by the server.
|
|
166
|
+
*
|
|
167
|
+
* @remarks
|
|
168
|
+
* This metadata is intended for debugging and transparency (e.g., duration,
|
|
169
|
+
* selected frames, warnings). Internal identifiers like upload ids are
|
|
170
|
+
* stripped to avoid leaking implementation details into the model context.
|
|
171
|
+
*/
|
|
172
|
+
readonly extraction: Record<string, unknown>;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Dependencies for {@link AnalyzeMediaTool}.
|
|
176
|
+
*/
|
|
177
|
+
export interface AnalyzeMediaToolDeps {
|
|
178
|
+
/**
|
|
179
|
+
* Creates an EnriProxy client with a base URL, API key, and timeout.
|
|
180
|
+
*
|
|
181
|
+
* @param serverUrl - EnriProxy URL
|
|
182
|
+
* @param apiKey - EnriProxy API key
|
|
183
|
+
* @param timeoutMs - Timeout in ms
|
|
184
|
+
* @returns Client instance
|
|
185
|
+
*/
|
|
186
|
+
readonly createClient: (serverUrl: string, apiKey: string, timeoutMs: number) => EnriProxyClient;
|
|
187
|
+
/**
|
|
188
|
+
* Default EnriProxy server URL.
|
|
189
|
+
*/
|
|
190
|
+
readonly defaultServerUrl: string;
|
|
191
|
+
/**
|
|
192
|
+
* Default EnriProxy API key.
|
|
193
|
+
*/
|
|
194
|
+
readonly defaultApiKey: string;
|
|
195
|
+
/**
|
|
196
|
+
* Default timeout in milliseconds.
|
|
197
|
+
*/
|
|
198
|
+
readonly defaultTimeoutMs: number;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* MCP tool that uploads and analyzes local media.
|
|
202
|
+
*/
|
|
203
|
+
export declare class AnalyzeMediaTool {
|
|
204
|
+
/**
|
|
205
|
+
* Tool dependencies.
|
|
206
|
+
*/
|
|
207
|
+
private readonly deps;
|
|
208
|
+
/**
|
|
209
|
+
* Creates a new {@link AnalyzeMediaTool}.
|
|
210
|
+
*
|
|
211
|
+
* @param deps - Tool dependencies
|
|
212
|
+
*/
|
|
213
|
+
constructor(deps: AnalyzeMediaToolDeps);
|
|
214
|
+
/**
|
|
215
|
+
* Validates raw MCP tool arguments.
|
|
216
|
+
*
|
|
217
|
+
* @param raw - Raw tool arguments
|
|
218
|
+
* @returns Validated parameters
|
|
219
|
+
*/
|
|
220
|
+
parseParams(raw: unknown): AnalyzeMediaToolParams;
|
|
221
|
+
/**
|
|
222
|
+
* Executes the tool.
|
|
223
|
+
*
|
|
224
|
+
* @param params - Validated parameters
|
|
225
|
+
* @returns Tool result
|
|
226
|
+
*/
|
|
227
|
+
execute(params: AnalyzeMediaToolParams): Promise<AnalyzeMediaToolResult>;
|
|
228
|
+
/**
|
|
229
|
+
* Removes internal identifiers (upload ids, routing-only values, etc.) from the
|
|
230
|
+
* extraction payload before returning it to the model.
|
|
231
|
+
*
|
|
232
|
+
* @param extraction - Raw extraction object returned by EnriProxy
|
|
233
|
+
* @returns Sanitized extraction object
|
|
234
|
+
*/
|
|
235
|
+
private stripInternalExtractionFields;
|
|
236
|
+
/**
|
|
237
|
+
* Recursively strips internal fields from an unknown value.
|
|
238
|
+
*
|
|
239
|
+
* @param value - Unknown value to sanitize
|
|
240
|
+
* @returns Sanitized value
|
|
241
|
+
*/
|
|
242
|
+
private stripInternalFields;
|
|
243
|
+
/**
|
|
244
|
+
* Ensures the sanitized extraction value is a plain JSON object.
|
|
245
|
+
*
|
|
246
|
+
* @param value - Sanitized value
|
|
247
|
+
* @returns Plain object
|
|
248
|
+
*/
|
|
249
|
+
private asPlainObject;
|
|
250
|
+
/**
|
|
251
|
+
* Validates that a path exists and is a readable file.
|
|
252
|
+
*
|
|
253
|
+
* @param filePath - Local filesystem path
|
|
254
|
+
* @returns File size in bytes
|
|
255
|
+
*/
|
|
256
|
+
private assertReadableFile;
|
|
257
|
+
/**
|
|
258
|
+
* Detects MIME type using file extension.
|
|
259
|
+
*
|
|
260
|
+
* @param filePath - File path
|
|
261
|
+
* @returns MIME type string
|
|
262
|
+
*/
|
|
263
|
+
private detectMimeType;
|
|
264
|
+
/**
|
|
265
|
+
* Uploads multiple local images as a single EnriVision media-set tar archive.
|
|
266
|
+
*
|
|
267
|
+
* @remarks
|
|
268
|
+
* This avoids creating many concurrent resumable upload sessions (which are
|
|
269
|
+
* capped per API key) and enables server-side batching + reduce for large
|
|
270
|
+
* screenshot sets.
|
|
271
|
+
*
|
|
272
|
+
* @param client - EnriProxy client
|
|
273
|
+
* @param filePaths - Absolute image file paths
|
|
274
|
+
* @param timeoutMs - Request timeout per HTTP request
|
|
275
|
+
* @param clientTraceId - Client trace id for correlation
|
|
276
|
+
* @returns Upload id for the created tar session
|
|
277
|
+
*/
|
|
278
|
+
private uploadImageSetAsMediaSetTar;
|
|
279
|
+
/**
|
|
280
|
+
* Uploads a file to EnriProxy in resumable chunks.
|
|
281
|
+
*
|
|
282
|
+
* @param client - EnriProxy client
|
|
283
|
+
* @param filePath - Local file path
|
|
284
|
+
* @param fileSize - Total file size in bytes
|
|
285
|
+
* @param session - Server-created session
|
|
286
|
+
* @param timeoutMs - Request timeout in milliseconds
|
|
287
|
+
* @returns Final offset
|
|
288
|
+
*/
|
|
289
|
+
private uploadFileResumable;
|
|
290
|
+
/**
|
|
291
|
+
* Uploads a single chunk with retry and offset resync.
|
|
292
|
+
*
|
|
293
|
+
* @param client - EnriProxy client
|
|
294
|
+
* @param uploadId - Upload id
|
|
295
|
+
* @param offset - Expected offset
|
|
296
|
+
* @param chunk - Chunk bytes
|
|
297
|
+
* @param timeoutMs - Timeout in ms
|
|
298
|
+
* @returns New offset
|
|
299
|
+
*/
|
|
300
|
+
private uploadChunkWithRetry;
|
|
301
|
+
}
|
|
302
|
+
//# sourceMappingURL=AnalyzeMediaTool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnalyzeMediaTool.d.ts","sourceRoot":"","sources":["../../src/tools/AnalyzeMediaTool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AASH,OAAO,EAAwD,KAAK,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAc1H;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEvB;;;;;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