@jupiterone/jupiterone-mcp 0.4.0 → 0.5.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/server/mcp-server.d.ts +1 -0
- package/dist/server/mcp-server.d.ts.map +1 -1
- package/dist/server/mcp-server.js +30 -14
- package/dist/server/mcp-server.js.map +1 -1
- package/dist/server/tools/telemetry.d.ts +7 -1
- package/dist/server/tools/telemetry.d.ts.map +1 -1
- package/dist/server/tools/telemetry.js.map +1 -1
- package/dist/server/tools/usage.d.ts +16 -0
- package/dist/server/tools/usage.d.ts.map +1 -0
- package/dist/server/tools/usage.js +103 -0
- package/dist/server/tools/usage.js.map +1 -0
- package/package.json +1 -1
|
@@ -11,6 +11,7 @@ export declare class JupiterOneMcpServer {
|
|
|
11
11
|
private validator;
|
|
12
12
|
private hasEnvironmentAccount;
|
|
13
13
|
private telemetry;
|
|
14
|
+
private envAccountId?;
|
|
14
15
|
constructor(config: JupiterOneConfig, options?: JupiterOneMcpServerOptions);
|
|
15
16
|
/**
|
|
16
17
|
* Single registration chokepoint: injects the per-request `accountId` parameter when no env
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../../src/server/mcp-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAO1D,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../../src/server/mcp-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAO1D,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAsB3E,MAAM,WAAW,0BAA0B;IACzC,6EAA6E;IAC7E,SAAS,CAAC,EAAE,aAAa,CAAC;CAC3B;AAED,qBAAa,mBAAmB;IACvB,MAAM,EAAE,SAAS,CAAC;IACzB,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,qBAAqB,CAAU;IACvC,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,YAAY,CAAC,CAAS;gBAElB,MAAM,EAAE,gBAAgB,EAAE,OAAO,GAAE,0BAA+B;IAgB9E;;;;OAIG;IACH,OAAO,CAAC,QAAQ;YAkCF,MAAM;IA2Dd,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAKtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAG5B"}
|
|
@@ -10,12 +10,14 @@ const j1ql_validator_js_1 = require("../utils/j1ql-validator.js");
|
|
|
10
10
|
const index_js_1 = require("./tools/index.js");
|
|
11
11
|
const errors_js_1 = require("./tools/errors.js");
|
|
12
12
|
const telemetry_js_1 = require("./tools/telemetry.js");
|
|
13
|
+
const usage_js_1 = require("./tools/usage.js");
|
|
13
14
|
class JupiterOneMcpServer {
|
|
14
15
|
server;
|
|
15
16
|
client;
|
|
16
17
|
validator;
|
|
17
18
|
hasEnvironmentAccount;
|
|
18
19
|
telemetry;
|
|
20
|
+
envAccountId;
|
|
19
21
|
constructor(config, options = {}) {
|
|
20
22
|
this.client = new jupiterone_client_js_1.JupiterOneClient(config);
|
|
21
23
|
this.validator = new j1ql_validator_js_1.J1QLValidator(this.client.j1qlService);
|
|
@@ -24,6 +26,7 @@ class JupiterOneMcpServer {
|
|
|
24
26
|
version: package_json_1.version,
|
|
25
27
|
});
|
|
26
28
|
this.hasEnvironmentAccount = !config.accountId;
|
|
29
|
+
this.envAccountId = config.accountId || undefined;
|
|
27
30
|
this.telemetry = options.telemetry ?? telemetry_js_1.stderrTelemetry;
|
|
28
31
|
for (const tool of index_js_1.allTools) {
|
|
29
32
|
this.register(tool);
|
|
@@ -35,15 +38,20 @@ class JupiterOneMcpServer {
|
|
|
35
38
|
* error formatting (C2), and per-call telemetry (O1).
|
|
36
39
|
*/
|
|
37
40
|
register(tool) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
const inputSchema = {
|
|
42
|
+
...tool.inputSchema,
|
|
43
|
+
reason: zod_1.z
|
|
44
|
+
.string()
|
|
45
|
+
.optional()
|
|
46
|
+
.describe('Optional: a brief statement of why you are calling this tool — what you are trying to find out or accomplish. Recorded for usage analytics only; does not affect behavior.'),
|
|
47
|
+
...(this.hasEnvironmentAccount
|
|
48
|
+
? {
|
|
49
|
+
accountId: zod_1.z
|
|
50
|
+
.string()
|
|
51
|
+
.describe('JupiterOne Account ID for this request. This should be explicitly asked for with the first tool call.'),
|
|
52
|
+
}
|
|
53
|
+
: {}),
|
|
54
|
+
};
|
|
47
55
|
const registerTool = this.server.registerTool.bind(this.server);
|
|
48
56
|
registerTool(tool.name, {
|
|
49
57
|
title: tool.title,
|
|
@@ -54,12 +62,15 @@ class JupiterOneMcpServer {
|
|
|
54
62
|
}, (params) => this.invoke(tool, params));
|
|
55
63
|
}
|
|
56
64
|
async invoke(tool, params) {
|
|
65
|
+
// `reason` (self-reported agent intent) is injected on every tool; strip it before the handler.
|
|
66
|
+
const { reason: rawReason, ...rest } = params;
|
|
67
|
+
const reason = typeof rawReason === 'string' && rawReason.length > 0 ? (0, usage_js_1.truncateReason)(rawReason) : undefined;
|
|
57
68
|
let client = this.client;
|
|
58
69
|
let validator = this.validator;
|
|
59
|
-
let toolParams =
|
|
60
|
-
let accountId;
|
|
70
|
+
let toolParams = rest;
|
|
71
|
+
let accountId = this.envAccountId;
|
|
61
72
|
if (this.hasEnvironmentAccount) {
|
|
62
|
-
const { accountId: requested, ...otherParams } =
|
|
73
|
+
const { accountId: requested, ...otherParams } = rest;
|
|
63
74
|
if (!requested || typeof requested !== 'string') {
|
|
64
75
|
return {
|
|
65
76
|
content: [
|
|
@@ -79,8 +90,9 @@ class JupiterOneMcpServer {
|
|
|
79
90
|
const startedAt = Date.now();
|
|
80
91
|
let outcome = 'success';
|
|
81
92
|
let errorClass;
|
|
93
|
+
let result;
|
|
82
94
|
try {
|
|
83
|
-
|
|
95
|
+
result = await tool.handler(toolParams, client, validator);
|
|
84
96
|
if (result.isError)
|
|
85
97
|
outcome = 'error';
|
|
86
98
|
return result;
|
|
@@ -88,9 +100,10 @@ class JupiterOneMcpServer {
|
|
|
88
100
|
catch (error) {
|
|
89
101
|
outcome = 'error';
|
|
90
102
|
errorClass = error instanceof Error ? error.constructor.name : 'UnknownError';
|
|
91
|
-
|
|
103
|
+
result = tool.formatError
|
|
92
104
|
? tool.formatError(error, toolParams, validator)
|
|
93
105
|
: (0, errors_js_1.toErrorResponse)(error, tool.errorContext);
|
|
106
|
+
return result;
|
|
94
107
|
}
|
|
95
108
|
finally {
|
|
96
109
|
this.telemetry({
|
|
@@ -99,6 +112,9 @@ class JupiterOneMcpServer {
|
|
|
99
112
|
durationMs: Date.now() - startedAt,
|
|
100
113
|
errorClass,
|
|
101
114
|
accountId,
|
|
115
|
+
reason,
|
|
116
|
+
input: (0, usage_js_1.summarizeInput)(toolParams),
|
|
117
|
+
result: result ? (0, usage_js_1.summarizeResult)(result) : undefined,
|
|
102
118
|
});
|
|
103
119
|
}
|
|
104
120
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-server.js","sourceRoot":"","sources":["../../src/server/mcp-server.ts"],"names":[],"mappings":";;;AAAA,oEAAoE;AACpE,wEAAiF;AACjF,6BAAwB;AACxB,yEAAkE;AAElE,qDAA6C;AAE7C,kEAA2D;AAC3D,+CAA4C;AAC5C,iDAAoD;AAEpD,uDAA2E;
|
|
1
|
+
{"version":3,"file":"mcp-server.js","sourceRoot":"","sources":["../../src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EAAE,IAAI,CAAC,IAAI;gBACf,OAAO;gBACP,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;gBAClC,UAAU;gBACV,SAAS;gBACT,MAAM;gBACN,KAAK,EAAE,IAAA,yBAAc,EAAC,UAAU,CAAC;gBACjC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,IAAA,0BAAe,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS;aACrD,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,SAAS,GAAG,IAAI,+BAAoB,EAAE,CAAC;QAC7C,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,IAAI;QACR,oBAAoB;IACtB,CAAC;CACF;AAlID,kDAkIC"}
|
|
@@ -5,8 +5,14 @@ export interface ToolTelemetryEvent {
|
|
|
5
5
|
durationMs: number;
|
|
6
6
|
/** Constructor name of a thrown error, when the handler threw. */
|
|
7
7
|
errorClass?: string;
|
|
8
|
-
/** Account the call ran against
|
|
8
|
+
/** Account the call ran against (env-configured or the per-request account). */
|
|
9
9
|
accountId?: string;
|
|
10
|
+
/** Self-reported agent intent from the optional `reason` arg, when provided (truncated). */
|
|
11
|
+
reason?: string;
|
|
12
|
+
/** Sanitized, allowlisted summary of the call inputs (redacted J1QL, IDs, limits, names). */
|
|
13
|
+
input?: Record<string, unknown>;
|
|
14
|
+
/** Result metadata derived from structuredContent (resultCount, hasNextPage, status, isError). */
|
|
15
|
+
result?: Record<string, unknown>;
|
|
10
16
|
}
|
|
11
17
|
/** Sink for tool telemetry. The remote injects a request-scoped logger that ships to New Relic. */
|
|
12
18
|
export type ToolTelemetry = (event: ToolTelemetryEvent) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../../../src/server/tools/telemetry.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,SAAS,GAAG,OAAO,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,kEAAkE;IAClE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gFAAgF;IAChF,SAAS,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../../../src/server/tools/telemetry.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,SAAS,GAAG,OAAO,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,kEAAkE;IAClE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gFAAgF;IAChF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4FAA4F;IAC5F,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6FAA6F;IAC7F,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,kGAAkG;IAClG,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,mGAAmG;AACnG,MAAM,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAC;AAEhE;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,aAE7B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../../../src/server/tools/telemetry.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../../../src/server/tools/telemetry.ts"],"names":[],"mappings":";;;AAoBA;;;GAGG;AACI,MAAM,eAAe,GAAkB,CAAC,KAAK,EAAE,EAAE;IACtD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,KAAK,EAAE,CAAC,IAAI,CAAC,CAAC;AAC/E,CAAC,CAAC;AAFW,QAAA,eAAe,mBAE1B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ToolResult } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Redacts string literals in a J1QL query, preserving structure (entity types, operators,
|
|
4
|
+
* property names) so query *shape* is captured for usage analytics without literal values.
|
|
5
|
+
*
|
|
6
|
+
* Ported from query-engine's `redactCypher` (sdk-graph/src/cypher/redact.ts), adapted for J1QL
|
|
7
|
+
* (single- and double-quoted literals). The patterns span escaped quotes (`\'` / `\"`) so a
|
|
8
|
+
* literal is always replaced in full; imperfect boundaries only ever over-redact, never leak.
|
|
9
|
+
*/
|
|
10
|
+
export declare function redactJ1ql(query: string): string;
|
|
11
|
+
export declare function truncateReason(reason: string): string;
|
|
12
|
+
/** Allowlisted, sanitized summary of tool inputs for usage telemetry. */
|
|
13
|
+
export declare function summarizeInput(params: Record<string, unknown>): Record<string, unknown>;
|
|
14
|
+
/** Result metadata (counts, pagination, status) derived from the structured payload. */
|
|
15
|
+
export declare function summarizeResult(result: ToolResult): Record<string, unknown>;
|
|
16
|
+
//# sourceMappingURL=usage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../../src/server/tools/usage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAIhD;AAID,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAErD;AA2BD,yEAAyE;AACzE,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CASvF;AAcD,wFAAwF;AACxF,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA4B3E"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.redactJ1ql = redactJ1ql;
|
|
4
|
+
exports.truncateReason = truncateReason;
|
|
5
|
+
exports.summarizeInput = summarizeInput;
|
|
6
|
+
exports.summarizeResult = summarizeResult;
|
|
7
|
+
/**
|
|
8
|
+
* Redacts string literals in a J1QL query, preserving structure (entity types, operators,
|
|
9
|
+
* property names) so query *shape* is captured for usage analytics without literal values.
|
|
10
|
+
*
|
|
11
|
+
* Ported from query-engine's `redactCypher` (sdk-graph/src/cypher/redact.ts), adapted for J1QL
|
|
12
|
+
* (single- and double-quoted literals). The patterns span escaped quotes (`\'` / `\"`) so a
|
|
13
|
+
* literal is always replaced in full; imperfect boundaries only ever over-redact, never leak.
|
|
14
|
+
*/
|
|
15
|
+
function redactJ1ql(query) {
|
|
16
|
+
return query
|
|
17
|
+
.replace(/'(?:[^'\\]|\\.)*'/g, "'[REDACTED]'")
|
|
18
|
+
.replace(/"(?:[^"\\]|\\.)*"/g, '"[REDACTED]"');
|
|
19
|
+
}
|
|
20
|
+
const REASON_MAX = 500;
|
|
21
|
+
function truncateReason(reason) {
|
|
22
|
+
return reason.length > REASON_MAX ? `${reason.slice(0, REASON_MAX)}…` : reason;
|
|
23
|
+
}
|
|
24
|
+
// Allowlist of scalar inputs safe to log verbatim. Everything not listed is dropped (default-deny),
|
|
25
|
+
// which keeps sensitive payloads out: action headers/endpoints/recipients/body, integration config,
|
|
26
|
+
// templates, J1QL variables/flags/scopeFilters, rule operations, and the raw widget input.
|
|
27
|
+
const SAFE_INPUT_KEYS = [
|
|
28
|
+
'ruleId',
|
|
29
|
+
'dashboardId',
|
|
30
|
+
'integrationJobId',
|
|
31
|
+
'integrationInstanceId',
|
|
32
|
+
'jobId',
|
|
33
|
+
'definitionId',
|
|
34
|
+
'rawDataKey',
|
|
35
|
+
'limit',
|
|
36
|
+
'size',
|
|
37
|
+
'pollingInterval',
|
|
38
|
+
'type',
|
|
39
|
+
'status',
|
|
40
|
+
'name',
|
|
41
|
+
'timestamp',
|
|
42
|
+
'beginTimestamp',
|
|
43
|
+
'endTimestamp',
|
|
44
|
+
'tag',
|
|
45
|
+
'includeConfig',
|
|
46
|
+
'includeDeleted',
|
|
47
|
+
];
|
|
48
|
+
/** Allowlisted, sanitized summary of tool inputs for usage telemetry. */
|
|
49
|
+
function summarizeInput(params) {
|
|
50
|
+
const out = {};
|
|
51
|
+
for (const key of SAFE_INPUT_KEYS) {
|
|
52
|
+
if (params[key] !== undefined)
|
|
53
|
+
out[key] = params[key];
|
|
54
|
+
}
|
|
55
|
+
if (typeof params.query === 'string')
|
|
56
|
+
out.query = redactJ1ql(params.query);
|
|
57
|
+
// The cursor is an opaque pagination token — record only that paging was requested.
|
|
58
|
+
if (params.cursor !== undefined)
|
|
59
|
+
out.hasCursor = true;
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
const COLLECTION_KEYS = [
|
|
63
|
+
'data',
|
|
64
|
+
'rules',
|
|
65
|
+
'instances',
|
|
66
|
+
'jobs',
|
|
67
|
+
'definitions',
|
|
68
|
+
'events',
|
|
69
|
+
'evaluations',
|
|
70
|
+
'activeAlerts',
|
|
71
|
+
'dashboards',
|
|
72
|
+
];
|
|
73
|
+
/** Result metadata (counts, pagination, status) derived from the structured payload. */
|
|
74
|
+
function summarizeResult(result) {
|
|
75
|
+
const out = { isError: !!result.isError };
|
|
76
|
+
const sc = result.structuredContent;
|
|
77
|
+
if (!sc || typeof sc !== 'object' || Array.isArray(sc))
|
|
78
|
+
return out;
|
|
79
|
+
const obj = sc;
|
|
80
|
+
if (typeof obj.status === 'string')
|
|
81
|
+
out.status = obj.status;
|
|
82
|
+
const explicit = obj.total ?? obj.returned ?? obj.totalCount;
|
|
83
|
+
if (typeof explicit === 'number') {
|
|
84
|
+
out.resultCount = explicit;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
for (const key of COLLECTION_KEYS) {
|
|
88
|
+
if (Array.isArray(obj[key])) {
|
|
89
|
+
out.resultCount = obj[key].length;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const pageInfo = obj.pageInfo;
|
|
95
|
+
if (pageInfo && typeof pageInfo === 'object' && 'hasNextPage' in pageInfo) {
|
|
96
|
+
out.hasNextPage = !!pageInfo.hasNextPage;
|
|
97
|
+
}
|
|
98
|
+
else if (typeof obj.cursor === 'string') {
|
|
99
|
+
out.hasNextPage = true;
|
|
100
|
+
}
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=usage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../../../src/server/tools/usage.ts"],"names":[],"mappings":";;AAUA,gCAIC;AAID,wCAEC;AA4BD,wCASC;AAeD,0CA4BC;AAlGD;;;;;;;GAOG;AACH,SAAgB,UAAU,CAAC,KAAa;IACtC,OAAO,KAAK;SACT,OAAO,CAAC,oBAAoB,EAAE,cAAc,CAAC;SAC7C,OAAO,CAAC,oBAAoB,EAAE,cAAc,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,GAAG,GAAG,CAAC;AAEvB,SAAgB,cAAc,CAAC,MAAc;IAC3C,OAAO,MAAM,CAAC,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC;AACjF,CAAC;AAED,oGAAoG;AACpG,oGAAoG;AACpG,2FAA2F;AAC3F,MAAM,eAAe,GAAG;IACtB,QAAQ;IACR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