@onlyflows/servicenow-mcp 2.3.0-dev.4 → 2.3.0-dev.5

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.
Files changed (164) hide show
  1. package/CHANGELOG.md +142 -0
  2. package/README.md +111 -5
  3. package/dist/atf-policy.d.ts +1 -1
  4. package/dist/atf-policy.d.ts.map +1 -1
  5. package/dist/atf-policy.js +2 -0
  6. package/dist/atf-policy.js.map +1 -1
  7. package/dist/credential-tables.d.ts +32 -0
  8. package/dist/credential-tables.d.ts.map +1 -0
  9. package/dist/credential-tables.js +58 -0
  10. package/dist/credential-tables.js.map +1 -0
  11. package/dist/encoded-query-policy.d.ts.map +1 -1
  12. package/dist/encoded-query-policy.js +8 -1
  13. package/dist/encoded-query-policy.js.map +1 -1
  14. package/dist/execution-context.d.ts +14 -0
  15. package/dist/execution-context.d.ts.map +1 -1
  16. package/dist/execution-context.js +8 -0
  17. package/dist/execution-context.js.map +1 -1
  18. package/dist/field-policy.d.ts +34 -1
  19. package/dist/field-policy.d.ts.map +1 -1
  20. package/dist/field-policy.js +308 -25
  21. package/dist/field-policy.js.map +1 -1
  22. package/dist/hidden-values.d.ts +225 -0
  23. package/dist/hidden-values.d.ts.map +1 -0
  24. package/dist/hidden-values.js +748 -0
  25. package/dist/hidden-values.js.map +1 -0
  26. package/dist/http-entrypoint.d.ts.map +1 -1
  27. package/dist/http-entrypoint.js +7 -0
  28. package/dist/http-entrypoint.js.map +1 -1
  29. package/dist/index.js +7 -0
  30. package/dist/index.js.map +1 -1
  31. package/dist/metadata-cache.d.ts +38 -0
  32. package/dist/metadata-cache.d.ts.map +1 -1
  33. package/dist/metadata-cache.js +76 -3
  34. package/dist/metadata-cache.js.map +1 -1
  35. package/dist/policy-card.d.ts +16 -1
  36. package/dist/policy-card.d.ts.map +1 -1
  37. package/dist/policy-card.js +13 -2
  38. package/dist/policy-card.js.map +1 -1
  39. package/dist/profile-manager.d.ts +12 -0
  40. package/dist/profile-manager.d.ts.map +1 -1
  41. package/dist/profile-manager.js +23 -1
  42. package/dist/profile-manager.js.map +1 -1
  43. package/dist/setup.d.ts.map +1 -1
  44. package/dist/setup.js +5 -1
  45. package/dist/setup.js.map +1 -1
  46. package/dist/structured-query.d.ts.map +1 -1
  47. package/dist/structured-query.js +6 -1
  48. package/dist/structured-query.js.map +1 -1
  49. package/dist/table-policy.d.ts +34 -1
  50. package/dist/table-policy.d.ts.map +1 -1
  51. package/dist/table-policy.js +95 -10
  52. package/dist/table-policy.js.map +1 -1
  53. package/dist/tool-error.d.ts +8 -1
  54. package/dist/tool-error.d.ts.map +1 -1
  55. package/dist/tool-error.js +23 -0
  56. package/dist/tool-error.js.map +1 -1
  57. package/dist/tool-table-access.d.ts.map +1 -1
  58. package/dist/tool-table-access.js +25 -6
  59. package/dist/tool-table-access.js.map +1 -1
  60. package/dist/tools/aggregate.js +2 -2
  61. package/dist/tools/aggregate.js.map +1 -1
  62. package/dist/tools/all-fields-cap.d.ts.map +1 -1
  63. package/dist/tools/all-fields-cap.js +29 -7
  64. package/dist/tools/all-fields-cap.js.map +1 -1
  65. package/dist/tools/atf-author-module.d.ts +1 -7
  66. package/dist/tools/atf-author-module.d.ts.map +1 -1
  67. package/dist/tools/atf-author-module.js +16 -7
  68. package/dist/tools/atf-author-module.js.map +1 -1
  69. package/dist/tools/atf-contracts.d.ts +69 -4
  70. package/dist/tools/atf-contracts.d.ts.map +1 -1
  71. package/dist/tools/atf-contracts.js +32 -2
  72. package/dist/tools/atf-contracts.js.map +1 -1
  73. package/dist/tools/atf-renderers.js +2 -1
  74. package/dist/tools/atf-renderers.js.map +1 -1
  75. package/dist/tools/atf-results-module.d.ts.map +1 -1
  76. package/dist/tools/atf-results-module.js +5 -3
  77. package/dist/tools/atf-results-module.js.map +1 -1
  78. package/dist/tools/atf-run-module.js +3 -2
  79. package/dist/tools/atf-run-module.js.map +1 -1
  80. package/dist/tools/atf-shared.d.ts +6 -0
  81. package/dist/tools/atf-shared.d.ts.map +1 -1
  82. package/dist/tools/atf-shared.js +49 -10
  83. package/dist/tools/atf-shared.js.map +1 -1
  84. package/dist/tools/atf-step-catalog.d.ts +13 -8
  85. package/dist/tools/atf-step-catalog.d.ts.map +1 -1
  86. package/dist/tools/atf-step-catalog.js +169 -5
  87. package/dist/tools/atf-step-catalog.js.map +1 -1
  88. package/dist/tools/batch.d.ts.map +1 -1
  89. package/dist/tools/batch.js +4 -2
  90. package/dist/tools/batch.js.map +1 -1
  91. package/dist/tools/flow-view-contracts.d.ts +57 -1
  92. package/dist/tools/flow-view-contracts.d.ts.map +1 -1
  93. package/dist/tools/flow-view-contracts.js +34 -2
  94. package/dist/tools/flow-view-contracts.js.map +1 -1
  95. package/dist/tools/flow-view-graph.d.ts +14 -0
  96. package/dist/tools/flow-view-graph.d.ts.map +1 -1
  97. package/dist/tools/flow-view-graph.js +43 -1
  98. package/dist/tools/flow-view-graph.js.map +1 -1
  99. package/dist/tools/flow-view-module.js +1 -1
  100. package/dist/tools/flow-view-module.js.map +1 -1
  101. package/dist/tools/flow-view-policy.d.ts +3 -3
  102. package/dist/tools/flow-view-policy.d.ts.map +1 -1
  103. package/dist/tools/flow-view-policy.js +5 -4
  104. package/dist/tools/flow-view-policy.js.map +1 -1
  105. package/dist/tools/flow-view-renderers.d.ts.map +1 -1
  106. package/dist/tools/flow-view-renderers.js +9 -21
  107. package/dist/tools/flow-view-renderers.js.map +1 -1
  108. package/dist/tools/index.d.ts.map +1 -1
  109. package/dist/tools/index.js +80 -13
  110. package/dist/tools/index.js.map +1 -1
  111. package/dist/tools/platform-view-contracts.d.ts +189 -0
  112. package/dist/tools/platform-view-contracts.d.ts.map +1 -0
  113. package/dist/tools/platform-view-contracts.js +353 -0
  114. package/dist/tools/platform-view-contracts.js.map +1 -0
  115. package/dist/tools/platform-view-evaluate.d.ts +11 -0
  116. package/dist/tools/platform-view-evaluate.d.ts.map +1 -0
  117. package/dist/tools/platform-view-evaluate.js +19 -0
  118. package/dist/tools/platform-view-evaluate.js.map +1 -0
  119. package/dist/tools/platform-view-module.d.ts +28 -0
  120. package/dist/tools/platform-view-module.d.ts.map +1 -0
  121. package/dist/tools/platform-view-module.js +111 -0
  122. package/dist/tools/platform-view-module.js.map +1 -0
  123. package/dist/tools/platform-view-scan.d.ts +57 -0
  124. package/dist/tools/platform-view-scan.d.ts.map +1 -0
  125. package/dist/tools/platform-view-scan.js +375 -0
  126. package/dist/tools/platform-view-scan.js.map +1 -0
  127. package/dist/tools/platform-view-upgrades.d.ts +152 -0
  128. package/dist/tools/platform-view-upgrades.d.ts.map +1 -0
  129. package/dist/tools/platform-view-upgrades.js +545 -0
  130. package/dist/tools/platform-view-upgrades.js.map +1 -0
  131. package/dist/tools/profile.d.ts.map +1 -1
  132. package/dist/tools/profile.js +1 -0
  133. package/dist/tools/profile.js.map +1 -1
  134. package/dist/tools/query-module.js +1 -1
  135. package/dist/tools/query-module.js.map +1 -1
  136. package/dist/tools/record-write-shared.d.ts.map +1 -1
  137. package/dist/tools/record-write-shared.js +4 -3
  138. package/dist/tools/record-write-shared.js.map +1 -1
  139. package/dist/tools/result-envelope.d.ts +116 -36
  140. package/dist/tools/result-envelope.d.ts.map +1 -1
  141. package/dist/tools/result-envelope.js +38 -3
  142. package/dist/tools/result-envelope.js.map +1 -1
  143. package/dist/tools/syslog-cursor.d.ts +61 -0
  144. package/dist/tools/syslog-cursor.d.ts.map +1 -0
  145. package/dist/tools/syslog-cursor.js +146 -0
  146. package/dist/tools/syslog-cursor.js.map +1 -0
  147. package/dist/tools/syslog.d.ts +2 -0
  148. package/dist/tools/syslog.d.ts.map +1 -1
  149. package/dist/tools/syslog.js +126 -2
  150. package/dist/tools/syslog.js.map +1 -1
  151. package/dist/update-set-eval/secret-patterns.d.ts +75 -0
  152. package/dist/update-set-eval/secret-patterns.d.ts.map +1 -0
  153. package/dist/update-set-eval/secret-patterns.js +570 -0
  154. package/dist/update-set-eval/secret-patterns.js.map +1 -0
  155. package/dist/update-set-eval/xml-reader.d.ts +117 -0
  156. package/dist/update-set-eval/xml-reader.d.ts.map +1 -0
  157. package/dist/update-set-eval/xml-reader.js +561 -0
  158. package/dist/update-set-eval/xml-reader.js.map +1 -0
  159. package/dist/version.d.ts +1 -1
  160. package/dist/version.js +1 -1
  161. package/docs/FLOW-VIEW.md +14 -5
  162. package/docs/PRODUCTION-SECURITY.md +63 -0
  163. package/package.json +1 -1
  164. package/server.json +2 -2
@@ -0,0 +1,375 @@
1
+ "use strict";
2
+ /**
3
+ * `sn_platform_view`, view `scan_findings`: the findings of one Instance Scan
4
+ * result, by check and as rows.
5
+ *
6
+ * Reads, each in its own response scope and never cached:
7
+ * 1. `scan_result`: the result (a given sys_id, or the latest complete one,
8
+ * chosen from the ten most recent) and its header;
9
+ * 2. `scan_finding`, together: one Aggregate API call grouped on `check`, and
10
+ * one page of the finding rows, both under the same filter;
11
+ * 3. `scan_check`: names, categories and priorities of the checks the groups
12
+ * and rows name, in chunks of at most 100 ids (a check is looked up by
13
+ * sys_id only). At most three chunks, read together.
14
+ *
15
+ * A `category`, `priority` or check-name filter is a dot-walk from the finding
16
+ * to its check (`check.category=...`). That reads `scan_check`, which is in the
17
+ * view's plan, and the filter is string equality: `category` and `priority`
18
+ * are String fields, not choice lists.
19
+ *
20
+ * Never requested, in any `sysparm_fields`, query or group: `finding_details`,
21
+ * `scan_finding.task`, `scan_finding.user`, `scan_check.script` and
22
+ * `scan_result.message`. A row the instance returns anyway is projected to the
23
+ * view's own fields, so these cannot reach the output.
24
+ *
25
+ * @module tools/platform-view-scan
26
+ */
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.handleScanFindings = exports.SCAN_UNAVAILABLE_HINT = exports.SCAN_DENIED_HINT = exports.SCAN_FINDINGS_FIELD_PLAN = exports.SCAN_CHECK_FIELDS = exports.SCAN_FINDING_FIELDS = exports.SCAN_RESULT_FIELDS = void 0;
29
+ exports.createScanFindingsHandler = createScanFindingsHandler;
30
+ exports.renderScanFindingsText = renderScanFindingsText;
31
+ const metadata_cache_js_1 = require("../metadata-cache.js");
32
+ const platform_view_upgrades_js_1 = require("./platform-view-upgrades.js");
33
+ const markdown_js_1 = require("./markdown.js");
34
+ /** Never `message`. */
35
+ exports.SCAN_RESULT_FIELDS = Object.freeze(["sys_id", "number", "state", "finding_count", "scan_type", "sys_created_on"]);
36
+ /** Never `finding_details`, `task` or `user`. */
37
+ exports.SCAN_FINDING_FIELDS = Object.freeze(["sys_id", "check", "source_table", "source", "count", "muted"]);
38
+ /** Never `script`. */
39
+ exports.SCAN_CHECK_FIELDS = Object.freeze(["sys_id", "name", "category", "priority", "short_description"]);
40
+ /**
41
+ * Every field this view may request or filter on, by table: what the module
42
+ * prepares in `resolveAccess` (intersected with what the profile may read; a
43
+ * field that is not readable is left out, never an error). `scan_finding.result`
44
+ * is filtered on, not requested.
45
+ */
46
+ exports.SCAN_FINDINGS_FIELD_PLAN = Object.freeze({
47
+ scan_result: exports.SCAN_RESULT_FIELDS,
48
+ scan_finding: [...exports.SCAN_FINDING_FIELDS, "result"],
49
+ scan_check: exports.SCAN_CHECK_FIELDS,
50
+ });
51
+ const RESULT_REQUIRED = Object.freeze(["sys_id", "state"]);
52
+ const FINDING_REQUIRED = Object.freeze(["sys_id", "check", "result"]);
53
+ /** The newest results read to find the latest complete one. */
54
+ const RECENT_RESULTS = 10;
55
+ /** Groups read from the Aggregate API, and checks shown from them. */
56
+ const MAX_GROUPS = 1_000;
57
+ const BY_CHECK_SHOWN = 25;
58
+ /** Check ids per `scan_check` read. */
59
+ const CHECK_CHUNK = 100;
60
+ exports.SCAN_DENIED_HINT = "Reading Instance Scan results was denied for this account.";
61
+ exports.SCAN_UNAVAILABLE_HINT = "Instance Scan is not available on this instance: its tables were not found.";
62
+ function isCompleteState(state) {
63
+ return state !== undefined && state.trim().toLowerCase().startsWith("complete");
64
+ }
65
+ function projectResult(row) {
66
+ const id = (0, platform_view_upgrades_js_1.scalar)(row.sys_id)?.trim().toLowerCase();
67
+ if (id === undefined || !platform_view_upgrades_js_1.SYS_ID.test(id))
68
+ return undefined;
69
+ const number = (0, platform_view_upgrades_js_1.cleanText)(row.number, 80);
70
+ const state = (0, platform_view_upgrades_js_1.cleanText)(row.state, 40);
71
+ const created = (0, platform_view_upgrades_js_1.cleanText)(row.sys_created_on, 40);
72
+ const type = (0, platform_view_upgrades_js_1.cleanText)(row.scan_type, 40);
73
+ const count = (0, platform_view_upgrades_js_1.wholeNumber)(row.finding_count);
74
+ return {
75
+ sys_id: id,
76
+ ...(number === undefined ? {} : { number }),
77
+ ...(state === undefined ? {} : { state }),
78
+ ...(count === undefined ? {} : { finding_count: count }),
79
+ ...(type === undefined ? {} : { scan_type: type }),
80
+ ...(created === undefined ? {} : { created }),
81
+ };
82
+ }
83
+ /** `[{check, findings, occurrences?}]` from an Aggregate API response, largest first. */
84
+ function checkGroups(response, withSum) {
85
+ const result = response?.result;
86
+ const groups = Array.isArray(result) ? result : typeof result === "object" && result !== null ? [result] : [];
87
+ const out = [];
88
+ for (const entry of groups) {
89
+ const group = (0, platform_view_upgrades_js_1.asRecord)(entry);
90
+ const fields = Array.isArray(group.groupby_fields) ? group.groupby_fields : [];
91
+ const keyed = fields.map(platform_view_upgrades_js_1.asRecord).find((field) => (0, platform_view_upgrades_js_1.scalar)(field.field) === "check");
92
+ const check = (0, platform_view_upgrades_js_1.scalar)(keyed?.value)?.trim().toLowerCase();
93
+ const stats = (0, platform_view_upgrades_js_1.asRecord)(group.stats);
94
+ const findings = (0, platform_view_upgrades_js_1.wholeNumber)(stats.count);
95
+ if (check === undefined || !platform_view_upgrades_js_1.SYS_ID.test(check) || findings === undefined)
96
+ continue;
97
+ const occurrences = withSum ? (0, platform_view_upgrades_js_1.wholeNumber)((0, platform_view_upgrades_js_1.asRecord)(stats.sum).count) : undefined;
98
+ out.push({ check, findings, ...(occurrences === undefined ? {} : { occurrences }) });
99
+ }
100
+ return out.sort((a, b) => b.findings - a.findings || (a.check < b.check ? -1 : 1));
101
+ }
102
+ /**
103
+ * Build the `view: "scan_findings"` handler. `handleScanFindings` is the one
104
+ * the module registers; a test builds its own with a fixed field access.
105
+ */
106
+ function createScanFindingsHandler(defaults = {}) {
107
+ return async (args, services, fieldAccess) => {
108
+ const access = (0, platform_view_upgrades_js_1.memoizedFieldAccess)(fieldAccess ?? defaults.fieldAccess ?? platform_view_upgrades_js_1.liveFieldAccess);
109
+ const ops = (0, metadata_cache_js_1.uncachedOperations)(services.serviceNow);
110
+ const signal = services.context?.signal;
111
+ const denied = (hint, status = "denied") => (0, platform_view_upgrades_js_1.viewResult)(args, { view: "scan_findings", status, hint });
112
+ // A filter, order or group on a field the profile cannot read would tell it
113
+ // something about that field, so every field this view queries must be readable.
114
+ const filterFields = {
115
+ scan_finding: [
116
+ ...FINDING_REQUIRED,
117
+ ...(args.include_muted === true ? [] : ["muted"]),
118
+ ...(args.source_table === undefined ? [] : ["source_table"]),
119
+ ],
120
+ scan_check: [
121
+ ...(args.check !== undefined && !platform_view_upgrades_js_1.SYS_ID.test(args.check) ? ["name"] : []),
122
+ ...(args.category === undefined ? [] : ["category"]),
123
+ ...(args.priority === undefined ? [] : ["priority"]),
124
+ ],
125
+ };
126
+ if (
127
+ // "Latest" sorts on `sys_created_on`; a named result does not.
128
+ (0, platform_view_upgrades_js_1.firstUnreadable)(access, "scan_result", [
129
+ ...RESULT_REQUIRED,
130
+ ...(args.result === undefined || args.result === "latest" ? ["sys_created_on"] : []),
131
+ ]) !== undefined ||
132
+ (0, platform_view_upgrades_js_1.firstUnreadable)(access, "scan_finding", filterFields.scan_finding) !== undefined ||
133
+ (0, platform_view_upgrades_js_1.firstUnreadable)(access, "scan_check", filterFields.scan_check) !== undefined) {
134
+ return denied(platform_view_upgrades_js_1.FIELD_POLICY_HINT);
135
+ }
136
+ // 1. The result.
137
+ const selected = args.result !== undefined && args.result !== "latest" ? args.result : undefined;
138
+ let resultRows;
139
+ try {
140
+ resultRows = (0, platform_view_upgrades_js_1.rowsOf)(await (0, platform_view_upgrades_js_1.inOwnScope)(signal, () => ops.get(`${platform_view_upgrades_js_1.TABLE_PATH}scan_result`, (0, platform_view_upgrades_js_1.listParams)({
141
+ fields: (0, platform_view_upgrades_js_1.readableOf)(access, "scan_result", exports.SCAN_RESULT_FIELDS),
142
+ query: selected === undefined ? "ORDERBYDESCsys_created_on" : `sys_id=${selected}`,
143
+ limit: selected === undefined ? RECENT_RESULTS : 1,
144
+ }))));
145
+ }
146
+ catch (error) {
147
+ if ((0, platform_view_upgrades_js_1.errorCategory)(error) === "authorization")
148
+ return denied(exports.SCAN_DENIED_HINT);
149
+ if ((0, platform_view_upgrades_js_1.isMissingTable)(error))
150
+ return denied(exports.SCAN_UNAVAILABLE_HINT, "unavailable");
151
+ throw error;
152
+ }
153
+ const resultFields = (0, platform_view_upgrades_js_1.readableOf)(access, "scan_result", exports.SCAN_RESULT_FIELDS);
154
+ const recent = resultRows
155
+ .map((row) => projectResult((0, platform_view_upgrades_js_1.readableRow)(access, "scan_result", row, resultFields)))
156
+ .filter((row) => row !== undefined);
157
+ const chosen = selected === undefined ? recent.find((row) => isCompleteState((0, platform_view_upgrades_js_1.scalar)(row.state))) : recent[0];
158
+ if (chosen === undefined) {
159
+ return (0, platform_view_upgrades_js_1.viewResult)(args, {
160
+ view: "scan_findings",
161
+ status: "ok",
162
+ summary: {
163
+ result: null,
164
+ ...(selected === undefined && recent.length > 0 ? { recent_results: recent.slice(0, 5) } : {}),
165
+ },
166
+ results: [],
167
+ hint: selected === undefined
168
+ ? "No complete scan result was found among the most recent ones. Pass result: <sys_id> to read one."
169
+ : "No scan result matches the given sys_id.",
170
+ });
171
+ }
172
+ const resultId = (0, platform_view_upgrades_js_1.scalar)(chosen.sys_id) ?? "";
173
+ // 2. The findings, grouped by check and as rows, under one filter.
174
+ const clauses = [`result=${resultId}`];
175
+ if (args.include_muted !== true)
176
+ clauses.push("muted=false");
177
+ if (args.source_table !== undefined)
178
+ clauses.push(`source_table=${args.source_table}`);
179
+ if (args.check !== undefined) {
180
+ clauses.push(platform_view_upgrades_js_1.SYS_ID.test(args.check.toLowerCase()) ? `check=${args.check.toLowerCase()}` : `check.name=${args.check}`);
181
+ }
182
+ if (args.category !== undefined)
183
+ clauses.push(`check.category=${args.category}`);
184
+ if (args.priority !== undefined)
185
+ clauses.push(`check.priority=${args.priority}`);
186
+ const filter = clauses.join("^");
187
+ const sumCount = access.canRead("scan_finding", "count");
188
+ const order = `${sumCount ? "^ORDERBYDESCcount" : ""}^ORDERBYsys_id`;
189
+ let groups;
190
+ let findingRows;
191
+ try {
192
+ [groups, findingRows] = await Promise.all([
193
+ (0, platform_view_upgrades_js_1.inOwnScope)(signal, () => ops.get(`${platform_view_upgrades_js_1.STATS_PATH}scan_finding`, {
194
+ sysparm_query: filter,
195
+ sysparm_group_by: "check",
196
+ sysparm_count: "true",
197
+ ...(sumCount ? { sysparm_sum_fields: "count" } : {}),
198
+ sysparm_limit: String(MAX_GROUPS + 1),
199
+ })).then((response) => checkGroups(response, sumCount)),
200
+ (0, platform_view_upgrades_js_1.inOwnScope)(signal, () => ops.get(`${platform_view_upgrades_js_1.TABLE_PATH}scan_finding`, (0, platform_view_upgrades_js_1.listParams)({
201
+ fields: (0, platform_view_upgrades_js_1.readableOf)(access, "scan_finding", exports.SCAN_FINDING_FIELDS),
202
+ query: `${filter}${order}`,
203
+ limit: args.limit + 1,
204
+ offset: args.offset,
205
+ }))).then(platform_view_upgrades_js_1.rowsOf),
206
+ ]);
207
+ }
208
+ catch (error) {
209
+ if ((0, platform_view_upgrades_js_1.errorCategory)(error) === "authorization")
210
+ return denied(exports.SCAN_DENIED_HINT);
211
+ throw error;
212
+ }
213
+ const groupsTruncated = groups.length > MAX_GROUPS;
214
+ const allGroups = groups.slice(0, MAX_GROUPS);
215
+ const shownGroups = allGroups.slice(0, BY_CHECK_SHOWN);
216
+ const { page, hasMore } = (0, platform_view_upgrades_js_1.pageOf)(findingRows, args.limit);
217
+ const findingFields = (0, platform_view_upgrades_js_1.readableOf)(access, "scan_finding", exports.SCAN_FINDING_FIELDS);
218
+ const rows = page.map((row) => (0, platform_view_upgrades_js_1.readableRow)(access, "scan_finding", row, findingFields));
219
+ // 3. The checks those name.
220
+ const wanted = new Set(shownGroups.map((group) => group.check));
221
+ for (const row of rows) {
222
+ const id = (0, platform_view_upgrades_js_1.scalar)(row.check)?.trim().toLowerCase();
223
+ if (id !== undefined && platform_view_upgrades_js_1.SYS_ID.test(id))
224
+ wanted.add(id);
225
+ }
226
+ const details = new Map();
227
+ const warnings = [];
228
+ const checkFields = (0, platform_view_upgrades_js_1.readableOf)(access, "scan_check", exports.SCAN_CHECK_FIELDS);
229
+ // Without `sys_id` a row cannot be matched to its check, and an empty
230
+ // projection would mean every field (`script` among them): read nothing.
231
+ const ids = checkFields.includes("sys_id") ? [...wanted] : [];
232
+ const chunks = [];
233
+ for (let start = 0; start < ids.length; start += CHECK_CHUNK)
234
+ chunks.push(ids.slice(start, start + CHECK_CHUNK));
235
+ try {
236
+ // At most three chunks, read together; `Promise.all` keeps their order,
237
+ // so the result does not depend on which read finishes first.
238
+ const perChunk = await Promise.all(chunks.map((chunk) => (0, platform_view_upgrades_js_1.inOwnScope)(signal, () => ops.get(`${platform_view_upgrades_js_1.TABLE_PATH}scan_check`, (0, platform_view_upgrades_js_1.listParams)({ fields: checkFields, query: `sys_idIN${chunk.join(",")}`, limit: chunk.length }))).then(platform_view_upgrades_js_1.rowsOf)));
239
+ for (const checkRows of perChunk) {
240
+ for (const raw of checkRows) {
241
+ const row = (0, platform_view_upgrades_js_1.readableRow)(access, "scan_check", raw, checkFields);
242
+ const id = (0, platform_view_upgrades_js_1.scalar)(row.sys_id)?.trim().toLowerCase();
243
+ if (id === undefined || !platform_view_upgrades_js_1.SYS_ID.test(id))
244
+ continue;
245
+ const name = (0, platform_view_upgrades_js_1.cleanText)(row.name, 100);
246
+ const category = (0, platform_view_upgrades_js_1.cleanText)(row.category, 40);
247
+ const priority = (0, platform_view_upgrades_js_1.cleanText)(row.priority, 40);
248
+ const short = (0, platform_view_upgrades_js_1.cleanText)(row.short_description, 120);
249
+ details.set(id, {
250
+ ...(name === undefined ? {} : { name }),
251
+ ...(category === undefined ? {} : { category }),
252
+ ...(priority === undefined ? {} : { priority }),
253
+ ...(short === undefined ? {} : { short_description: short }),
254
+ });
255
+ }
256
+ }
257
+ }
258
+ catch (error) {
259
+ if ((0, platform_view_upgrades_js_1.errorCategory)(error) !== "authorization")
260
+ throw error;
261
+ warnings.push("Check details were not readable; checks are shown by sys_id.");
262
+ }
263
+ const byCheck = shownGroups.map((group) => ({
264
+ check: group.check,
265
+ ...details.get(group.check),
266
+ findings: group.findings,
267
+ ...(group.occurrences === undefined ? {} : { occurrences: group.occurrences }),
268
+ }));
269
+ const results = rows.flatMap((row) => {
270
+ const id = (0, platform_view_upgrades_js_1.scalar)(row.sys_id)?.trim().toLowerCase();
271
+ if (id === undefined || !platform_view_upgrades_js_1.SYS_ID.test(id))
272
+ return [];
273
+ const check = (0, platform_view_upgrades_js_1.scalar)(row.check)?.trim().toLowerCase();
274
+ const name = check === undefined ? undefined : details.get(check)?.name;
275
+ const sourceTable = (0, platform_view_upgrades_js_1.cleanText)(row.source_table, 80);
276
+ const source = (0, platform_view_upgrades_js_1.cleanText)(row.source, 32);
277
+ const count = (0, platform_view_upgrades_js_1.wholeNumber)(row.count);
278
+ const muted = (0, platform_view_upgrades_js_1.flag)(row.muted);
279
+ return [
280
+ {
281
+ sys_id: id,
282
+ ...(check === undefined ? {} : { check }),
283
+ ...(name === undefined ? {} : { check_name: name }),
284
+ ...(sourceTable === undefined ? {} : { source_table: sourceTable }),
285
+ ...(source === undefined ? {} : { source }),
286
+ ...(count === undefined ? {} : { count }),
287
+ ...(muted === undefined ? {} : { muted }),
288
+ },
289
+ ];
290
+ });
291
+ if (groupsTruncated)
292
+ warnings.push(`More than ${MAX_GROUPS} checks have findings; the totals cover the first ${MAX_GROUPS}.`);
293
+ const totalFindings = allGroups.reduce((sum, group) => sum + group.findings, 0);
294
+ return (0, platform_view_upgrades_js_1.viewResult)(args, {
295
+ view: "scan_findings",
296
+ status: "ok",
297
+ summary: {
298
+ result: chosen,
299
+ filters: {
300
+ include_muted: args.include_muted === true,
301
+ ...(args.check === undefined ? {} : { check: args.check }),
302
+ ...(args.category === undefined ? {} : { category: args.category }),
303
+ ...(args.priority === undefined ? {} : { priority: args.priority }),
304
+ ...(args.source_table === undefined ? {} : { source_table: args.source_table }),
305
+ },
306
+ totals: { findings: totalFindings, checks: allGroups.length },
307
+ by_check: byCheck,
308
+ ...(allGroups.length > shownGroups.length ? { by_check_truncated: true } : {}),
309
+ },
310
+ results,
311
+ record_count: results.length,
312
+ has_more: hasMore,
313
+ ...(hasMore ? { next_offset: args.offset + page.length } : {}),
314
+ ...(warnings.length > 0 ? { warnings } : {}),
315
+ });
316
+ };
317
+ }
318
+ /** The handler the dispatcher registers. */
319
+ exports.handleScanFindings = createScanFindingsHandler();
320
+ // ---------------------------------------------------------------------------
321
+ // Text
322
+ // ---------------------------------------------------------------------------
323
+ function shown(value) {
324
+ return (0, platform_view_upgrades_js_1.scalar)(value) ?? "-";
325
+ }
326
+ /**
327
+ * The readable text of a `scan_findings` result. Every value is instance text:
328
+ * names and categories are escaped table cells, check descriptions and the
329
+ * finding rows sit inside an `untrustedBlock`.
330
+ */
331
+ function renderScanFindingsText(data) {
332
+ const record = (0, platform_view_upgrades_js_1.asRecord)(data);
333
+ if (record.view !== "scan_findings")
334
+ return undefined;
335
+ const summary = (0, platform_view_upgrades_js_1.asRecord)(record.summary);
336
+ if (record.status !== "ok") {
337
+ return (0, markdown_js_1.renderMarkdown)((0, markdown_js_1.headline)("Instance Scan", { status: "fail", detail: (0, platform_view_upgrades_js_1.scalar)(record.hint) ?? "not available" }));
338
+ }
339
+ const result = (0, platform_view_upgrades_js_1.asRecord)(summary.result);
340
+ if (summary.result === null || Object.keys(result).length === 0) {
341
+ return (0, markdown_js_1.renderMarkdown)((0, markdown_js_1.headline)("Instance Scan findings", { status: "warn", detail: "no result" }), (0, platform_view_upgrades_js_1.scalar)(record.hint) === undefined ? undefined : (0, markdown_js_1.text)((0, platform_view_upgrades_js_1.scalar)(record.hint)));
342
+ }
343
+ const totals = (0, platform_view_upgrades_js_1.asRecord)(summary.totals);
344
+ const blocks = [
345
+ (0, markdown_js_1.headline)("Instance Scan findings", {
346
+ status: "pass",
347
+ detail: `${shown(result.number)} (${shown(result.state)}), ${shown(totals.findings)} findings in ${shown(totals.checks)} checks`,
348
+ }),
349
+ ];
350
+ const byCheck = Array.isArray(summary.by_check) ? summary.by_check.map(platform_view_upgrades_js_1.asRecord) : [];
351
+ blocks.push((0, markdown_js_1.table)(["Check", "Category", "Priority", "Findings", "Occurrences"], byCheck.map((entry) => [
352
+ (0, platform_view_upgrades_js_1.scalar)(entry.name) ?? shown(entry.check),
353
+ shown(entry.category),
354
+ shown(entry.priority),
355
+ shown(entry.findings),
356
+ shown(entry.occurrences),
357
+ ])));
358
+ const described = byCheck.filter((entry) => (0, platform_view_upgrades_js_1.scalar)(entry.short_description) !== undefined);
359
+ if (described.length > 0) {
360
+ blocks.push((0, markdown_js_1.untrustedBlock)("Check descriptions", described.map((entry) => `${(0, platform_view_upgrades_js_1.scalar)(entry.name) ?? shown(entry.check)}: ${shown(entry.short_description)}`).join("\n")));
361
+ }
362
+ if (summary.by_check_truncated === true)
363
+ blocks.push((0, markdown_js_1.text)("Only the checks with the most findings are listed."));
364
+ const rows = Array.isArray(record.results) ? record.results.map(platform_view_upgrades_js_1.asRecord) : [];
365
+ blocks.push((0, markdown_js_1.untrustedBlock)("Findings (check | source table | source | count | muted)", rows
366
+ .map((row) => `${(0, platform_view_upgrades_js_1.scalar)(row.check_name) ?? shown(row.check)} | ${shown(row.source_table)} | ${shown(row.source)} | ${shown(row.count)} | ${shown(row.muted)}`)
367
+ .join("\n")));
368
+ if (record.has_more === true)
369
+ blocks.push((0, markdown_js_1.text)(`More rows: next_offset ${shown(record.next_offset)}.`));
370
+ const warnings = Array.isArray(record.warnings) ? record.warnings : [];
371
+ if (warnings.length > 0)
372
+ blocks.push((0, markdown_js_1.bulletList)(warnings.map((warning) => String((0, platform_view_upgrades_js_1.scalar)(warning) ?? ""))));
373
+ return (0, markdown_js_1.renderMarkdown)(...blocks);
374
+ }
375
+ //# sourceMappingURL=platform-view-scan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform-view-scan.js","sourceRoot":"","sources":["../../src/tools/platform-view-scan.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;;AAwHH,8DA2OC;AAkBD,wDA4DC;AA5aD,4DAA0D;AAC1D,2EAwBqC;AAErC,+CAAyH;AAGzH,uBAAuB;AACV,QAAA,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAC/H,iDAAiD;AACpC,QAAA,mBAAmB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;AAClH,sBAAsB;AACT,QAAA,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,mBAAmB,CAAC,CAAC,CAAC;AAEhH;;;;;GAKG;AACU,QAAA,wBAAwB,GAAgD,MAAM,CAAC,MAAM,CAAC;IACjG,WAAW,EAAE,0BAAkB;IAC/B,YAAY,EAAE,CAAC,GAAG,2BAAmB,EAAE,QAAQ,CAAC;IAChD,UAAU,EAAE,yBAAiB;CAC9B,CAAC,CAAC;AAEH,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;AAC3D,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC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Ac,EAAC,GAAG,MAAM,CAAC,CAAC;AACnC,CAAC"}
@@ -0,0 +1,152 @@
1
+ /**
2
+ * `sn_platform_view`, view `upgrade_skipped`: the skipped files of one upgrade
3
+ * run, and what the run's own counters say.
4
+ *
5
+ * Reads, in this order, each in its own response scope and never cached:
6
+ * 1. `sys_upgrade_history`: the run (a given sys_id, or the latest of its
7
+ * `kind`) and, for "latest", up to five other recent runs, in one read;
8
+ * 2. `sys_upgrade_history_log`: the page of skipped files of that run, with
9
+ * dispositions in {4, 9, 10, 11, 104} only. A 403 here is not an error: the
10
+ * run summary is returned with `log: "denied"` and a fixed hint that names
11
+ * the `upgrade_admin` role;
12
+ * 3. `sys_choice`: the labels of the dispositions. Its query is fixed, so it
13
+ * starts together with the log read, and its answer is used only when log
14
+ * rows come back. It cannot fail the call: without it, codes are `unknown(n)`.
15
+ *
16
+ * The run's counters are exactly `skipped`, `skipped_error`,
17
+ * `skipped_manual_merge` and `skipped_apply_once`. `kind` is a heuristic: a
18
+ * run whose `from_version` is empty or "n/a" is an app install, anything else
19
+ * an upgrade, and the result says so.
20
+ *
21
+ * Never requested: `payload`, `payload_diff`, `comments`, `file_path`.
22
+ * Every row passes the field access the module supplies (see
23
+ * `PlatformViewFieldAccess`) before it is projected.
24
+ *
25
+ * Text: instance strings are bounded here and rendered by
26
+ * `renderUpgradeSkippedText` through `markdown.ts` (escaped cells and an
27
+ * `untrustedBlock`), never concatenated.
28
+ *
29
+ * @module tools/platform-view-upgrades
30
+ */
31
+ import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
32
+ import { type ToolErrorCategory } from "../tool-error.js";
33
+ import { type CanonicalPlatformViewArgs, type PlatformViewData, UPGRADE_KINDS } from "./platform-view-contracts.js";
34
+ import type { ServiceNowToolHandlerServices } from "./tool-module.js";
35
+ /**
36
+ * What a view needs from field policy, supplied by the module per call:
37
+ * - `canRead(table, field)`: whether the profile may read the field. A view
38
+ * asks for, filters on and orders by readable fields only, so an unreadable
39
+ * field is never an oracle.
40
+ * - `filter(table, row)`: the row with only its readable fields. Every row an
41
+ * upstream read returns passes through it before it is projected.
42
+ *
43
+ * The module builds it from the call's prepared field arguments
44
+ * (`preparedReadableFields` and `filterReadableRecord`) and passes it as the
45
+ * handler's third argument. Without it a handler falls back to
46
+ * `liveFieldAccess`, which asks the field policy of the current scope.
47
+ */
48
+ export interface PlatformViewFieldAccess {
49
+ canRead(table: string, field: string): boolean;
50
+ filter(table: string, row: Readonly<Record<string, unknown>>): Record<string, unknown>;
51
+ }
52
+ /**
53
+ * A view handler as the dispatcher's `PlatformViewHandler`, plus the module's
54
+ * field access as an optional third argument. Assignable to `PlatformViewHandler`.
55
+ */
56
+ export type FieldAccessHandler = (args: CanonicalPlatformViewArgs, services: ServiceNowToolHandlerServices, fieldAccess?: PlatformViewFieldAccess) => Promise<CallToolResult>;
57
+ /** The current scope's field policy, for a handler the module has not given an access. */
58
+ export declare const liveFieldAccess: PlatformViewFieldAccess;
59
+ /** A per-call memo of `canRead`: a view asks about the same field many times. */
60
+ export declare function memoizedFieldAccess(access: PlatformViewFieldAccess): PlatformViewFieldAccess;
61
+ /**
62
+ * One upstream row, as the view may show it: it passes the module's `filter`,
63
+ * then only the fields the view asked for stay, so a field the instance
64
+ * returned unasked (or the policy hid after the request) never reaches a
65
+ * projection.
66
+ */
67
+ export declare function readableRow(access: PlatformViewFieldAccess, table: string, row: Readonly<Record<string, unknown>>, asked: readonly string[]): Record<string, unknown>;
68
+ /** The fields of `candidates` the profile may read on `table`, in order. */
69
+ export declare function readableOf(access: PlatformViewFieldAccess, table: string, candidates: readonly string[]): string[];
70
+ export declare const TABLE_PATH = "/api/now/table/";
71
+ export declare const STATS_PATH = "/api/now/stats/";
72
+ export declare const SYS_ID: RegExp;
73
+ /** Rows of a Table API response, or none. */
74
+ export declare function rowsOf(response: unknown): Record<string, unknown>[];
75
+ /** A field value as text: a string, or the `value` of a `{value, display_value}` pair. */
76
+ export declare function scalar(value: unknown, depth?: number): string | undefined;
77
+ /** Instance text: control characters replaced, trimmed, cut at `max` without splitting a surrogate pair. */
78
+ export declare function cleanText(value: unknown, max: number): string | undefined;
79
+ /** A whole number from a string field, or undefined. */
80
+ export declare function wholeNumber(value: unknown): number | undefined;
81
+ /** A boolean field. */
82
+ export declare function flag(value: unknown): boolean | undefined;
83
+ /** The category of an issued tool error, or undefined for anything else. */
84
+ export declare function errorCategory(error: unknown): ToolErrorCategory | undefined;
85
+ /**
86
+ * What the Table API returns (HTTP 400) for a table that does not exist: an
87
+ * issued `upstream` error with no retry and no reason. An error with a reason
88
+ * (an HTML page, a redirect, a hibernating instance) is a bad response, not a
89
+ * missing table.
90
+ */
91
+ export declare function isMissingTable(error: unknown): boolean;
92
+ /**
93
+ * Run `operation` in a fresh response scope bound to the call's signal, so one
94
+ * read's bytes do not count against the next one's 1 MiB allowance. Without a
95
+ * signal (a handler called directly) it runs in the caller's scope.
96
+ */
97
+ export declare function inOwnScope<T>(signal: AbortSignal | undefined, operation: () => Promise<T>): Promise<T>;
98
+ /** Parameters of one Table API list read. Raw values only: no display values, no links. */
99
+ export declare function listParams(options: {
100
+ readonly fields: readonly string[];
101
+ readonly query: string;
102
+ readonly limit: number;
103
+ readonly offset?: number;
104
+ }): Record<string, string>;
105
+ /** The first table in `table` that has none of `required` readable, as a field name; undefined when all are. */
106
+ export declare function firstUnreadable(access: PlatformViewFieldAccess, table: string, required: readonly string[]): string | undefined;
107
+ export declare const FIELD_POLICY_HINT = "Field policy hides a field this view needs.";
108
+ /** The result of a view. The envelope adds counts, paging and limits. */
109
+ export declare function viewResult(args: CanonicalPlatformViewArgs, data: PlatformViewData): CallToolResult;
110
+ /** One page of rows read with one look-ahead row: the page, and whether more exist. */
111
+ export declare function pageOf<T>(rows: readonly T[], limit: number): {
112
+ readonly page: T[];
113
+ readonly hasMore: boolean;
114
+ };
115
+ /** Dispositions of `sys_upgrade_history_log` that mean a file was skipped. */
116
+ export declare const SKIPPED_DISPOSITIONS: readonly [4, 9, 10, 11, 104];
117
+ /** The four run counters, and no other `skipped*` field. */
118
+ export declare const RUN_COUNTER_FIELDS: readonly ["skipped", "skipped_error", "skipped_manual_merge", "skipped_apply_once"];
119
+ export declare const RUN_FIELDS: readonly string[];
120
+ /** Never `payload`, `payload_diff`, `comments` or `file_path`. */
121
+ export declare const UPGRADE_LOG_FIELDS: readonly string[];
122
+ /**
123
+ * Every field this view may request or filter on, by table: what the module
124
+ * prepares in `resolveAccess` (intersected with what the profile may read; a
125
+ * field that is not readable is left out, never an error).
126
+ */
127
+ export declare const UPGRADE_SKIPPED_FIELD_PLAN: Readonly<Record<string, readonly string[]>>;
128
+ export declare const UPGRADE_LOG_DENIED_HINT = "Reading the upgrade log needs the `upgrade_admin` role.";
129
+ export declare const UPGRADE_HISTORY_DENIED_HINT = "Reading the upgrade history was denied for this account.";
130
+ export declare const KIND_BASIS = "Heuristic: a run whose from_version is empty or n/a is an app install; any other run is an upgrade.";
131
+ export type UpgradeKind = Exclude<(typeof UPGRADE_KINDS)[number], "all">;
132
+ /** A run's `kind`: an app install has no `from_version` (empty or "n/a"). */
133
+ export declare function upgradeKindOf(fromVersion: string | undefined): UpgradeKind;
134
+ /** The label of a disposition, from the choice list; `unknown(n)` when the list has none. */
135
+ export declare function dispositionLabel(value: number, labels: ReadonlyMap<number, string>): string;
136
+ /**
137
+ * Build the `view: "upgrade_skipped"` handler. `handleUpgradeSkipped` is the
138
+ * one the module registers; a test builds its own with a fixed field access.
139
+ */
140
+ export declare function createUpgradeSkippedHandler(defaults?: {
141
+ readonly fieldAccess?: PlatformViewFieldAccess;
142
+ }): FieldAccessHandler;
143
+ /** The handler the dispatcher registers. */
144
+ export declare const handleUpgradeSkipped: FieldAccessHandler;
145
+ export declare function asRecord(value: unknown): Record<string, unknown>;
146
+ /**
147
+ * The readable text of an `upgrade_skipped` result. `data` is the envelope's
148
+ * `data`; every value in it is instance text, so it reaches the output only as
149
+ * an escaped table cell, escaped inline text or inside an `untrustedBlock`.
150
+ */
151
+ export declare function renderUpgradeSkippedText(data: unknown): string | undefined;
152
+ //# sourceMappingURL=platform-view-upgrades.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform-view-upgrades.d.ts","sourceRoot":"","sources":["../../src/tools/platform-view-upgrades.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAMzE,OAAO,EAA+C,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAEvG,OAAO,EACL,KAAK,yBAAyB,EAC9B,KAAK,gBAAgB,EACrB,aAAa,EACd,MAAM,8BAA8B,CAAC;AAGtC,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC;AAMtE;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IAC/C,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACxF;AAED;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAC/B,IAAI,EAAE,yBAAyB,EAC/B,QAAQ,EAAE,6BAA6B,EACvC,WAAW,CAAC,EAAE,uBAAuB,KAClC,OAAO,CAAC,cAAc,CAAC,CAAC;AAE7B,0FAA0F;AAC1F,eAAO,MAAM,eAAe,EAAE,uBAe5B,CAAC;AAEH,iFAAiF;AACjF,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,uBAAuB,GAAG,uBAAuB,CAc5F;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,uBAAuB,EAC/B,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,QAAQ,CAAC,MAAM,CAA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