@etm-professional-control/winccoa-mcp-server 1.4.0 → 1.5.1
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/.env.example +6 -2
- package/LEGAL_INFO.md +47 -0
- package/LICENSE.md +21 -0
- package/OSS.md +178 -0
- package/README.md +57 -6
- package/build/config/demo-project-instructions.md +28 -0
- package/build/config/server.config.d.ts +16 -1
- package/build/config/server.config.d.ts.map +1 -1
- package/build/config/server.config.js +60 -10
- package/build/config/server.config.js.map +1 -1
- package/build/fields/default.md +50 -0
- package/build/fields/oil.md +46 -0
- package/build/fields/transport.md +70 -0
- package/build/helpers/icons/IX_ICONS_LIST.txt +1407 -0
- package/build/helpers/icons/IconGenerator.d.ts +54 -3
- package/build/helpers/icons/IconGenerator.d.ts.map +1 -1
- package/build/helpers/icons/IconGenerator.js +104 -22
- package/build/helpers/icons/IconGenerator.js.map +1 -1
- package/build/helpers/icons/IconList.d.ts +17 -2
- package/build/helpers/icons/IconList.d.ts.map +1 -1
- package/build/helpers/icons/IconList.js +41 -19
- package/build/helpers/icons/IconList.js.map +1 -1
- package/build/helpers/pmon/PmonClient.d.ts.map +1 -1
- package/build/helpers/pmon/PmonClient.js +53 -27
- package/build/helpers/pmon/PmonClient.js.map +1 -1
- package/build/index_http.d.ts +14 -1
- package/build/index_http.d.ts.map +1 -1
- package/build/index_http.js +122 -45
- package/build/index_http.js.map +1 -1
- package/build/server.d.ts +37 -3
- package/build/server.d.ts.map +1 -1
- package/build/server.js +173 -122
- package/build/server.js.map +1 -1
- package/build/systemprompt.md +50 -0
- package/build/tool_loader.d.ts +21 -1
- package/build/tool_loader.d.ts.map +1 -1
- package/build/tool_loader.js +65 -10
- package/build/tool_loader.js.map +1 -1
- package/build/tools/archive/archive_query.d.ts.map +1 -1
- package/build/tools/archive/archive_query.js +2 -5
- package/build/tools/archive/archive_query.js.map +1 -1
- package/build/tools/common/common_query.d.ts.map +1 -1
- package/build/tools/common/common_query.js +51 -37
- package/build/tools/common/common_query.js.map +1 -1
- package/build/tools/dashboards/widget.d.ts.map +1 -1
- package/build/tools/dashboards/widget.js +12 -2
- package/build/tools/dashboards/widget.js.map +1 -1
- package/build/tools/datapoints/dp_basic.d.ts.map +1 -1
- package/build/tools/datapoints/dp_basic.js +106 -34
- package/build/tools/datapoints/dp_basic.js.map +1 -1
- package/build/tools/datapoints/dp_types.d.ts.map +1 -1
- package/build/tools/datapoints/dp_types.js +31 -10
- package/build/tools/datapoints/dp_types.js.map +1 -1
- package/build/tools/icons/icon.d.ts.map +1 -1
- package/build/tools/icons/icon.js +52 -7
- package/build/tools/icons/icon.js.map +1 -1
- package/build/tools/pv_range/pv_range_query.d.ts +12 -0
- package/build/tools/pv_range/pv_range_query.d.ts.map +1 -1
- package/build/tools/pv_range/pv_range_query.js +63 -31
- package/build/tools/pv_range/pv_range_query.js.map +1 -1
- package/build/utils/helpers.d.ts +56 -4
- package/build/utils/helpers.d.ts.map +1 -1
- package/build/utils/helpers.js +144 -14
- package/build/utils/helpers.js.map +1 -1
- package/build/utils/logger.d.ts +29 -0
- package/build/utils/logger.d.ts.map +1 -0
- package/build/utils/logger.js +56 -0
- package/build/utils/logger.js.map +1 -0
- package/build/utils/projectPath.d.ts +52 -0
- package/build/utils/projectPath.d.ts.map +1 -0
- package/build/utils/projectPath.js +102 -0
- package/build/utils/projectPath.js.map +1 -0
- package/manifest.cjs +50 -0
- package/package.json +84 -71
- package/postinstall.cjs +10 -4
- package/sbom.json +5500 -0
|
@@ -5,8 +5,33 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { z } from 'zod';
|
|
7
7
|
import { createSuccessResponse, createErrorResponse } from '../../utils/helpers.js';
|
|
8
|
-
import { IconGenerator } from '../../helpers/icons/IconGenerator.js';
|
|
8
|
+
import { IconGenerator, IconStorageError, InvalidIconNameError, ICON_NAME_PATTERN, ICON_NAME_WITH_SVG_PATTERN } from '../../helpers/icons/IconGenerator.js';
|
|
9
9
|
import { IconList } from '../../helpers/icons/IconList.js';
|
|
10
|
+
import { resolveProjectPathWithSource } from '../../utils/projectPath.js';
|
|
11
|
+
import * as log from '../../utils/logger.js';
|
|
12
|
+
/**
|
|
13
|
+
* The HTTP transport registers tools on every request, so log the resolved
|
|
14
|
+
* icons directory once per process, not once per request.
|
|
15
|
+
*/
|
|
16
|
+
let projectPathLogged = false;
|
|
17
|
+
/**
|
|
18
|
+
* Turn an icon storage problem into a clean tool error instead of a stack trace.
|
|
19
|
+
* @returns An error response, or undefined if the error is something else
|
|
20
|
+
*/
|
|
21
|
+
function storageErrorResponse(error) {
|
|
22
|
+
if (error instanceof IconStorageError) {
|
|
23
|
+
log.warn(error.message);
|
|
24
|
+
return createErrorResponse(error.message, {
|
|
25
|
+
errorType: 'ICON_STORAGE_UNAVAILABLE',
|
|
26
|
+
...(error.iconsPath ? { iconsPath: error.iconsPath } : {})
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (error instanceof InvalidIconNameError) {
|
|
30
|
+
return createErrorResponse(error.message, { errorType: 'INVALID_ICON_NAME' });
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
const ICON_NAME_MESSAGE = 'Invalid icon name: use 1-64 letters, digits, "_" or "-", starting with a letter or digit';
|
|
10
35
|
/**
|
|
11
36
|
* Register icon tools with the MCP server
|
|
12
37
|
* @param server - MCP server instance
|
|
@@ -14,12 +39,23 @@ import { IconList } from '../../helpers/icons/IconList.js';
|
|
|
14
39
|
* @returns Number of tools registered
|
|
15
40
|
*/
|
|
16
41
|
export function registerTools(server, context) {
|
|
17
|
-
const
|
|
42
|
+
const { path: projectPath, source } = resolveProjectPathWithSource(context?.winccoa);
|
|
43
|
+
const iconGenerator = new IconGenerator(projectPath);
|
|
18
44
|
const iconList = new IconList();
|
|
45
|
+
if (!projectPathLogged) {
|
|
46
|
+
projectPathLogged = true;
|
|
47
|
+
if (projectPath) {
|
|
48
|
+
log.info(`Icon tools: project path ${projectPath} (from ${source}), icons in ${iconGenerator.getIconsPath()}`);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
log.warn('Icon tools: WinCC OA project path unknown - custom icons cannot be created or listed. ' +
|
|
52
|
+
'Set WINCCOA_PROJ_PATH or run inside the WinCC OA JavaScript manager.');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
19
55
|
// ==================== CREATE CUSTOM ICON ====================
|
|
20
56
|
server.tool('create-custom-icon', `Create a custom SVG icon for dashboard widgets.
|
|
21
57
|
|
|
22
|
-
Icons are saved to
|
|
58
|
+
Icons are saved to <project>/data/WebUI/icons/ (URL /data/WebUI/icons/<name>.svg) and can be referenced in widget headers/footers.
|
|
23
59
|
After creating an icon, use its path in the titleIcon or subtitleIcon parameter when editing widgets.
|
|
24
60
|
|
|
25
61
|
IMPORTANT: Icons must be small (24x24 pixels by default) to match Siemens IX icon library.
|
|
@@ -69,7 +105,7 @@ When creating custom SVG icons, follow Siemens Industrial Experience standards t
|
|
|
69
105
|
---
|
|
70
106
|
|
|
71
107
|
Parameters:
|
|
72
|
-
- name: Icon filename (without .svg extension) (required)
|
|
108
|
+
- name: Icon filename (without .svg extension) (required). Only letters, digits, "_" and "-" (1-64 characters, must start with a letter or digit); anything else is rejected.
|
|
73
109
|
- type: Icon type - "simple", "trend", "gauge", "alert", or "custom" (required)
|
|
74
110
|
- color: SVG color (optional, default: "currentColor" for theme support)
|
|
75
111
|
- size: Viewbox size in pixels (optional, default: 24, supported: 16, 24, 32)
|
|
@@ -155,7 +191,7 @@ After creating the icon, use it in a widget header or footer:
|
|
|
155
191
|
"titleIcon": "/data/WebUI/icons/production-trend.svg",
|
|
156
192
|
"headerTitle": "Production Line 1"
|
|
157
193
|
}`, {
|
|
158
|
-
name: z.string().
|
|
194
|
+
name: z.string().regex(ICON_NAME_PATTERN, ICON_NAME_MESSAGE),
|
|
159
195
|
type: z.enum(['simple', 'trend', 'gauge', 'alert', 'custom']),
|
|
160
196
|
color: z.string().optional(),
|
|
161
197
|
size: z.number().int().min(16).max(32).optional(),
|
|
@@ -183,6 +219,9 @@ After creating the icon, use it in a widget header or footer:
|
|
|
183
219
|
});
|
|
184
220
|
}
|
|
185
221
|
catch (error) {
|
|
222
|
+
const storageError = storageErrorResponse(error);
|
|
223
|
+
if (storageError)
|
|
224
|
+
return storageError;
|
|
186
225
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
187
226
|
console.error('Error creating icon:', error);
|
|
188
227
|
return createErrorResponse(`Failed to create icon: ${errorMessage}`);
|
|
@@ -213,6 +252,9 @@ Call this tool to see all available custom icons, then use the path in edit-widg
|
|
|
213
252
|
});
|
|
214
253
|
}
|
|
215
254
|
catch (error) {
|
|
255
|
+
const storageError = storageErrorResponse(error);
|
|
256
|
+
if (storageError)
|
|
257
|
+
return storageError;
|
|
216
258
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
217
259
|
console.error('Error listing icons:', error);
|
|
218
260
|
return createErrorResponse(`Failed to list icons: ${errorMessage}`);
|
|
@@ -222,13 +264,13 @@ Call this tool to see all available custom icons, then use the path in edit-widg
|
|
|
222
264
|
server.tool('delete-custom-icon', `Delete a custom icon from /data/WebUI/icons/.
|
|
223
265
|
|
|
224
266
|
Parameters:
|
|
225
|
-
- name: Icon filename (with or without .svg extension) (required)
|
|
267
|
+
- name: Icon filename (with or without .svg extension) (required). Same rules as create-custom-icon: letters, digits, "_", "-" only.
|
|
226
268
|
|
|
227
269
|
Example:
|
|
228
270
|
{
|
|
229
271
|
"name": "my-icon.svg"
|
|
230
272
|
}`, {
|
|
231
|
-
name: z.string().
|
|
273
|
+
name: z.string().regex(ICON_NAME_WITH_SVG_PATTERN, ICON_NAME_MESSAGE)
|
|
232
274
|
}, async (params) => {
|
|
233
275
|
try {
|
|
234
276
|
const { name } = params;
|
|
@@ -245,6 +287,9 @@ Example:
|
|
|
245
287
|
}
|
|
246
288
|
}
|
|
247
289
|
catch (error) {
|
|
290
|
+
const storageError = storageErrorResponse(error);
|
|
291
|
+
if (storageError)
|
|
292
|
+
return storageError;
|
|
248
293
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
249
294
|
console.error('Error deleting icon:', error);
|
|
250
295
|
return createErrorResponse(`Failed to delete icon: ${errorMessage}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icon.js","sourceRoot":"","sources":["../../../src/tools/icons/icon.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAEpF,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"icon.js","sourceRoot":"","sources":["../../../src/tools/icons/icon.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAEpF,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAC5J,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,KAAK,GAAG,MAAM,uBAAuB,CAAC;AAE7C;;;GAGG;AACH,IAAI,iBAAiB,GAAG,KAAK,CAAC;AAE9B;;;GAGG;AACH,SAAS,oBAAoB,CAAC,KAAc;IAC1C,IAAI,KAAK,YAAY,gBAAgB,EAAE,CAAC;QACtC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACxB,OAAO,mBAAmB,CAAC,KAAK,CAAC,OAAO,EAAE;YACxC,SAAS,EAAE,0BAA0B;YACrC,GAAG,CAAC,KAAK,CAAC,S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,CAAC,MAAM;gBACnB,cAAc,EAAE,UAAU;gBAC1B,KAAK;gBACL,UAAU,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;oBACpC,IAAI,EAAE,GAAG,CAAC,IAAI;oBACd,WAAW,EAAE,GAAG,CAAC,WAAW;oBAC5B,SAAS,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM;iBAC5B,CAAC,CAAC;gBACH,OAAO,EAAE,QAAQ;oBACf,CAAC,CAAC,SAAS,KAAK,CAAC,MAAM,yBAAyB,QAAQ,GAAG;oBAC3D,CAAC,CAAC,MAAM;wBACN,CAAC,CAAC,SAAS,KAAK,CAAC,MAAM,sBAAsB,MAAM,GAAG;wBACtD,CAAC,CAAC,WAAW,KAAK,CAAC,MAAM,OAAO,UAAU,kBAAkB;gBAChE,KAAK,EAAE,iEAAiE;aACzE,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC5E,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;YAChD,OAAO,mBAAmB,CAAC,4BAA4B,YAAY,EAAE,CAAC,CAAC;QACzE,CAAC;IACH,CAAC,CACF,CAAC;IAEF,OAAO,CAAC,CAAC,CAAC,6BAA6B;AACzC,CAAC"}
|
|
@@ -4,6 +4,18 @@
|
|
|
4
4
|
* MCP tool for querying existing pv_range configurations from datapoint elements.
|
|
5
5
|
*/
|
|
6
6
|
import type { ServerContext } from '../../types/index.js';
|
|
7
|
+
/**
|
|
8
|
+
* True if the error only says the attribute does not exist in the config
|
|
9
|
+
* (code 19, directly or in every nested detail). That is the normal answer
|
|
10
|
+
* for a datapoint element without a pv_range config, not a failure.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isNotConfiguredError(error: unknown): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Query range configuration for a datapoint element
|
|
15
|
+
* @returns The configuration, or null if no pv_range config exists
|
|
16
|
+
* @throws On real WinCC OA errors (not on "not configured")
|
|
17
|
+
*/
|
|
18
|
+
export declare function queryRangeConfig(winccoa: any, dpe: string): Promise<any>;
|
|
7
19
|
/**
|
|
8
20
|
* Register pv_range query tools
|
|
9
21
|
* @param server - MCP server instance
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pv_range_query.d.ts","sourceRoot":"","sources":["../../../src/tools/pv_range/pv_range_query.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"pv_range_query.d.ts","sourceRoot":"","sources":["../../../src/tools/pv_range/pv_range_query.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAK1D;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAM5D;AAmBD;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CA0B9E;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,CA+EzE"}
|
|
@@ -4,38 +4,68 @@
|
|
|
4
4
|
* MCP tool for querying existing pv_range configurations from datapoint elements.
|
|
5
5
|
*/
|
|
6
6
|
import { z } from 'zod';
|
|
7
|
-
import { createSuccessResponse, createErrorResponse } from '../../utils/helpers.js';
|
|
7
|
+
import { createSuccessResponse, createErrorResponse, describeWinccoaError, logWinccoaError } from '../../utils/helpers.js';
|
|
8
|
+
import * as log from '../../utils/logger.js';
|
|
8
9
|
import { DpConfigType } from '../../types/winccoa/constants.js';
|
|
10
|
+
/** WinCC OA error 19: "attribute does not exist in this config" - i.e. not configured. */
|
|
11
|
+
const ERR_ATTRIBUTE_NOT_IN_CONFIG = 19;
|
|
9
12
|
/**
|
|
10
|
-
*
|
|
13
|
+
* True if the error only says the attribute does not exist in the config
|
|
14
|
+
* (code 19, directly or in every nested detail). That is the normal answer
|
|
15
|
+
* for a datapoint element without a pv_range config, not a failure.
|
|
11
16
|
*/
|
|
12
|
-
|
|
17
|
+
export function isNotConfiguredError(error) {
|
|
18
|
+
const described = describeWinccoaError(error);
|
|
19
|
+
if (described.details.length > 0) {
|
|
20
|
+
return described.details.every(d => d.code === ERR_ATTRIBUTE_NOT_IN_CONFIG);
|
|
21
|
+
}
|
|
22
|
+
return described.code === ERR_ATTRIBUTE_NOT_IN_CONFIG;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Read one _pv_range attribute.
|
|
26
|
+
* @returns The value, or undefined if the attribute does not exist in this config
|
|
27
|
+
* @throws Any other WinCC OA error
|
|
28
|
+
*/
|
|
29
|
+
async function readRangeAttribute(winccoa, dpe, attribute) {
|
|
13
30
|
try {
|
|
14
|
-
|
|
15
|
-
const [configType, minValue, maxValue, includeMin, includeMax] = await Promise.all([
|
|
16
|
-
winccoa.dpGet(`${dpe}:_pv_range.._type`),
|
|
17
|
-
winccoa.dpGet(`${dpe}:_pv_range.._min`),
|
|
18
|
-
winccoa.dpGet(`${dpe}:_pv_range.._max`),
|
|
19
|
-
winccoa.dpGet(`${dpe}:_pv_range.._incl_min`),
|
|
20
|
-
winccoa.dpGet(`${dpe}:_pv_range.._incl_max`)
|
|
21
|
-
]);
|
|
22
|
-
// Check if configuration exists
|
|
23
|
-
if (configType === DpConfigType.DPCONFIG_NONE || configType === null || configType === undefined) {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
return {
|
|
27
|
-
type: configType,
|
|
28
|
-
min: minValue,
|
|
29
|
-
max: maxValue,
|
|
30
|
-
includeMin: includeMin,
|
|
31
|
-
includeMax: includeMax,
|
|
32
|
-
configured: true
|
|
33
|
-
};
|
|
31
|
+
return await winccoa.dpGet(`${dpe}:_pv_range.._${attribute}`);
|
|
34
32
|
}
|
|
35
33
|
catch (error) {
|
|
36
|
-
|
|
34
|
+
if (isNotConfiguredError(error)) {
|
|
35
|
+
log.debug(`${dpe}:_pv_range.._${attribute} does not exist in this config`);
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Query range configuration for a datapoint element
|
|
43
|
+
* @returns The configuration, or null if no pv_range config exists
|
|
44
|
+
* @throws On real WinCC OA errors (not on "not configured")
|
|
45
|
+
*/
|
|
46
|
+
export async function queryRangeConfig(winccoa, dpe) {
|
|
47
|
+
// Read the config type first: without a config, the other attributes do not
|
|
48
|
+
// exist and reading them only produces errors.
|
|
49
|
+
const configType = await readRangeAttribute(winccoa, dpe, 'type');
|
|
50
|
+
if (configType === DpConfigType.DPCONFIG_NONE || configType === null || configType === undefined) {
|
|
37
51
|
return null;
|
|
38
52
|
}
|
|
53
|
+
// Not every range type has every attribute (e.g. a set range check has no
|
|
54
|
+
// min/max); those come back as undefined.
|
|
55
|
+
const [minValue, maxValue, includeMin, includeMax] = await Promise.all([
|
|
56
|
+
readRangeAttribute(winccoa, dpe, 'min'),
|
|
57
|
+
readRangeAttribute(winccoa, dpe, 'max'),
|
|
58
|
+
readRangeAttribute(winccoa, dpe, 'incl_min'),
|
|
59
|
+
readRangeAttribute(winccoa, dpe, 'incl_max')
|
|
60
|
+
]);
|
|
61
|
+
return {
|
|
62
|
+
type: configType,
|
|
63
|
+
min: minValue,
|
|
64
|
+
max: maxValue,
|
|
65
|
+
includeMin: includeMin,
|
|
66
|
+
includeMax: includeMax,
|
|
67
|
+
configured: true
|
|
68
|
+
};
|
|
39
69
|
}
|
|
40
70
|
/**
|
|
41
71
|
* Register pv_range query tools
|
|
@@ -62,7 +92,9 @@ export function registerTools(server, context) {
|
|
|
62
92
|
- includeMax: Whether maximum is included in valid range
|
|
63
93
|
- configured: true if a configuration exists
|
|
64
94
|
|
|
65
|
-
|
|
95
|
+
If no pv_range configuration exists, returns
|
|
96
|
+
{"dpe": "...", "configured": false, "message": "No pv_range configuration exists for this datapoint element"}.
|
|
97
|
+
Attributes that do not exist for the configured range type are omitted.
|
|
66
98
|
`, {
|
|
67
99
|
dpe: z.string().describe('Datapoint element name (e.g., System1:MyTag.)')
|
|
68
100
|
}, async ({ dpe }) => {
|
|
@@ -98,12 +130,12 @@ export function registerTools(server, context) {
|
|
|
98
130
|
});
|
|
99
131
|
}
|
|
100
132
|
catch (error) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
133
|
+
logWinccoaError('PV Range Query Failed', error);
|
|
134
|
+
const described = describeWinccoaError(error);
|
|
135
|
+
return createErrorResponse(`Failed to query pv_range configuration: ${described.message}`, {
|
|
136
|
+
...(described.code !== undefined ? { errorCode: described.code } : {}),
|
|
137
|
+
...(described.details.length > 0 ? { details: described.details } : {})
|
|
138
|
+
});
|
|
107
139
|
}
|
|
108
140
|
});
|
|
109
141
|
return 1; // Number of tools registered
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pv_range_query.js","sourceRoot":"","sources":["../../../src/tools/pv_range/pv_range_query.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"pv_range_query.js","sourceRoot":"","sources":["../../../src/tools/pv_range/pv_range_query.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,wBAAwB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,OAAO,mBAAmB,CAAC,2CAA2C,SAAS,CAAC,OAAO,EAAE,EAAE;gBACzF,GAAG,CAAC,SAAS,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACtE,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACxE,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CACF,CAAC;IAEF,OAAO,CAAC,CAAC,CAAC,6BAA6B;AACzC,CAAC"}
|
package/build/utils/helpers.d.ts
CHANGED
|
@@ -2,14 +2,66 @@
|
|
|
2
2
|
* Utility helper functions for MCP tool responses and datapoint operations
|
|
3
3
|
*/
|
|
4
4
|
import type { WinccoaManager } from 'winccoa-manager';
|
|
5
|
-
import type {
|
|
5
|
+
import type { McpToolResponse, DatapointChild } from '../types/index.js';
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Filter datapoint type names, dropping internal types (starting with _) unless requested
|
|
8
8
|
* @param arr - Array of type names
|
|
9
9
|
* @param withInternals - Whether to include internal types (starting with _)
|
|
10
|
-
* @returns
|
|
10
|
+
* @returns Filtered type names
|
|
11
11
|
*/
|
|
12
|
-
export declare function
|
|
12
|
+
export declare function filterTypeNames(arr: ReadonlyArray<string | undefined>, withInternals?: boolean): string[];
|
|
13
|
+
/** One flattened WinCC OA error (see describeWinccoaError). */
|
|
14
|
+
export interface WinccoaErrorDetail {
|
|
15
|
+
code?: number;
|
|
16
|
+
message: string;
|
|
17
|
+
dpe?: string;
|
|
18
|
+
}
|
|
19
|
+
/** Flattened view of a WinCC OA error, including its nested details. */
|
|
20
|
+
export interface WinccoaErrorDescription {
|
|
21
|
+
/** Effective code: the inner code if all inner errors agree, else the outer code */
|
|
22
|
+
code?: number;
|
|
23
|
+
/** Outer code as reported by the manager (e.g. 9399 "multiple errors") */
|
|
24
|
+
outerCode?: number;
|
|
25
|
+
/** Human-readable message: the inner messages if there are any, else the outer message */
|
|
26
|
+
message: string;
|
|
27
|
+
/** Inner errors, flattened */
|
|
28
|
+
details: WinccoaErrorDetail[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Flatten a WinccoaError into code, message and inner details.
|
|
32
|
+
*
|
|
33
|
+
* A failing dpGet usually throws 9399 "multiple errors (N errors total)" with
|
|
34
|
+
* the real cause - e.g. 71 "DP does not exist" naming the element - only in
|
|
35
|
+
* `details`. Forwarding `error.message` alone hides that from the client.
|
|
36
|
+
* Nested details are flattened (their own details are pulled up one level).
|
|
37
|
+
*
|
|
38
|
+
* @param e - Caught error
|
|
39
|
+
* @param fallbackDpe - DPE the caller requested; used for inner details that carry no dpe themselves
|
|
40
|
+
* @returns Flattened description
|
|
41
|
+
*/
|
|
42
|
+
export declare function describeWinccoaError(e: unknown, fallbackDpe?: string): WinccoaErrorDescription;
|
|
43
|
+
/**
|
|
44
|
+
* Log a caught WinCC OA error as a single line.
|
|
45
|
+
*
|
|
46
|
+
* Expected not-found codes (71 DP does not exist, 57 DP type does not exist,
|
|
47
|
+
* 19 attribute not in config) are client mistakes and go out at warn level.
|
|
48
|
+
* Everything else is logged at error level; the stack is added only at
|
|
49
|
+
* MCP_LOG_LEVEL=debug. The error object itself is never dumped.
|
|
50
|
+
*
|
|
51
|
+
* @param context - What was being attempted, e.g. "Error getting type name for X"
|
|
52
|
+
* @param e - Caught error
|
|
53
|
+
* @param fallbackDpe - DPE the caller requested
|
|
54
|
+
*/
|
|
55
|
+
export declare function logWinccoaError(context: string, e: unknown, fallbackDpe?: string): void;
|
|
56
|
+
/**
|
|
57
|
+
* Build the uniform error envelope for a caught WinCC OA error:
|
|
58
|
+
* `{error, message, errorCode?, errorType?, details}`.
|
|
59
|
+
*
|
|
60
|
+
* @param prefix - Message prefix, e.g. "Failed to get type name for X"
|
|
61
|
+
* @param e - Caught error
|
|
62
|
+
* @param fallbackDpe - DPE the caller requested (fills empty details[].dpe)
|
|
63
|
+
*/
|
|
64
|
+
export declare function winccoaErrorResponse(prefix: string, e: unknown, fallbackDpe?: string): McpToolResponse;
|
|
13
65
|
/**
|
|
14
66
|
* Recursively add description and unit information to datapoint children
|
|
15
67
|
* @param children - Array of child datapoint elements
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAGV,eAAe,EACf,cAAc,EACf,MAAM,mBAAmB,CAAC;AAG3B;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,aAAa,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,aAAa,CAAC,EAAE,OAAO,GAAG,MAAM,EAAE,CAIzG;AAED,+DAA+D;AAC/D,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,wEAAwE;AACxE,MAAM,WAAW,uBAAuB;IACtC,oFAAoF;IACpF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0EAA0E;IAC1E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0FAA0F;IAC1F,OAAO,EAAE,MAAM,CAAC;IAChB,8BAA8B;IAC9B,OAAO,EAAE,kBAAkB,EAAE,CAAC;CAC/B;AAqCD;;;;;;;;;;;GAWG;AACH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/
|
|
4
|
+
import * as log from './logger.js';
|
|
4
5
|
/**
|
|
5
|
-
*
|
|
6
|
+
* Filter datapoint type names, dropping internal types (starting with _) unless requested
|
|
6
7
|
* @param arr - Array of type names
|
|
7
8
|
* @param withInternals - Whether to include internal types (starting with _)
|
|
8
|
-
* @returns
|
|
9
|
+
* @returns Filtered type names
|
|
9
10
|
*/
|
|
10
|
-
export function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
export function filterTypeNames(arr, withInternals) {
|
|
12
|
+
return arr.filter((item) => typeof item === 'string' && (withInternals === true || !item.startsWith('_')));
|
|
13
|
+
}
|
|
14
|
+
/** Read a numeric `code` from an error-like value. */
|
|
15
|
+
function errorCode(e) {
|
|
16
|
+
const code = e?.code;
|
|
17
|
+
if (typeof code === 'number')
|
|
18
|
+
return code;
|
|
19
|
+
if (typeof code === 'string' && code.trim() !== '' && !Number.isNaN(Number(code)))
|
|
20
|
+
return Number(code);
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
/** Read a message from an error-like value. */
|
|
24
|
+
function errorMessage(e) {
|
|
25
|
+
if (e instanceof Error)
|
|
26
|
+
return e.message;
|
|
27
|
+
if (typeof e === 'string')
|
|
28
|
+
return e;
|
|
29
|
+
const message = e?.message;
|
|
30
|
+
return typeof message === 'string' ? message : String(e);
|
|
31
|
+
}
|
|
32
|
+
/** Read the dpe an error refers to, if the manager attached one. */
|
|
33
|
+
function errorDpe(e) {
|
|
34
|
+
const err = e;
|
|
35
|
+
if (typeof err?.dpe === 'string')
|
|
36
|
+
return err.dpe;
|
|
37
|
+
if (typeof err?.dpName === 'string')
|
|
38
|
+
return err.dpName;
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
/** Nested WinCC OA errors, if any. */
|
|
42
|
+
function errorDetails(e) {
|
|
43
|
+
const details = e?.details;
|
|
44
|
+
if (Array.isArray(details))
|
|
45
|
+
return details;
|
|
46
|
+
// A single nested error instead of an array
|
|
47
|
+
if (details instanceof Error || (typeof details === 'object' && details !== null && 'message' in details)) {
|
|
48
|
+
return [details];
|
|
49
|
+
}
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Flatten a WinccoaError into code, message and inner details.
|
|
54
|
+
*
|
|
55
|
+
* A failing dpGet usually throws 9399 "multiple errors (N errors total)" with
|
|
56
|
+
* the real cause - e.g. 71 "DP does not exist" naming the element - only in
|
|
57
|
+
* `details`. Forwarding `error.message` alone hides that from the client.
|
|
58
|
+
* Nested details are flattened (their own details are pulled up one level).
|
|
59
|
+
*
|
|
60
|
+
* @param e - Caught error
|
|
61
|
+
* @param fallbackDpe - DPE the caller requested; used for inner details that carry no dpe themselves
|
|
62
|
+
* @returns Flattened description
|
|
63
|
+
*/
|
|
64
|
+
export function describeWinccoaError(e, fallbackDpe) {
|
|
65
|
+
const outerCode = errorCode(e);
|
|
66
|
+
const outerMessage = errorMessage(e);
|
|
67
|
+
const details = [];
|
|
68
|
+
const push = (inner) => {
|
|
69
|
+
const detail = { message: errorMessage(inner) };
|
|
70
|
+
const code = errorCode(inner);
|
|
71
|
+
if (code !== undefined)
|
|
72
|
+
detail.code = code;
|
|
73
|
+
const dpe = errorDpe(inner) || fallbackDpe;
|
|
74
|
+
if (dpe)
|
|
75
|
+
detail.dpe = dpe;
|
|
76
|
+
details.push(detail);
|
|
77
|
+
};
|
|
78
|
+
for (const inner of errorDetails(e)) {
|
|
79
|
+
const nested = errorDetails(inner);
|
|
80
|
+
if (nested.length > 0) {
|
|
81
|
+
nested.forEach(push);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
push(inner);
|
|
21
85
|
}
|
|
22
86
|
}
|
|
23
|
-
|
|
87
|
+
if (details.length === 0) {
|
|
88
|
+
return {
|
|
89
|
+
...(outerCode !== undefined ? { code: outerCode, outerCode } : {}),
|
|
90
|
+
message: outerMessage,
|
|
91
|
+
details
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const innerCodes = new Set(details.map(d => d.code));
|
|
95
|
+
const commonCode = innerCodes.size === 1 ? [...innerCodes][0] : undefined;
|
|
96
|
+
const code = commonCode !== undefined ? commonCode : outerCode;
|
|
97
|
+
const message = [...new Set(details.map(d => d.message))].join('; ');
|
|
98
|
+
return {
|
|
99
|
+
...(code !== undefined ? { code } : {}),
|
|
100
|
+
...(outerCode !== undefined ? { outerCode } : {}),
|
|
101
|
+
message,
|
|
102
|
+
details
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/** Codes meaning "the client asked for something that does not exist": expected, not a server fault. */
|
|
106
|
+
const EXPECTED_NOT_FOUND_CODES = new Set([71, 57, 19]);
|
|
107
|
+
/**
|
|
108
|
+
* Log a caught WinCC OA error as a single line.
|
|
109
|
+
*
|
|
110
|
+
* Expected not-found codes (71 DP does not exist, 57 DP type does not exist,
|
|
111
|
+
* 19 attribute not in config) are client mistakes and go out at warn level.
|
|
112
|
+
* Everything else is logged at error level; the stack is added only at
|
|
113
|
+
* MCP_LOG_LEVEL=debug. The error object itself is never dumped.
|
|
114
|
+
*
|
|
115
|
+
* @param context - What was being attempted, e.g. "Error getting type name for X"
|
|
116
|
+
* @param e - Caught error
|
|
117
|
+
* @param fallbackDpe - DPE the caller requested
|
|
118
|
+
*/
|
|
119
|
+
export function logWinccoaError(context, e, fallbackDpe) {
|
|
120
|
+
const described = describeWinccoaError(e, fallbackDpe);
|
|
121
|
+
// WinccoaError messages already start with "<code>, "; do not repeat the code.
|
|
122
|
+
const hasCodePrefix = described.code !== undefined && described.message.trimStart().startsWith(`${described.code},`);
|
|
123
|
+
const codePrefix = described.code !== undefined && !hasCodePrefix ? `[${described.code}] ` : '';
|
|
124
|
+
const line = `${context}: ${codePrefix}${described.message}`;
|
|
125
|
+
if (described.code !== undefined && EXPECTED_NOT_FOUND_CODES.has(described.code)) {
|
|
126
|
+
log.warn(line);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
log.error(line);
|
|
130
|
+
if (e instanceof Error && e.stack)
|
|
131
|
+
log.debug(e.stack);
|
|
132
|
+
}
|
|
133
|
+
/** errorType per WinCC OA error code, for winccoaErrorResponse. */
|
|
134
|
+
const WINCCOA_ERROR_TYPES = {
|
|
135
|
+
71: 'DP_NOT_EXIST',
|
|
136
|
+
57: 'DP_TYPE_NOT_EXIST'
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Build the uniform error envelope for a caught WinCC OA error:
|
|
140
|
+
* `{error, message, errorCode?, errorType?, details}`.
|
|
141
|
+
*
|
|
142
|
+
* @param prefix - Message prefix, e.g. "Failed to get type name for X"
|
|
143
|
+
* @param e - Caught error
|
|
144
|
+
* @param fallbackDpe - DPE the caller requested (fills empty details[].dpe)
|
|
145
|
+
*/
|
|
146
|
+
export function winccoaErrorResponse(prefix, e, fallbackDpe) {
|
|
147
|
+
const described = describeWinccoaError(e, fallbackDpe);
|
|
148
|
+
const errorType = described.code !== undefined ? WINCCOA_ERROR_TYPES[described.code] : undefined;
|
|
149
|
+
return createErrorResponse(`${prefix}: ${described.message}`, {
|
|
150
|
+
errorCode: described.code,
|
|
151
|
+
...(errorType ? { errorType } : {}),
|
|
152
|
+
details: described.details
|
|
153
|
+
});
|
|
24
154
|
}
|
|
25
155
|
/**
|
|
26
156
|
* Recursively add description and unit information to datapoint children
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AASH,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AAEnC;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,GAAsC,EAAE,aAAuB;IAC7F,O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AI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QACpC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,uDAAuD;IACvD,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACtB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,mBAAmB;IACnB,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AACvE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,+BAA+B,CAAC,IAAc;IAC5D,MAAM,OAAO,GAAa,EAAE,CAAC;IAE7B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,CAAC,6BAA6B,CAAC,GAAG,CAAC,EAAE,CAAC;YACxC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IAED,OAAO;QACL,KAAK,EAAE,OAAO,CAAC,MAAM,KAAK,CAAC;QAC3B,OAAO;KACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal level-based logger.
|
|
3
|
+
*
|
|
4
|
+
* The HTTP server previously logged a running commentary on every request,
|
|
5
|
+
* including request headers and the first 8 characters of both the presented and
|
|
6
|
+
* the expected API token. Anything reaching a WinCC OA manager log is readable by
|
|
7
|
+
* anyone with log access, so token material must never be written there, and the
|
|
8
|
+
* per-request commentary belongs behind a level.
|
|
9
|
+
*
|
|
10
|
+
* Controlled by MCP_LOG_LEVEL: debug | info | warn | error (default: info).
|
|
11
|
+
*/
|
|
12
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
13
|
+
/** Verbose per-request tracing. Off unless MCP_LOG_LEVEL=debug. */
|
|
14
|
+
export declare function debug(...args: unknown[]): void;
|
|
15
|
+
/** Normal operational messages: startup, listening, tool registration. */
|
|
16
|
+
export declare function info(...args: unknown[]): void;
|
|
17
|
+
export declare function warn(...args: unknown[]): void;
|
|
18
|
+
export declare function error(...args: unknown[]): void;
|
|
19
|
+
/**
|
|
20
|
+
* Describe a secret without disclosing any of it.
|
|
21
|
+
*
|
|
22
|
+
* Use this instead of `token.substring(0, 8)`: a prefix is still secret material,
|
|
23
|
+
* and for a short or low-entropy token it can be most of it.
|
|
24
|
+
*
|
|
25
|
+
* @param secret - The value to describe
|
|
26
|
+
* @returns "set (N chars)" or "not set"
|
|
27
|
+
*/
|
|
28
|
+
export declare function describeSecret(secret: string | undefined | null): string;
|
|
29
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAmB3D,mEAAmE;AACnE,wBAAgB,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAE9C;AAED,0EAA0E;AAC1E,wBAAgB,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAE7C;AAED,wBAAgB,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAE7C;AAED,wBAAgB,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAE9C;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,MAAM,CAExE"}
|