@onlyflows/servicenow-mcp 2.2.0-dev.5 → 2.2.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/.env.example +6 -3
- package/CHANGELOG.md +312 -0
- package/README.md +504 -101
- package/dist/atf-form.d.ts +3 -15
- package/dist/atf-form.d.ts.map +1 -1
- package/dist/atf-result-cache.d.ts +23 -59
- package/dist/atf-result-cache.d.ts.map +1 -1
- package/dist/auth.d.ts +1 -0
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +17 -0
- package/dist/auth.js.map +1 -1
- package/dist/batch-limits.d.ts +18 -0
- package/dist/batch-limits.d.ts.map +1 -0
- package/dist/batch-limits.js +21 -0
- package/dist/batch-limits.js.map +1 -0
- package/dist/bounded-input.d.ts +49 -0
- package/dist/bounded-input.d.ts.map +1 -0
- package/dist/bounded-input.js +81 -0
- package/dist/bounded-input.js.map +1 -0
- package/dist/client.d.ts +25 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +92 -18
- package/dist/client.js.map +1 -1
- package/dist/command-resolution.d.ts +53 -0
- package/dist/command-resolution.d.ts.map +1 -0
- package/dist/command-resolution.js +154 -0
- package/dist/command-resolution.js.map +1 -0
- package/dist/encoded-query-policy.d.ts +11 -0
- package/dist/encoded-query-policy.d.ts.map +1 -1
- package/dist/encoded-query-policy.js +10 -1
- package/dist/encoded-query-policy.js.map +1 -1
- package/dist/field-policy.d.ts +82 -3
- package/dist/field-policy.d.ts.map +1 -1
- package/dist/field-policy.js +609 -80
- package/dist/field-policy.js.map +1 -1
- package/dist/html-response.d.ts +34 -0
- package/dist/html-response.d.ts.map +1 -0
- package/dist/html-response.js +72 -0
- package/dist/html-response.js.map +1 -0
- package/dist/http-runtime.d.ts.map +1 -1
- package/dist/http-runtime.js +8 -0
- package/dist/http-runtime.js.map +1 -1
- package/dist/incident-journal-policy.d.ts +27 -5
- package/dist/incident-journal-policy.d.ts.map +1 -1
- package/dist/incident-journal-policy.js +34 -21
- package/dist/incident-journal-policy.js.map +1 -1
- package/dist/json-shape-limits.d.ts +71 -0
- package/dist/json-shape-limits.d.ts.map +1 -0
- package/dist/json-shape-limits.js +131 -0
- package/dist/json-shape-limits.js.map +1 -0
- package/dist/metadata-cache.d.ts +46 -21
- package/dist/metadata-cache.d.ts.map +1 -1
- package/dist/metadata-cache.js +228 -195
- package/dist/metadata-cache.js.map +1 -1
- package/dist/policy-card.d.ts +131 -0
- package/dist/policy-card.d.ts.map +1 -0
- package/dist/policy-card.js +409 -0
- package/dist/policy-card.js.map +1 -0
- package/dist/profile-admin.d.ts.map +1 -1
- package/dist/profile-admin.js +3 -0
- package/dist/profile-admin.js.map +1 -1
- package/dist/profile-manager.d.ts +17 -3
- package/dist/profile-manager.d.ts.map +1 -1
- package/dist/profile-manager.js +98 -6
- package/dist/profile-manager.js.map +1 -1
- package/dist/record-identifier-policy.d.ts +2 -8
- package/dist/record-identifier-policy.d.ts.map +1 -1
- package/dist/risky-grants.d.ts +25 -0
- package/dist/risky-grants.d.ts.map +1 -0
- package/dist/risky-grants.js +77 -0
- package/dist/risky-grants.js.map +1 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +74 -0
- package/dist/server.js.map +1 -1
- package/dist/setup-prompts.js +1 -0
- package/dist/setup-prompts.js.map +1 -1
- package/dist/setup.d.ts +8 -1
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +492 -111
- package/dist/setup.js.map +1 -1
- package/dist/stdio-runtime.d.ts +15 -0
- package/dist/stdio-runtime.d.ts.map +1 -1
- package/dist/stdio-runtime.js +60 -0
- package/dist/stdio-runtime.js.map +1 -1
- package/dist/structured-query.d.ts +100 -115
- package/dist/structured-query.d.ts.map +1 -1
- package/dist/structured-query.js +132 -16
- package/dist/structured-query.js.map +1 -1
- package/dist/table-policy.d.ts +10 -4
- package/dist/table-policy.d.ts.map +1 -1
- package/dist/table-policy.js +1 -1
- package/dist/table-policy.js.map +1 -1
- package/dist/tool-error.d.ts +18 -0
- package/dist/tool-error.d.ts.map +1 -1
- package/dist/tool-error.js +69 -0
- package/dist/tool-error.js.map +1 -1
- package/dist/tool-table-access.d.ts.map +1 -1
- package/dist/tool-table-access.js +32 -2
- package/dist/tool-table-access.js.map +1 -1
- package/dist/tools/aggregate.d.ts +13 -19
- package/dist/tools/aggregate.d.ts.map +1 -1
- package/dist/tools/aggregate.js +2 -3
- package/dist/tools/aggregate.js.map +1 -1
- package/dist/tools/all-fields-cap.d.ts.map +1 -1
- package/dist/tools/all-fields-cap.js +3 -38
- package/dist/tools/all-fields-cap.js.map +1 -1
- package/dist/tools/atf-author-module.d.ts +28 -7
- package/dist/tools/atf-author-module.d.ts.map +1 -1
- package/dist/tools/atf-author-module.js +4 -2
- package/dist/tools/atf-author-module.js.map +1 -1
- package/dist/tools/atf-contracts.d.ts +135 -829
- package/dist/tools/atf-contracts.d.ts.map +1 -1
- package/dist/tools/atf-shared.js +2 -2
- package/dist/tools/atf-shared.js.map +1 -1
- package/dist/tools/atf-step-catalog.d.ts +3 -7
- package/dist/tools/atf-step-catalog.d.ts.map +1 -1
- package/dist/tools/atf-step-catalog.js +12 -5
- package/dist/tools/atf-step-catalog.js.map +1 -1
- package/dist/tools/atf.d.ts +8 -24
- package/dist/tools/atf.d.ts.map +1 -1
- package/dist/tools/atf.js +2 -2
- package/dist/tools/atf.js.map +1 -1
- package/dist/tools/attach.d.ts +6 -22
- package/dist/tools/attach.d.ts.map +1 -1
- package/dist/tools/batch.d.ts +18 -71
- package/dist/tools/batch.d.ts.map +1 -1
- package/dist/tools/batch.js +544 -96
- package/dist/tools/batch.js.map +1 -1
- package/dist/tools/catalog.d.ts +2 -2
- package/dist/tools/catalog.d.ts.map +1 -1
- package/dist/tools/catalog.js +7 -1
- package/dist/tools/catalog.js.map +1 -1
- package/dist/tools/codesearch.d.ts +1 -13
- package/dist/tools/codesearch.d.ts.map +1 -1
- package/dist/tools/create-module.d.ts +9 -14
- package/dist/tools/create-module.d.ts.map +1 -1
- package/dist/tools/create-module.js +4 -8
- package/dist/tools/create-module.js.map +1 -1
- package/dist/tools/delete.d.ts +1 -9
- package/dist/tools/delete.d.ts.map +1 -1
- package/dist/tools/delete.js +2 -3
- package/dist/tools/delete.js.map +1 -1
- package/dist/tools/discover.d.ts +6 -14
- package/dist/tools/discover.d.ts.map +1 -1
- package/dist/tools/flow-view-contracts.d.ts +1023 -0
- package/dist/tools/flow-view-contracts.d.ts.map +1 -0
- package/dist/tools/flow-view-contracts.js +570 -0
- package/dist/tools/flow-view-contracts.js.map +1 -0
- package/dist/tools/flow-view-graph.d.ts +86 -0
- package/dist/tools/flow-view-graph.d.ts.map +1 -0
- package/dist/tools/flow-view-graph.js +993 -0
- package/dist/tools/flow-view-graph.js.map +1 -0
- package/dist/tools/flow-view-gzip.d.ts +52 -0
- package/dist/tools/flow-view-gzip.d.ts.map +1 -0
- package/dist/tools/flow-view-gzip.js +179 -0
- package/dist/tools/flow-view-gzip.js.map +1 -0
- package/dist/tools/flow-view-mermaid.d.ts +37 -0
- package/dist/tools/flow-view-mermaid.d.ts.map +1 -0
- package/dist/tools/flow-view-mermaid.js +337 -0
- package/dist/tools/flow-view-mermaid.js.map +1 -0
- package/dist/tools/flow-view-module.d.ts +61 -0
- package/dist/tools/flow-view-module.d.ts.map +1 -0
- package/dist/tools/flow-view-module.js +378 -0
- package/dist/tools/flow-view-module.js.map +1 -0
- package/dist/tools/flow-view-policy.d.ts +106 -0
- package/dist/tools/flow-view-policy.d.ts.map +1 -0
- package/dist/tools/flow-view-policy.js +461 -0
- package/dist/tools/flow-view-policy.js.map +1 -0
- package/dist/tools/flow-view-renderers.d.ts +68 -0
- package/dist/tools/flow-view-renderers.d.ts.map +1 -0
- package/dist/tools/flow-view-renderers.js +513 -0
- package/dist/tools/flow-view-renderers.js.map +1 -0
- package/dist/tools/flow-view-table.d.ts +115 -0
- package/dist/tools/flow-view-table.d.ts.map +1 -0
- package/dist/tools/flow-view-table.js +1002 -0
- package/dist/tools/flow-view-table.js.map +1 -0
- package/dist/tools/get-module.d.ts +36 -42
- package/dist/tools/get-module.d.ts.map +1 -1
- package/dist/tools/health.d.ts +9 -6
- package/dist/tools/health.d.ts.map +1 -1
- package/dist/tools/incident-journal-module.d.ts +8 -7
- package/dist/tools/incident-journal-module.d.ts.map +1 -1
- package/dist/tools/index.d.ts +4 -4
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +43 -6
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/markdown.d.ts +27 -0
- package/dist/tools/markdown.d.ts.map +1 -1
- package/dist/tools/markdown.js +104 -1
- package/dist/tools/markdown.js.map +1 -1
- package/dist/tools/nl.d.ts +1 -11
- package/dist/tools/nl.d.ts.map +1 -1
- package/dist/tools/profile.d.ts +1 -1
- package/dist/tools/profile.d.ts.map +1 -1
- package/dist/tools/profile.js +19 -1
- package/dist/tools/profile.js.map +1 -1
- package/dist/tools/query-module.d.ts +59 -71
- package/dist/tools/query-module.d.ts.map +1 -1
- package/dist/tools/query-module.js +2 -2
- package/dist/tools/query-module.js.map +1 -1
- package/dist/tools/record-write-shared.d.ts.map +1 -1
- package/dist/tools/record-write-shared.js +19 -2
- package/dist/tools/record-write-shared.js.map +1 -1
- package/dist/tools/relationships.d.ts +6 -22
- package/dist/tools/relationships.d.ts.map +1 -1
- package/dist/tools/result-envelope.d.ts +2255 -1357
- package/dist/tools/result-envelope.d.ts.map +1 -1
- package/dist/tools/result-envelope.js +24 -2
- package/dist/tools/result-envelope.js.map +1 -1
- package/dist/tools/schema-module.d.ts +36 -21
- package/dist/tools/schema-module.d.ts.map +1 -1
- package/dist/tools/schema-module.js +106 -65
- package/dist/tools/schema-module.js.map +1 -1
- package/dist/tools/script.d.ts +1 -11
- package/dist/tools/script.d.ts.map +1 -1
- package/dist/tools/syslog.d.ts +11 -18
- package/dist/tools/syslog.d.ts.map +1 -1
- package/dist/tools/syslog.js +2 -3
- package/dist/tools/syslog.js.map +1 -1
- package/dist/tools/table-hierarchy.d.ts +35 -0
- package/dist/tools/table-hierarchy.d.ts.map +1 -0
- package/dist/tools/table-hierarchy.js +74 -0
- package/dist/tools/table-hierarchy.js.map +1 -0
- package/dist/tools/tool-module.d.ts +40 -15
- package/dist/tools/tool-module.d.ts.map +1 -1
- package/dist/tools/tool-module.js +755 -205
- package/dist/tools/tool-module.js.map +1 -1
- package/dist/tools/update-module.d.ts +11 -17
- package/dist/tools/update-module.d.ts.map +1 -1
- package/dist/tools/update-module.js +10 -12
- package/dist/tools/update-module.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/dist/write-value-policy.d.ts +20 -12
- package/dist/write-value-policy.d.ts.map +1 -1
- package/dist/write-value-policy.js +179 -67
- package/dist/write-value-policy.js.map +1 -1
- package/docs/ADDING-TOOLS.md +22 -13
- package/docs/CLIENT-SETUP.md +110 -52
- package/docs/CROSS-CLIENT-RELEASE-MATRIX.md +2 -2
- package/docs/FLOW-VIEW.md +214 -0
- package/docs/PRODUCTION-SECURITY.md +154 -25
- package/docs/RELEASE-VALIDATION.md +2 -2
- package/docs/TESTING-OAUTH.md +1 -1
- package/docs/V2-MIGRATION.md +404 -30
- package/package.json +21 -6
- package/scripts/release-validate.mjs +56 -0
- package/server.json +22 -0
- package/tools/inspector/package-lock.json +163 -201
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `sn_flow_view`: read-only view of one Flow Designer flow, optionally with
|
|
4
|
+
* the subflows it calls, as a bounded graph plus a Mermaid diagram and an
|
|
5
|
+
* outline.
|
|
6
|
+
*
|
|
7
|
+
* Every read goes through the Table API (`flow-view-table.ts`). Flow
|
|
8
|
+
* Designer's internal ProcessFlow API is never called: its flow GET writes a
|
|
9
|
+
* Workflow Studio history row, which a read-only tool must not do.
|
|
10
|
+
*
|
|
11
|
+
* Upstream budget: the client caps the JSON one response scope may read
|
|
12
|
+
* (1 MiB). Each load therefore runs in its own scope, bound to the call's
|
|
13
|
+
* cancellation signal, and at most `MAX_UPSTREAM_SCOPES` scopes are opened
|
|
14
|
+
* per call:
|
|
15
|
+
* - root flow: one scope to resolve the record (with its pill labels when
|
|
16
|
+
* selected by sys_id), one to load it;
|
|
17
|
+
* - each subflow: one scope that reads its record and pill labels, then
|
|
18
|
+
* loads it. The subflows of one level load together.
|
|
19
|
+
* - a load that overflows its scope with input values is retried once
|
|
20
|
+
* without them, in a new scope, while scopes remain.
|
|
21
|
+
* Without retries that is at most 2 + 8 subflows = 10 scopes. Inside a
|
|
22
|
+
* load, independent reads are issued together; the client bounds how many
|
|
23
|
+
* run at once. Each raw response is projected and then dropped.
|
|
24
|
+
*
|
|
25
|
+
* @module tools/flow-view-module
|
|
26
|
+
*/
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.flowViewToolModule = exports.SUBFLOW_LOAD_CONCURRENCY = exports.FlowViewScopeBudget = void 0;
|
|
29
|
+
exports.expandFlowViewSubflows = expandFlowViewSubflows;
|
|
30
|
+
const zod_1 = require("zod");
|
|
31
|
+
const client_js_1 = require("../client.js");
|
|
32
|
+
const metadata_cache_js_1 = require("../metadata-cache.js");
|
|
33
|
+
const tool_error_js_1 = require("../tool-error.js");
|
|
34
|
+
const tool_table_access_js_1 = require("../tool-table-access.js");
|
|
35
|
+
const utils_js_1 = require("../utils.js");
|
|
36
|
+
const flow_view_contracts_js_1 = require("./flow-view-contracts.js");
|
|
37
|
+
const flow_view_graph_js_1 = require("./flow-view-graph.js");
|
|
38
|
+
const flow_view_policy_js_1 = require("./flow-view-policy.js");
|
|
39
|
+
const flow_view_renderers_js_1 = require("./flow-view-renderers.js");
|
|
40
|
+
const flow_view_table_js_1 = require("./flow-view-table.js");
|
|
41
|
+
const result_envelope_js_1 = require("./result-envelope.js");
|
|
42
|
+
const tool_module_js_1 = require("./tool-module.js");
|
|
43
|
+
const L = flow_view_contracts_js_1.FLOW_VIEW_LIMITS;
|
|
44
|
+
const SYS_ID = /^[0-9a-f]{32}$/u;
|
|
45
|
+
const schema = (0, tool_module_js_1.withRequiredProfile)(zod_1.z
|
|
46
|
+
.object({
|
|
47
|
+
flow: zod_1.z
|
|
48
|
+
.string()
|
|
49
|
+
.trim()
|
|
50
|
+
.min(1)
|
|
51
|
+
.max(flow_view_contracts_js_1.FLOW_VIEW_MAX_FLOW_SELECTOR_CHARS)
|
|
52
|
+
.describe("Flow or subflow sys_id (32 hex characters), or its exact, case-sensitive name"),
|
|
53
|
+
depth: zod_1.z
|
|
54
|
+
.number()
|
|
55
|
+
.int()
|
|
56
|
+
.min(1)
|
|
57
|
+
.max(L.MAX_DEPTH)
|
|
58
|
+
.optional()
|
|
59
|
+
.describe("1 = this flow only (default); 2-3 also expand the subflows it calls"),
|
|
60
|
+
include_inputs: zod_1.z
|
|
61
|
+
.boolean()
|
|
62
|
+
.optional()
|
|
63
|
+
.describe("Show step input values (default true); false reads no value fields at all"),
|
|
64
|
+
format: zod_1.z
|
|
65
|
+
.enum(flow_view_contracts_js_1.FLOW_VIEW_FORMATS)
|
|
66
|
+
.optional()
|
|
67
|
+
.describe("Text format: both (default), mermaid or outline; structuredContent is always the full graph"),
|
|
68
|
+
max_nodes: zod_1.z
|
|
69
|
+
.number()
|
|
70
|
+
.int()
|
|
71
|
+
.min(L.MIN_MAX_NODES)
|
|
72
|
+
.max(L.MAX_MAX_NODES)
|
|
73
|
+
.optional()
|
|
74
|
+
.describe(`Most graph nodes returned, including the trigger (default ${L.DEFAULT_MAX_NODES})`),
|
|
75
|
+
max_response_bytes: zod_1.z
|
|
76
|
+
.number()
|
|
77
|
+
.int()
|
|
78
|
+
.min(L.MIN_MAX_RESPONSE_BYTES)
|
|
79
|
+
.max(L.MAX_MAX_RESPONSE_BYTES)
|
|
80
|
+
.optional()
|
|
81
|
+
.describe(`Byte budget for the whole result (default ${L.DEFAULT_MAX_RESPONSE_BYTES})`),
|
|
82
|
+
})
|
|
83
|
+
.strict());
|
|
84
|
+
/** Counts the 1 MiB response scopes one call opens. */
|
|
85
|
+
class FlowViewScopeBudget {
|
|
86
|
+
max;
|
|
87
|
+
used = 0;
|
|
88
|
+
constructor(max = L.MAX_UPSTREAM_SCOPES) {
|
|
89
|
+
this.max = max;
|
|
90
|
+
}
|
|
91
|
+
/** Claim one scope; false when the per-call allowance is spent. */
|
|
92
|
+
take() {
|
|
93
|
+
if (this.used >= this.max)
|
|
94
|
+
return false;
|
|
95
|
+
this.used += 1;
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
get opened() {
|
|
99
|
+
return this.used;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.FlowViewScopeBudget = FlowViewScopeBudget;
|
|
103
|
+
/**
|
|
104
|
+
* Subflows of one level loaded at the same time. The client sends at most 4
|
|
105
|
+
* requests per instance and starts each request's timeout before it waits
|
|
106
|
+
* for a slot, so a deep queue can time a request out unsent; two loads keep
|
|
107
|
+
* the queue to about two loads' waves (measured in flow-f-dev.md).
|
|
108
|
+
*/
|
|
109
|
+
exports.SUBFLOW_LOAD_CONCURRENCY = 2;
|
|
110
|
+
/**
|
|
111
|
+
* Run `operation` in a fresh response-byte scope bound to `parent` (the
|
|
112
|
+
* call's signal, or a level's), as `sn_batch` does per chunk. The scope gets
|
|
113
|
+
* its own abort: when the operation fails, reads it launched alongside the
|
|
114
|
+
* failing one are cancelled instead of still reaching the instance. Without
|
|
115
|
+
* a signal (a direct handler call) it runs in the caller's scope.
|
|
116
|
+
*/
|
|
117
|
+
async function inOwnResponseBudget(parent, operation) {
|
|
118
|
+
if (!(parent instanceof AbortSignal))
|
|
119
|
+
return operation();
|
|
120
|
+
const controller = new AbortController();
|
|
121
|
+
try {
|
|
122
|
+
return await (0, client_js_1.runWithServiceNowRequestSignal)(AbortSignal.any([parent, controller.signal]), operation);
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
controller.abort();
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/** Map with at most `limit` calls in flight; results keep input order; stops launching on the first failure. */
|
|
130
|
+
async function mapWithConcurrency(items, limit, run) {
|
|
131
|
+
const results = new Array(items.length);
|
|
132
|
+
let next = 0;
|
|
133
|
+
let failed = false;
|
|
134
|
+
const worker = async () => {
|
|
135
|
+
while (!failed && next < items.length) {
|
|
136
|
+
const index = next;
|
|
137
|
+
next += 1;
|
|
138
|
+
try {
|
|
139
|
+
results[index] = await run(items[index]);
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
failed = true;
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
|
|
148
|
+
return results;
|
|
149
|
+
}
|
|
150
|
+
function selectorFor(flow) {
|
|
151
|
+
return SYS_ID.test(flow) ? { sys_id: flow } : { name: flow };
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* A load that did not fit its response scope: the client's byte-limit error
|
|
155
|
+
* for one response or a scope's cumulative JSON. Any other RangeError (a
|
|
156
|
+
* bug, a stack overflow) is not this, and fails the call.
|
|
157
|
+
*/
|
|
158
|
+
function isTooLarge(error, signal) {
|
|
159
|
+
return (0, client_js_1.isServiceNowResponseTooLarge)(error) && signal?.aborted !== true;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Why a subflow could not be used. Cancellation (of the call, or of the
|
|
163
|
+
* level after a sibling failed the call) and broken credentials propagate.
|
|
164
|
+
*/
|
|
165
|
+
function unavailableFrom(error, signal) {
|
|
166
|
+
if (signal?.aborted || (0, client_js_1.isServiceNowRequestCancellation)(error))
|
|
167
|
+
throw error;
|
|
168
|
+
if ((0, client_js_1.isServiceNowResponseTooLarge)(error))
|
|
169
|
+
return { unavailable: "too_large" };
|
|
170
|
+
const category = (0, tool_error_js_1.trustedToolErrorDescriptor)(error)?.category;
|
|
171
|
+
// Broken credentials fail the whole call, as they would for the root flow.
|
|
172
|
+
if (category === "authentication")
|
|
173
|
+
throw error;
|
|
174
|
+
if (category === "timeout")
|
|
175
|
+
return { unavailable: "timeout" };
|
|
176
|
+
return { unavailable: category === "authorization" ? "denied" : "not_found" };
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Read one subflow's record (with its pill labels) and load it, in one
|
|
180
|
+
* response scope under `parent`. Too large, timed out, missing and denied
|
|
181
|
+
* subflows come back as markers; cancellation and broken credentials
|
|
182
|
+
* propagate.
|
|
183
|
+
*/
|
|
184
|
+
function loadSubflow(ops, plan, id, includeInputs, parent) {
|
|
185
|
+
return inOwnResponseBudget(parent, async () => {
|
|
186
|
+
const resolution = await (0, flow_view_table_js_1.resolveFlowRecord)(ops, plan, { sys_id: id }, {
|
|
187
|
+
withLabelCache: { include_inputs: includeInputs },
|
|
188
|
+
});
|
|
189
|
+
if (resolution.status !== "found")
|
|
190
|
+
return { unavailable: "not_found" };
|
|
191
|
+
return (0, flow_view_table_js_1.loadFlowFromTables)(ops, resolution.header, plan, {
|
|
192
|
+
include_inputs: includeInputs,
|
|
193
|
+
...(resolution.label_cache === undefined ? {} : { label_cache: resolution.label_cache }),
|
|
194
|
+
});
|
|
195
|
+
}).catch((error) => unavailableFrom(error, parent));
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Load the subflows the root calls, breadth first, one level per depth step;
|
|
199
|
+
* at most SUBFLOW_LOAD_CONCURRENCY subflows of a level load at once, each in
|
|
200
|
+
* its own scope. Never loads a flow twice (that also stops cycles); the
|
|
201
|
+
* graph builder marks cycles, depth and limits at each call site from what
|
|
202
|
+
* is in the map. A failure that fails the call cancels the level's other
|
|
203
|
+
* loads.
|
|
204
|
+
*/
|
|
205
|
+
async function expandFlowViewSubflows(ops, plan, options, root, scopes, signal) {
|
|
206
|
+
const subflows = new Map();
|
|
207
|
+
const limits = new Set();
|
|
208
|
+
const warnings = new Set();
|
|
209
|
+
const visited = new Set([root.header.sys_id]);
|
|
210
|
+
let expansions = 0;
|
|
211
|
+
let frontier = (0, flow_view_graph_js_1.subflowCallTargets)(root);
|
|
212
|
+
for (let level = 1; level < options.depth && frontier.length > 0; level += 1) {
|
|
213
|
+
const targets = [];
|
|
214
|
+
for (const id of frontier) {
|
|
215
|
+
if (visited.has(id) || targets.includes(id))
|
|
216
|
+
continue;
|
|
217
|
+
if (expansions + targets.length >= L.MAX_SUBFLOW_EXPANSIONS) {
|
|
218
|
+
limits.add("max_subflow_expansions");
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
if (!scopes.take()) {
|
|
222
|
+
limits.add("upstream_scopes");
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
targets.push(id);
|
|
226
|
+
}
|
|
227
|
+
if (targets.length === 0)
|
|
228
|
+
break;
|
|
229
|
+
const levelAbort = new AbortController();
|
|
230
|
+
const levelSignal = signal instanceof AbortSignal ? AbortSignal.any([signal, levelAbort.signal]) : undefined;
|
|
231
|
+
let loaded;
|
|
232
|
+
try {
|
|
233
|
+
loaded = await mapWithConcurrency(targets, exports.SUBFLOW_LOAD_CONCURRENCY, (id) => loadSubflow(ops, plan, id, options.include_inputs, levelSignal));
|
|
234
|
+
}
|
|
235
|
+
catch (error) {
|
|
236
|
+
levelAbort.abort();
|
|
237
|
+
throw error;
|
|
238
|
+
}
|
|
239
|
+
// Retries run one at a time, in call order, so which subflow gets a
|
|
240
|
+
// remaining scope does not depend on timing.
|
|
241
|
+
const next = [];
|
|
242
|
+
for (const [index, id] of targets.entries()) {
|
|
243
|
+
visited.add(id);
|
|
244
|
+
let result = loaded[index];
|
|
245
|
+
if ("unavailable" in result && result.unavailable === "too_large" && options.include_inputs) {
|
|
246
|
+
if (scopes.take()) {
|
|
247
|
+
result = await loadSubflow(ops, plan, id, false, levelSignal);
|
|
248
|
+
if (!("unavailable" in result))
|
|
249
|
+
warnings.add("inputs_omitted_too_large");
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
limits.add("upstream_scopes");
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
subflows.set(id, result);
|
|
256
|
+
if ("unavailable" in result)
|
|
257
|
+
continue;
|
|
258
|
+
expansions += 1;
|
|
259
|
+
next.push(...(0, flow_view_graph_js_1.subflowCallTargets)(result));
|
|
260
|
+
}
|
|
261
|
+
frontier = next;
|
|
262
|
+
}
|
|
263
|
+
return { subflows, limits, warnings };
|
|
264
|
+
}
|
|
265
|
+
/** A flow known only by its record: what is shown when even its structure is too large. */
|
|
266
|
+
function recordOnly(header) {
|
|
267
|
+
return {
|
|
268
|
+
source: "table",
|
|
269
|
+
header,
|
|
270
|
+
trigger: null,
|
|
271
|
+
steps: [],
|
|
272
|
+
label_cache: [],
|
|
273
|
+
variables: [],
|
|
274
|
+
warnings: [],
|
|
275
|
+
limits_hit: [],
|
|
276
|
+
items_dropped: 0,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
async function handleFlowView(args, services) {
|
|
280
|
+
const options = (0, flow_view_contracts_js_1.canonicalFlowViewArgs)(args);
|
|
281
|
+
const plan = (0, flow_view_policy_js_1.flowFieldPlanFromArgs)(args);
|
|
282
|
+
const ops = (0, metadata_cache_js_1.uncachedOperations)(services.serviceNow);
|
|
283
|
+
const signal = services.context?.signal;
|
|
284
|
+
const scopes = new FlowViewScopeBudget();
|
|
285
|
+
const warnings = new Set();
|
|
286
|
+
// The first two scopes always fit: MAX_UPSTREAM_SCOPES is well above 3.
|
|
287
|
+
scopes.take();
|
|
288
|
+
const resolveRoot = (withLabels) => inOwnResponseBudget(signal, () => (0, flow_view_table_js_1.resolveFlowRecord)(ops, plan, selectorFor(options.flow), withLabels ? { withLabelCache: { include_inputs: options.include_inputs } } : {}));
|
|
289
|
+
let resolution;
|
|
290
|
+
try {
|
|
291
|
+
resolution = await resolveRoot(true);
|
|
292
|
+
}
|
|
293
|
+
catch (error) {
|
|
294
|
+
// A label_cache too large for the record read: read the record without
|
|
295
|
+
// it, in a new scope; the load then reads (or drops) the labels itself.
|
|
296
|
+
if (!isTooLarge(error, signal) || !scopes.take())
|
|
297
|
+
throw error;
|
|
298
|
+
resolution = await resolveRoot(false);
|
|
299
|
+
}
|
|
300
|
+
if (resolution.status === "not_found") {
|
|
301
|
+
throw (0, tool_error_js_1.createToolError)("not_found", "retry_after_correction");
|
|
302
|
+
}
|
|
303
|
+
if (resolution.status === "ambiguous") {
|
|
304
|
+
// The dispatcher accepts only fixed-category errors from module
|
|
305
|
+
// handlers, so the candidates cannot be listed; the description tells
|
|
306
|
+
// the caller to pass a sys_id instead.
|
|
307
|
+
throw (0, tool_error_js_1.createToolError)("conflict", "retry_after_correction");
|
|
308
|
+
}
|
|
309
|
+
const loadRoot = (includeInputs) => inOwnResponseBudget(signal, () => (0, flow_view_table_js_1.loadFlowFromTables)(ops, resolution.header, plan, {
|
|
310
|
+
include_inputs: includeInputs,
|
|
311
|
+
...(includeInputs && resolution.label_cache !== undefined ? { label_cache: resolution.label_cache } : {}),
|
|
312
|
+
}));
|
|
313
|
+
scopes.take();
|
|
314
|
+
let root;
|
|
315
|
+
try {
|
|
316
|
+
root = await loadRoot(options.include_inputs);
|
|
317
|
+
}
|
|
318
|
+
catch (error) {
|
|
319
|
+
if (!isTooLarge(error, signal))
|
|
320
|
+
throw error;
|
|
321
|
+
}
|
|
322
|
+
if (root === undefined && options.include_inputs && scopes.take()) {
|
|
323
|
+
try {
|
|
324
|
+
root = await loadRoot(false);
|
|
325
|
+
warnings.add("inputs_omitted_too_large");
|
|
326
|
+
}
|
|
327
|
+
catch (error) {
|
|
328
|
+
if (!isTooLarge(error, signal))
|
|
329
|
+
throw error;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
if (root === undefined)
|
|
333
|
+
warnings.add("flow_too_large");
|
|
334
|
+
const expansion = root !== undefined && options.depth > 1
|
|
335
|
+
? await expandFlowViewSubflows(ops, plan, options, root, scopes, signal)
|
|
336
|
+
: undefined;
|
|
337
|
+
const graph = (0, flow_view_graph_js_1.buildFlowGraph)({
|
|
338
|
+
root: root ?? recordOnly(resolution.header),
|
|
339
|
+
subflows: expansion?.subflows ?? new Map(),
|
|
340
|
+
options,
|
|
341
|
+
limits_hit: [...(expansion?.limits ?? [])],
|
|
342
|
+
warnings: [...warnings, ...(expansion?.warnings ?? [])],
|
|
343
|
+
});
|
|
344
|
+
services.logger?.write({
|
|
345
|
+
level: "debug",
|
|
346
|
+
event: "flow_view.graph_built",
|
|
347
|
+
correlationId: services.context?.correlationId ?? "",
|
|
348
|
+
tool: "sn_flow_view",
|
|
349
|
+
});
|
|
350
|
+
return (0, result_envelope_js_1.envelopeCompatibilityResult)("sn_flow_view", args, (0, utils_js_1.ok)(graph));
|
|
351
|
+
}
|
|
352
|
+
(0, flow_view_renderers_js_1.registerFlowViewRenderer)();
|
|
353
|
+
exports.flowViewToolModule = (0, tool_module_js_1.defineServiceNowToolModule)({
|
|
354
|
+
runtime: "servicenow",
|
|
355
|
+
definition: {
|
|
356
|
+
name: "sn_flow_view",
|
|
357
|
+
description: "View a Flow Designer flow or subflow (by sys_id or exact name) as a graph: trigger, steps, branches, loops and called subflows (depth 2-3), with input values under field policy. Returns a Mermaid diagram and an outline as text and the full graph as structuredContent. A name that matches more than one flow fails with a conflict; pass the sys_id instead. Reads only through the Table API; never calls Flow Designer's internal API, so it changes nothing on the instance. Flow text is untrusted instance data.",
|
|
358
|
+
annotations: {
|
|
359
|
+
title: "View Flow Designer flow",
|
|
360
|
+
readOnlyHint: true,
|
|
361
|
+
destructiveHint: false,
|
|
362
|
+
idempotentHint: true,
|
|
363
|
+
openWorldHint: true,
|
|
364
|
+
},
|
|
365
|
+
},
|
|
366
|
+
inputSchema: schema,
|
|
367
|
+
outputSchema: result_envelope_js_1.productionToolOutputSchemas.sn_flow_view,
|
|
368
|
+
requirements: {
|
|
369
|
+
permissions: ["read"],
|
|
370
|
+
tables: { kind: "static", names: flow_view_contracts_js_1.FLOW_VIEW_TABLES },
|
|
371
|
+
apis: ["table"],
|
|
372
|
+
fieldPolicies: ["read"],
|
|
373
|
+
capabilities: ["flow:view"],
|
|
374
|
+
},
|
|
375
|
+
resolveAccess: (candidate, policy) => (0, tool_table_access_js_1.resolveToolTableAccess)("sn_flow_view", schema.parse(candidate), policy.encodedQueryAccess),
|
|
376
|
+
handler: handleFlowView,
|
|
377
|
+
});
|
|
378
|
+
//# sourceMappingURL=flow-view-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow-view-module.js","sourceRoot":"","sources":["../../src/tools/flow-view-module.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;;AA8NH,wDAkEC;AA9RD,6BAAwB;AACxB,4CAIsB;AACtB,4DAA0D;AAC1D,oDAA+E;AAC/E,kEAAiE;AACjE,0CAAiC;AACjC,qEAUkC;AAClC,6DAI8B;AAC9B,+DAAkF;AAClF,qEAAoE;AACpE,6DAI8B;AAC9B,6DAAgG;AAChG,qDAI0B;AAE1B,MAAM,CAAC,GAAG,yCAAgB,CAAC;AAC3B,MAAM,MAAM,GAAG,iBAAiB,CAAC;AAEjC,MAAM,MAAM,GAAG,IAAA,oCAAmB,EAChC,OAAC;KACE,MAAM,CAAC;IACN,IAAI,EAAE,OAAC;SACJ,MAAM,EAAE;SACR,IAAI,EAAE;SACN,GAAG,CAAC,CAAC,CAAC;SACN,GAAG,CAAC,0DAAiC,CAAC;SACtC,QAAQ,CAAC,+EAA+E,CAAC;IAC5F,KAAK,EAAE,OAAC;SACL,MAAM,EAAE;SACR,GAAG,EAAE;SACL,GAAG,CAAC,CAAC,CAAC;SACN,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;SAChB,QAAQ,EAAE;SACV,QAAQ,CAAC,qEAAqE,CAAC;IAClF,cAAc,EAAE,OAAC;SACd,OAAO,EAAE;SACT,QAAQ,EAAE;SACV,QAAQ,CAAC,2EAA2E,CAAC;IACxF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CAAC,YAAY;IACtD,YAAY,EAAE;QACZ,WAAW,EAAE,CAAC,MAAM,CAAC;QACrB,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,yCAAgB,EAAE;QACnD,IAAI,EAAE,CAAC,OAAO,CAAC;QACf,aAAa,EAAE,CAAC,MAAM,CAAC;QACvB,YAAY,EAAE,CAAC,WAAW,CAAC;KAC5B;IACD,aAAa,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,CACnC,IAAA,6CAAsB,EAAC,cAAc,EAAE,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,kBAAkB,CAAC;IAC5F,OAAO,EAAE,cAAc;CACxB,CAAC,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Field policy for `sn_flow_view`.
|
|
3
|
+
*
|
|
4
|
+
* The Table API loader reads a fixed table closure. Preflight
|
|
5
|
+
* (`flowViewFieldSelection`, called from the `sn_flow_view` access resolver)
|
|
6
|
+
* fixes the readable set per table; the handler recovers it as a
|
|
7
|
+
* FlowFieldPlan. Every graph element is then shown only when every
|
|
8
|
+
* `(table, field)` it comes from is in that set, across V1 and V2 storage, so
|
|
9
|
+
* the same profile shows the same data whichever storage a flow uses.
|
|
10
|
+
*
|
|
11
|
+
* Inputs rule: when `include_inputs` is false (`inputsIncluded(plan)` is
|
|
12
|
+
* false), loaders omit inputs entirely; they never call `policyInput`.
|
|
13
|
+
* `policyInput` still answers `not_requested` as a fail-safe.
|
|
14
|
+
*
|
|
15
|
+
* @module tools/flow-view-policy
|
|
16
|
+
*/
|
|
17
|
+
import { type FlowElementKey, type FlowInputValue, type FlowTableName, type FlowText, type FlowValueElementKey } from "./flow-view-contracts.js";
|
|
18
|
+
export interface FlowFieldPlan {
|
|
19
|
+
readonly readable: ReadonlyMap<FlowTableName, ReadonlySet<string>>;
|
|
20
|
+
/**
|
|
21
|
+
* Whether inputs were requested. Absent on a hand-built plan, where it is
|
|
22
|
+
* derived: a plan that holds no value field did not request them. Read it
|
|
23
|
+
* through `inputsIncluded`. The readable set alone decides what is shown.
|
|
24
|
+
*/
|
|
25
|
+
readonly include_inputs?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Input types whose values are always redacted. `password2` is the
|
|
29
|
+
* confirmed spelling (Brazil capture: `internal_type` and `parameter.type`);
|
|
30
|
+
* the others are kept as a precaution.
|
|
31
|
+
*/
|
|
32
|
+
export declare const FLOW_SENSITIVE_INPUT_TYPES: ReadonlySet<string>;
|
|
33
|
+
/**
|
|
34
|
+
* The exact field list to prepare for one closure table.
|
|
35
|
+
*
|
|
36
|
+
* - Every required (structural) field must be readable; the first one that is
|
|
37
|
+
* not throws an actionable FieldPolicyError naming the table and field.
|
|
38
|
+
* - Optional fields are intersected with the readable set, never a denial.
|
|
39
|
+
* - Value fields are added only with `includeInputs`, then intersected.
|
|
40
|
+
*/
|
|
41
|
+
export declare function flowViewFieldSelection(table: FlowTableName, includeInputs: boolean): readonly string[];
|
|
42
|
+
/**
|
|
43
|
+
* Recover the plan prepared at preflight. Throws when any closure table has
|
|
44
|
+
* no issued marker, or a marker lacks a required field.
|
|
45
|
+
*/
|
|
46
|
+
export declare function flowFieldPlanFromArgs(args: Record<string, unknown>): FlowFieldPlan;
|
|
47
|
+
/** True when every source of the element is in the prepared readable set. */
|
|
48
|
+
export declare function canShow(plan: FlowFieldPlan, element: FlowElementKey): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* The `sysparm_fields` value for one closure table, in FLOW_TABLE_FIELDS
|
|
51
|
+
* order. Never empty: an empty sysparm_fields means "every field".
|
|
52
|
+
*/
|
|
53
|
+
export declare function sysparmFieldsFor(plan: FlowFieldPlan, table: FlowTableName): string;
|
|
54
|
+
/**
|
|
55
|
+
* Project one text element: field policy first, then control stripping and
|
|
56
|
+
* truncation (UTF-16 units; `original_length` set when cut). Empty text is
|
|
57
|
+
* `null`. Text taken from inputs (a value element, such as the trigger's
|
|
58
|
+
* table or condition) is `not_requested` when inputs were not requested.
|
|
59
|
+
*/
|
|
60
|
+
export declare function policyText(plan: FlowFieldPlan, element: FlowElementKey, raw: unknown, maxChars: number): FlowText;
|
|
61
|
+
/**
|
|
62
|
+
* Convert a name or label to a policy identifier, the form
|
|
63
|
+
* `isSensitiveFieldName` understands: camelCase and letter-digit boundaries
|
|
64
|
+
* split, ASCII-folded, lowercased, every other character `_`, runs collapsed,
|
|
65
|
+
* edge underscores trimmed, a leading digit prefixed with `x`.
|
|
66
|
+
*
|
|
67
|
+
* Unlike a single 80-character cut, the result keeps up to the first 512
|
|
68
|
+
* source characters; `isSensitivePolicyName` checks every 80-character
|
|
69
|
+
* window, so a term past position 80 is still found.
|
|
70
|
+
*/
|
|
71
|
+
export declare function policyIdentifier(raw: unknown): string;
|
|
72
|
+
/**
|
|
73
|
+
* True when the identifier form of `raw` is sensitive. An identifier that is
|
|
74
|
+
* empty (no ASCII letter or digit) is reported as `emptyResult`.
|
|
75
|
+
*/
|
|
76
|
+
export declare function isSensitivePolicyName(raw: unknown, emptyResult: boolean): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Whether inputs were requested. When false, loaders omit every input (no
|
|
79
|
+
* `inputs` on steps, nodes or the trigger) instead of listing redacted ones.
|
|
80
|
+
*/
|
|
81
|
+
export declare function inputsIncluded(plan: FlowFieldPlan): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Project one input. The name, label and type are always kept (bounded,
|
|
84
|
+
* controls stripped). The value is redacted, in this order, when inputs were
|
|
85
|
+
* not requested, the element is not showable, the name or label is
|
|
86
|
+
* sensitive, or the type is sensitive. Otherwise the display value is
|
|
87
|
+
* preferred, nested JSON is scrubbed, and the value is cut to
|
|
88
|
+
* MAX_INPUT_VALUE_CHARS with `original_length`.
|
|
89
|
+
*/
|
|
90
|
+
export declare function policyInput(plan: FlowFieldPlan, element: FlowValueElementKey, raw: {
|
|
91
|
+
name: unknown;
|
|
92
|
+
label?: unknown;
|
|
93
|
+
type?: unknown;
|
|
94
|
+
value?: unknown;
|
|
95
|
+
displayValue?: unknown;
|
|
96
|
+
script?: boolean;
|
|
97
|
+
}): FlowInputValue;
|
|
98
|
+
/**
|
|
99
|
+
* Copy a decoded JSON value, dropping sensitive-named keys and the value of
|
|
100
|
+
* any `{name: "<sensitive>", value: …}` pair. Bounded by
|
|
101
|
+
* MAX_DECODED_JSON_DEPTH and MAX_DECODED_JSON_NODES: deeper values become
|
|
102
|
+
* `null`, and entries past the node budget are omitted. Proxies, accessors,
|
|
103
|
+
* non-plain objects and non-JSON values are dropped.
|
|
104
|
+
*/
|
|
105
|
+
export declare function scrubNestedKeys(value: unknown): unknown;
|
|
106
|
+
//# sourceMappingURL=flow-view-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow-view-policy.d.ts","sourceRoot":"","sources":["../../src/tools/flow-view-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAWH,OAAO,EAML,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,QAAQ,EACb,KAAK,mBAAmB,EAEzB,MAAM,0BAA0B,CAAC;AAGlC,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,aAAa,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IACnE;;;;OAIG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC;CACnC;AAED;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,EAAE,WAAW,CAAC,MAAM,CAEnC,CAAC;AAwBzB;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,aAAa,EACpB,aAAa,EAAE,OAAO,GACrB,SAAS,MAAM,EAAE,CAYnB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAA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