@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,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ENRIVISION MCP SERVER
|
|
3
|
+
*
|
|
4
|
+
* Implements a minimal MCP server (stdio transport) exposing a single tool:
|
|
5
|
+
* `analyze_media`.
|
|
6
|
+
*
|
|
7
|
+
* @module server/EnriVisionServer
|
|
8
|
+
*/
|
|
9
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
10
|
+
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
11
|
+
/**
|
|
12
|
+
* MCP server exposing EnriVision tools.
|
|
13
|
+
*/
|
|
14
|
+
export class EnriVisionServer {
|
|
15
|
+
/**
|
|
16
|
+
* Underlying MCP server implementation.
|
|
17
|
+
*/
|
|
18
|
+
server;
|
|
19
|
+
/**
|
|
20
|
+
* Analyze media tool implementation.
|
|
21
|
+
*/
|
|
22
|
+
analyzeMediaTool;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new {@link EnriVisionServer}.
|
|
25
|
+
*
|
|
26
|
+
* @param config - Server configuration
|
|
27
|
+
*/
|
|
28
|
+
constructor(config) {
|
|
29
|
+
this.analyzeMediaTool = config.analyzeMediaTool;
|
|
30
|
+
this.server = new Server({ name: config.name, version: config.version }, {
|
|
31
|
+
capabilities: {
|
|
32
|
+
tools: {
|
|
33
|
+
listChanged: false
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
this.registerToolHandlers();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Connects the server to a transport and starts listening.
|
|
41
|
+
*
|
|
42
|
+
* @param transport - MCP transport (stdio)
|
|
43
|
+
*/
|
|
44
|
+
async connect(transport) {
|
|
45
|
+
await this.server.connect(transport);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Registers tool list and tool call handlers.
|
|
49
|
+
*/
|
|
50
|
+
registerToolHandlers() {
|
|
51
|
+
const analyzeMediaDefinition = this.getAnalyzeMediaToolDefinition();
|
|
52
|
+
this.server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
53
|
+
return { tools: [analyzeMediaDefinition] };
|
|
54
|
+
});
|
|
55
|
+
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
56
|
+
if (request.params.name !== "analyze_media") {
|
|
57
|
+
return {
|
|
58
|
+
isError: true,
|
|
59
|
+
content: [{ type: "text", text: `Unknown tool: ${request.params.name}` }]
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
const args = request.params.arguments ?? {};
|
|
64
|
+
const params = this.analyzeMediaTool.parseParams(args);
|
|
65
|
+
const result = await this.analyzeMediaTool.execute(params);
|
|
66
|
+
return {
|
|
67
|
+
isError: false,
|
|
68
|
+
content: [
|
|
69
|
+
{
|
|
70
|
+
type: "text",
|
|
71
|
+
text: `ANALYSIS (${result.media_type}):\n${result.analysis}`
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
structuredContent: result
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
79
|
+
return {
|
|
80
|
+
isError: true,
|
|
81
|
+
content: [{ type: "text", text: message }]
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Returns the JSON schema tool definition for `analyze_media`.
|
|
88
|
+
*
|
|
89
|
+
* @returns Tool definition
|
|
90
|
+
*/
|
|
91
|
+
getAnalyzeMediaToolDefinition() {
|
|
92
|
+
return {
|
|
93
|
+
name: "analyze_media",
|
|
94
|
+
description: "Upload and analyze a local file via EnriProxy (server-side extraction + model analysis).\n" +
|
|
95
|
+
"\n" +
|
|
96
|
+
"When to use:\n" +
|
|
97
|
+
"- Large PDFs (many pages) or scanned PDFs where client-side Read may truncate or miss content.\n" +
|
|
98
|
+
"- Video/audio or other binary media your client cannot Read.\n" +
|
|
99
|
+
"- Audio files in common formats (mp3, wav, flac, m4a, aac, ogg/oga, opus, wma, weba, mka, aiff/aif/aifc, caf, m4b/m4r, mp1/mp2/mpa/mpga).\n" +
|
|
100
|
+
"- HEIC/AVIF/TIFF/APNG/SVG/Office docs when your client Read is unreliable.\n" +
|
|
101
|
+
"- Very large files where resumable uploads are required (up to 4GB).\n" +
|
|
102
|
+
"- Large PDFs/videos: set `analysis_mode` to 'multipass' for better coverage (auto prefers multipass for PDFs > 20 pages).\n" +
|
|
103
|
+
"- For time-specific video questions (e.g., \"what happens at 12:34?\"), set `video.clip_start_seconds` and `video.clip_duration_seconds`.\n" +
|
|
104
|
+
"\n" +
|
|
105
|
+
"Rules:\n" +
|
|
106
|
+
"- Use `path` for one file, or `paths` for multiple images (UI screenshots/photo sets).\n" +
|
|
107
|
+
"- `path`/`paths` are absolute paths on the machine running this MCP server (the client).\n" +
|
|
108
|
+
"- Requires a valid EnriProxy API key (env `ENRIPROXY_API_KEY`, sent as Authorization: Bearer ...).\n" +
|
|
109
|
+
"- Prefer the client's native Read tool only for small/simple text/PDF/common images when it works; prefer this tool for large PDFs.\n" +
|
|
110
|
+
"- Answer strictly from the tool output; if frames/transcript are missing, say so.\n" +
|
|
111
|
+
"- Video: frames + transcript belong to the SAME video timeline (not unrelated images).\n" +
|
|
112
|
+
"- Animated GIF/WebP/APNG/SVG inputs are converted into representative key frames.\n" +
|
|
113
|
+
"- Set `language` (e.g., 'es') to match the user request and avoid language drift.",
|
|
114
|
+
inputSchema: {
|
|
115
|
+
type: "object",
|
|
116
|
+
properties: {
|
|
117
|
+
path: {
|
|
118
|
+
type: "string",
|
|
119
|
+
description: "Absolute path to a local file on the machine running the MCP server (e.g., C:\\\\Users\\\\User\\\\Downloads\\\\video.mp4)."
|
|
120
|
+
},
|
|
121
|
+
paths: {
|
|
122
|
+
type: "array",
|
|
123
|
+
description: "Absolute paths to multiple local image files (UI screenshots/photo sets). When provided, EnriVision uploads a single media-set archive for server-side batching + reduce.",
|
|
124
|
+
items: {
|
|
125
|
+
type: "string"
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
context: {
|
|
129
|
+
type: "string",
|
|
130
|
+
description: "Optional analysis hint: ui, diagram, chart, error, code, meeting, tutorial, photo. Leave empty for auto-detection."
|
|
131
|
+
},
|
|
132
|
+
question: {
|
|
133
|
+
type: "string",
|
|
134
|
+
description: "Optional explicit question to answer about the file."
|
|
135
|
+
},
|
|
136
|
+
language: {
|
|
137
|
+
type: "string",
|
|
138
|
+
description: "Preferred response language code (ISO 639-1), e.g. 'es', 'en'."
|
|
139
|
+
},
|
|
140
|
+
max_frames: {
|
|
141
|
+
type: "integer",
|
|
142
|
+
description: "Optional max frames for videos (1-20) in single-pass mode. For targeted timestamps, prefer video.clip_start_seconds + video.clip_duration_seconds. For multipass, use video.max_frames_per_segment."
|
|
143
|
+
},
|
|
144
|
+
transcribe: {
|
|
145
|
+
type: "boolean",
|
|
146
|
+
description: "Optional override to enable/disable audio transcription for videos."
|
|
147
|
+
},
|
|
148
|
+
transcription_language: {
|
|
149
|
+
type: "string",
|
|
150
|
+
description: "Optional Whisper language hint for audio/video transcription (e.g., 'auto', 'es', 'en')."
|
|
151
|
+
},
|
|
152
|
+
analysis_mode: {
|
|
153
|
+
type: "string",
|
|
154
|
+
description: "Optional analysis mode selector: auto, single, or multipass."
|
|
155
|
+
},
|
|
156
|
+
video: {
|
|
157
|
+
type: "object",
|
|
158
|
+
description: "Optional video multipass tuning. Used only when analyzing videos.",
|
|
159
|
+
properties: {
|
|
160
|
+
clip_start_seconds: {
|
|
161
|
+
type: "number",
|
|
162
|
+
description: "Optional clip start offset in seconds for time-targeted video analysis."
|
|
163
|
+
},
|
|
164
|
+
clip_duration_seconds: {
|
|
165
|
+
type: "number",
|
|
166
|
+
description: "Optional clip duration in seconds for time-targeted video analysis."
|
|
167
|
+
},
|
|
168
|
+
segment_seconds: {
|
|
169
|
+
type: "number",
|
|
170
|
+
description: "Segment duration in seconds."
|
|
171
|
+
},
|
|
172
|
+
max_segments: {
|
|
173
|
+
type: "integer",
|
|
174
|
+
description: "Maximum number of segments to analyze."
|
|
175
|
+
},
|
|
176
|
+
max_frames_per_segment: {
|
|
177
|
+
type: "integer",
|
|
178
|
+
description: "Maximum frames to extract per segment."
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
document: {
|
|
183
|
+
type: "object",
|
|
184
|
+
description: "Optional document multipass tuning (PDF).",
|
|
185
|
+
properties: {
|
|
186
|
+
max_pages_total: {
|
|
187
|
+
type: "integer",
|
|
188
|
+
description: "Maximum number of pages to analyze in total."
|
|
189
|
+
},
|
|
190
|
+
pages_per_batch: {
|
|
191
|
+
type: "integer",
|
|
192
|
+
description: "Pages per batch for multipass map calls."
|
|
193
|
+
},
|
|
194
|
+
max_images_per_batch: {
|
|
195
|
+
type: "integer",
|
|
196
|
+
description: "Maximum rendered pages (images) per batch."
|
|
197
|
+
},
|
|
198
|
+
scanned_text_threshold_chars: {
|
|
199
|
+
type: "integer",
|
|
200
|
+
description: "Minimum extracted text length to treat a page as textual."
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
audio: {
|
|
205
|
+
type: "object",
|
|
206
|
+
description: "Optional audio multipass tuning (used only when analyzing audio files).",
|
|
207
|
+
properties: {
|
|
208
|
+
timestamps: {
|
|
209
|
+
type: "boolean",
|
|
210
|
+
description: "Whether to include timestamped segments in audio extraction."
|
|
211
|
+
},
|
|
212
|
+
segment_seconds: {
|
|
213
|
+
type: "number",
|
|
214
|
+
description: "Segment duration in seconds for audio multipass."
|
|
215
|
+
},
|
|
216
|
+
max_segments: {
|
|
217
|
+
type: "integer",
|
|
218
|
+
description: "Maximum number of audio segments to analyze."
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
images: {
|
|
223
|
+
type: "object",
|
|
224
|
+
description: "Optional image-set multipass tuning (used only with `paths`).",
|
|
225
|
+
properties: {
|
|
226
|
+
max_images_total: {
|
|
227
|
+
type: "integer",
|
|
228
|
+
description: "Maximum number of images to analyze in total."
|
|
229
|
+
},
|
|
230
|
+
images_per_batch: {
|
|
231
|
+
type: "integer",
|
|
232
|
+
description: "Images per batch for multipass map calls."
|
|
233
|
+
},
|
|
234
|
+
max_dimension: {
|
|
235
|
+
type: "integer",
|
|
236
|
+
description: "Maximum dimension for images (width/height)."
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
anyOf: [{ required: ["path"] }, { required: ["paths"] }]
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
//# sourceMappingURL=EnriVisionServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnriVisionServer.js","sourceRoot":"","sources":["../../src/server/EnriVisionServer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAEnE,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EAGvB,MAAM,oCAAoC,CAAC;AAwB5C;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAC3B;;OAEG;IACc,MAAM,CAAS;IAEhC;;OAEG;IACc,gBAAgB,CAAmB;IAEpD;;;;OAIG;IACH,YAAmB,MAA8B;QAC/C,IAAI,CAAC,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAC;QAEhD,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CACtB,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,EAC9C;YACE,YAAY,EAAE;gBACZ,KAAK,EAAE;oBACL,WAAW,EAAE,KAAK;iBACnB;aACF;SACF,CACF,CAAC;QAEF,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAC9B,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,OAAO,CAAC,SAAoB;QACvC,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACvC,CAAC;IAED;;OAEG;IACK,oBAAoB;QAC1B,MAAM,sBAAsB,GAAG,IAAI,CAAC,6BAA6B,EAAE,CAAC;QAEpE,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,sBAAsB,EAAE,KAAK,IAAI,EAAE;YAC/D,OAAO,EAAE,KAAK,EAAE,CAAC,sBAAsB,CAAC,EAA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,EAAE,+DAA+D;wBAC5E,UAAU,EAAE;4BACV,gBAAgB,EAAE;gCAChB,IAAI,EAAE,SAAS;gCACf,WAAW,EAAE,+CAA+C;6BAC7D;4BACD,gBAAgB,EAAE;gCAChB,IAAI,EAAE,SAAS;gCACf,WAAW,EAAE,2CAA2C;6BACzD;4BACD,aAAa,EAAE;gCACb,IAAI,EAAE,SAAS;gCACf,WAAW,EAAE,8CAA8C;6BAC5D;yBACF;qBACF;iBACF;gBACD,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;aACzD;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TAR UTILITIES
|
|
3
|
+
*
|
|
4
|
+
* Small, dependency-free tar (ustar) helpers used to package multiple local
|
|
5
|
+
* files into a single resumable upload stream.
|
|
6
|
+
*
|
|
7
|
+
* @module shared/tar
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Source for a tar entry.
|
|
11
|
+
*/
|
|
12
|
+
export type TarEntrySource = {
|
|
13
|
+
/**
|
|
14
|
+
* Inline buffer payload.
|
|
15
|
+
*/
|
|
16
|
+
readonly type: "buffer";
|
|
17
|
+
/**
|
|
18
|
+
* Buffer content.
|
|
19
|
+
*/
|
|
20
|
+
readonly buffer: Buffer;
|
|
21
|
+
} | {
|
|
22
|
+
/**
|
|
23
|
+
* File-backed payload.
|
|
24
|
+
*/
|
|
25
|
+
readonly type: "file";
|
|
26
|
+
/**
|
|
27
|
+
* Absolute file path.
|
|
28
|
+
*/
|
|
29
|
+
readonly path: string;
|
|
30
|
+
/**
|
|
31
|
+
* File size in bytes.
|
|
32
|
+
*/
|
|
33
|
+
readonly sizeBytes: number;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Tar entry description.
|
|
37
|
+
*/
|
|
38
|
+
export interface TarEntry {
|
|
39
|
+
/**
|
|
40
|
+
* Tar entry name (ustar limit: 100 bytes for the simple header form).
|
|
41
|
+
*/
|
|
42
|
+
readonly name: string;
|
|
43
|
+
/**
|
|
44
|
+
* Entry payload source.
|
|
45
|
+
*/
|
|
46
|
+
readonly source: TarEntrySource;
|
|
47
|
+
/**
|
|
48
|
+
* Unix mtime seconds used in the header.
|
|
49
|
+
*/
|
|
50
|
+
readonly mtimeSeconds: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Computes the total tar size in bytes, including the 1024-byte end marker.
|
|
54
|
+
*
|
|
55
|
+
* @param entries - Tar entries
|
|
56
|
+
* @returns Total tar size in bytes
|
|
57
|
+
*/
|
|
58
|
+
export declare function computeTarSizeBytes(entries: ReadonlyArray<TarEntry>): number;
|
|
59
|
+
/**
|
|
60
|
+
* Streaming tar generator that can start from an arbitrary byte offset.
|
|
61
|
+
*/
|
|
62
|
+
export declare class TarStream {
|
|
63
|
+
/**
|
|
64
|
+
* Precomputed tar layout.
|
|
65
|
+
*/
|
|
66
|
+
private readonly layout;
|
|
67
|
+
/**
|
|
68
|
+
* Total tar size.
|
|
69
|
+
*/
|
|
70
|
+
private readonly totalSizeBytes;
|
|
71
|
+
/**
|
|
72
|
+
* Creates a new {@link TarStream}.
|
|
73
|
+
*
|
|
74
|
+
* @param entries - Tar entries in order
|
|
75
|
+
*/
|
|
76
|
+
constructor(entries: ReadonlyArray<TarEntry>);
|
|
77
|
+
/**
|
|
78
|
+
* Returns the total tar size in bytes.
|
|
79
|
+
*
|
|
80
|
+
* @returns Total size
|
|
81
|
+
*/
|
|
82
|
+
getSizeBytes(): number;
|
|
83
|
+
/**
|
|
84
|
+
* Iterates tar bytes as chunks, starting from a given offset.
|
|
85
|
+
*
|
|
86
|
+
* @param startOffset - Starting byte offset (for resumable uploads)
|
|
87
|
+
* @param chunkSize - Maximum bytes per yielded chunk
|
|
88
|
+
* @returns Async iterator of buffers
|
|
89
|
+
*/
|
|
90
|
+
iterateChunks(startOffset: number, chunkSize: number): AsyncGenerator<Buffer, void, void>;
|
|
91
|
+
/**
|
|
92
|
+
* Internal seek state for reading.
|
|
93
|
+
*/
|
|
94
|
+
private seek;
|
|
95
|
+
/**
|
|
96
|
+
* Reads up to maxBytes from the current state and advances the state.
|
|
97
|
+
*/
|
|
98
|
+
private readNext;
|
|
99
|
+
/**
|
|
100
|
+
* Ensures a file handle is open for the current file-backed entry.
|
|
101
|
+
*/
|
|
102
|
+
private ensureFileHandle;
|
|
103
|
+
/**
|
|
104
|
+
* Closes any open file handle for the current state.
|
|
105
|
+
*/
|
|
106
|
+
private closeFileHandle;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=tar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tar.d.ts","sourceRoot":"","sources":["../../src/shared/tar.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB;IACE;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAExB;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,GACD;IACE;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEN;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAEhC;;OAEG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AA+CD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,GAAG,M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